akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>

using namespace std;

typedef pair<int, int> P;

int N, M;
vector<vector<int>> E, rE;

const int INF = 114514;

vector<int> ans(INF);
P bef[1000 + 10];

void bfs(int start) {
	for (int i = 0; i < N; i++)bef[i].first = INF, bef[i].second = INF;
	bef[start].first = -1, bef[start].second = 0;
	queue<int> q;
	q.push(start);
	while (q.size()) {
		int nowpos = q.front(); q.pop();
		for (int i = 0; i < E[nowpos].size(); i++) {
			int nxt = E[nowpos][i];
			if (bef[nxt].second == INF) {
				bef[nxt].second = bef[nowpos].second + 1;
				bef[nxt].first = nowpos;
				q.push(nxt);
			}
		}
	}

	int tmp = ans.size(), memo;
	for (int i = 0; i < rE[start].size(); i++) {
		int nxt = rE[start][i];
		if (tmp > bef[nxt].second + 1) {
			tmp = bef[nxt].second + 1;
			memo = nxt;
		}
	}
	if (tmp == ans.size())return;
	ans.clear();
	ans.push_back(memo);
	while (memo != -1) {
		if(bef[memo].first != -1)
			ans.push_back(bef[memo].first);
		memo = bef[memo].first;
	}
}

