akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
int main()
{
	long int L, R, i, j, min_temp ;
	int min= 2019;
 
	scanf("%ld", &L);
	scanf("%ld", &R);
 
	if(R-L >= 2019-1){
		min = 0;
		printf("%d", min);
		return 0;
	}
 
	for(i=L; i<=R-1; i++){
		for(j=i+1; j<=R; j++){
			if((i*j)%2019 < min){
				min = (i*j)%2019;
			}
		}
	}
	
	printf("%d", min);		
 
	return 0;
}

Measured memory_bytes: 128
import sys 
sys.setrecursionlimit(2147483647)

memo = [float("inf")]*100005

def rec(n):
    if n==0:
        return 0
    if memo[n]!=float("inf"):
        return memo[n]
    res = float("inf")
    val = 1
    while val<=n:
        res = min(res,rec(n-val)+1)
        val*=6
    
    val = 1
    while val<=n:
        res = min(res,rec(n-val)+1)
        val*=9
    memo[n]=res
    return memo[n]

if __name__ == "__main__":
    N = int(input())
    print(rec(N))

Measured memory_bytes: 94504
#include <bits/stdc++.h>
#include <string>
#define INF 100000
using namespace std;
int sx, sy;
typedef long long ll;
ll H, W,N;
int main(){
    cin >> N;
    vector<ll> l(N);
    for(int i=0;i<N;i++){
        cin >> l[i];
    }
    ll totans=N*(N-1)*(N-2);
    totans /= 6;
    sort(l.begin(),l.end(),greater<int>());
    for(ll i=0;i<N-2;i++){
        for(ll j=i+1;j<N-1;j++){
            for(ll k=j+1;k<N;k++){
                if(l[i]>=l[j]+l[k]){
                    totans = totans - (N-k);
                    break;
                }
            }
        }
    }
    cout << totans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

int main(){
	
	int A,B;
	cin>>A>>B;
	
	cout<<max(0,A-2*B)<<endl;
	
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  ll n,c=0,y,i,k=0;
  cin>>n;
  for(i=1;i<=n;i++)
  {
  	y=i;
  	while(y>0)
  	{
  	y=y/10;
  	c++;	
  	}
  	if(c%2!=0)
  	k++;
  	c=0;
  }
  cout<<k<<endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

string tree[1024];

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

  int N;
  while (cin >> N, N) {
    REP(i, N) cin >> tree[i];

    int last_dot = 0;
    FOR(i, 1, N) {
      last_dot = min(last_dot, (int)tree[i].size()-1);
      if (tree[i][last_dot] == '.') {
	if (tree[i][last_dot+1] == '.') last_dot++;
	tree[i][last_dot] = '+';
	for (int j = last_dot-1; j >= 0; j--) tree[i][j] = ' ';
	
      } else {
	while (tree[i][last_dot] != '.') last_dot--;
	for (int j = last_dot-1; j >= 0; j--) tree[i][j] = ' ';
	tree[i][last_dot] = '+';
	for (int j = i-1; j >= 0 && tree[j][last_dot] == ' '; j--) tree[j][last_dot] = '|';
      }
    }
    REP(i, N) cout << tree[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1800
#include <iostream>
#include <vector>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

static const int N = 1000;
static const int INF = 1e+9 + 7;
vector<P> prime;

void findPrimeNumber(){
    for(int i = 2; i < N; i++){
        bool flag = true;
        for(int j = 2; j < i; j++){
            if(i % j == 0) flag = false;
        }
        if(flag) prime.push_back(make_pair(i, 0));
    }
    return;
}

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

    findPrimeNumber();

    for(int i = 1; i <= n; i++)
        rep(j, prime.size()){
            int p = prime[j].first, copy = i;
            if(p > i) break;
            while(copy % p == 0){
                prime[j].second++;
                copy /= p;
            }
        }

    ll ans = 1;
    rep(i, prime.size()){
        ans = ans * (prime[i].second + 1) % INF;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD           1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define endl "\n"
#define PI 3.14159265358979323846264338327950L
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int fc[100001], in[100001];
/*int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}*/

/*void dfs(int i,int par)
{
	for(int x:adj[i])
	{
		if(x!=par)
		{
			dfs(x,i);
		    sub[i]+=sub[x];
		}
	}
}*/
int pow(int a, int b, int m)
{
	int ans = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans % m;
}
/*vector<int> sq(5002);
void pre()
{
	for (int i = 0; i <= 5000; ++i)
		sq.pb(i * i);
}*/

bool compare(pair<int, pair<int, int>> a, pair<int, pair<int, int>> b)
{
	if (a.ss.ff != b.ss.ff)
		return (a.ss.ff > b.ss.ff);
	else
		return (a.ff < b.ff);
}
bool comp(string a, string b)
{
	if (a.size() == b.size())
		return a < b;
	return a.size() < b.size();
}
int32_t main()
{
	FIO;
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> c(100005);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		c[a[i]]++;
	}

	int sum = 0;

	for (int i = 0; i < 100005; i++)
		sum += c[i] * i;

	int q;
	cin >> q;

	while (q--)
	{
		int b, c1;
		cin >> b >> c1;

		sum -= (c[b] * b);
		sum += (c[b] * c1);
		c[c1] += c[b];
		c[b] = 0;

		//for (int i = 1; i <= 4; i++)
		//	cout << c[i] << "hii" << endl;
		cout << sum << endl;
	}

}


Measured memory_bytes: 4820
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define FOR(i,a,b)      for(int i=a;i<b;i++)
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void solve(){
  int n , k;
  cin >> n >> k;
  vector<int> a (n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<bool> dp (k + 1);
  int first = 0;
  int second = 1;
  dp[0] = second;
  for (int i = 1; i <= k; i++){
    dp[i] = second;
    for (int ch = 0; ch < n; ch++){
      if (i - a[ch] >= 0 && dp[i - a[ch]] == second) {
        dp[i] = first;
        break;
      }
    }
  }
  if (dp[k] == first) cout << "First\n";
  else cout << "Second\n";
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#pragma warning(disable : 4996)

using namespace std;

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

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

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

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int a, b, c;
	
	cin >> a >> b >> c;
	
	int f = 0;
	
	if (a > 1){
		REP(i,55){
			if ((a*i)%b == c){
				f = 1;
				break;
			}
		}
	}
	else f = 1;
	
	if (f) cout << "YES" << endl;
	else cout <<"NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,b,s;
  while(cin>>s,s){
    int a[10]={0};
    while(s--){
      cin>>b;
      a[b]++;
    }
  r(i,10){
    if(a[i])r(j,a[i])cout<<'*';
    else cout<<'-';
    cout<<endl;
  }
}
}

Measured memory_bytes: 3000
#include<bits/stdc++.h>
#include<sstream>
#include<string>
using namespace std;
#define rep(i,ii,n) for(int i=ii;i<n;i++)
#define inf INT_MAX
#define mod (1000000007LL)
#define ll long long 
#define ull unsigned long long 
#define all v.begin(),v.end()
#define vi vector<int>
#define pb push_back

int main(){ 
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
    



 return 0;   
}//main



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int N,M,a[2000],b[2000];
vector <int>connect[50];
int path[50]={0};
int node=1;
int passed[50]={0};

int dfs(int current,int na,int nb){
  int sum(0);
  passed[current]=1;
  bool all(true);
  for (int i(0);i<N;i++){
    if (passed[i]!=1)all=false;
  }
  if (all==true)return 1;
  for (int i(0);i<connect[current].size();i++){
    int next=connect[current][i];
    if (passed[next]==1)continue;
    if ((current==na&&next==nb)||(current==nb&&next==na)) continue;
    sum+=dfs(next,na,nb);
  }
  passed[current]==0;
  if (sum!=0) return 1;
  else return 0;
}
 
int main() {
  cin>>N>>M;
  for (int i(0);i<M;i++){
    cin>>a[i]>>b[i];
    connect[a[i]-1].push_back(b[i]-1);
    connect[b[i]-1].push_back(a[i]-1);
  }
  int ans(0);
  for (int i(0);i<M;i++){
    for (int i(0);i<N;i++)passed[i]=0;
    ans += dfs(0,a[i]-1,b[i]-1);
    // cout << ans<< " ";
  }
  cout << M-ans <<endl;
}


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

int main() {
  int N;
  cin >> N;
  int M;
  if (N%1000!=0) {
    M=abs((N/1000+1)*1000-N);
  }
  if (N%1000==0) {
    M=0;
  }
  cout << M << endl;
}

Measured memory_bytes: 3632
import bisect
import sys
input=sys.stdin.readline
n=int(input())
lst=sorted(map(int,input().split()))
s=sum(lst)
sum_lst=[0]
for i in range(1,10**5+1):
    sum_lst.append(bisect.bisect_right(lst,i)-bisect.bisect_left(lst,i))
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    s+=((c-b)*sum_lst[b])
    print(s)
    sum_lst[c]+=sum_lst[b]
    sum_lst[b]=0

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

int main()
{
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	int A[N][M];
	int sum = 0;
	int answers = 0;
	for (int i = 0; i < M; i++)
	{
		cin >> B.at(i);
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cin >> A[i][j];
			sum += A[i][j] * B.at(j);
		}
		sum += C;

		if (sum > 0)
		{
			answers++;
		}
		sum = 0;
	}
	cout << answers << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	int n,m,p;
	cin>>n>>m>>p;
	vector<mp> a(m);
	for(int i=0;i<m;i++){
		int d;
		cin>>d;
		int c = (d-p+n)%n;
		a[i] = mp( c, n-c);
	}
	sort(a.begin(),a.end() );
	ll res = min(a[m-1].first,a[0].second);
	for(int i=0;i<m-1;i++){
		res = min(res, min(a[i].first*2 + a[(i+1)].second,a[i].first + a[i+1].second*2) );
	}
	cout<<res*100<<endl;

	return 0;
}



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

#define int long long

int32_t main(){
	int n , w ;
	cin >> n >> w ;
	int dp[w+1] = {} ;
	for(int i = 0 ; i < n ; i++){
		int x , y ; 
		cin >> x >> y ;
		for(int j = w - x ; j >= 0 ; j--){
			dp[j+x] = max(dp[j+x] , dp[j] + y) ;
		}
	}
	cout << dp[w] ;
	return 0 ;
}



Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
#define pii pair< ll,ll>
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define mp make_pair
#define ll long long int
#define mod 1000000007
#define mxn 2000002
#define sqr 320
ll num[100000]={0},pro[100000]={0},rel[100000]={0} , kk [100000];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,i,m;
    cin>>n>>m;
    ll l , r, d;
    for(i=0;i<m;i++)
     {
        cin>>l>>r>>d;
        ll po = l ,to =r;
        ll dis1=0,dis2=0;
        while(num[po])
            {
                dis1+=pro[po];
                po=num[po];
            }
        while(num[to])
            {
                dis2+=pro[to];
                to=num[to];
            }
        if(po==to)
        {
            if(dis2-dis1!=d)
            {
                cout<<"No";
                return 0;
            }
            continue;
        }
        if(dis2<=d)
        {
         num[to]=po;
         pro[to]=d-dis2+dis1;
        }
        else
        {
            if(dis2>=dis1+d)
            {
                num[po]=to;
                pro[po]=dis2-dis1-d;
            }
            else
            {
              num[to]=po;
              pro[to]=dis1+d-dis2;
            }
        }
     }
     cout<<"Yes";
         return 0;
    }

Measured memory_bytes: 1792
N,A,B = map(int, input().split())
H = []
for _ in range(N):
  H.append(int(input()))

def is_ok(arg):
  # 条件を満たすかどうか？問題ごとに定義
  cnt = 0
  C = A-B
  for h in H:
    wk = h - B*arg
    if wk<0:
      continue
    else:
      cnt += (wk+C-1) // C
  return cnt <= arg

def meguru_bisect(ng, ok):
  '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
  '''
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

ng = 0
ok = 10**16

print(meguru_bisect(ng,ok))

Measured memory_bytes: 13096
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string n;
    cin>>n;
    int b=0,e;
    e=n.size()-1;
    while(b<e){
        if(n[b]!=n[e]) {
            cout<<"No"<<endl;
            return 0;
    }
    b++;
    e--;
    }
    cout<<"Yes"<<endl;
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e5+5,mod=1e9+7,inf=0x3f3f3f3f;
ll ans,s;
ll fac[maxn],inv[maxn];
ll qpow(ll a,ll b){
    ll ans=1,base=a;
    while(b){
        if(b&1){
            ans=ans*base%mod;
        }
        base=base*base%mod;
        b=b>>1;
    }
    return ans;
}
ll cal(ll a,ll b){
//    if(a<b) return 0;
    return fac[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(){
    fac[0]=inv[0]=1;
    for(int i=1;i<=4000;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=qpow(fac[i],mod-2);
    }
    scanf("%lld",&s);
    for(int i=1;i<=s/3;i++){
        ll rest=s-i*3;
//        cout<<rest<<endl;
//        cout<<i+rest-1<<" "<<i-1<<endl;
        ans=(ans+cal(i+rest-1,i-1))%mod;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3904
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	double a;
	cin >> a;
	cout << fixed << setprecision(10) << a * acos(-1) * 2 << endl;	
	
}





Measured memory_bytes: 3796
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[305];
llint dp[45][2][3];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint b = 0;
	for(int i = 3; i <= n; i++) b ^= a[i];
	
	for(int i = 44; i >= 0; i--){
		for(int j = 0; j < 2; j++){
			for(int k = -1; k <= 1; k++){
				dp[i][j][k+1] = inf;
			}
		}
	}
	dp[44][0][0+1] = 0;
	
	for(int i = 44; i > 0; i--){
		llint c = (a[1]>>(i-1))&1LL, d = (a[2]>>(i-1))&1LL, y = (b>>(i-1))&1LL;
		for(int j = 0; j < 2; j++){
			for(int k = -1; k <= 1; k++){
				//cout << i << " " << j << " " << k << " " << dp[i][j][k+1] << endl;
				for(int p = 0; p < 2; p++){
					for(int q = 0; q < 2; q++){
						if(y != (p+q)%2) continue;
						if(j == 0 && d > q) continue;
						llint nj = j;
						if(d < q) nj = 1;
						llint s = (q-d) + (p-c);
						
						llint nk;
						if(k == -1){
							if(s == 2) nk = 0;
							else if (s == 1) nk = -1;
							else continue;
						}
						if(k == 1){
							if(s == -2) nk = 0;
							else if (s == -1) nk = 1;
							else continue;
						}
						if(k == 0){
							if(abs(s) == 2) continue;
							nk = s;
						}
						chmin(dp[i-1][nj][nk+1], dp[i][j][k+1] + (q-d)*(1LL<<(i-1)));
					}
				}
			}
		}
	}
	
	/*for(int j = 0; j < 2; j++){
		for(int k = -1; k <= 1; k++){
			cout << 0 << " " << j << " " << k << " " << dp[0][j][k+1] << endl;
		}
	}*/
	
	llint ans = min(dp[0][0][0+1], dp[0][1][0+1]);
	if(ans > inf/2) ans = -1;
	if(ans == a[1]) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N, M;
	cin >> N >> M;
	cout << abs((N - 2)*(M - 2)) << endl;
}








Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(array, 10, sizeof(int), compare_int)

int main(){
	int n, array[120], count=0;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &array[i]);
		if((i%2==0) && (array[i]%2==1)) count++;
	}
	
	printf("%d\n", count);
	
	
	return 0;
}



Measured memory_bytes: 1736
# https://atcoder.jp/contests/abc116/tasks/abc116_d

Sushi = Struct.new(:t, :d, :max)

N, K = gets.split.map(&:to_i)
vs = Array.new(N)
N.times do |i|
  vs[i] = Sushi.new(*gets.split.map(&:to_i), false)
end

vs
.group_by { |v| v.t }
.each do |k, ws|
  ws.sort_by { |w| w.d }.last.max = true
end

xs, os = vs.partition { |v| v.max }.map { |vs| vs.sort_by { |v| -v.d }}

xacc = xs.each_with_object([0]) { |x, arr| arr.push(arr.last + x.d) }
oacc = os.each_with_object([0]) { |o, arr| arr.push(arr.last + o.d) }

ans = 0
1.upto(K) do |i|
  next unless xacc[i] && oacc[K - i]
  ans = [ans, xacc[i] + oacc[K - i] + i * i].max
end

puts ans


Measured memory_bytes: 25848
#include<bits/stdc++.h>
using namespace std;
#define re register
#define in inline
#define get getchar()
#define ll long long
in ll read()
{
	ll t=0,x=1; char ch=get;
	while((ch<'0'||ch>'9')&&ch!='-')ch=get;
	if(ch=='-')ch=get,x=-1;
	while(ch<='9'&&ch>='0')t=t*10+ch-'0',ch=get;
	return t*x;
}
const int _=1e6+5;
ll h[_],n,tot,m,d[_],fa[_];ll ans[_];
struct edge{
	int x,y;
}e[_];
in int find(int x)
{
	if(x==fa[x])return x;
	int k=fa[x];
	fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
	n=read(),m=read();
	for(re int i=1;i<=m;i++)e[i].x=read(),e[i].y=read();
	for(re int i=1;i<=n;i++)d[i]=1,fa[i]=i;
	ans[m+1]=(n-1)*n/2;
	for(re int i=m;i>=1;i--)
	{
		int x=e[i].x,y=e[i].y;
		int fx=find(x),fy=find(y);
		ans[i] = ans[i + 1];
		if(fx==fy)continue;
		ans[i]-=d[fx]*d[fy];
		fa[fx]=fy;
		d[fy] += d[fx];
	}
	for(re int i=2;i<=m+1;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 14336
n = int(input())
a = list(int(i) for i in input().split())  
ctplus = 0
ctminu = 0
checksum = 0
for i in range(n):
  checksum += a[i]
  if i%2 ==0:
    if checksum <= 0:
      ctplus += abs(checksum)+1
      checksum += abs(checksum)+1
  else:
    if checksum >= 0:
      ctplus += abs(checksum)+1
      checksum -= (abs(checksum)+1)
checksum = 0
for j in range(n):
  checksum += a[j]
  if j%2 ==1:
    if checksum <= 0:
      ctminu += abs(checksum)+1
      checksum += abs(checksum)+1
  else:
    if checksum >= 0:
      ctminu += abs(checksum)+1
      checksum -= (abs(checksum)+1)      
print(min(ctplus,ctminu))

Measured memory_bytes: 14468
#include <iostream>
#include <vector>

using namespace std;

void print_attr(vector<int> v) {
 for(int i = 0;i < v.size();i++) {
  cout << v.at(i);
 
  if(i < v.size() - 1)
   cout << " ";
 }
 
 cout << endl;
}

void insertion_sort(vector<int> va) {
 int i, j;
 int tmp;
 
 for(int i = 0;i < va.size();i++) {
  tmp = va.at(i);
  j = i - 1;

  while(0 <= j && va[j]>tmp) {
      va[j + 1] = va[j];
      j--;
  }
   
  va[j + 1] = tmp;
  print_attr(va);
 }
}

int main() {
 int n;
 vector<int> a;

 cin >> n;

 a.resize(n);

 for(int i = 0;i < n;i++) {
  cin >> a[i];
 }
 
 insertion_sort(a);
 
 return 0;
}

 

Measured memory_bytes: 3160
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Program
  {
    public static void Main()
    {
      var w = int.Parse(Console.ReadLine());
      int.Parse(Console.ReadLine());
      var lots = Enumerable.Range(1, w).ToArray();
      foreach (var pair in GetNumbers())
        SwapArray(lots, pair[0] - 1, pair[1] - 1);
      foreach (var x in lots)
        Console.WriteLine(x);
    }

    static IEnumerable<int[]> GetNumbers()
    {
      string line;
      while ((line = Console.ReadLine()) != null)
        yield return line.Split(',').Select(s => int.Parse(s)).ToArray();
    }

    static void SwapArray<T>(IList<T> list, int i, int j)
    {
      T tmp = list[i];
      list[i] = list[j];
      list[j] = tmp;
    }
  }
}

Measured memory_bytes: 5904
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;



int main(){
    int N;
    cin >> N;
    vector<int> moti(N);
    vector<int> flag(101);
    int aa;
    for(int i=0;i<N;i++){
        cin >> aa;
        flag.at(aa) = 1;
    }
    
    int count = 0;
    
    for(int j=0;j<101;j++){
        count = count + flag.at(j);
    }

    cout << count << endl;

}

Measured memory_bytes: 256
main = do
  [_, w] <- map read . words <$> getLine
  _ <- getLine
  as <- map read . words <$> getLine
  let zs = zip as [1 ..]
  f w (g zs) 0
 
g [] = []
g (z:zs) = (take a . repeat $ show n) ++ g zs
  where (a, n) = z
 
f w cs p
  | cs == [] = putStr ""
  | p == 0 = (putStrLn $ unwords as) >> f w bs 1
  | p == 1 = (putStrLn . unwords $ reverse as) >> f w bs 0
    where (as, bs) = splitAt w cs

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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<bool> s(N, false);
  
  for(int i = 0; i < K; i++){
    int d;
    cin >> d;
    for(int j = 0; j < d; j++){
      int A;
      cin >> A;
      A--;
      s[A] = true;
    }
  }
  
  int p = 0;
  for(int i = 0; i < N; i++) if(!s[i]) p++;
  
  cout << p << endl;
  
  return 0;
}

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

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  string S,T;
  cin>>N>>S>>T;

  for(int i=0;i<N;i++){
    cout<<S.at(i)<<T.at(i);
  }
  cout<<endl;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i32 = read();
    let k: i32 = read();
    println!(
        "{}",
        if (n == 1 || n == 2) && k == 1 {
            "YES"
        } else if n < 3 {
            "NO"
        } else if (n % 2 == 0 && n / 2 >= k) || (n % 2 == 1 && n / 2 + 1 >= k) {
            "YES"
        } else {
            "NO"
        }
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];
	sort(a.begin(), a.end());
	
	int ave;
	int ans = INF;
	for (ave = a[0]; ave <= a[N - 1]; ave++) {
		int ansOne = 0;
		REP(i, N) {
			ansOne += (a[i] - ave) * (a[i] - ave);
		}
		ans = min(ansOne, ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
def main():

    a,b,k = map(int,input().split())
    next = 'a'
    for i in range(k):
        if next == 'a':
            if a % 2 == 1:
                a -= 1
            a = a // 2
            b += a
            next = 'b'
        else:
            if b % 2 == 1:
                b -= 1
            b = b // 2
            a += b
            next = 'a'

    print(a,b)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>

char *str[7] = {"Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"};
int tuki[13] = {0,31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
	int a,b;
	int i,d;
	
	while( scanf("%d%d",&a,&b) ){
		if( a == 0 )break;
		d = 0;
		
		for( i = 0;i < a;i++ ){
			d += tuki[i];
		}
		d += b-1;
		
		printf("%s\n",str[ d%7 ] );
	}
	return 0;
}

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

typedef long long ll;
typedef double lb;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

const int N = 1e6 + 69, mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;

ll n, C;
ll height[200005];

struct line{
        int k = INF;
        ll b;
};

struct bla{
        line ln;
        int left = INF, right = INF;
};

line L;

int tot = 1;
bla tree[N*2];

ll point(ll x, line ln){
        return x*ln.k + ln.b;
}

void upd(int node, int l, int r,line new_line){
        //cout << node << " " << l << " " << r << " " << tree[node].left << " " << tree[node].right << " " << new_line.k << " " << new_line.b << endl;

        if(tree[node].ln.k == INF){
                tree[node].ln = new_line;
                return ;
        }

        line old_line = tree[node].ln;

        if(l == r){
                lb y_new = point(l,new_line);
                lb y_old = point(l,old_line);
                if(y_new < y_old){
                        tree[node].ln = new_line;
                }
                return ;
        }

        int mid_point = ((l + r) >> 1);

        bool lef = point(l,new_line) < point(l,old_line);
        bool mid = point(mid_point,new_line) < point(mid_point,old_line);

        if(mid){
                swap(new_line, old_line);
                tree[node].ln = old_line;
        }

        if(tree[node].left == INF){
                tree[node].left = ++tot;
                tree[node].right = ++tot;
        }

        if(lef != mid){
                //tree[tree[node].right].ln = old_line;
                upd(tree[node].left, l, mid_point, new_line);
        } else {
                //tree[tree[node].left].ln = old_line;
                upd(tree[node].right, mid_point+1, r, new_line);
        }
}


ll get(int node, int l, int r, ll x){

        //cout << node << " " << l << " " << r <<" "<< x << endl;
        if(tree[node].left == INF){
                return point(x,tree[node].ln);
        }

        int mid = ((l+r) >> 1);

        ll y = point(x,tree[node].ln);

        if(mid >= x){
                ll y1 = get(tree[node].left, l, mid, x);
                return min(y, y1);
        } else {
                ll y1 = get(tree[node].right, mid+1, r, x);
                return min(y, y1);
        }
}

int main(){

        ios::sync_with_stdio(0);

        cin >> n >> C;

        for(int i = 1 ; i <= n; i++){
                cin >> height[i];
        }

        L.k = -2*height[1];
        L.b = height[1]*height[1];

        upd(1, 1, N, L);

        for(int i = 2; i <= n; i++){

                ll answer = get(1, 1, N, height[i]);
                answer += height[i]*height[i] + C;

                if(i == n) {
                        cout << answer << endl;
                        return 0;
                }

                //cout << "update ------------------" << endl;
                L.k = -2*height[i];
                L.b = height[i]*height[i] + answer;
                upd(1, 1, N, L);

                //cout << endl;
        }




}



Measured memory_bytes: 48768
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N;
    string S[60];
    int t[60];
    string X;
    
    // 入力
    cin >> N;
    for (int i=0;i<N;i++) cin >> S[i] >> t[i];
    cin >> X;

    int count = 0;
    int flag = 0;
    for (int i=0;i<N;i++) {
        if (flag) {
            count += t[i];
        }
        if (S[i]==X) {
            flag = 1;
        }
    }
    
    cout << count << endl;
    

    
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b != 0:
        t = b
        b = a % b
        a = t
    return a

def lcm(a, b):
    return abs(a*b) / gcd(a, b)

a, b = map(int, input().strip().split(" "))

print(int(lcm(a, b)))

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

#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
    int a, b;
    cin >> a >> b;

    if ((a * b) % 2 == 0) {
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl; 
    }

    return 0;
}

Measured memory_bytes: 3628
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=2e5+5;

int n;
int p[N],x;
struct node{
    long long u,c[2];
    bool operator<(const node& d)const{
        return c[0]*d.c[1]==c[1]*d.c[0]?
            u<d.u:c[0]*d.c[1]<c[1]*d.c[0];
    }
}a[N];

set<node> s;

int f[N];
void init(int lim){FOR(i,0,n)f[i]=i;}
int get(int u){return f[u]==u?u:f[u]=get(f[u]);}

long long ans;

int main(){
    scanf("%d",&n);
    FOR(i,2,n)scanf("%d",&p[i]);
    FOR(i,1,n)scanf("%d",&x),a[i].c[x]++;
    FOR(i,1,n)a[i].u=i;
    FOR(i,1,n)s.insert(a[i]);
    init(n);
    FOR(i,1,n-1){
        node u=*s.rbegin();
        s.erase(u);
        if(get(p[u.u])==0){--i;continue;}
        //printf("(%d,C0=%d,C1=%d)\n",u.u,u.c[0],u.c[1]);
        int fa=get(p[u.u]);
        node v=a[fa];
        //u合并到v上
        s.erase(v);
        a[fa]={v.u,v.c[0]+u.c[0],v.c[1]+u.c[1]};
        f[u.u]=v.u;//merge
        ans+=v.c[1]*1ll*u.c[0];
        s.insert(a[fa]);
    }
    assert(s.size()==1);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
int n;
long long he[2000010],xo[2000010];
int x;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		he[i]=he[i-1]+x;
		xo[i]=xo[i-1]^x;
	}
	int l=1;
	long long res=0;
	for(int r=1;r<=n;r++){
		while((he[r]-he[l-1])!=(xo[r]^xo[l-1]))
			l++;
		res+=(r-l+1);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 6016
#include<iostream>
#include<cstdio>
using namespace std;
int n,x[1010],y[1010],m,ma;
long long ln[101010];
int aabs(int x){ return x<0?-x:x;} 
void print(int X,int Y,int d)
{
	if(!d) return ;
	if(aabs(X)>aabs(Y))
	{
		if(X<0) print(X+ln[d],Y,d-1),putchar('L');
		else print(X-ln[d],Y,d-1),putchar('R');
	}
	else 
	{
		if(Y<0) print(X,Y+ln[d],d-1),putchar('D');
		else print(X,Y-ln[d],d-1),putchar('U');
	}
}
int main()
{
	scanf("%d",&n);
	int fl=-1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		if(fl==-1) fl=(x[i]+y[i])&1;
		else if(((x[i]+y[i])&1)!=fl) return puts("-1"),0;
	}
	if(fl)
	{
		for(int i=1;i<=n;i++) ma=max(ma,aabs(x[i])+aabs(y[i]));
		for(long long l=1;l-1<ma;l<<=1) ln[++m]=l;
		printf("%d\n",m);
		for(int i=1;i<=m;i++) printf("%d ",ln[i]);
		puts("");
		for(int i=1;i<=n;i++)
		print(x[i],y[i],m),puts("");
	}
	else
	{
		for(int i=1;i<=n;i++) ma=max(ma,aabs(x[i])+aabs(y[i]+1));
		for(long long l=1;l-1<ma;l<<=1) ln[++m]=l;
		printf("%d\n1 ",m+1);
		for(int i=1;i<=m;i++) printf("%d ",ln[i]);
		puts("");
		for(int i=1;i<=n;i++)
		printf("D"),print(x[i],y[i]+1,m),puts("");
	}
	return 0;
}
		
		

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int R; cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  } else if (R < 2800) {
    cout << "ARC" << endl;
  } else {
    cout << "AGC" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()	{
  long long h, w;
  cin >> h >> w;
  char img[h][w];
  for (long long i = 0; i < h; i++)	{
    for (long long j = 0; j < w; j++)	{
      cin >> img[i][j];
    }
  }
  for (int i = 0; i < w + 2; i++)	{
    cout << "#";
  }
  cout << endl;
  for (int i = 0; i < h; i++)	{
    cout << "#";
    for (int j = 0; j < w; j++)	{
      cout << img[i][j];
    }
    cout << "#";
    cout << endl;
  }
  for (int i = 0; i < w + 2; i++)	{
    cout << "#";
  }
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define pb push_back
    #define mk make_pair
    #define ft first
    #define sc second
    #define ppb pop_back
    #define sz size
    #define forn(i,a,n) for(i=a;i<n;i++)
    #define M 1000000007
    #define inf 2e18


    int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
        
    ll h,w;
    cin>>h>>w;
    vector<vector<ll>> v(h,vector<ll> (w,0));
    char c;
    for(ll i=0;i<h;i++)for(ll j=0;j<w;j++){ cin>>c; v[i][j]= c=='#'; }
    
    ll dx[4]={1,-1,0,0}, dy[4]={0,0,-1,1};
    ll ans=0;
    for(ll i=0;i<h;i++){

        for(ll j=0;j<w;j++){

            if(v[i][j]) continue;
            queue<pair<ll,ll>> q;
            q.push({i,j});
            ll dist[h][w];
            for(ll k=0;k<h;k++)for(ll l=0;l<w;l++) dist[k][l]=-1;
            dist[i][j]=0;
            while(!q.empty()){
                ll x= q.front().ft , y=q.front().sc;
                q.pop();
                for(ll s=0;s<4;s++){
                    ll nx=x+dx[s], ny=y+dy[s];
                    if(nx<0 || nx>=h || ny<0 || ny>=w) continue;
                    if(v[nx][ny])continue;
                    if(dist[nx][ny]!=-1)continue;
                    dist[nx][ny]= dist[x][y]+1;
                    ans=max(ans,dist[nx][ny]);
                    q.push({nx,ny});
                }
            }
            
        }
    }        
    cout<<ans;
    return 0;
    }

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

type sortRunes []rune

func (s sortRunes) Less(i, j int) bool {
	return s[i] < s[j]
}

func (s sortRunes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s sortRunes) Len() int {
	return len(s)
}

func SortString(s string) string {
	r := []rune(s)
	sort.Sort(sortRunes(r))
	return string(r)
}

func main() {
	input := bufio.NewReader(os.Stdin)

	var N int
	fmt.Fscanf(input, "%d\n", &N)
	m := make(map[string]int)
	for n := 0; n < N; n++ {
		var s string
		fmt.Fscanf(input, "%s\n", &s)
		s = SortString(s)
		m[s]++
	}

	var ans int64
	for _, v := range m {
		tmp := int64(v) * int64(v-1)
		tmp >>= 1
		ans += tmp
	}
	fmt.Println(ans)
}


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

using namespace std;
typedef long long ll;
const int MAXN = 1000100;

int N;
int arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N;

    int cres = 0;
    int ck = 0;
    int cm = 0;
    for (int i = 0; i < N; i++)
    {
        char c; cin >> c;
        arr[i] = c - '1';

        if (arr[i] == 1) ck = -1e9;

        if (cm == 0)
        {
            //cout << i << " " << arr[i] << "\n";
            cres = (cres + arr[i]) % 2;
            ck = (ck + arr[i] / 2);
        }

        if (i == N - 1) continue;

        int dv = N - 1 - i;
        while (dv % 2 == 0)
        {
            dv /= 2;
            cm++;
        }
        dv = i + 1;
        while (dv % 2 == 0)
        {
            dv /= 2;
            cm--;
        }
    }

    if (ck >= 0)
        cout << 2 * (ck % 2) << "\n";
    else
        cout << cres % 2 << "\n";
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,t,k,ans=0;
	cin>>n>>k;
	ans+=(n-1)/(k-1);
	if((n-1)%(k-1))ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, x, ans = 0;
  scanf("%lld%lld", &n, &x);
  ans = n;
  n = n - x;
  while(x) {
    ans += n / x * x * 2;
    ll t = n % x;
    n = x, x = t;
  }
  printf("%lld", ans - n);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define INF 10000000

int main(void)
{
	double A[10] = {35.50, 37.50, 40.00, 43.00, 50.00, 55.00, 70.00, INF};
	double B[10] = {71.00, 77.00, 83.00, 89.00, 105.00, 116.00, 148.00, INF};
	char rank[10][5] = {"AAA", "AA", "A", "B", "C", "D", "E", "NA"};
	double yA, yB;
	int i, rA, rB;
	
	while (scanf("%lf%lf", &yA, &yB) != EOF){
		for (i = 0; i < 8; i++){
			if (yA < A[i]){
				rA = i;
				break;
			}
		}
		for (i = 0; i < 8; i++){
			if (yB < B[i]){
				rB = i;
				break;
			}
		}
		
		printf("%s\n", rank[rA > rB ? rA : rB]);
	}
	
	return (0);
}

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

int main() {

	string S;
	cin >> S;

	int sum = 0;
	for (int i = 0; i < 4; i++) {
		if (S.at(i) == '+') sum += 1;
		else sum -= 1;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

int check_freq(std::vector<int> v) {
	if (v[0] != 0) {
		return 0;
	}
	
	int pro = 0;
	for (std::vector<int>::iterator itr = v.begin(); itr != v.end(); ++itr) {
		if ( (*itr - pro) > 1 ) {
			return pro+1;
		}
		else {
			pro = *itr;
		}
	}

	return -1;
}

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

	std::vector<int> d;
	std::vector<int> data(n);
	for (int i = 0; i < n; i++) {
		cin >> data[i];
		d.push_back(data[i]);
	}

	std::sort(d.begin(), d.end());
	int ret = check_freq(d);
	if (!(ret < 0)) {
		cout << ret << endl;
	}

	int num;
	for (int k = 2; k < n+1 && ret < 0; k++) {

		for (int i = 0; i < n-k+1; i++) {
			num = 0;
			for (int j = 0; j < k; j++) {
				num += data[i+j] * pow(10,k-j-1);
			}
			d.push_back(num);
		}

		std::sort(d.begin(), d.end());
		ret = check_freq(d);
		if (ret > 0) {
			cout << ret << endl;
		}
	}

	if (ret < 0) {
		cout << d[d.size()-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3376
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}

int main()
{
	ios::sync_with_stdio(false);
	int x;
	cin>>x,cout<<x*x<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

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

typedef long long ll;
// #define int ll
#define pb push_back
const int INF = 1e9;

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);


	string s; cin>>s;

	int n = s.size();
	vector<int> dp(2019,0), next(2019,0);
	int ans = 0;
	for(int i=0;i<n;i++){
		next.assign(2019,0);
		int cur = s[i] - '0';
		next[cur] = 1;
		for(int j=0;j<2019;j++){
			next[(10*j + cur)%2019] += dp[j];
		}

		for(int j=0;j<2019;j++)
			dp[j] = next[j];

		ans += dp[0];

	}	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,l,k,i,j,kk;
    scanf("%d %d",&n,&m);
    kk=0;
    for(i=0;i<m;i++)
    {
        scanf("%d",&k);
        kk+=k;
    }
   if(kk>=n)
    printf("Yes\n");
   else
    printf("No\n");
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    // Your code here!
    val n = readLine()!!.split(" ").map(String::toInt)
    val v = readLine()!!.split(" ").map(String::toInt)
   val c = readLine()!!.split(" ").map(String::toInt)
   var ans = 0;
   for(i in 0..n[0]-1)
   {
   if(v[i]>c[i]) 
   {
   ans += v[i]-c[i]
   }
   }
    println(ans)
}

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

int main() {
  int N, M, k, a1, a2, b1, b2, c1, c2, d1, d2, e1, e2;
  cin >> N, 
  a1 = N + N * N + N * N * N;
  cout << a1 << endl;
  
  
  
  
 
}




Measured memory_bytes: 3608
n,k=map(int,input().split())
s=input()
wa=[]
now=1
cnt=0
for i in range(n):
    if s[i]==str(0+now):
        cnt+=1
    else:
        wa.append(cnt)
        now=1-now
        cnt=1
if cnt!=0:
    wa.append(cnt)

if len(wa)%2==0:
    wa.append(0)

add=2*k+1
ans=0
s=[0]*(len(wa)+1)
for i in range(len(s)-1):
    s[i+1]=s[i]+wa[i]




for i in range(0,len(wa),2):
    left=i
    right=min(i+add, len(wa))
    tmp=s[right]-s[left]

    ans=max(tmp,ans)
print(ans)


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back



int main(){
    int n,k;
    cin >> n >> k;
    int count=1;
    int ans=1;
    while(true){
        if(count*k>n){
            break;
        }
        count=count*k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256