akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  int i;
  NodePointer x = nil->next;
  while(x->key != key){
    if(x==nil) return x;
    x = x->next;
  }
  return x;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t;
  t = nil->next;
  if(t == nil) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t;
  t = nil->prev;
  if(t==nil) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
  x=listSearch(key);
  if(x == nil) return;
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  x->prev = nil;
  nil->next = x;
  x->next->prev = x;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s",com);
    if ( com[0] == 'i' ) {scanf("%d",&key); insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	scanf("%d",&key);
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}

Measured memory_bytes: 31784
N = int(input())
A = list(map(int,input().split(" ")))

one = 0
two = 0
four = 0
for a in A:
    if a % 4:
        if a % 2:
            one += 1
        else:
            two += 1
    else:
        four += 1

if two:
    if one <= four:
        print("Yes")
    else:
        print("No")
else:
    if one - 1 <= four:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
using namespace std;
INT n, m, ans, i;
pair<INT, INT> x[100010];

int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ ) cin>>x[i].first>>x[i].second;
    sort(x, x+n);
    while( m-- )
    {
        if( x[i].second == 0 ) i++;
        ans += x[i].first, x[i].second--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

#define N 10000
#define M 500



int main(){
  int i,j,n,m,S[N],T[M],c=0,key;

  scanf("%d",&n);

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

  scanf("%d",&m);

  for(i=0;i<n;i++){
    scanf("%d",&T[i]);
  }
  
  for(j=0;j<m;j++){
    S[n]=T[j];
    key=T[j];
    i=0;
    while(S[i]!=key){
      i++;
    }
    if(i!=n){
      c++;
    }
  }

  printf("%d\n",c);
  
  return 0;
}



Measured memory_bytes: 2144
N,M=map(int,input().split())
A=[int(input())for _ in range(M)]

route=[0]*3+[0]*max(0,N-2)
for a in A:
    route[a]=-1

if route[1]!=-1:
    route[1]=1
else:
    route[1]=0

if route[2]!=-1:
    route[2]=1+route[1]
else:
    route[2]=0

i=3
while i<=N:
    if route[i]==-1:
        route[i]=0
    else:
        route[i]=(route[i-1]+route[i-2])%1000000007
    i+=1

print(route[N])

Measured memory_bytes: 14300
#include<bits/stdc++.h>
using namespace std;
int main()
{
     
     long long int n,i,j=1,c=0,f=0000000000,l,k,x,y,z,m,b,a;
     string s="",s1;
    /* char o;
     set <int, greater <int> > st;
     stack<char>sta;
     //int a[5];
    //long long  int arr[n+2][n+2];
     vector<char>ch(27);
     vector<string>str;
     vector<int>vect,vect3;
     map<int,int>mp;*/
     cin>>s;
     for(i=0;i<s.length();i++)
     {
         if(s[i]=='R')
           {
               c++;
               f=max(f,c);
           }
         else
            c=0;
     }
     cout<<f<<endl;
    

}



Measured memory_bytes: 3596
#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, N = 4010;

int a[N], b[N], c[N], d[N], e[N], f[N];
bool l[N][N], r[N][N], u[N][N], dd[N][N]; // blocked ? 
bool vis[N][N];

int dir[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

vi xs({-INF, INF}), ys({-INF, INF});

queue<pi> q;

void BFS(int x, int y) {
	vis[x][y] = 1;
	q.push({x, y});
	while(q.size()) {
		int x = q.front().F, y = q.front().S;
		q.pop();
		for(int i = 0; i < 4; i++) {
			if(i == 0 && u[x][y]) continue;
			if(i == 1 && dd[x][y]) continue;
			if(i == 2 && r[x][y]) continue;
			if(i == 3 && l[x][y]) continue;
			int xx = x + dir[i][0];
			int yy = y + dir[i][1];
			if(xx < 0 || yy < 0) continue;
			if(xx >= xs.size() - 1 || yy >= ys.size() - 1) continue;
			if(vis[xx][yy]) continue;
			vis[xx][yy] = 1;
			q.push({xx, yy});
		}
	}
}

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
		xs.PB(a[i]);
		xs.PB(b[i]);
		ys.PB(c[i]);
	}
	for(int i = 0; i < m; i++) {
		cin >> d[i] >> e[i] >> f[i];
		xs.PB(d[i]);
		ys.PB(e[i]);
		ys.PB(f[i]);
	}
	sort(ALL(xs));
	sort(ALL(ys));
	xs.resize(unique(ALL(xs)) - xs.begin());
	ys.resize(unique(ALL(ys)) - ys.begin());
	int x = lower_bound(ALL(xs), 0) - xs.begin();
	int y = lower_bound(ALL(ys), 0) - ys.begin();
	x--, y--;
	for(int i = 0; i < n; i++) {
		int aa = lower_bound(ALL(xs), a[i]) - xs.begin();
		int bb = lower_bound(ALL(xs), b[i]) - xs.begin();
		int cc = lower_bound(ALL(ys), c[i]) - ys.begin();
		for(int j = aa; j < bb; j++) {
			u[j][cc-1] = 1;
			dd[j][cc] = 1;
		}
	}
	for(int i = 0; i < m; i++) {
		int ddd = lower_bound(ALL(xs), d[i]) - xs.begin();
		int ee = lower_bound(ALL(ys), e[i]) - ys.begin();
		int ff = lower_bound(ALL(ys), f[i]) - ys.begin();
		for(int j = ee; j < ff; j++) {
			r[ddd-1][j] = 1;
			l[ddd][j] = 1;
		}
	}
	BFS(x, y);
	if(vis[0][0] || vis[xs.size() - 1][ys.size() - 1]) {
		cout << "INF" << endl;
		return 0;
	}
	ll ans = 0;
	for(int i = 0; i < xs.size() - 1; i++) {
		for(int j = 0; j < ys.size() - 1; j++) {
			if(vis[i][j]) {
				ans += (ll) (xs[i + 1] - xs[i]) * (ys[j + 1] - ys[j]);
			}
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 49940
def gcd(a,b):
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

n,*h=map(int,open(0).read().split())

gh=gcd(h[0],h[1])
for i in range(2,n):
    gh=gcd(h[i],gh)

print(gh)

Measured memory_bytes: 14052
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			try{
				int N = in.nextInt();
				int M = in.nextInt();
				String L =Integer.toString(N + M);
				System.out.println(L.length());
			}catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 20448
#include<bits/stdc++.h>
using namespace std;
void *wmem;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void rd(string &x){
  char *buf=(char *)wmem;
  rd(buf);
  x = buf;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
char memarr[96000000];
string S;
int main(){
  int h, n;
  wmem = memarr;
  rd(S);
  for(;;){
    S.erase(S.end()-1);
    n = S.size();
    if(n%2){
      continue;
    }
    h = n / 2;
    if(S.substr(0,h) == S.substr(h)){
      break;
    }
  }
  wt_L(n);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// string S;
// {
//   int n, h;
//   rd(S);
//   for(;;){
//     S.erase(S.end()-1);
//     n = S.size();
//     if(n%2) continue;
//     h = n / 2;
//     if(S.substr(0,h) == S.substr(h)) break;
//   }
//   wt(n);
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int H, W, N; 
	cin >> H >> W >> N; 
	pair<int, int> A[400010] = {}; 
	pair<int, int> C[400010] = {}; 
	for(int i = 0; i < N; i++){
		cin >> A[i].first >> A[i].second; 
		C[i].first = A[i].second; C[i].second = A[i].first; 
	}
	for(int i = N; i < N+W; i++){
		A[i].first = H + 1; A[i].second = i - N + 1;
		C[i].first = A[i].second; C[i].second = A[i].first; 
	}
	sort(A, A+N); 
	sort(C, C+N+W); 
	int mashita = C[0].second; 
	int sugumigi = 0; 
	pair<int, int> S; 
	S.first = 2, S.second = 2; 
	int D = lower_bound(C, C+N+W, S) - C; 
	for(int i = 0; i < H; i++){
		if(C[D+i].first != 2 || C[D+i].second != 2 + i){
			sugumigi = 2 + i; break; 
		}
	}
	int ans = 0; 
    int dif = 1 - sugumigi; 
	if(mashita == 2){ans = 1;}
	else if(mashita <= sugumigi){ans = mashita - 1;}
	else{
		bool kiwadoi = false; 
		for(int i = 0; i < N + W; i++){
            pair<int, int> Q; 
            Q.first = A[i].second; Q.second = A[i].first;  
			if(A[i].first < sugumigi || 
				A[i].second - A[i].first > dif + 1){continue;}
			else if(A[i].second - A[i].first == dif + 1){kiwadoi = true;}
            else if(A[i].second - A[i].first < dif && 
                    (C[(lower_bound(C, C+N+W, Q) - C) - 1].first != A[i].second
                      || C[(lower_bound(C, C+N+W, Q) - C) - 1].second != A[i].first - 1)){
				ans = A[i].first - 1; break; 
			}
			else if(A[i].second - A[i].first < dif && 
                    (C[(lower_bound(C, C+N+W, Q) - C) - 1].first == A[i].second
                      && C[(lower_bound(C, C+N+W, Q) - C) - 1].second == A[i].first - 1)){
				dif = A[i].second - A[i].first; 
			}
            else if(kiwadoi && A[i].second - A[i].first == dif){
				dif --; 
			}
			else if(!kiwadoi && A[i].second - A[i].first == dif){
				ans = A[i].first - 1; break; 
			}
		}
	}
    cout << ans << endl; 
}

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

namespace {
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define LEN(x) (int)((x).size())
#define X first
#define Y second

#define FOR(i, begin, end)  \
  for (__typeof(end) i = (begin) - ((begin) > (end));  \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

  
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<ll> vll;
template<typename T> using min_pq = priority_queue<T, vector<T>, greater<T>>;

ll expmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

struct IOS { IOS() { ios::sync_with_stdio(0); cin.tie(0); } } IOS;
}

const int MAX_N = 200000;
const ll MODD = 1000000009LL;
const ld EPS = 1e-9;

int main() {
	ll A, B, C;
	cin >> A >> B >> C;
	
	if (A%2 == 0 || B%2 == 0 || C%2 == 0) {
		cout << 0 << endl;
	}
	else {
		cout << min(A*B, min(A*C, B*C)) << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k; cin >> k; 
    long s = 7,cnt = 1;
    bool T = true;
    s %= k;
    while(1){
        if(s == 0)break;
        s = s*10+7;
        s %= k;
        cnt++;
        if(cnt == 100000000){
            T = false;
            break;
        }
    }
    if(T)cout << cnt << endl;
    else cout << -1 << endl;
}


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

using namespace std;

int bin_mod(int a, int n, int mod)
{
    int ret = 1;
    while (n)
    {
        if (n & 1)
            ret = (ret * 1ll * a) % mod;
        a = (a * 1ll * a) % mod;
        n >>= 1;
    }
    return ret;
}

int bits(int x)
{
    int ret = 0;
    while (x > 0)
    {
        if (x & 1) ret++;
        x /= 2;
    }
    return ret;
}

int fun(int x)
{
    int ret = 1;
    while (x > 0)
    {
        ret++;
        x %= bits(x);
    }
    return ret;
}

int main()
{
    int n, ones = 0, one = 0, zero = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '1') ones++;
    }
    int X = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == '1')
        {
            X += (1 << i);
            if (ones > 1)
                one = (one + bin_mod(2, n - i - 1, ones - 1)) % (ones - 1);
            zero = (zero + bin_mod(2, n - i - 1, ones + 1)) % (ones + 1);
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '0')
        {
            cout << fun((zero + bin_mod(2, n - i - 1, ones + 1)) % (ones + 1)) << endl;
        }
        if (s[i] == '1')
        {
            if (ones > 1)
                cout << fun((one - bin_mod(2, n - i - 1, ones - 1) + ones - 1) % (ones - 1)) << endl;
            else
                cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 3760
#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;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
const int N=1e5+5;

int n;
int a[N];
int maxa,maxp,mina,minp;

pii ans[N];
int la;

int main(){
    scanf("%d",&n);
    FOR(i,1,n)scanf("%d",&a[i]);
    if(a[1]<a[2])mina=a[1],minp=1,maxa=a[2],maxp=2;
    else mina=a[2],minp=2,maxa=a[1],maxp=1;
    FOR(i,1,n)if(a[i]<mina)mina=a[i],minp=i;
    FOR(i,1,n)if(a[i]>maxa)maxa=a[i],maxp=i;
    FOR(i,1,n){
        if(i==minp||i==maxp)continue;
        if(a[i]<=0){
            ans[++la]=(pii){maxa,a[i]},maxa-=a[i];
        }else {
            ans[++la]=(pii){mina,a[i]},mina-=a[i];
        }
    }
    ans[++la]=(pii){maxa,mina},maxa-=mina;
    printf("%d\n",maxa);
    FOR(i,1,la)printf("%d %d\n",ans[i].fi,ans[i].se);
    return 0;
}


Measured memory_bytes: 3072
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
typedef long long int ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
ll n, k, ans = 0, o; vector<ll> a;
int main() {
    cin >> n; vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    vector<vector<int>> dp(n+1, vector<int>(3,0));
    rep(i, n) {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b[i];
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i];
    }cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

Measured memory_bytes: 6912
#include <iostream>
#include<string>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
#define MAX_B 1001001
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL

int main(){
    string s;
    string add[4]={"dream","dreamer","erase","eraser"};
    cin>>s;
    rep(i,4)reverse(ALL(add[i]));
    reverse(ALL(s));
    bool ans=false;
    int i=0;
    while(i<s.length()){
        ans=false;
        rep(k,4){
            string p=s.substr(i,add[k].length());
            if(p==add[k]){
                i+=add[k].length();
                ans=true;
                break;
            }
            }
            if(!ans){
                cout<<"NO"<<endl;
                return 0;
        }
    }
    cout<<"YES"<<endl;
}

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

int main(){
    int n;
    vector<int> p;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    
    sort(p.begin(), p.end());
    
    p[p.size() - 1] /= 2;

    int sum = 0;
    for(auto i : p)
    {
        sum += i;
    }
    
    cout << sum;

    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# # 整数の入力
# a = int(input())
# # スペース区切りの整数の入力
# b, c = map(int, input().split())

# 整数の入力
a, b = map(int, input().split())

if a+1 == b:
    print(1)
else:
    res_count_list = []

    min_before = 0
    max_before = 0
    for i in range(b, a+2):
        if min_before == 0 and max_before == 0:
            min_before = sum(range(i))
            max_before = sum(range(a, a-i, -1))
        else:
            min_before = min_before + i - 1
            max_before = max_before + a - i + 1
        # print(max)
        # print(min_before)
        # print(max_before)
        res_count_list.append(max_before - min_before + 1)

    print(sum(res_count_list) % (10 ** 9 + 7))

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

public class TripleDots
{
    public static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());

        string S = Console.ReadLine();

        int len = S.Length;

        if(K >= len){ Console.WriteLine(S);}
        else
        { Console.WriteLine(S.Substring(0, K) + "..."); }
    }
}



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

int main(){
	string s;
	cin >> s;
	int l=s.size();
	
	vector<bool> exist(26,false);
	for(int i=0;i<l;i++)exist[s[i]-'a']=true;
	
	int ans=l;
	
	for(int i=0;i<26;i++){
		if(!exist[i])continue;
		char t='a'+i;
		int tmp=0;
		int c=0;
		for(int j=0;j<l;j++){
			if(s[j]!=t)c++;
			else{
				tmp=max(tmp,c);
				c=0;
			}
		}
		tmp=max(tmp,c);
		ans=min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

public class Main {
    static int MOD = 1000000007;

    public static class Mas {
        int x;
        int y;
        int step;

        Mas(int x, int y, int step) {
            this.x = x;
            this.y = y;
            this.step = step;
        }
    }

    private static final int[] vX = { 1, 0, 0, -1 };
    private static final int[] vY = { 0, 1, -1, 0 };

    public static void main(String[] args) {

        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        if(a%3==0 || b%3==0 || (a+b)%3==0)
            System.out.println("Possible");
            else
                System.out.println("Impossible");

    }

}


Measured memory_bytes: 22996
package main

import (
	"fmt"
)

func main() {
	var N, D, X int
	fmt.Scanf("%d", &N)
	fmt.Scanf("%d %d", &D, &X)
	A := make([]int, N)
	ans := X
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
		ans += (D - 1) / A[i] + 1
	}
	fmt.Printf("%d\n", ans)
	return
}


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

using namespace std;

#define forn(i, n) for (int64_t i = 0; i < (int64_t) (n); ++i)
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int p[N], pos[N];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> p[i];

    return true;
}

void solve() {
    forn (i, n)
        pos[--p[i]] = i;

    set<int> ids;
    ids.insert(-1);
    ids.insert(n);
    long long ans = 0;

    for (int i = n - 1; i >= 0; --i) {
        int x = pos[i];
        auto lmx = *(--ids.upper_bound(x));
        auto rmx = *(ids.upper_bound(x));

        if (lmx != -1) {
            int l = *(--ids.lower_bound(lmx));
            int r = *(ids.upper_bound(x));
            ans += (long long) (lmx - l) * (r - x) * (i + 1);
        }

        if (rmx != n) {
            int l = *(--ids.upper_bound(x));
            int r = *(ids.upper_bound(rmx));
            ans += (long long) (x - l) * (r - rmx) * (i + 1);
        }

        ids.insert(x);
    }
    
    cout << ans << endl;
}

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

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 5760
import sys
import itertools

N, M, Q = map(int, input().split())
abcd = []
z = [x for x in range(1,M+1)]
s = 0
d = 0
for i in range(Q):
    abcd.append(list(map(int, input().split())))

for A in itertools.combinations_with_replacement(z, N):
    d = 0
    for y in abcd:
        if A[y[1]-1] - A[y[0]-1] == y[2]:
            d += y[3]
    s = max(d, s)

print(s)

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

// n個の重複しない整数(min ~ max)用いてsを表す組み合わせの数
int ci(int n, int s, int min, int max) {
  if (s < min || n < 1) return 0;
  if (n == 1) return (s > max)? 0: 1;
  int r = 0;
  for (int i=min; i<s && i<=max; i++) {
    r += ci(n - 1, s - i, i + 1, max);
  }
  return r;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!n && !s) break;
    cout << ci(n, s, 0, 9) << endl;
  }
  return 0;
}


Measured memory_bytes: 2984
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

ll d[1001]={};
int a[100001]={};
int main() {
	int n;
	int a1;
	int k=1000000000;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a1;
		int j=0;
		while(a1%2==0){
			a1=a1/2;
			j++;
		}
		k=min(k,j);
	}
	cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans,n,a[10001]; 
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a,a+n+1);
	for(int i=1;i<=n-1;i++) ans+=a[i];
	ans+=a[n]/2;
	cout<<ans; 
}
 

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	string S; cin >> S;
	vector<LL> c(26,0);
	for(auto a : S) c[a-'a']++;
	LL ans = 1;
	const LL mod = 1e9+7;
	repp(i,0,26) (ans *= c[i]+1) %= mod;
	cout << (ans+mod-1)%mod << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

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;}

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

