akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

C = [-1] * N
C[0] = 0
for n in range(1, N):
    for m in range(max(0, n-K), n):
        C[n] = abs(H[n] - H[m]) + \
            C[m] if C[n] < 0 else min(abs(H[n] - H[m]) + C[m], C[n])

print(C[N-1])


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

void solve(long long A, long long B)
{
    cout << ((A > 12) ? B : ((A >= 6) ? B / 2 : 0)) << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){

    int H, W;
    int x = 0;
    int y = 0;

    cin >> H >> W;

    while(H != 0 && W != 0){
        if(y == 0){
            while(x != W){
                cout << '#';
                x++;
            }
            cout << endl;
            x = 0;
            y++;
        }
        while(y != H-1){
            if(x == 0){
                cout << '#';
                x++;
            }
            while(x != W-1){
                cout << '.';
                x++;
            }
            cout << '#';                
            cout << endl;
            x = 0;
            y++;
        }
        while(x != W){
            cout << '#';
            x++;
        }
        cout << endl << endl;
        cin >> H >> W;
        x = 0;
        y = 0;
    }

    return 0;
}


Measured memory_bytes: 3100
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200005],s[200005],sp[200005];
int main()
{
 
    int n,m,i,j,sum=1,p=0,x;
    memset(s,0,sizeof s);
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    x=a[0];
    a[n]=-1;
    for(i=1;i<n+1;i++)
    {
    	if(a[i]==x)
    	sum++;
    	else
    	{
	    	s[x]=sum;
	    	x=a[i];
	    	sum=1;
	    }
    }
    sort(s,s+200005);
    for(i=0;i<200005;i++)
    {
        if(s[i]==0)continue;
        else
            sp[p++]=s[i];
    }
    //printf("p:%d\n",p);
    if(p<=m)
        printf("0\n");
    else
    {
        int so=0;
        for(i=0;i<p-m;i++)
        {
            so+=sp[i];
        }
        printf("%d\n",so);
    }
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  cin >> n;
  ll ans = 0;
  REP(i, n){
    if((i+1)%3 == 0 || (i+1)%5 == 0) continue;
    ans += i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3676
n, m = map(int, input().split())
start, end = [], []
for _ in range(m):
    t1, t2 = map(int, input().split())
    if t1==1:
        start.append(t2)
    if t2==n:
        end.append(t1)

start, end = set(start), set(end)
if len(start)+len(end)==len(start | end):
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 32588
#include "bits/stdc++.h"
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(ll i=0;i<n;++i)
#define END(x) (*(x.end()-1))
#define INF (INT_MAX / 2)
#define VEC2(type,name,w,h) vector<vector<type>>name(h,vector<type>(w))

using namespace std;
typedef long long ll;


template<typename T>
T gcd(T a, T b){
   if (a%b == 0){
       return(b);
   }
   else{
       return(gcd(b, a%b));
   }
}

template<typename T>
T lcm(T a,T b){
    return a/gcd(a,b)*b;
}

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        a[i+1]=gcd(a[i],a[i+1]);
    }
    cout<<a[n-1];
}
/*
*/

Measured memory_bytes: 3900
#include <stdio.h>
#include <queue>
using namespace std;
typedef pair<int,int> P;

int main()
{
	int x,y;
	char map[100][101];
	bool visited[100][100];
	char mapkind[5] = {"><^v"};
	int tx[4] = {1,-1,0,0},ty[4] = {0,0,-1,1};
	queue<P> que;
	P now;

	scanf("%d%d",&y,&x);

	while(x != 0 && y != 0){
		for(int i = 0; i < y; i++){
			for(int j = 0; j < x; j++){
				visited[i][j] = false;
			}
		}
		for(int i = 0; i < y; i++){
			scanf("%s",map[i]);
		}

		now.first = 0; now.second = 0;
		que.push(now);

		while(!que.empty()){
			now = que.front();
			for(int i = 0; i < 4; i++){
				if(map[now.second][now.first] == mapkind[i]){
					if(!visited[now.second + ty[i]][now.first + tx[i]] ){
						visited[now.second + ty[i]][now.first + tx[i]] = true;
						now.second += ty[i];
						now.first += tx[i];
						que.push(now);
						break;
					}
				}
			}
			que.pop();
		}

		if(map[now.second][now.first] == '.'){
			printf("%d %d\n",now.first,now.second);
		}
		else{
			printf("LOOP\n");
		}

		scanf("%d%d",&y,&x);
	}
	
	
	return 0;
}

