akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	long long n, m, p, x, i, j, k, last, id;
	cin >> n >> m;
	vector<pair<pair<long long, long long>, long long>> v;
	for (i = 1; i <= m; i++) {
		cin >> p >> x;
		v.push_back({ { p, x }, i });
	}
	sort(v.begin(), v.end());
	string s1, s2, s3;
	last = -9999;
	id = 0;
	vector<string> ans(m + 1);
	for (i = 0; i < v.size(); i++) {
		s1 = to_string(v[i].first.first);
		if (v[i].first.first == last) id++;
		else {
			last = v[i].first.first;
			id = 1;
		}
		s2 = to_string(id);
		while (s1.length() < 6) s1 = "0" + s1;
		while (s2.length() < 6) s2 = "0" + s2;

		ans[v[i].second] = s1 + s2;
	}

	for (i = 1; i <= m; i++) cout << ans[i] << "\n";


	return 0;
}

Measured memory_bytes: 9712
#include <bits/stdc++.h>
using namespace std;

int main () {
    long long n, b, r;
    cin >> n >> b >> r;

    long long group=b+r;
    
    if (n%group<=b) {
        cout << n/group*b+n%group << endl;
    }
    else {
        cout << n/group*b+b << endl;
    }
}
        


Measured memory_bytes: 3608
/******************************************
* AUTHOR : ARPIT *
* NICK : arpitfalcon *
* INSTITUTION : BIT MESRA *
* Ab m game m hu. *
******************************************/

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007 -
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vin                    \
    ll n;                      \
    cin >> n;                  \
    vector<ll> x(n);           \
    for (ll i = 0; i < n; i++) \
    cin >> x[i]
#define vout                   \
    for (ll i = 0; i < n; i++) \
    cout << x[i] << " "
#define T     \
    ll t = 1; \
    cin >> t; \
    while (t--)
#define ain                    \
    ll n, k;                   \
    cin >> n >> k;             \
    ll a[n];                   \
    for (ll z = 0; z < n; z++) \
    cin >> a[z]
#define aout                   \
    for (ll i = 0; i < n; i++) \
    cout << a[i] << " "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl "\n"
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define max4(a, b, c, d) max(a, max3(b, c, d))
#define min4(a, b, c, d) min(a, min3(b, c, d))
#define blink                \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI = 3.141592653589793238463;

#define forn(i, n) for (ll(i) = 0; (i) < (n); ++(i))
#define for1(i, n) for (ll(i) = 1; (i) <= (n); ++(i))
#define forr(i, n) for (ll(i) = (n)-1; (i) >= 0; --(i))
#define forab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))

/*
__builtin_ffs(x)
  Number of set bits: __builtin_popcount(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
*/