long long INF = 1LL<<60;
long long dp[100010][3];
int v[100010][3];

int main(){
    int n;
    cin>>n;
    rep(i,n)
        rep(j,3)
            cin>>v[i][j];
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(j==k)continue;
                chmax(dp[i+1][k],dp[i][j]+v[i][k]);
            }}}
    long long  max=0;
    rep(i,3){
        chmax(max,dp[n][i]);
    }
    cout<<max<<endl;
    return 0; 
}




Measured memory_bytes: 3712
def set_root(tower,root):
    tower[root[0] - 1][1].append(root[1]-1)
    tower[root[1] - 1][1].append(root[0]-1)


def compare(tower,index):
    if(len(tower[index][1]) == 0):
        return 1

    for i in tower[index][1]:
        if(tower[index][0] <= tower[i][0]):
            return 0
    
    return 1


def resolve():
    ti,root = map(int,input().split())
    tower =[[int(i),[]] for i in input().split()]
    sum = 0
    for i in range(root):
        set_root(tower,[int(i) for i in input().split()])
    
    for j in range(ti):
        sum +=compare(tower,j)

    print(sum)
resolve()

Measured memory_bytes: 37332
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int solve()
{
    int n;
    cin>>n;
    ll arr[n];
    rep(i,n)
    {
        cin>>arr[i];
    }
    ll dp[n];
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    rep_a(i,2,n)
    {
        dp[i] = min(dp[i-2] + abs(arr[ i - 2] - arr[i]),dp[i-1] + abs(arr[ i - 1] - arr[i])) ;
    }
    cout<<dp[n-1]<<endl;
    return 0;
}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */

    return 0;
} 

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