Measured memory_bytes: 1088
use proconio::input;
use proconio::marker::Usize1;
use petgraph::unionfind::UnionFind;
use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        m: usize,
        bri: [(Usize1, Usize1); m], 
    }

    let mut uf = UnionFind::new(n); 
    let mut set = HashSet::new();

    for &b in &bri {
        uf.union(b.0, b.1);
    }

    for i in 0..n {
        set.insert(uf.find(i));
    }

    println!("{}", set.len() - 1);


}



Measured memory_bytes: 6244
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
//#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)

int main(){
    int x, y;cin>>x>>y;
    cout << x + y/2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <cmath>
#include <math.h>
#include <iomanip>
using namespace std;


int main()
{
    int n;
    cin >> n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    double sum = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            sum+=sqrt(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2));
        }
    }
    double ans = sum/n;
    cout << setprecision(9) << ans;

}



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


int main(){
    
    int ans=0,i,j,k,n,m,D,t;
    string s;  
    cin>>n>>k;
    while(n>0){
        ans+=1;
        n=n/k;
    }
    cout<<ans;
    
   // cout<<"YES"<<endl;
  //  cout<<"NO"<<endl;
   // cout<<"Yes"<<endl;
   // cout<<"No"<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){

    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){

    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){

    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

/*
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
	rfact[800000] = rui(fact[800000],mod - 2);
	for(ll i=800000; i>=1; i--){
	   rfact[i-1] = rfact[i] * i;
	   rfact[i-1] %= mod;
	}
	return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;}
*/

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r,idx;
ll x[500005],y[500005],z[500005];
char s[500005],t[500005];
//bool used[500005];
bool flag,dame;


int main(){
	cin >> n;
    for(i=1;i<=n;i++){
        cin >> x[i];
        sum += x[i];
    }
    ans = INF;
    for(i=1;i<=n;i++){
        x[i] += x[i-1];
    }
    for(i=1;i<=n;i++){
        ans = min(ans,abs(x[i] - (sum - x[i])));
    }
    p(ans);

	return 0;
}

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

int main() {
  int N,a,b,c,d;
  cin>>N;
  a=N/1000;
  b=N%1000/100;
  c=N%100/10;
  d=N%10;
  if (a==b && a==c){
    cout<<"Yes"<<endl;
  }
  
  else if (b==c && c==d){
    cout<<"Yes"<<endl;
  }
  
  else{
    cout<<"No"<<endl;
  }
}


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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, ans = 0;
   cin >> N;
   map<int, int> A;

   rep(i, N) {
     int tmp;
     cin >> tmp;
     A[tmp]++;
   }

   for(auto p: A) {
     ans += p.second % 2;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 4864
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

#define int long long

signed main() {
  int h,w;
  cin >> h >> w;

  if (h % 3 == 0 or w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }

  auto search = [](int w, int h) {
    int ave = w / 2;
    int res = INF;
    for (int i = 0; i <= h; ++i) {
      int mmin = 10000000;
      int mmax = -1;
      int remain_edge = h - i;
      int sa, sb, sc;
      sa = remain_edge * w;
      sb = ave * i;
      sc = (w - ave) * i;

      mmin = min({sa, sb, sc});
      mmax = max({sa, sb, sc});

      res = min({abs(mmin - mmax), res});

      sa = h * i;
      sb = ave * remain_edge;
      sb = (w - ave) * remain_edge;

      mmin = min({sa, sb, sc});
      mmax = max({sa, sb, sc});

      res = min({abs(mmin - mmax), res});
    }

    return res;
  };

  auto three = [=](int x) {
    return x;
  };

  cout << min({search(h, w), search(w, h), three(h), three(w)}) << endl;
}


Measured memory_bytes: 256
n=int(input())
l ='MARCH'
cnt=[0,0,0,0,0]
 
for i in range(n):
    s = input()
    for j in range(len(l)):
        if s[0]==l[j]: 
            cnt[j]+=1
 
ans = 0
for i in range(len(cnt)):
    for j in range(i+1, len(cnt)):
        for k in range(j+1, len(cnt)):
            ans += cnt[i]*cnt[j]*cnt[k]
        
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <iostream>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
//https://codeforces.com/contest/1228/problems
//https://codeforces.com/contest/1228/submit
int a[100050];
int main() {
    int n;
    s(n)
    for(int i = 0; i < n; i ++){
        s(a[i])
    }
    sort(a,a+n);
    int c = 0,d = 0;
    int flag = 0;
    for(int i = n-1; i >= 1; i --){
        if(a[i] == a[i-1] && flag == 0){
            c = a[i];
            i --;
            flag = 1;
        }else if(a[i] == a[i-1] && flag == 1){
            d = a[i];
            break;
        }
    }
    pld((ll)c*(ll)d) pn
    return 0;
}
/*

2
3 1 2
4 1 10


*/



Measured memory_bytes: 640
def solve(n):
    can = [[[-1, float('inf')] for _ in range(101)] for _ in range(101)]
    for k in range(n):
        x, y, h = map(int, input().split())
        for i in range(101):
            for j in range(101):
                if can[i][j] is None:
                    continue
                hh = h + abs(x - i) + abs(y - j)
                hl = 1 if h == 0 else hh
                nl, nh = max(can[i][j][0], hl), min(can[i][j][1], hh)
                if nl > nh:
                    can[i][j] = None
                else:
                    can[i][j][0] = nl
                    can[i][j][1] = nh

    for i in range(101):
        for j in range(101):
            if can[i][j] is None:
                continue
            return i, j, can[i][j][0]


n = int(input())
print(*solve(n))


Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0 ; i--)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    rep(i, N) cin >> w[i] >> v[i];
    vector<ll> dp(W+1,0);
    rep(i,N){
        rrep(j,W+1){
            if(j-w[i]>=0){
                dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
            }
        }
    }
    cout<<*max_element(dp.begin(),dp.end())<<endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 1024
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    int ara[6];
    
    for(i=1;i<=5;i++)
    	cin>>ara[i];
    cin>>k;
    
    for(i=1;i<4;i++)
    {
    	for(j=i+1;j<=5;j++)
    	{
    		if(abs(ara[j]-ara[i])>k){
    			cout<<":("<<endl; return 0;	}
		}
	}
	
	cout<<"Yay!\n";

    return 0;
}

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

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    ll x,t;
    cin >> x >> t;
    if(x-t>=0){
        cout << x-t << endl;
    }else{
        cout << '0' << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

bool dfs(vector<string>& S, int from, int tmp, vector<int>& vis)
{
    if(vis[tmp] != -1) return vis[from] != vis[tmp];

    int N = S.size();

    vis[tmp] = (from == -1) ? 1 : 1 - vis[from];
    bool ret = true;
    for(int j=0; j<N; j++){
        if(S[tmp][j] == '1' && j != from)
            ret &= dfs(S, tmp, j, vis);
    }

    return ret;
}

class Edge{
public:
    int from, to;
    long long cost;
    Edge(): from(0), to(0), cost(0){};
    Edge(int u, int v, long long w): from(u), to(v), cost(w){};
    ~Edge(){};
};

void Warshall_Floyd(std::vector<Edge> &edge, int V,
    std::vector<std::vector<long long> > &d)
{
    int E = edge.size();
    const long long infty = 1e+16;
    d.clear(); d.resize(V);
    for(int i=0; i<V; i++){
        for(int j=0; j<V; j++) d[i].push_back(infty);
    }
    // initialize
    for(int i=0; i<E; i++){
        d[edge[i].from][edge[i].to] = edge[i].cost;
    }
    for(int i=0; i<V; i++) d[i][i] = 0;

    // dp
    for(int k=0; k<V; k++){
        for(int i=0; i<V; i++){
            for(int j=0; j<V; j++) d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++){
        cin >> S[i];
    }

    vector<int> vis(N, -1);
    bool flag = dfs(S, -1, 0, vis);

    if(!flag){cout << -1 << endl; return 0;}

    vector<Edge> edge;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(S[i][j] == '1') edge.emplace_back(i, j, 1);
        }
    }

    Vvec<ll> dist;
    Warshall_Floyd(edge, N, dist);

    ll ans = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            ans = max(ans, dist[i][j]);
        }
    }

    cout << ans+1 << endl;
}