int main()
{
    blink
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    // your code goes here
    long long int num, n;
    cin >> num;
    n = num;
    long long int sum = 0;

    while (num)
    {
        sum += num % 10;
        num /= 10;
    }
    if (n % sum == 0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'

int main() {
  fast_io;
  int a, p;
  cin >> a >> p;
  cout << (3 * a + p) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
using namespace std;


bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int main(){
	int n,value;
	cin>>n;	
	vector<pair<int, int> >v;
	for(int i=0 ;i<n; i++){
		cin>>value;
		v.push_back(make_pair(i+1,value));
	}
	sort(v.begin(), v.end(), sortbysec);
	for(int i=0; i<n; i++){
		cout<<v[i].first<<endl;
	}
}

Measured memory_bytes: 1780
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  solve
  def solve: Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0) return
    val values = readLine.trim.split(' ').map(_.toInt).filter(_ <= m).sorted
    println(
      values.indices.flatMap{i ⇒
        val idx = upperBound(values, m - values(i)) - 1
        if (i != idx && idx >= 0) Some(values(i) + values(idx))
        else None
      } match {
        case a if a.nonEmpty ⇒ a.max
        case _ ⇒ "NONE"
      }
    )
    solve
  }
  def upperBound[T](array: Array[T], target: T, leftLimit: Int, rightLimit: Int)(implicit  ord: Ordering[T]): Int = {
    var left = leftLimit
    var right = rightLimit
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  def upperBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    upperBound(array, target, 0, array.length)
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 56452
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <bitset>
#include <cmath>
#define ff first
#define ss second
#define MAXN 300005
#define INF 1000000001000000001LL
#define int long long

using namespace std;

const int mod = 998244353; //1000000007;
int n, i, x, R, G, B, RG, RB, GB, ans = 1;
string s;

main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base :: sync_with_stdio(false);
    cin.tie();
    cin >> n >> s; x = n;

    for(i = 0; i < 3 * n; i++){
        if(s[i] == 'G'){
            if(RB != 0)
                ans = ans * RB, RB--;
            else{
                if(R != 0 || B != 0){
                    ans = ans * (R + B);

                    if(R) R--, RG++;
                    else B--, GB++;
                }
                else
                    G++, ans *= x, x--;
            }
        }
        if(s[i] == 'R'){
            if(GB != 0)
                ans = ans * GB, GB--;
            else{
                if(G != 0 || B != 0){
                    ans = ans * (G + B);

                    if(G) G--, RG++;
                    else B--, RB++;
                }
                else
                    R++, ans *= x, x--;
            }
        }
        if(s[i] == 'B'){
            if(RG != 0)
                ans = ans * RG, RG--;
            else{
                if(G != 0 || R != 0){
                    ans = ans * (G + R);

                    if(G) G--, GB++;
                    else R--, RB++;
                }
                else
                    B++, ans *= x, x--;
            }
        }

        ans %= mod;
    }

    cout << ans;
    return 0;
}







Measured memory_bytes: 720
#include <stdio.h>
#include <stdlib.h>

int main(){
  int N,*A,i,j,k,v;
 
  scanf("%d",&N);
  A=(int*)malloc(sizeof(int)*N);
  
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  for(i=0;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k!=N-1) printf(" ");
    }
    printf("\n");
  }
  free(A);
  return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {

long double r;
cin>>r;
long double ans=r*M_PI*2;
//cout<<ans<<endl;
printf("%.100Lf\n",ans);
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3796
import java.util.*;

class Main {
	  static long mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long N = sc.nextLong();
      long[] a = new long[(int)N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
      }
      long ans = 0;
      long cnt = 0;
      
      
      for (int i =(int)N-1;i>0;i--) {
    	  if(a[i]<=a[i-1]) {
    		  cnt++;
    	  } else {
    		  if(cnt>ans) {
    			  ans = cnt;
    		  }
    		  cnt=0;
    	  }
      }
	  if(cnt>ans) {
		  ans = cnt;
	  }

      
	  System.out.println(ans);
  }
  
 
}

Measured memory_bytes: 59160
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int days = sc.nextInt();
		int basic = sc.nextInt();
		int basic_pay = sc.nextInt();
		int un_basic_pay = sc.nextInt();
		
		int payment = 0;
		int minus = 0;

		if (basic < days) {
			minus = (days - basic) *(un_basic_pay - basic_pay);
		}

		payment = days * basic_pay + minus;
		System.out.println(payment);
	}
}

Measured memory_bytes: 10192
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

S = input()

ans = 'NO'
if S == 'keyence': ans = 'YES'
else:
    for i in range(len(S)+1):
        for j in range(i+1, len(S)+1):
            if S[0:i] + S[j:len(S)] == 'keyence':
                ans = 'YES'
                break
print(ans)



Measured memory_bytes: 5296
n,k=map(int,input().split())
d=set(map(str,input().split()))
while True:
    flag=True
    a=list(str(n))
    for i in range(len(str(n))):
        if str(n)[i] in d:
            flag=False
            n+=1
            break
    if flag:
        break