int main() {
	cin >> N >> M;
	E.resize(N), rE.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		E[a].push_back(b);
		rE[b].push_back(a);
	}
	for (int i = 0; i < N; i++) {
		bfs(i);
	}
	if (ans.size() == INF) {
		cout << -1 << endl;
	}
	else {
		cout << ans.size() << endl;
		for (int i = 0; i < ans.size(); i++) {
			cout << ans[i] + 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=1000000007;


int main() {
  string s;
  cin >> s;
  if(s=="SSS")
  cout << 0 << endl;
  if(s=="RSS")
  cout << 1 << endl;
  if(s=="RRS")
  cout << 2 << endl;
  if(s=="SRS")
  cout << 1 << endl;
  if(s=="SSR")
  cout << 1 << endl;
  if(s=="SRR")
  cout << 2 << endl;
  if(s=="RSR")
  cout << 1 << endl;
  if(s=="RRR")
  cout << 3 << endl;
}



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

int main(){
    int N;
    cin>>N;
    vector<int> V,C;
    for(int i=0;i<N;i++){
        int v;
        cin>>v;
        V.push_back(v);
    } 
    for(int i=0;i<N;i++){
        int c;
        cin>>c;
        C.push_back(c);
    } 
    int ans = 0;
    for(int i=0;i<N;i++){
        if (V[i] > C[i]) ans += V[i] - C[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import qualified Data.IntMap as M
import Data.List

main :: IO ()
main = do
    [_, m] <- readInts
    as <- readInts
    print $ solve m as

readInts :: IO [Int]
readInts = map read . words <$> getLine

solve :: Int -> [Int] -> Int
solve m =  M.foldr (\x y -> (x * (x - 1) `div` 2) + y) 0
     . foldr (M.alter $ return . maybe 1 succ)  M.empty
     . scanl' (\x y -> (x + y) `mod` m) 0


Measured memory_bytes: 36220
from operator import mul
from functools import reduce
import collections


def cmb(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    elif r < 0:
        return 0
    numer = reduce(mul, range(n, n - r, -1))
    denom = reduce(mul, range(1, r + 1))
    return numer // denom


N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += cmb(n, 2)
print(ans)


Measured memory_bytes: 23596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] c = new String[3];
		for(int i = 0;i < c.length;++i)
			c[i] = sc.next();
		sc.close();
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < c.length;++i)
			sb.append(c[i].charAt(i));
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 21588
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
using namespace std;
#define INF (2147483647)
#define mod (1000000007)
#define max (7368791)

int main(void){
  int N,M;
  while(true){
    cin >> M >> N;
    if(N==0){
      break;
    }else{
      vector<bool> IsPrime;
      IsPrime.assign(max+1,true);

      for (size_t i = 0; i < M; i++){
        IsPrime[0] = false;
      }

      for(size_t i=M; i<=max; ++i){
        if(IsPrime[i]){
          if(N==0){
            cout << i << endl;
            break;
          }
          N -= 1;
          for(size_t j=2; i*j<=max; ++j){
            IsPrime[i*j] = false;
          }
        }
      }

    }
  }
}



Measured memory_bytes: 3992
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for x in range(n-m+1):
    for y in range(n-m+1):
        check = 0
        for i in range(m):
            for j in range(m):
                if a[x+i][y+j] != b[i][j]:
                    check = 1
                    break
            else:
                continue
            break
        if check == 0:
            print('Yes')
            exit()

print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;
    sort(_all(a));

    using R = double;
    R res = a[0];
    rep(i, 1, n){
        res = (res + a[i]) / 2.0;
    }

    cout.precision(20);
    cout << fixed << res << endl;

    return 0;
}


Measured memory_bytes: 256
import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict,deque
import math
def main():
    n = int(input())
    ans = 0
    for i in range(1,n):
        if n%i==0:
            ans+=(n//i-1)
        else:
            ans+=n//i
    print(ans)

# region fastio
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9556
#include <bits/stdc++.h>
#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(){
	int N,M;
	cin>>N>>M;
	cout<<(N*(N-1)+M*(M-1))/2<<endl;
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 384
A, B = map(int, input().split())
def f(x):
    if x % 4 == 0: return x
    elif x % 4 == 1: return 1
    elif x % 4 == 2: return x ^ 1
    elif x % 4 == 3: return 0
print(f(A - 1) ^ f(B))    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int a[200010], b[200010];
vector<int>v;
int main() {
	int n, m;
	cin >> n;
	rep(i, n)cin >> a[i];
	cin >> m;
	rep(i, m)cin >> b[i];
	rep(i, n)if (!binary_search(b, b + m, a[i]))v.push_back(a[i]);
	rep(i, m)if (!binary_search(a, a + n, b[i]))v.push_back(b[i]);
	sort(v.begin(), v.end());
	for (auto i : v)cout << i << endl;
	return 0;
}


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

int main(){
    int data, count = 0;
    vector<int> data_vector;
    while(1){
        cin >> data;
        if (data == 0) break;
        data_vector.push_back(data);
        count++;
    }
    for (int i = 0; i < count; i++){
        cout << "Case " << i+1 << ": " << data_vector[i] << endl;
    }
}



Measured memory_bytes: 3144
n, k = map(int, input().split())
l = []
for i in range(k):
    d = int(input())
    a = input().split()
    for j in range(d):
        l.append(int(a[j]))
c = 0
for i in range(1, n + 1):
    if i not in l:
        c += 1
print(c)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=2e5+5;
const ll inf=1e17;





ll ar[ms];



int main()
{
    idfc;

    int n;
    cin>>n;
    int i;
    for(i=1;i<=n;i++)cin>>ar[i];


    ll s=0;
    ll a=0;
    ll x;
    int fl=0;
    for(i=1;i<=n;i++)
    {
        s+=ar[i];

        if(fl)
        {
            x=max(1ll,s);
            a+=(x-s);
            s=x;
        }
        else{
            x=min(-1ll,s);
            a+=(s-x);
            s=x;
        }
        fl=!fl;
    }
    ll ans=a;
    a=0;
    s=0;
    fl=1;
    for(i=1;i<=n;i++)
    {
        s+=ar[i];

        if(fl)
        {
            x=max(1ll,s);
            a+=(x-s);
            s=x;
        }
        else{
            x=min(-1ll,s);
            a+=(s-x);
            s=x;
        }
        fl=!fl;
    }
    cout<<min(ans,a);
    return 0;
}

Measured memory_bytes: 4336
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i=1; i<=n; i++ ) scanf("%d", &A[i]);
  
  trace(A, n);
  
  for(i=2;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;
    }
    trace(A, n);
  }
return 0;
}

Measured memory_bytes: 608
from sys import stdin
R,G,B,N=[int(x) for x in stdin.readline().rstrip().split()]
ans=0
for r in range(0,N//R+1):
    for g in range(0,(N-(R*r))//G+1):
        if (N - R*r - G*g) % B == 0:
            ans+=1
print(ans)

Measured memory_bytes: 42364
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, Q;
	while (cin >> N >> Q) {
		if (N == 0 && Q == 0) return 0;
		vector<int> COUNT(101, 0);
		for (int i = 0; i < N; i++) {
			int M;
			cin >> M;
			for (int j = 0; j < M; j++) {
				int D;
				cin >> D;
				COUNT[D]++;
			}
		}
		for (int i = N; i >= Q; i--) {
			for (int j = 1; j <= 100; j++) {
				if (COUNT[j] == i) {
					cout << j << endl;
					goto NEXT;
				}
			}
		}
		cout << 0 << endl;
	NEXT:;
	}
}


Measured memory_bytes: 3048
#include<stdio.h> 
main()
{   
	int n,a,i,max,min;   
	double sum;   
	scanf("%d",&n);   
	scanf("%d",&max);   
	min=max;   
	sum=max;   
	for(i=1;i<n;i++)
	{     
		scanf("%d",&a);     
		if(a>max)
		{ 
		max=a;
		}     
		if(a<min)
		{ 
		min=a;
		}     
		sum=sum+a;   
	}   
		printf("%d %d %.0f\n",min,max,sum);   
		return 0; 
}

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

#define ll long long
#define ull unsigned long long

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll sx, sy, tx, ty;
    ll dx, dy;
    cin >> sx >> sy >> tx >> ty;
    dx = tx - sx;
    dy = ty - sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 22;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, c, k; cin >> n >> c >> k;
  vi t(n);
  REP(i, n) {
    cin >> t[i];
  }

  sort(ALL(t));
  
  int now = t[0];
  int cnt = 1;
  int ans = 1;
  FOR(i, 1, n) {
    if(t[i] > now + k || cnt >= c) {
      now = t[i];
      cnt = 1;
      ans++;
    } else {
      cnt++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    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;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/

signed main(){
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    int ans[110][110];
    int cnth=0;
    int cntw=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            ans[cnth][cntw]=i+1;
            cntw++;
            if(cntw>=w){
                cntw=0;
                cnth++;
            }
        }
    }
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;j++)cout<<ans[i][j]<<" ";
            cout<<endl;
        }else{
            for(int j=w-1;j>=0;j--)cout<<ans[i][j]<<" ";
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);
	if(a < b) {
		printf("a < b\n");
	}else if(a > b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    string s;
    cin >> s;
    YN(s[2] == s[3] && s[4] == s[5]);
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	ll k;
	cin >> n >> k;
	vi a(n + 1);
	vb vis(n + 1, 0);
	for (int i = 1;i <= n;i++)
		cin >> a[i];
	int cur = 1;
	deque<int> arr;
	while (!vis[cur]) {
		vis[cur] = 1;
		arr.pb(cur);
		cur = a[cur];
	}
	if (k < arr.size()) {
		cout << arr[k] << '\n';
	}
	else {
		while (arr.front() != cur) {
			arr.pop_front();
			k--;
		}
		cout << arr[k % arr.size()] << '\n';
	}
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
const int N = 110;

inline int read()
{
  char ch=getchar(); int p=0; int f=1;
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+(ch-'0'); ch=getchar();}
  return p*f;
}

int c[N][N];

int main()
{

  int w = read(); int b = read();
  int x = 1; int y = 0; int r=1;
  for(int i=1;i<=w-1;i++)
  {
    y++; c[x][y] = r; r^=1; y++; c[x][y] = r; r^=1;
    if(y==96)
    {
      x++; for(int j=1;j<=96;j++) c[x][j] = 0;
      x++; y=0;
    }
  }

  for(int j=y+1;j<=96;j++) c[x][j] = 0;
  x++; for(int j=1;j<=96;j++) c[x][j] = 0;

  x++; for(int j=1;j<=96;j++) c[x][j] = 1; x++; y=0; r=0;
  for(int i=1;i<=b-1;i++)
  {
    y++; c[x][y] = r; r^=1; y++; c[x][y] = r; r^=1;
    if(y==96)
    {
      x++; for(int j=1;j<=96;j++) c[x][j] = 1;
      x++; y=0;
    }
  }
  for(int j=y+1;j<=96;j++) c[x][j] = 1;
  x++; for(int j=1;j<=96;j++) c[x][j] = 1;

  printf("%d %d\n",x,96);
  for(int i=1;i<=x;i++)
  {
    for(int j=1;j<=96;j++)
    {
      if(c[i][j] == 1) printf(".");
      else printf("#");
    }printf("\n");
  }

  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		long[] num = new long[N], den = new long[N];
		for (int i = 0; i < N; i++) {
			String val = sc.next();
			String dec = "0";
			int pos = val.indexOf('.');
			if (pos != -1) {
				dec = val.substring(pos + 1);
				val = val.substring(0, pos);
			}
			num[i] = Long.parseLong(val);
			den[i] = 1;
			char[] ff = dec.toCharArray();
			for (int j = 0; j < ff.length; j++) {
				num[i] *= 10;
				num[i] += ff[j] - '0';
				den[i] *= 10;
			}
			long gcd = gcd(num[i], den[i]);
			num[i] /= gcd;
			den[i] /= gcd;
		}
		int MINUS = 10;
		long[][] count = new long[60][60];
		for (int i = 0; i < N; i++) {
			int two = get(num[i], 2) - get(den[i], 2);
			int five = get(num[i], 5) - get(den[i], 5);
			count[two + MINUS][five + MINUS]++;
		}
		long ans = 0;
		for (int i = 0; i < 60; i++) {
			for (int j = 0; j < 60; j++) if (i + j - 2 * MINUS >= 0) {
				for (int k = 0; k < 60; k++) {
					for (int l = 0; l < 60; l++) if (k + l - 2 * MINUS >= 0) {
						ans += count[i][k] * count[j][l];
					}
				}
			}
		}
		long tmp = 0, plus = 0;
		for (int i = MINUS; i < 60; i++) {
			for (int j = MINUS; j < 60; j++) {
				tmp += count[i][j] * count[i][j];
				plus += count[i][j] * (count[i][j] - 1) / 2;
			}
		}
		ans -= tmp;
		ans /= 2;
		ans += plus;
		out.println(ans);
		
		out.flush();
	}

	static int get(long val, int factor) {
		int ret = 0;
		while (val % factor == 0) {
			val /= factor;
			ret++;
		}
		return ret;
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 58880
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, A, B;
    cin >> N >> A >> B;
    if(A == 0) { cout << 0; return 0; }
    long long c = (N / (A + B)) * A;
    long long r = N % (A + B);
    c += min(r, A);
    cout << c;
    return 0;
}

Measured memory_bytes: 256
// ALDS1_5_B.cpp
// Divide and Conquer - Merge Sort

#include <iostream>
#include <vector>
using namespace std;
int cnt = 0;
const int SENTINEL = 1E9 + 5;
void trace(vector<int>& nums)
{
	for (int i = 0; i < nums.size(); i++) {
		if (i > 0) cout << " ";
		cout << nums[i];
	}
	cout << endl;
}

void merge(vector<int>& nums, int left, int mid, int right)
{
	vector<int> L(nums.begin() + left, nums.begin() + mid);
	vector<int> R(nums.begin() + mid, nums.begin() + right);
	L.push_back(SENTINEL);
	R.push_back(SENTINEL);
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			nums[k] = L[i++];
		}
		else {
			nums[k] = R[j++];
		}
	}
}