Measured memory_bytes: 1024
x,y = map(int, input().split())
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 2e5 + 5;



int main()
{
    FAST
  int n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++)
  {
      for(int j=1;j<=n;j++)
      {
          for(int k=1;k<=n;k++)
          {
              ans+=__gcd(i,__gcd(j,k));
          }
      }
  }
  cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>

using namespace std;

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

	vector<int> argA(argN);
	for (int i = 0; i < argN; ++i) {
		cin >> argA.at(i);
	}

	sort(argA.begin(), argA.end(), greater<int>());

	int sumA = 0;
	int sumB = 0;
	for (int i = 0; i < argN; i += 2) {
		sumA += argA.at(i);
		if (i + 1 < argN) {
			sumB += argA.at(i + 1);
		}
	}

	cout << sumA - sumB << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int K, X; cin >> K >> X;
  for(int i=X-K+1; i<X+K; ++i) {
    cout << i;
    if(i==X+K-1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 256
def main():

	nbOperation = 0

	sentenceS = list(input())
	sentenceToT = input()

	for i in range(len(sentenceS)):
		if sentenceS[i] != sentenceToT[i]:
			
			sentenceS[i] = sentenceToT[i]
			nbOperation += 1
			

	print(nbOperation)

main()

Measured memory_bytes: 10912
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define vi vector<int>
#define srt(a) sort(a.begin(), a.end());
#define se second
#define fi first
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)

LL dp[100005][3];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    int n;
    cin >> n;
    LL a[3];
    forn(i, 3) cin >> dp[0][i];

    for1(i, n - 1)
    {
        forn(j, 3) cin >> a[j];
        forn(j, 3)
        {
            LL m = 0;
            forn(k, 3) if (k != j) m = max(m, dp[i - 1][k]);
            dp[i][j] = m + a[j];
        }
    }
    LL an = 0;
    forn(i, 3) an = max(dp[n - 1][i], an);
    cout << an << endl;
    return 0;
}