print(n)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll sum[214514];
int main() {
	ll n,k;
	cin>>n>>k;
	ll mod=1e9+7;
	for(int i=1;i<=n+1;i++){
		sum[i]=i;
		sum[i]+=sum[i-1];
		//cout<<sum[i]<<endl;
	}
	ll ans=0;
	for(int i=k;i<=n+1;i++){
		if(i==n+1)ans++;
		else ans+=sum[n]-sum[n-i]-sum[i-1]+1;
		ans%=mod;
		//cout<<ans<<endl;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5196
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		System.out.println(Math.min(n * a, b));
		sc.close();
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int n, s;
int a[3010]; 
ll dp[3010][3010], ans;
const ll mod = 998244353;
int main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; i++)scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= s; j++)dp[i][j] = dp[i - 1][j];
		dp[i][a[i]] = (dp[i][a[i]] + i) % mod;
		for (int j = 0; j + a[i] <= s; j++)
			dp[i][j + a[i]] = (dp[i][j + a[i]] + dp[i - 1][j]) % mod;
		ans = (ans + dp[i][s]) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< int, ll > pil;
typedef pair< ll, int > pli;
typedef pair< ll, ll > pll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< double > vd;
typedef vector< vd > vvd;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< bool > vb;
typedef vector< vb > vvb;

template< class T1, class T2 >
bool upmin( T1 &x, T2 v ){
    if( x > v ){
        x = v;
        return true;
    }
    return false;
}

template< class T1, class T2 >
bool upmax( T1 &x, T2 v ){
    if( x < v ){
        x = v;
        return true;
    }
    return false;
}

void solve(){
    int N; cin >> N;
    vi A( N );
    for( int i = 0; i < N; ++i )
        cin >> A[ i ];
    vi _d = A;
    sort( _d.begin(), _d.end() );
    map< int, int > mp;
    for( int i = 0; i < _d.size(); ++i )
        mp[ _d[ i ] ] = i;
    int ans = 0;
    for( int i = 0; i < N; ++i ){
        ans += ( mp[ A[ i ] ] & 1 ) ^ ( i & 1 );
    }
    cout << ans / 2 << endl;
}

int main(){
    ios::sync_with_stdio( false );
    solve();
    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;

int main(){
    int n ,a , ans;
    bool c;
    
    while(1){
        cin >> n;
        ans=0; c=false;
        if(n==0) break;
        for(int i=0;i<n;i++){
            cin >> a;
            if(a>0) ans++;
            if(a>1) c=true;
        }
        if(ans!=0&&c==true) cout << ans+1 << endl;
        else cout << "NA" << endl; 
    }
    
    
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
bool s[205][205];
int v[205];
char c; int n, sol, ans=-1;
deque<int> x;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=1; i<=n; i++){
	for (int j=1; j<=n; j++){
		cin >> c;
		if (c=='1') s[i][j]=1;
	}
}
for (int start=1; start<=n; start++){
	for (int i=1; i<=n; i++) v[i]=0;
	x.push_back(start); sol=0; v[start]=1;
	while (!x.empty()){
		int ob=x.front(); x.pop_front();
		for (int i=1; i<=n; i++){
			if (s[i][ob]){
				if (!v[i]){
					v[i]=v[ob]+1;
					x.push_back(i);
				}
				else if (v[ob]==(v[i]+1) or v[ob]==(v[i]-1)) continue;
				else sol=-1;
			}
		}
		if (sol!=0) break;
	}
	if (sol==0) for (int i=1; i<=n; i++) sol=max(sol, v[i]);
	ans=max(sol, ans);
}
cout << ans;
return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
  int a,b,c,d,i;
  cin >> a;
  cin >> b;
  cin >> c;
  d = 0;
  for(i=a;i<=b;i++){
      if(c%i == 0){
          d = d+1;
      }
      else d = d;
  }
  cout << d << endl;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    int c[H + 1][W + 1];
    for (int i = 1; i <= H; i++)
    {

        string s;
        cin >> s;
        for (int j = 1; j <= W; j++)
        {
            c[i][j] = (s.at(j - 1) == '.') ? 0 : 1;
        }
    }
    int r = H + W;
    bool red[r];
    int bound = 1 << r;
    int sum = 0;
    for (int n = 0; n < bound; n++)
    {
        int m = n;
        for (int i = 0; i < r; i++)
        {
            red[i] = (((m >> 1 << 1) ^ m) == 1);
            m >>= 1;
        }
        int black = 0;
        for (int i = 1; i <= H; i++)
        {
            for (int j = 1; j <= W; j++)
            {
                if (red[i - 1] || red[j + H - 1])
                    continue;
                black += c[i][j];
            }
        }
        if (black == K)
            sum++;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

int main() {
	char S[27], end = 0;
	memset(S, 0, sizeof(S));
	scanf("%s", S)+1;

	int len = strlen(S);
	map<int, int> mci;
	for (int i = 0; i < len; i++) {
		mci[S[i] - 'a']++;
	}
	if (len < 26) {
		for (int i = 0; i < 26; i++) {
			if (mci[i] == 0) {
				S[len] = i + 'a';
				break;
			}
		}
	} else {
		for (int i = 25; i > 0 && end == 0; i--) {
			mci[S[i] - 'a']--;
			for (char j = S[i - 1] - 'a'; j < 26; j++) {
				if (mci[j] == 0) {
					S[i - 1] = j + 'a';
					S[i] = '\0';
					end = 1;
					break;
				}
			}
		}
		if (end == 0) {
			S[0] = '-';
			S[1] = '1';
			S[2] = '\0';
		}
	}

	printf("%s", S);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll a, b;
  cin >> a >> b;
  if(a<=8&&b<=8){
    print("Yay!");
  }
  else{
    print(":(");
  }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var m = int.Parse(_[1]);

            var f = new int[m];
            for(var i = 0; i < n; i++){
                var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                for(var j = 0; j < a[0]; j++){
                    var idx = a[j+1];
                    f[idx-1] += 1;
                }
            }

            Console.WriteLine(f.Count(x => x == n));
        }
    }
}