int main() {
  int n;
  cin>>n;
  long long dp[n];
  dp[0]=2;
  dp[1]=1;
  for(int i=2;i<=n;i++) dp[i]=dp[i-1]+dp[i-2];
  cout<<dp[n]<<endl;
}


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

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

    if(abs(a - b) <= d && abs(b - c) <= d){
        cout << "Yes" << endl;
    }else if(abs(a - c) <= d){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n;
	while (cin >> n && n) {
		VI a(n); rep(i, n)cin >> a[i];
		VI data(9);

		rep(i, n) {
			int x;
			if (a[i] < 10)x = 0;
			else if (a[i] < 20)x = 1;
			else if (a[i] < 30)x = 2;
			else if (a[i] < 40)x = 3;
			else if (a[i] < 50)x = 4;
			else if (a[i] < 60)x = 5;
			else x = 6;

			data[x]++;
		}

		rep(i, 7)cout << data[i] << endl;
	}
}


Measured memory_bytes: 6684
#include <stdio.h>

int main(void){
	short a,b,c;
	scanf("%d%d%d",&a,&b,&c);

	short sum;
	if(a<=b){
		if(b<=c){sum=a+b;}
		else{sum=a+c;}
	}
	else //a>b
	{	if(a<=c){sum=a+b;}
		else{sum=b+c;}
	}
	printf("%d",sum);
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
IOS;
long long int k=0;
string s;
cin>>s;
for(int i=0;i<s.size();i++){
    k+=s[i]-48;
    k%=9;
}
if(k==0)cout<<"Yes\n";
else cout<<"No\n";
}
/*sjleepy*/