Measured memory_bytes: 2560
use std::fmt::Debug;
fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_multi_line<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for i in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.parse().ok().expect("Can't Parse"));
    }
    vec
}

macro_rules! ignore {
    ($id:ident) => {};
}
macro_rules! assign {
    (let $($id:ident),* = $value:expr) => {
        let ($($id), *) = {
            let mut iter = $value.into_iter();
            ($({ignore!($id); iter.next().unwrap()}), *)
        }
    };
}
fn inspect<T: Debug>(vec: &Vec<T>) -> () {
    if let Some(first) = vec.first() {
        println!("Vec({:?}", first);
        for i in 1..vec.len() {
            println!(", {:?}", vec[i]);
        }
        println!(")");
    }else {
        println!("Vec()");
    }
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    }else {
        gcd(b, a % b)
    }
}

fn main() {
    let k = read_value::<usize>();
    let mut sum = 0usize;
    for a in 1 ..= k {
        for b in 1 ..= k {
            let g = gcd(a, b);
            for c in 1 ..= k {
                sum += gcd(g, c);
            }
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2152
import java.util.*;

public class Main{
  public static void main(String aargs[]){
    Scanner sc = new Scanner(System.in);
    
    int ans = sc.nextInt() % 1000;
    
    ans = (ans == 0) ? 0 : 1000 - ans;
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 35720
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    cin >> N;
    ll a[3333];
    ll i, j;
    ll dp[3333][3333]={};
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    for(i=N-1; i>=0; i--) {
        for(j=1; j<=N; j++) {
            if(i>=j) continue;
            
            if(N%2==(j-i)%2)
                dp[i][j]=max(dp[i+1][j]+a[i], dp[i][j-1]+a[j-1]);
            else
                dp[i][j]=min(dp[i+1][j]-a[i], dp[i][j-1]-a[j-1]);
        }
    }
    
    pt(dp[0][N]);
    
}




Measured memory_bytes: 87040
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;
int dp[100010];
int main() {
  int n, m;
  cin >> n >> m;
  rep(i,m) {
    int a; cin >> a;
    dp[a] = -1;
  }
  dp[0] = 1;
  if (dp[1] == 0) dp[1] = 1;
  //if (dp[1] == 1 && dp[2] == 0) dp[2] = 2;  
  for (int i = 2; i <= n; i++)
  {
    if (dp[i] == -1) continue;
    dp[i] = max(dp[i-1],0) + max(dp[i-2],0);
    
    //if (dp[i-1] !=-1 && dp[i-2] != -1) dp[i] += dp[i-2];
    dp[i] %= MOD;
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3960
#include <stdio.h>

int main(void)
{
	int a[11][11];
	int n, i, j;

	scanf("%d", &n);
	while (n != 0)
	{
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				scanf("%d", &a[i][j]);

		a[n][n] = 0;
		for (i = 0; i < n; i++)
		{
			a[i][n] = 0;
			for (j = 0; j < n; j++)
				a[i][n] += a[i][j];
			a[n][n] += a[i][n];
		}

		for (j = 0; j < n; j++)
		{
			a[n][j] = 0;
			for (i = 0; i < n; i++)
				a[n][j] += a[i][j];
		}

		for (i = 0; i <= n; i++)
		{
			for (j = 0; j <= n; j++)
				printf("%5d", a[i][j]);
			printf("\n");
		}
		
		scanf("%d", &n);
	}

	return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<ld, ld>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

const int NMAX = 100005;

int sz[NMAX];
bool can[NMAX];

int main() {
    cin.sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    can[1] = 1;
    for (int i = 1; i <= n; i++) {
        sz[i] = 1;
    }

    for (; m; m--) {
        int x, y;
        cin >> x >> y;

        can[y] |= can[x];
        sz[y]++;
        sz[x]--;
        if (sz[x] == 0) {
            can[x] = 0;
        }
    }

    int sol = 0;
    for (int i = 1; i <= n; i++) {
        if (can[i]) {
            sol++;
        }
    }

    cout << sol;

    return 0;
}


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

using namespace std;

int n, a[10];

int main(){
    cin >> n;
    for (int i = 1; i <= 4; i++)
    {
        a[i] = n % 10;
        n /= 10;
    }
    if (a[1] == a[2] && a[1] == a[3]) cout << "Yes";
    else if (a[2] == a[3] && a[2] == a[4]) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int N = sc.nextInt();

        List<E> odd = new ArrayList<>(100_001);
        List<E> even = new ArrayList<>(100_001);
        for (int i = 0; i < 100_001; i++) {
            E oddE = new E(i);
            odd.add(oddE);
            E evenE = new E(i);
            even.add(evenE);
        }

        for (int i = 0; i < N; i++) {
            if (i % 2 == 0) {
                E oddE = odd.get(sc.nextInt());
                oddE.count++;
            } else {
                E evenE = even.get(sc.nextInt());
                evenE.count++;
            }
        }

        Collections.sort(odd);
        Collections.sort(even);

        E firstOdd = odd.get(0);
        E firstEven = even.get(0);

        if (firstEven.num == firstOdd.num) {
            if (firstEven.count + odd.get(1).count >= firstOdd.count + even.get(1).count) {
                firstOdd = odd.get(1);
            } else {
                firstEven = even.get(1);
            }
        }

        System.out.println(N - (firstEven.count + firstOdd.count));
    }

    static class E implements Comparable<E> {

        int num;
        int count;

        public E(int num) {
            this.num = num;
        }

        @Override
        public int compareTo(E o) {
            return o.count - this.count;
        }

    }
}

Measured memory_bytes: 67760
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 500000;
char s[N];
int x[N];

int main(){
	scanf("%s", s);
	int n = strlen(s) + 1;
	f(i, 1, n)x[i] = s[i - 1] == '<' ? x[i - 1] + 1: 0;
	for (int i = n - 2; i >= 0; --i)if (s[i] == '>')x[i] = max(x[i], x[i + 1] + 1);
	ll an = 0;
	f(i, 0, n)an += x[i];
	printf("%lld\n", an);
}

Measured memory_bytes: 2688
import java.io.IOException;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

// ALDS1_7_C
public class Main {
	List<Integer> treeSearch(Node[] A, int root, String str) {
		Node[] copyA = A.clone();
		for (int i = 0; i < copyA.length; i++) {
			copyA[i] = new Node(A[i].number);
			copyA[i].left = A[i].left;
			copyA[i].right = A[i].right;
			copyA[i].parent = A[i].parent;
		}
		List<Integer> list = new ArrayList<Integer>();
		int i = root;
		boolean[] check = new boolean[copyA.length];
		Arrays.fill(check, true);
		while (i > -1) {
			switch(str) {
			case "preorder":
				if (check[i]) {
					list.add(copyA[i].number);
					check[i] = false;
				}
				break;
			case "inorder":
				if (copyA[i].left == -1 && check[i]) {
					list.add(copyA[i].number);
					check[i] = false;
				}
				break;
			case "postorder":
				if (copyA[i].left == -1 && copyA[i].right == -1 && check[i]) {
					list.add(copyA[i].number);
					check[i] = false;
				}
				break;
			}
			if (copyA[i].left != -1) i = copyA[i].left;
			else if (copyA[i].right != -1) i = copyA[i].right;
			else {
				if (copyA[i].parent != -1) {
					if (copyA[copyA[i].parent].left == i) copyA[copyA[i].parent].left = -1;
					else if (copyA[copyA[i].parent].right == i) copyA[copyA[i].parent].right = -1;
				}
				i = copyA[i].parent;
			}
		}
		return list;
	}
	
	void printList(List<Integer> list, String str) {
		StringBuilder build = new StringBuilder();
		build.append(str + "\n");
		for (Integer n : list) {
			build.append(" " + n);
		}
		build.append("\n");
		System.out.print(build);
	}
	
	void run() throws IOException {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] tree = new Node[n];
		for (int i = 0; i < n; i++) {
			tree[i] = new Node(i);
		}
		for (int i = 0; i < n; i++) {
			int number = sc.nextInt();
			int left = sc.nextInt();
			int right = sc.nextInt();
			tree[number].left = left;
			tree[number].right = right;
			if (left != -1 && right != -1) {
				tree[left].parent = number;
				tree[right].parent = number;
			} else if (left != -1 || right != -1) {
				if (left != -1) tree[left].parent = number;
				if (right != -1) tree[right].parent = number;
			}
		}
		// search root
		int root = 0;
		for (int i = 0; i < tree.length; i++) {
			if (tree[i].parent == -1) {
				root = i;
			}
		}
		printList(treeSearch(tree, root, "preorder"), "Preorder");
		printList(treeSearch(tree, root, "inorder"), "Inorder");
		printList(treeSearch(tree, root, "postorder"), "Postorder");
		sc.close();
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}

class Node {
	int number;
	int parent = -1;
	int left;
	int right;
	Node(int number) {
		this.number = number;
	}
}


Measured memory_bytes: 26200
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
ll C, D;
/* function */
ll gcd(ll x, ll y) {
    ll r;
    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll g(ll x, ll r) { return x / r; }
ll f(ll x) { return x - (g(x, C) + g(x, D) - g(x, lcm(C, D))); }
/* main */
int main(){
    ll A, B;
    cin >> A >> B >> C >> D;

    cout << f(B) - f(A - 1) << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }

}

Measured memory_bytes: 22612
import numpy as np
n = int(input())
s = list(input())
west = np.array(list(map(lambda x: 1 if(x == "W") else 0, s)))
east = np.array(list(map(lambda x: 1 if(x == "E") else 0, s))[::-1])
west_amount = np.cumsum(west)
east_amount = np.cumsum(east)[::-1]
res = []
for i in range(n):
  res.append(west_amount[i] + east_amount[i] - 1)
print(min(res))

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

int main() {
    int sum = 0, c[] = {1,5,10,50,100,500};
    REP(i,6){
        int a;
        cin >> a;
        sum += a*c[i];
    }
    cout << (sum>=1000?1:0) << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 998244353;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define sz(x) ((int)(x).size())

int n, d;
vvi a;

bool intdist(int x, int y){
    ll sqd = 0;
    for(int i = 0; i < d; i++){
        sqd += (a[x][i] - a[y][i]) * (a[x][i] - a[y][i]);
    }
    for(ll i = 0; 1; i++){
        if(i*i == sqd) return true;
        if(i*i > sqd) return false;
    }
}

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

    cin >> n >> d;
    a = vvi(n, vi(d));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++) cin >> a[i][j];
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){
            if(intdist(i, j)) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//-------------------

int main(){
    ld A,B,H,M;
    cin >> A >> B >> H >> M;
    
    H = H + M/60.0;
    ld argL = H / 12.0;
    ld argS = M / 60.0;

    ld theta = argL - argS;
    cout << fixed << setprecision(15) << sqrt(A*A + B*B - 2.0 * A * B * cos(2.0*theta*M_PI)) << endl;
    return 0;
}


Measured memory_bytes: 4124
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInt2() (int, int) {
	return nextInt(), nextInt()
}

func nextInt3() (int, int, int) {
	return nextInt(), nextInt(), nextInt()
}

func nextInt4() (int, int, int, int) {
	return nextInt(), nextInt(), nextInt(), nextInt()
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, k := nextInt2()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt() - 1
	}

	cnt := make([]int, n)
	for i := range cnt {
		cnt[i] = -1
	}
	cnt[0] = 0
	beforeLoop := 0
	loopT := 0
	beginLoop := 0
	for now := 0; ; {
		pre := now
		// テレポート
		now = a[now]
		if cnt[now] >= 0 {
			beforeLoop = cnt[now]
			loopT = cnt[pre] + 1 - cnt[now]
			beginLoop = now
			break
		}
		cnt[now] = cnt[pre] + 1
	}

	// puts(k, cnt, beginLoop, loopT, beforeLoop)

	r := k
	if k <= beforeLoop {
		beginLoop = 0
	} else {
		r = (k - beforeLoop) % loopT
	}
	// beginLoopからr回テレポート
	ans := beginLoop
	for i := 0; i < r; i++ {
		ans = a[ans]
	}
	puts(ans + 1)
}


Measured memory_bytes: 6540
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll INF = 1e18;

int N;
ll A[5000];
vector<int> G[5000];
vector<ll> dp[5000][2]; // 0 -> comなし、1 -> comあり
bool used[50000];

void dfs(int v){
    used[v] = true;
    if(A[v] < 0){
        dp[v][0].push_back(-INF);
        dp[v][1].push_back(-A[v]);
    }else{
        dp[v][0].push_back(-A[v]);
        dp[v][1].push_back(-INF);
    }
    for(int to : G[v]){
        if(!used[to]){
            dfs(to);
            int sl = dp[v][0].size();
            int sr = dp[to][0].size();
            int sum = sl+sr;
            // cout << "sum:" << sum << endl;
            vector<ll> buf0(sum, -INF);
            vector<ll> buf1(sum, -INF);
            for(int i = 0; i < sl; i++){
                for(int j = 0; j < sr; j++){
                    if(A[v] > 0){
                        if(dp[to][0][j] < 0 && dp[to][0][j] > -1e13){
                            // (0, 0)
                            buf0[i+j] = max(buf0[i+j], dp[v][0][i]+dp[to][0][j]);
                            buf0[i+j+1] = max(buf0[i+j+1], dp[v][0][i]); // comなしは切ってもいい
                        }
                        // (0, 1)
                        buf1[i+j] = max(buf1[i+j], dp[v][0][i]+dp[to][1][j]);
                        if(dp[to][1][j] > 0 ) buf0[i+j+1] = max(buf0[i+j+1], dp[v][0][i]);
                    }
                    // (1, 0)
                    if(dp[to][0][j] < 0 && dp[to][0][j] > -1e13){
                        buf1[i+j] = max(buf1[i+j], dp[v][1][i]+dp[to][0][j]);
                        buf1[i+j+1] = max(buf1[i+j+1], dp[v][1][i]); // comなしは切ってもいい
                    }
                    // (1, 1)
                    buf1[i+j] = max(buf1[i+j], dp[v][1][i]+dp[to][1][j]);
                    if(dp[to][1][j] > 0 ) buf1[i+j+1] = max(buf1[i+j+1], dp[v][1][i]);
                }
            }
            dp[v][0].resize(sum); dp[v][1].resize(sum);
            for(int i = 0; i < sum; i++){
                dp[v][0][i] = buf0[i];
                dp[v][1][i] = buf1[i];
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N-1; i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0);
    for(int i = 0; i < dp[0][1].size(); i++){
        // cout << dp[0][0][i] << ' ' << dp[0][1][i] << endl;
        if(dp[0][1][i] > 0 || (dp[0][0][i] < 0 && dp[0][0][i] >= -1e13)){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 183168
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a, b, c, d;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    a.resize(n);
    b.resize(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }
    c.resize(m);
    d.resize(m);
    rep(i,m){
        cin>>c[i]>>d[i];
    }
    vector<int> ans(n);
    rep(i,n){
        int ans_a=INF;
        int ansi;
        rep(j,m){
            int temp=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(ans_a>temp){
                ans_a=temp;
                ansi=j;
            }
        }
        ans[i]=ansi+1;
    }
    rep(i,n)cout<<ans[i]<<"\n";
}


Measured memory_bytes: 256
/*Name - Rishabh Kumar Gupta 
   NIT Patna B.tech CSE 
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	//#ifndef ONLINE_JUDGE
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
//#endif
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	string s;
	cin>>s;
	string s1="",s2="";
	for(ll i=0;i<s.length();i++){
		if(i&1){
			s1+='0';
			s2+='1';
		}
		else{
			s1+='1';
			s2+='0';
		}
	}
	//cout<<s1<<" "<<s2<<endl;
	ll c1=0,c2=0;
	for(ll i=0;i<s.length();i++){
		if(s[i]!=s1[i]) c1++;
		if(s[i]!=s2[i]) c2++;
	}
	//cout<<c1<<" "<<c2<<endl;
	cout<<min(c1,c2)<<endl;
	return 0;
}

Measured memory_bytes: 720
#include<iostream>

using namespace std;

int main()
{
	bool result = false;
	int arr[10] = {0};
	int num;
	for(int i = 0; i < 3; i++)
	{
		cin >> num;
		arr[num]++;
		if(arr[num] == 2)
		{
			result = true;
		}
		else if(arr[num] == 3)
		{
			result = false;
		}
	}
	if(result == true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<utility>
using namespace std;

int n;
int a[20];

int check(int q, int k, int x){
	if(q==x) return 1;
	if(k==n) return 0;
	return (check(q, k+1, x) | check(q, k+1, x+a[k]));

}

int main(){
	int q;
	int m[200];
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	cin >> q;
	for(int i=0; i<q; i++) cin >> m[i];

	for(int i=0; i<q; i++){
		if(check(m[i], 0, 0)) cout << "yes" << endl;
		else cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;

    int n = s.size();
    char c;
    stack<char> st;
    rep (i, n)
    {
        c = s[i];
        if (!st.empty() && st.top() != c)
        {
            st.pop();
        }
        else
        {
            st.push(c);
        }
    }

    cout << n - st.size() << "\n";
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int N, M;
int d[5010][5010];
int h[5010][5010];
int t[5010][5010];

int main() {
  cin >> N >> M;
  for (int i=0; i<M; i++) {
    int a, b, x;
    cin >> a >> b >> x;
    a--;
    b--;
    d[a][b]   += 1;
    d[a][b+1] -= 1;
    d[a+x+1][b]   -= 1;
    d[a+x+2][b+1] += 1;
    d[a+x+1][b+x+2] += 1;
    d[a+x+2][b+x+1+1] -= 1;
  }

  for (int i=0; i<=N; i++) {
    for (int j=0; j<=N; j++) {
      h[i][j] = ((i>0&&j>0)? h[i-1][j-1] : 0) + d[i][j];
    }
  }

  for (int i=0; i<=N; i++) {
    int g = 0;
    for (int j=0; j<=N; j++) {
      g += h[j][i];
      t[j][i] = g;
    }
  }

  int ans = 0;
  for (int i=0; i<N; i++) {
    int g = 0;
    for (int j=0; j<=i; j++) {
      g += t[i][j];
      if (g > 0) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 265352
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

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

int main()
{
     int n,i,j,k,sum=0;
     cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                
                int g=gcd(i,j);
                sum+=gcd(g,k);
            }
        }
    }

  cout<<sum;




}


Measured memory_bytes: 3584
import sys
 
input = sys.stdin.readline
 
N, K = map(int, input().rstrip("\n").split())
a = [int(i) for i in input().rstrip("\n").split()]

dp = [True for j in range(K+1)]
dp[0] = False

for j in range(K):
    for i in range(N):
        if j+1 - a[i] >= 0:
            dp[j+1] = dp[j+1] and dp[j+1 - a[i]]
    dp[j+1] = not dp[j+1]

if dp[-1]:
    print("First")
else:
    print("Second")

Measured memory_bytes: 45168