Measured memory_bytes: 13396
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if(z >= 0 && z <= k){
                ans++;
            }
        }
    }
    cout << ans;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

struct UnionFind{
private:
    vector<int> par;
    vector<int> rank;
public:
    UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        for (int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    int root(int x){
        if(par[x]==x)return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(rank[x]<rank[y])swap(x,y);
        if(rank[x]==rank[y])++rank[x];
        par[y]=x;
        return true;
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    UnionFind uf(2*n);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        --a,--b;
        uf.merge(a,b+n);
        uf.merge(a+n,b);
    }
    if(uf.issame(0,n)){
        cout<<n*(n-1)/2-m<<endl;
    }
    else{
        ll cnt=0;
        for(int i=0;i<n;i++){
            if(uf.issame(0,i))++cnt;
        }
        cout<<cnt*(n-cnt)-m<<endl;
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){



string s;
cin>>s;
long long  l_len=0;
long long  r_len=0;
long long ans=0;
for(int i=0;i<s.size();i++){
    //if(s[i]=='>' && s[i+1]=='<')continue;
    if(s[i]=='<'){
        if(r_len>0){
            ans+=((r_len-1)*r_len)/2;
            ans+=max(l_len,r_len);
            r_len=0;
            l_len=0;
        }
        l_len++;
        ans+=(l_len-1);
    }
    if(s[i]=='>'){
        r_len++;
    }
}
if(r_len>0){
            ans+=((r_len-1)*r_len)/2;
            ans+=max(l_len,r_len);
        }
if(l_len>0 && r_len==0)ans+=l_len;

cout<<ans<<endl;
 return 0;
}
/*
<>>

3

<>>><<><<<<<>>><

28
*/

Measured memory_bytes: 900
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {
    const MAX_N : usize = 110;

    let n = read_t_in_line::<i32>()[0];
    let mut f : Vec<Vec<i32>> = Vec::new();
    let mut p : Vec<Vec<i32>> = Vec::new();

    for _ in 0..n {
        let f_vec = read_t_in_line::<i32>();
        f.push(f_vec)
    }
    for _ in 0..n {
        let p_vec = read_t_in_line::<i32>();
        p.push(p_vec);
    }

    let mut opt = -2000000000;

    for mask in 1..(1 << f[0].len()) {
        let mut freq = [0 ; MAX_N];
        // 日付ごとに取る
        for i in 0..f[0].len() {
            if ((mask >> i) & 1) == 1 {
                for j in 0..n {
                    if f[j as usize][i as usize] == 1 {
                        freq[j as usize] += 1;
                    }
                }
            }
        }
        let mut score = 0;
        for i in 0..n {
            score += p[i as usize][freq[i as usize] as usize]
        }
        opt = max::<i32>(opt, score);
    }
    
    println!("{}", opt);

}


Measured memory_bytes: 4352
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
c[a[0]] = c[a[0]]-1
ans = [0]*n
for i,j in c.items():
    ans[i-1] = j*(j-1)//2
d = sum(ans)
print(d)

for k in range(1,n):
    d -= ans[a[k-1]-1]
    d -= ans[a[k]-1]
    c[a[k]] = c[a[k]]-1
    c[a[k-1]] = c[a[k-1]]+1
    x = (c[a[k]]-1)*c[a[k]]//2
    y = (c[a[k-1]]-1)*c[a[k-1]]//2
    ans[a[k]-1] = x
    ans[a[k-1]-1] = y
    d += x+y
    print(d)

Measured memory_bytes: 26772
import java.util.Scanner;

public class Main {

	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int[] a = new int[10001];
		a[0]=1;
		for(int i=1;i<10001;i++){
			a[i]=a[i-1]+i;
		}
		for(;cin.hasNext();){
			System.out.println(a[cin.nextInt()]);
		}
	}

}

Measured memory_bytes: 17236
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "PP.hpp"
#define deb(x...) cerr << "[" << #x << "] = " << x << "\n";
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
  	