void MergeSort(vector<int>& nums, int left, int right)
{
	if (left + 1 >= right) return;
	int mid = left + (right - left) / 2;
	MergeSort(nums, left, mid);
	MergeSort(nums, mid, right);
	merge(nums, left, mid, right);
}

int main()
{
	int n;
	cin >> n;
	vector<int> nums(n);
	for (int i = 0; i < n; i++) {
		cin >> nums[i];
	}
	MergeSort(nums, 0, n);
	trace(nums);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 8812
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
const int INF = 1e9;

int main(){
  int h, w;
  cin >> h >> w;
  int a[h][w], b[h][w], c[h][w];
  rep(i,h) rep(j,w) cin >> a[i][j];
  rep(i,h) rep(j,w) cin >> b[i][j];
  rep(i,h) rep(j,w) c[i][j] = abs(a[i][j]-b[i][j]);
  const int S = 12800;
  const int MAX = S*2+1;
  vector<vector<vector<bool>>> dp(h,vector<vector<bool>>(w,vector<bool>(MAX,false)));
  dp[0][0][S+c[0][0]] = true;
  dp[0][0][S-c[0][0]] = true;
  rep(i,h) {
    rep(j,w) {
      rep(k,MAX) {
        if(i-1 >= 0 && dp[i-1][j][k] && k + c[i][j] < MAX) dp[i][j][k+c[i][j]] = true;
        if(i-1 >= 0 && dp[i-1][j][k] && k - c[i][j] >= 0) dp[i][j][k-c[i][j]] = true;
        if(j-1 >= 0 && dp[i][j-1][k] && k + c[i][j] < MAX) dp[i][j][k+c[i][j]] = true;
        if(j-1 >= 0 && dp[i][j-1][k] && k - c[i][j] >= 0) dp[i][j][k-c[i][j]] = true;
      }
    }
  }
  int ans = INF;
  rep(i,MAX) {
    if(dp[h-1][w-1][i]) {
      ans = min(ans,abs(i-S));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20992
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

bool cmp(const pair<int, int> &lhs, const pair<int, int> &rhs) {
  return lhs.first < rhs.first;
}

int main()
{
  int N, M;
  cin >> N >> M;

  vector< pair<int, int> > S;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    S.push_back(make_pair(A, B));
  }

  sort(S.begin(), S.end(), cmp);

  unsigned long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (S[i].second >= M) {
      ans += (unsigned long long)S[i].first * (unsigned long long)M;
      break;
    } else {
      ans += (unsigned long long)S[i].first * (unsigned long long)S[i].second;
      M -= S[i].second;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int used[7]={},l=s.length(),lt=7,rt=-1;
	string t="keyence";
	int ll=t.length();
	if(l<ll){
		cout<<"NO"<<endl;
		return 0;
	}
	FOR(i,0,ll){
		if(s[i]!=t[i]){
			lt=i;
			break;
		}
	}
	FOR(i,0,ll){
		if(s[l-1-i]!=t[ll-1-i]){
			rt=6-i;
			break;
		}
	}
	//cerr<<rt<<" "<<lt<<endl;
	if(lt>rt){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void) {
    int n, m;
    cin >> n >> m;

    priority_queue<ll> prices;
    for (int i = 0; i < n; ++i) {
        ll temp;
        cin >> temp;
        prices.push(temp);
    }

    for (int i = 0; i < m; ++i) {
        ll max_price = prices.top();
        prices.pop();
        prices.push(max_price / 2LL);
    }

    ll ans = 0;
    while (!prices.empty()) {
        ans += prices.top();
        prices.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 1400
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve (n)

type Input  = (Int)
type Output = Int

solve :: Input -> Output
solve n = if n `mod` 2 == 0 then n else 2*n

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define MaxSize 100005
ll n,m,sum=0;
ll a[MaxSize];
P res[MaxSize];
void Solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<m;i++) cin>>res[i].second>>res[i].first;
    sort(res,res+m,greater<P>());
    sort(a,a+n);
    int tmp=0;
    for(int i=0;i<m;i++){
        int tmp1=tmp;
        for(int j=tmp1;j<tmp1+res[i].second;j++){
            if(tmp>=n) break;
            else if(a[j]<res[i].first){
                a[j]=res[i].first;
                tmp++;
            }
            else break;
        }
    }
    for(int i=0;i<n;i++) sum+=a[i];
    cout<<sum<<endl;
}
int main(){
    Solve();
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];

int main(){
    int N,X,Y;
    int tmp;
    cin >> N >> X >> Y;
    vector<int> Ans(N);
    for (int i = 1; i < N; i++){
        for (int j = i+1; j <= N; j++){
            if(i <= X && Y <= j){
                Ans[(j-Y)+(X-i)+1]++;
            }else if(i <= X && Y >= j){
                Ans[min(j-i,(Y-j)+(X-i)+1)]++;
            }else if(X <= i && Y >= j){
                Ans[min(j-i,(Y-j)+(i-X)+1)]++;
            }else{
                Ans[min(j-i,(j-Y)+(i-X)+1)]++;
            }
        }
    }
    for (int i = 1; i < N; i++){
        cout << Ans[i] << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  char S[100000];
  int i;
  int sum_1=0,sum_2=0;
  scanf("%s",S);
     for(i=0; S[i]!='\0'; i++){
        if((i%2==0 && S[i]=='1') || (i%2==1 && S[i]=='0'))
          sum_1++;}
     for(i=0; S[i]!='\0'; i++){
        if((i%2==0 && S[i]=='0') || (i%2==1 && S[i]=='1'))
           sum_2++;}
  
  if(sum_1>sum_2)
  	printf("%d",sum_2);
  else if(sum_1<=sum_2)
    printf("%d",sum_1);
         
  return 0;
}

Measured memory_bytes: 256
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
const long long int N = 6999999;
#define all(x) begin(x),end(x)
#define ll long long int
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
using namespace std;
int n,m,ans = 0;
int u[2005][2005],r[2005][2005],l[2005][2005],d[2005][2005];
char s[2005][2005];
int main()
{
 
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i)
  {
     scanf("%s",s[i]+1);
  }
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= m; ++j)
     {
        if (s[i][j] == '.')
        {
          u[i][j] = u[i-1][j]+1;
          l[i][j] = l[i][j-1]+1;
        }
     } 
  }
  for (int i = n; i >= 1; i--)
  {
    for (int j = m; j >= 1; j--)
     {
        if (s[i][j] == '.' )
        {
          d[i][j] = d[i+1][j]+1;
          r[i][j] = r[i][j+1]+1;
        }
     } 
  }
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= m; ++j)
     {
        if (s[i][j] == '.')
        {
          ans = max(ans,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3);
        }
     } 
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 66944
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int sumTime = m * 1900 + (n - m) * 100;
    double p = Math.pow(0.5, m);
    double a = sumTime * p;
    double ans = a;
    for(int i = 1; i <= 10000; i++){
      ans += a * (i + 1) * Math.pow((1 - p), i);
    }
    System.out.println((int)Math.round(ans));
  }
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

ll lcm(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	ll x = a*b;
	ll r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}
	return x/b;
}

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

	int N=in();
	vector<pair<int,int>> P(N);
	REP(i,N){
		P[i].first=in(),P[i].second=in();
	}
	sort(ALL(P),[](pair<int,int>& l,pair<int,int>& r){return l.second==r.second ? l.first<r.first : l.second<r.second;});
	ll sum=0;
	REP(i,N){
		sum += P[i].first;
		if(sum>P[i].second){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
 
int main() {
    int n, W;

    cin >> n >> W;
    int v[n+1], w[n+1];

    for(int i = 0; i < n; i++) cin >> w[i] >> v[i];
    int pivot = w[0];
    for(int i = 0; i < n; i++) w[i] -= pivot;

    ll dp[n+1][n+1][1005];
    memset(dp, -1, sizeof dp);

    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            for(int k = 0; k < 1e3; k++) {
                if(dp[i][j][k] == -1) continue;

                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                dp[i+1][j+1][k+w[i]] = max(dp[i+1][j+1][k+w[i]], dp[i][j][k] + v[i]); 
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
            for(int k = 0; k < 1e3; k++) {
                ll lim = W - 1LL*j*pivot;

                if(k <= lim) ans = max(ans, dp[i][j][k]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 80384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n; cin >> n;

    int ans = (0+n-1) * n / 2;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int main() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i ++){
        if (s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3628
s = str(input())
n = len(s)
ps1 = s[:int((n-1)/2)]
ps2 = s[int((n+3)/2)-1:]

if s == s[::-1] and ps1 == ps1[::-1] and ps2 == ps2[::-1]:
    print("Yes")
else:
    print("No")


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    if(N%2){
        cout << N*2 << endl;
    }
    else{
        cout << N << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

// https://atcoder.jp/contests/abc147/submissions/15394248
const int N = 83;
int dp[N][N][4 * N * N];
void solve() {
    int h, w;
    cin >> h >> w;
    
    vector<vector<int> > a(h + 1, vector<int>(w + 1));
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) { int b; cin >> b; a[i][j] -= b; }
    
    dp[0][0][2 * N * N + a[0][0]] = 1;
    rep(i, h) rep(j, w) {
        rep(k, 4 * N * N) {
            if (dp[i][j][k] == 0) continue;
            dp[i + 1][j][k + a[i + 1][j]] = 1;
            dp[i][j + 1][k + a[i][j + 1]] = 1;
            dp[i + 1][j][k - a[i + 1][j]] = 1;
            dp[i][j + 1][k - a[i][j + 1]] = 1;
        }
    }
    int ans = inf;
    rep(k, 4 * N * N) if (dp[h - 1][w - 1][k]) chmin(ans, abs(2 * N * N - k));
    cout << ans << endl;
}



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

int main(void) {
    int n, a[100], t, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            t = abs(a[i] - a[j]);
            ans = max(ans, t);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())
A = [int(i) for i in input().split()][::-1]

cb, cu = 2, 2
for a in A:
    nb = ((cb+a-1)//a)*a
    nu = (cu//a+1)*a-1
    if nb > cu:
        print(-1)
        exit()
    cb, cu = nb, nu
print(nb, nu)


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


int main() {
  string o,e; cin >> o >> e;
  int x; x = o.size();
  int y; y = e.size();
  int n; n = x + y;
  string pass;
  
  
  for(int i=0; i < n; i++){
    if(i % 2 == 1){
      pass += e.at(i/2);
    }
    else{
      pass += o.at(i/2);
    }
  }
  
  cout << pass << endl;
}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vii A(N);
  vi B(N);
  rep(i,0,N) cin>>B[i];
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    A[X-1].pb(Y-1);
    A[Y-1].pb(X-1);
  }
  int ans=0;
  vector<bool> F(N,1);
  rep(i,0,N){
    if(F[i]){
      F[i]=0;
      queue<int> Q;
      Q.push(i);
      set<int> S,T;
      S.insert(i);
      T.insert(B[i]-1);
      while(Q.size()>0){
        int K=Q.front();
        Q.pop();
        rep(j,0,A[K].size()){
          int P=A[K][j];
          if(F[P]){
            Q.push(P);
            F[P]=0;
            S.insert(P);
            T.insert(B[P]-1);
          }
        }
      }
      for(auto p:S){
        if(T.count(p))
          ans++;
      }
    }
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 15872
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

const int M = 998244353;
const int maxn = 300100;

int f[maxn], rf[maxn];

int n, a, b, k;

int ans;

int power(int x, int y)
{
  int ret = 1;
  while (y)
    {
      if (y & 1ll)
	ret = ret * x % M;
      x = x * x % M;
      y >>= 1;
    }
  return ret;
}

int c(int x, int y)
{
  return ((f[x] * rf[y]) % M * rf[x - y]) % M;
}

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

  f[0] = 1;
  for (int i = 1; i < maxn; i ++)
    f[i] = f[i - 1] * i % M;
  rf[maxn - 1] = power(f[maxn - 1], M - 2);
  for (int i = maxn - 1; i --;)
    rf[i] = rf[i + 1] * (i + 1) % M;
  
  cin >> n >> a >> b >> k;

  for (int j, i = 0; i <= n; i ++)
    {
      int s = i * a;
      if (s <= k)
	{
	  s = k - s;
	  if (s % b == 0)
	    {
	      j = s / b;
	      if (j <= n)
		ans = (ans + c(n, i) * c(n, j) % M) % M;
	    }
	}
    }

  cout << ans << endl;
  
  return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n, k;
    cin >> n >> k;
    vector<int32> p(n);
    REP(i,n)cin >> p[i];
    vector<int32> mn(n - k + 1);
    deque<int32> deq;
    REP(i,n){
        while(!deq.empty() && p[deq.back()] >= p[i]){
            deq.pop_back();
        }
        deq.push_back(i);
        if(i >= k - 1){
            mn[i - k + 1] = p[deq.front()];
            if(i - k + 1 == deq.front())deq.pop_front();
        }
    }
    vector<int32> mx(n - k + 1);
    deq.resize(0);
    REP(i,n){
        while(!deq.empty() && p[deq.back()] <= p[i]){
            deq.pop_back();
        }
        deq.push_back(i);
        if(i >= k - 1){
            mx[i - k + 1] = p[deq.front()];
            if(i - k + 1 == deq.front())deq.pop_front();
        }
    }
    vector<int32> invertCnt(n-k+2,0);
    REP(i,n-1){
        if(p[i] > p[i+1]){
            invertCnt[max<int32>(0, i - k + 2)]++;
            invertCnt[min<int32>(n-k+1, i + 1)]--;
        }
    }
    REP(i, n-k+1)invertCnt[i + 1] += invertCnt[i];
    int32 ans = n - k + 1;
    int32 sorted = 0;
    if(invertCnt[0] == 0)sorted++;
    REP(i, n-k){
        if(mn[i] == p[i] && mx[i+1] == p[i+k]){
            ans--;
        }else if(invertCnt[i+1] == 0){
            sorted++;
        }
    }
    if(sorted >= 2){
        ans -= sorted - 1;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>

int main(){
  int n, d;
  int i,j,k;

  int num=0, ans =0;

  scanf("%d %d",&n, &d);
  int A[n][d];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&A[i][j]);
    }
  }
  int S[100] = {};

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(k=0;k<d;k++){
        S[num] += (A[i][k] - A[j][k])*(A[i][k] - A[j][k]);
      }
      num++;
    }
  }

  for(j=0;j<num;j++){
    for(i=0;i<150;i++){
      if(i*i==S[j]){
        ans++;
        break;
      }
      if(i*i>S[j]){break;}
    }
  }

  printf("%d\n",ans);


  return 0;
}


Measured memory_bytes: 128