Measured memory_bytes: 3740
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main{
    //WRWWRWRR     wwwrrrrwwwwrrr
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        String[] ss = new String[n];
        Set<String> res = new HashSet<>();
        for(int i=0;i<n;i++){
            res.add(in.next());
        }
        out.println(res.size());

    }
    //	public static void main(String[] args){
//		Scanner scanner = new Scanner(new InputStreamReader(System.in));
//		int n  = Integer.parseInt(scanner.nextLine());
//		String s = scanner.nextLine();
//		LinkedList<Integer> q = new LinkedList<>();
//		for(int i=0;i<n;i++){
//			if(s.charAt(i)=='W'){
//				q.add(i);
//			}
//		}
//		int res = 0;
//		for(int i=n-1;i>=0;i--){
//			if(q.size()==0) break;
//			if(s.charAt(i)=='R'){
//				int v = q.poll();
//				if(v>i) break;
//				res++;
//			}
//		}
//		System.out.println(res);
//
//	}
    public static void main(String[] args){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Main solver = new Main();
//        int num = in.nextInt();
//        while(num-->0){
//            solver.solve(1, in, out);
//        }
        solver.solve(1, in, out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 999999999;

int main(){
   int a,b,c,d;
   cin >> a>>b>>c>>d;
   cout << min(a,b)+min(c,d);
   
   return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
c_list = []

for i in range (-101, 102, 1):
  c_list.append(i)

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  for i in range(len(p)):
    c_list[c_list.index(p[i])] = 250
  # print(c_list)
  diff = 500
  for i in range(len(c_list)):
    if abs(x - c_list[i]) < diff:
      diff = x - c_list[i]
      ans = c_list[i]

print(ans)


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

int a[82][82],b[82][82];
bool dp[82][82][13050]={};

int main(){
    int h,w; scanf("%d%d",&h,&w);
    rep(i,0,h)rep(j,0,w)scanf("%d",&a[i][j]);
    rep(i,0,h)rep(j,0,w)scanf("%d",&b[i][j]);
    rep(i,0,h)rep(j,0,w){
        a[i][j]-=b[i][j]; if(a[i][j]<0)a[i][j]*=-1;
    }
    dp[0][0][a[0][0]]=1;
    rep(i,0,h)rep(j,0,w)rep(k,0,13005)if(dp[i][j][k]){
        if(j!=w-1){
            if(abs(k-a[i][j+1])<=13000)dp[i][j+1][abs(k-a[i][j+1])]=1;
            if(abs(k+a[i][j+1])<=13000)dp[i][j+1][abs(k+a[i][j+1])]=1;
        }
        if(i!=h-1){
            if(abs(k-a[i+1][j])<=13000)dp[i+1][j][abs(k-a[i+1][j])]=1;
            if(abs(k+a[i+1][j])<=13000)dp[i+1][j][abs(k+a[i+1][j])]=1;
        }
    }
    rep(i,0,13005)if(dp[h-1][w-1][i]){printf("%d\n",i); return 0;}
    return 0;
}

Measured memory_bytes: 83456
from collections import deque

n, q = map(int, input().split())
deq = deque()

for _ in range(n):
    name, time = input().split()
    time = int(time)
    deq.append((time, name))
    
ans = []
cur = 0

while deq:
    time, name = deq.popleft()
    
    if time <= q:
        cur += time
        ans.append(f"{name} {cur}")
    else:
        cur += q
        deq.append((time - q, name))
        
for a in ans:
    print(a)


Measured memory_bytes: 12868
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int64_t ans=0;
  for(int i=0;i<N;i++)
    ans=(ans+A.at(i))%mod;
  ans=((N-1)*ans)%mod;
  vector<int64_t>B(61,0);
  for(int i=0;i<N;i++){
  int64_t b=A.at(i);
    for(int j=0;j<=60;j++){
    if(b%2==1)
      B.at(j)++;
      b/=2;
    }
  }int64_t ans1=0;
  for(int i=0;i<=60;i++){
  int64_t k=((B.at(i)*(B.at(i)-1))/2)%mod;
    int64_t m=powl(2,i+1);
    ans1=(ans1+(m%mod)*k)%mod;
  }int64_t ans2=(mod+ans-ans1)%mod;
  cout<<ans2<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 52;
const int mo = 1e9 + 7;

int n;
long long k;

// struct Matrix {
//     vector<vector<int>> m;

//     Matrix(vector<vector<int>> &d) {
//         m = d;
//     }
// }

void mul(vector<vector<int> > &a, vector<vector<int> > &b) {
    vector<vector<int> > c(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            for (int k = 0; k < n; ++k)
                c[i][j] = (c[i][j] + (long long)a[i][k] * b[k][j] % mo) % mo;

    a = c;
}

int main() {

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

    
    cin >> n >> k;
    vector<vector<int> > d(n, vector<int>(n)), res(n, vector<int>(n));

    for (int i = 0; i < n; ++i) {
        res[i][i] = 1;
        for (int j = 0; j < n; ++j) {
            cin >> d[i][j];
        }
    }

    while (k > 0) {
        if (k & 1)
            mul(res, d);

        mul(d, d);
        k >>= 1;
    }
	
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j)
            ans += res[i][j];

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

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

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i=1; i<=n; i++) {
    if (i % 3 != 0 && i % 5 != 0) sum += i;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#define MAX_N 1000010
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 100000005
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;

int gcm(int a,int b){
    if(a<b){swap(a,b);}
    while(b>0){
        a%=b;
        swap(a,b);
    }
    return a;
}

int lcm(int a,int b){
    return a/gcm(a,b)*b;
}

int main(){
    int n,a,b;
    int LCM,GCM;
    bool flag[MAX_N];
    int count[MAX_N];
    while(1){
        cin>>n>>a>>b;
        if(n==0)
            break;
        rep(i,MAX_N){
            flag[i]=0;
        }
        LCM=lcm(a,b);
        GCM=gcm(a,b);
        int ans;
        int irange = min(MAX_N-1,LCM)/a+1;
        rep(i,irange){
            int jrange =(min(MAX_N-1,LCM)-a*i)/b+1;
            rep(j,jrange){flag[a*i+b*j]=true;}
        }
        count[0]=0;
        rep(i,MAX_N-1){
            count[i+1]=count[i]+flag[i+1];
        }
        if(n<LCM){
            ans=count[n];
        }
        else{
            ans=count[LCM]+(n-LCM)/GCM;
        }
        cout<<n-ans<<endl;
    }
}

Measured memory_bytes: 6040
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    a.push_back(x);
    sort(a.begin(), a.end());
    int nwd = a[1] - a[0];
    for (int i = 1; i < (int) a.size() - 1; ++i)
        nwd = __gcd(nwd, a[i + 1] - a[i]);
    cout << nwd;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

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

int main(){
   int n;
   cin >> n;
   vector<int> v(n);
   rep(i,n) cin >> v[i];
   vector<int> left(n+1,0);
   vector<int> right(n+1,0); 
   for (int i = 0; i < n;i++){
      left[i+1] = gcd(left[i],v[i]);
   }
   for (int i = n-1;i >= 0;i--){
      right[i] = gcd(right[i+1],v[i]);
   }
   int ans = 0;
   for (int i = 0;i < n;i++){
      int l = left[i];
      int r = right[i+1];
      ans = max(gcd(l,r),ans);
   }
   cout << ans << endl; 

    
    return 0;

}

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

using namespace std;

int main()
{
    int a, b, wynik = 0;
    cin >> a >> b;
    
    wynik = max(wynik, a + a - 1);
    wynik = max(wynik, b + b - 1);
    wynik = max(wynik, a + b);
    
    cout << wynik;
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int x, a, b;
    cin>>x>>a>>b;
    x -= a;
    x %= b;
    cout<<x<<endl;
}

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

int main() {
  vector<int> nums;
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    nums.push_back(l);
  }
  vector<int> candidits;
  int min = -1;
  for(int i = 0; i < n - 1; ++i) {
    if(min == -1 || min > nums[i]) {
      min = nums[i];
      int max = *max_element(nums.begin() + i + 1, nums.end());
      candidits.push_back(max - min);
    }
  }
  int max = *max_element(candidits.begin(), candidits.end());
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 2064
#include<iostream>

using namespace std;

int main(){
    int n, l, s;
    cin >> n >> l;
    s = n * (2 * l + n - 1) / 2;
    cout << (l >= 0 ? s - l : (l + n - 1 < 0 ? s - (l + n - 1) : s));  
}
   

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

int main(){
  
  int N,count=0;
  cin >> N;
  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
    if(data.at(i)!=i+1){
      count++;
    }
  }
  
  if(count<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > G; // G[i]はAの同じ数字のiteratorの集合
vector<int> visit, indx, ans;
int N;
long long int K;

void dfs(int i){ // iは数列Aのiterator
  if(i==N) return;

  if(G[indx[i]].size()==1) {
    ans.push_back(i);
    dfs(i+1);
  } else {
    for(int j=0; j<G[indx[i]].size(); j++){
      if(i==G[indx[i]][j]){
        if(j==G[indx[i]].size()-1) {
          visit[G[indx[i]][0]] = 1;
          ans.push_back(G[indx[i]][0]);
          dfs(G[indx[i]][0]+1);
        } else {
          visit[G[indx[i]][j+1]] = 1;
          ans.push_back(G[indx[i]][j+1]);
          dfs(G[indx[i]][j+1]+1);
        }
      }
    }
  }
}

int main(){
  cin >>N >>K;
  int A[N];
  pair<int,int> B[N]; // B[i] = (A_i, i)
  for(int i=0;i<N;i++){
    cin >>A[i];
    B[i] = make_pair(A[i],i);
  }
  sort(B, B+N);

  int a = B[0].first; int x=0;
  indx.assign(N,-1); // indx[i]はite iが含まれているG[j]のjを格納
  vector<int> ite;
  for(int i=0;i<N;i++){ // グラフ作成
    if(a != B[i].first) {
      G.push_back(ite);
      x++;
      ite.clear();
      a = B[i].first;
    }
    ite.push_back(B[i].second);
    indx[B[i].second] = x;
  }
  G.push_back(ite);

  visit.assign(N+1,0);
  visit[0] = 1;
  dfs(0);

  vector<int> final_ans;
  if(ans[0]==0) final_ans.push_back(1);
  for(int i=1; i<ans.size(); i++){
    if(ans[i]<=ans[i-1]+1) final_ans.push_back(ans[i-1]+1);
  }

  int k = K%(final_ans.size()+1);
  if(k==1 && final_ans[0]==1){
    cout << A[0] << " ";
  }

  if(k==0) cout << " " << endl;
  else {
    for(int i=final_ans[k-1]; i<N; i++){
      for(int j=0; j<G[indx[i]].size(); j++){
        if(i==G[indx[i]][j]){
          if(j!=G[indx[i]].size()-1) {
            i = G[indx[i]][j+1];
            break;
          }
          else {
            cout << A[i] << " ";
          }
        }
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 29356
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string t;
    cin>>t;
    int m=s.length();
    int c=0;
    for(int i=0;i<m;i++)
    {
        if(s[i] == t[i])
            c++;
    }
    cout<<m-c<<endl;
}


Measured memory_bytes: 3848
s=input()
ans=len(s)
def check(m):
  a=len(m)
  if a%2==1:
    return False
  else:
    if s[0:a//2]==s[a//2:a]:
      return True
    else:
      return False
for i in range(len(s)-1,0,-1):
  ans-=1
  if check(s[0:i])==True:
    print(ans)
    break
  


Measured memory_bytes: 2940
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int a;
    ll b,n;
    cin>> a>> b>> n;
    ll num=n/b;
    ll y=n;
    ll ans=((a*y)/b)/1-a*((y/b)/1);
    rep2(i,num){
        ll x=b*i-1;
        ll temp=((a*x)/b)/1-a*((x/b)/1);
        ans=max(ans,temp);
    } 
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())


a,b=LI()

if a >= 1 and b >= 1 and a <= 9 and b <= 9:
    print(a*b)
else:
    print(-1)


Measured memory_bytes: 3064