	string s, t;
	cin >> s >> t;
	int ans = 0;
	forn(i, s.size())if(s[i] != t[i])ans++;
	cout << 3 - ans << '\n';
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t x;
    cin>>x;
    //6⇒5⇒6..を繰り返せばいい
    int64_t ans=0;
    ans += (x/11)*2;
    x -= 11*ans/2;
    if(x>6){
        ans +=2;
    }
    else if(x!=0){
        ans +=1;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main() {
  int a[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x, y;
  cin >> x >> y;
  
  if(a[x]==a[y]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
ll a,b,c,d,k;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>a>>b>>c>>k;
  if(abs(a-b) >= pow(10,18)) cout<<"Unfair"<<endl;
  else if(k%2==0) cout<<a-b<<endl;
  else cout<<b-a<<endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, q, l;
    cin >> n;
    akari<int> xs(n);
    for (int i = 0; i < n; i++)
    {
        cin >> xs[i];
    }
    cin >> l >> q;
    yukari<int> dp(n, akari<int>(36));
    for (int i = 0; i < n; i++)
    {
        dp[i][0] = distance(xs.begin(), upper_bound(xs.begin(), xs.end(), xs[i] + l)) - 1;
    }
    for (int k = 0; k < 35; k++)
    {
        for (int i = 0; i < n; i++)
        {
            dp[i][k + 1] = dp[dp[i][k]][k];
        }
    }
    while (q--)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (a > b)
        {
            swap(a, b);
        }
        int ans = 0;
        for (int k = 35; k >= 0; k--)
        {
            if (dp[a][k] < b)
            {
                a = dp[a][k];
                ans |= 1 << k;
            }
        }
        ans++;
        cout << ans << '\n';
    }
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 19200
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	ll h[n];
	for(int i=0; i<n; i++) cin >> h[i];
	
	int ans=0, cnt=0;
	for(int i=0; i<n; i++){
		if(h[i]>=h[i+1] && i+1<n) cnt++;
		else{
			ans=max(ans, cnt);
			cnt=0;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

int main(){
  int n=0;
  cin>>n;

  vector<int> lis(100010);
  rep(i,0,100011){lis[i]=0;}
  rep(i,0,n){
    int tmp;
    cin>>tmp;
    lis[tmp]++;
  }
  
  int tmpmax,ans=0;
  rep(i,1,100010){
    tmpmax=0;
    tmpmax=lis[i-1]+lis[i]+lis[i+1];
    ans=max(ans,tmpmax);
  }
  
  cout<<ans<<endl;

  return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define INF 1e9+7
#define cases int t;cin>>t;while(t--)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define ff first
#define ss second

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

ll power(ll a,ll b){
	ll n=1;
	while(b--){
		n*=a;
	}
	return n;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	ll n;
	cin>>n;
	ll p;
	ll sum=n;
	rep(i,1,15){
		if(n<=power(26,i)){
			p=i;
			break;
		}
		n-=power(26,i);
	}
	// test2(p,n)
	ll x;
	char c;
	while(p>1){
		rep(i,0,26){
			if(n<=power(26,p-1)){
				c='a'+i;
				cout<<c;
				break;
			}
			n-=power(26,p-1);
		}
		p--;
	}
	c='a'+n-1;
	cout<<c;

	
	// test1(x)
	
	
	return 0;
}	

Measured memory_bytes: 3672
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        String str = "#"+sc.next()+"#";

        if(str.substring(A,C+1).contains("##")) System.out.println("No");
        else if(str.substring(B,D+1).contains("##")) System.out.println("No");
        else if(C>D) {
            String line = str.substring(B-1,D+2);
            if(line.contains("...")) {
                System.out.println("Yes");
            }else {
                System.out.println("No");
            }

        }else {
            System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 30136
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  int a,b;
  string u;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  if(s==u){
    cout<<a-1<<" "<<b<<endl;
  }
  else{
    cout<<a<<" "<<b-1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
color=[i for i in input().split()]
num=[int(i) for i in input().split()]
rem=input()

if rem==color[0]:
    num[0]-=1
    print(str(num[0])+" "+str(num[1]))
    
else :
    num[1]-=1
    print(str(num[0])+" "+str(num[1]))
    
print()

Measured memory_bytes: 3060
#include<bits/stdc++.h> 
using namespace std;
const int Mod = 1000000007;
char s1[100],s2[100];
int n;
long long Ans;
int main(){
	scanf("%d",&n);
	scanf("%s%s",s1,s2);
	Ans = 1;
	int i = 0;
	if (s1[0] == s2[0]){
		Ans = 3;
		i+=1;
	} else{
		Ans = 6;
		i+=2;
	}
	for (;i<n;){
		if (s1[i] == s2[i]){
			if (s1[i-1] == s2[i-1]){
				Ans = Ans * 2 % Mod;
			} else{
				Ans = Ans * 1 % Mod;
			}
			i++;
		} else{
			if (s1[i-1] == s2[i-1]){
				Ans = Ans * 2 % Mod;
			} else
				Ans = Ans * 3 % Mod;
			i+=2;
		}
	}
	printf("%lld\n",Ans);
}



	/*
	-- -- 
	-- -- 
	这样的话 右边有
	12 
	21
	
	13 
	21
	
	12 
	23
	3种
	
	-- |
	-- |
	这样的话
	有1种
	
	|--
	|--
	这样的话有
	12
	13
	
	13
	12
	有2种
	
	||
	||
	这样的话有2种
	12
	12
	
	13
	13
	*/


Measured memory_bytes: 256
<?php
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
  while ($line = fgets(STDIN)) {
      list($a, $b) = explode(' ', $line);
      $c = null;
      $a = (int)$a;
      $b = (int)$b;
      if ($a == $b) {
        echo 'a == b';
      } else if ($a > $b) {
        echo 'a > b';
      } else {
        echo 'a < b';
      }
  }
}
?>

Measured memory_bytes: 15436
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pi 3.14159265359

int main(){
    vector<vector<int>> A(3, vector<int>(3));
    for(int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }
    int N; cin >> N;
    int b;
    for(int i = 0; i < N; i++) {
        cin >> b;
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 3; k++) {
                if(A.at(j).at(k) == b) {
                    A.at(j).at(k) = 0;
                }
            }
        }
    }
    string ans = "No";
    for(int i = 0; i < 3; i++) {
        if(A.at(i).at(0) == 0 && A.at(i).at(1) == 0 && A.at(i).at(2) == 0) {
            ans = "Yes";
        }
        if(A.at(0).at(i) == 0 && A.at(1).at(i) == 0 && A.at(2).at(i) == 0) {
            ans = "Yes";
        }
    }
    if(A.at(0).at(0) == 0 && A.at(1).at(1) == 0 && A.at(2).at(2) == 0) {
        ans = "Yes";
    }
    if(A.at(0).at(2) == 0 && A.at(1).at(1) == 0 && A.at(2).at(0) == 0) {
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include  <stdio.h>
 int main(){
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d=a/b;
    r=a%b;
    f=(double)a/b;
    printf("%d %d %f",d,r,f);
    return 0;
}

Measured memory_bytes: 1852
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A.sort()
dic = defaultdict(int)
for a in A:
    dic[a] += 1
ctr = defaultdict(int)
ans = 0
for a in A:
    if dic[a] == 1 and ctr[a] == 0:
        ans += 1
    if ctr[a] == 0:
        m = 1
        while a*m <= 10**6:
            ctr[a*m] += 1
            m += 1
print(ans)


Measured memory_bytes: 181716
#include <stdio.h>

int main(void){
	int H;
	int W = 301;
	do {
		if (W <= 300) {
			for (int h = 1; h <= H; h++) {
				for (int w = 1; w <= W; w++) {
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
		scanf("%d %d", &H, &W);
	} while (H > 0 && W > 0);
	
	return 0;
}

Measured memory_bytes: 2676
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N= gi();

        int a=Math.floorDiv(N, 15);


        System.out.print(N*800-a*200);
//        if (a==b) {
//        	System.out.print("Draw");
//        }else if(a==1){
//        	System.out.print("Alice");
//        }else if(b==1){
//        	System.out.print("Bob");
//        }

	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35644
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)


a, b, c, d = map(int, input().split())
min_div = (a-1)//c + (a-1)//d - (a-1)//lcm(c, d)
max_div = b//c + b//d - b//lcm(c, d)
print(b-a+1-(max_div-min_div))

Measured memory_bytes: 3064
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n;
ll A[1000000];
ll B[1000000];

int main(){

    cin >> n;
    for(ll i=0; i<n+1; i++) cin >> A[i];
    for(ll i=0; i<n; i++) cin >> B[i];


    ll sum=0;
    ll left=A[0];
    for(ll i=0; i<n; i++){
        if( left>=B[i]){
            sum+=B[i];
            left = A[i+1];
        }else{
            sum += left;
            if( A[i+1] >= (B[i]-left)){
                sum += B[i]-left;
                left = A[i+1] - (B[i]-left);
            }else{
                sum += A[i+1];
                left = 0;
            }
        } 
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define st first
#define nd second

typedef pair<int,int> pii;
const int N = 1e2+5 , M = 1e5+5 , inf = 0x3f3f3f3f3f3f3f3f;

int n , w , mx , dp[N][M];
pii A[N];

main(){

  cin >> n >> w;

  for(int i = 0 ; i < N ; i++)
    for(int j = 1 ; j < M ; j++) dp[i][j] = inf;

  for(int i = 1 ; i <= n ; i++) cin >> A[i].st >> A[i].nd;

  for(int i = 1 ; i <= n ; i++){
    for(int j = 0 ; j < M ; j++){
      if(j-A[i].nd >= 0) dp[i][j] = min(dp[i][j],dp[i-1][j-A[i].nd]+A[i].st);
      dp[i][j] = min(dp[i][j],dp[i-1][j]);
    }
  }

  for(int i = 0 ; i < M ; i++)
    if(dp[n][i] <= w) mx = max(mx,i);

  cout << mx << "\n";

}

Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
int a,b,c=1,len,e,d,bb;
int main()
{
	cin>>a>>b;
	bb= b;
	
	for(int i=1;i<=1000;i++)
	{
		if(b>=1)	
		len++;
		b=b/10;
	}
	
	c= 1;
	for(int i=1;i<=len;i++)
	{
		c=c*10;
	}
	c=c*a+bb;
	
	for(int j=1;j<=c;j++)
	{
		if(c==j*j)
		e++;
	}
	
	if(e==1)	
	cout<<"Yes";
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main{
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(bf.readLine());
		
		ArrayList<CustomNumber> arr = new ArrayList<>();
		
		for(int i = 0 ; i < N ; i++){
			int tmp = Integer.parseInt(bf.readLine());
			arr.add(new CustomNumber(tmp, i));
		}
		
		Collections.sort(arr);
		
		int ctr = 0;
		
		for(int i = 0 ; i < N ; i++){
			CustomNumber curr = arr.get(i);
			
			if(curr.pos % 2 == 0 && i%2 == 1) ctr++;
			else if(curr.pos % 2 == 1 && i%2 == 0) ctr++;
		}
		
		if(ctr !=0) System.out.println(ctr/2);
		else System.out.println(0);
	}
}

class CustomNumber implements Comparable<CustomNumber>{
	int value;
	int pos;
	
	public CustomNumber(int val, int po){
		value = val;
		pos = po;
	}
	
	@Override
	public int compareTo(CustomNumber sec) {
		return value - sec.value;
	}
}

Measured memory_bytes: 22012
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()

using namespace std;
using ll = int64_t;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, a, b;
  cin >> n >> a >> b;

  if (n == 1 && (a != b)) {
  	cout << 0 << endl;
  } else if (a > b) {
  	cout << 0 << endl;
  } else {
  	ll mn = a * (n - 1) + b;
  	ll mx = a + (n - 1) * b;
  	ll result = mx - mn + 1;
  	cout << result << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,k,x[100000],ans=500000000,ans1,ans2;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>x[i];
	}
	for(int i=0;i<=n-k;i++){
		ans1=abs(x[i])+abs(x[k+i-1]-x[i]);
		ans2=abs(x[i+k-1])+abs(x[i]-x[k+i-1]);
		ans1=min(ans1,ans2);
		if(ans1<ans){
			ans=ans1;
		}
	}
	if(ans==500000000)
		cout<<"0"<<endl;
	else
		cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 1024
A, B, N = map(int, input().split())

if A % B == 0:
    print(0)

else:
    if N > B:
        print(int(A * (B - 1) / B))
    else:
        if A * N % B == 0:
            print(int(A * (N - 1) / B))
        else: 
            print(int(A * N / B))

Measured memory_bytes: 61796
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

using namespace std;

int GCD(int x, int y) {
    return x ? GCD(y % x, x) : y;
}

int main() {
    
    ll N,X;
    cin >> N >> X;
    vector<ll> x(N);
    FOR(i, 0, N){
        cin >> x[i];
    }
    int ans;
    
    if(N==1){
        ans = abs(x[0]-X);
    }else{
    vector<ll> g(N);
    FOR(i, 0, N){
        g[i] = abs(x[i] - X);
    }
    int great = GCD(g[0],g[1]);
    FOR(i, 0, N-1){
        great = GCD(great, g[i+1]);
    }
    
    ans = great;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;


int main(){

  string s;cin>>s;
  ll n=s.size();
  string left=s.substr(0,(n-1)/2);
  string right=s.substr((n+3)/2-1,(n-1)/2);

  string t=s;
  reverse(all(t));
  string l=left;
  reverse(all(l));
  string r=right;
  reverse(all(r));

  if(s==t&&left==l&&right==r)out("Yes");
  else out("No");




  // out(left<<":"<<right);


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG

int main(){
  int n;
  cin >> n;
  
  vector<string> blue(n); //プラスのカードblue
  for(int i=0; i<n; i++){
    cin >> blue[i];
  }
  
  int m;
  cin >> m;
  
  vector<string> red(m); //マイナスのカードred
  for(int i=0; i<m; i++){
    cin >> red[i];
  }
  
  int ans;
  int count;
  int maximum = 0;
  
  for(int i=0; i<n; i++){
    ans = i;
    count = 1;
    for(int k=i+1; k<n; k++){
      if(blue[i]==blue[k])
        count++;
    }
    for(int j=0; j<m; j++){
      if(blue[i]==red[j]){
        count--;
      }
      if(count<0)
        break;
    }
    if(count<0)
      continue;
    if(count>maximum)
      maximum = count;
  }
  cout << maximum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int N;
int n[4];

int main() {
  cin >> N;
  for(int i=0; i<4; i++) {
    n[i] = N % 10;
    N /= 10;
  }
  int pre = n[0];
  for(int i=1; i<4; i++) {
    if(pre == n[i]) {
      cout << "Bad" << endl;
      return 0;
    }
    pre = n[i];
  }
  cout << "Good" << endl;
  return 0;
}



Measured memory_bytes: 256