akhauriyash/Code-Regression huggingface dataset:
// ~/BAU/ACM-ICPC/Teams/Rampage/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 21;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

ll grundy(ll n, ll k) {
	if (n < k) return 0;
	if (n%k == 0) return n / k;
	ll d = n - ((n / k)*k);
	ll w = n / k + 1;
	d = (d + w - 1) / w;
	return grundy(n - w * d, k);
}

int main() {
	int n;
	ll m, k, x = 0;
	scanf("%d", &n);
	while (n--) {
		scanf("%lld%lld", &m, &k);
		x ^= grundy(m, k);
	}
	puts(x == 0 ? "Aoki" : "Takahashi");
	return 0;
}

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

 int main()
{
	int N; int M;
	cin >> N >> M;
	vector<int> pass(100001,0);

	int Lmax{ 0 }, Rmin{ 100001 };
	for (int i = 0; i < M; ++i) {
		int L, R;
		cin >> L >> R;
		Lmax = max(Lmax, L);
		Rmin = min(Rmin, R);
	}
	int count = Rmin - Lmax + 1;
	if (count >= 0) {
		cout << count << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b && a!=c) cout<<"Yes";
	else if(b==c && a!=c) cout<<"Yes";
	else if(a==c && b!=c) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3624
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))
L.sort()


pare = list(combinations(L, 3))
count = 0
#print(pare)

for x, y, z in pare:
    if x+y > z and y+z > x and z+x > y and x != y and y != z and z != x:
        count += 1
        #print(x, y, z)
print(count)

Measured memory_bytes: 20348
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    string s;
    cin >> s;

    if (s[2] == s[3] and s[4] == s[5]) {
        cout << "Yes" << endl;

    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

class WeightedUnionFind {
public:
    vector<int> par;
    vector<int> rank;
    vector<int> diff_weight;
    
    WeightedUnionFind() {}
    WeightedUnionFind(int size, int weight){
        rank.resize(size,0);
        par.resize(size,0);
        diff_weight.resize(size,0);
        for(int i=0; i<size; i++) makeSet(i,weight);
    }
    
    void makeSet(int x, int weight){
        par[x] = x;
        rank[x] = 0;
        diff_weight[x] = weight;
    }
    
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    bool relate(int x, int y, int w){
        w += weight(x); w -= weight(y);
        x = findSet(x); y = findSet(y);
        
        if(x == y) return false;
        if(rank[x] < rank[y]){
            swap(x,y);
            w = -w;
        }
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
    
    int weight(int x){
        findSet(x);
        return diff_weight[x];
    }
    
    int findSet(int x){
        if(par[x] == x){
            return x;
        }
        else {
            int r = findSet(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }
    
};

int main() {
    int n, q;
    cin >> n >> q;
    
    WeightedUnionFind wuf = WeightedUnionFind(n, 0);
    
    for(int i=0; i<q; i++){
        int t, x, y;
        cin >> t >> x >> y;
        if(t==0){
            int z; cin >> z;
            wuf.relate(x, y, z);
        }
        else if(t==1){
            if(!wuf.same(x,y)){
                cout << '?' << endl;
                continue;
            }
            cout << wuf.diff(x,y) << endl;
        }
    }
}



Measured memory_bytes: 3908
N=int(input())
abc=[]
for _ in range(N):
    a,b,c=map(int,input().split())
    abc.append([a,b,c])
dp=[[0,0,0] for i in range(N)]
dp[0]=abc[0]
for i in range(N-1):
    dp[i+1][0]=max(dp[i][1]+abc[i+1][0], dp[i][2]+abc[i+1][0])
    dp[i+1][1]=max(dp[i][2]+abc[i+1][1], dp[i][0]+abc[i+1][1])
    dp[i+1][2]=max(dp[i][0]+abc[i+1][2], dp[i][1]+abc[i+1][2])
print(max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])))


Measured memory_bytes: 75608
package main

import "fmt"

func main() {
	var A, B, C, D int
	fmt.Scan(&A, &B, &C, &D)
	if A+B < C+D {
		fmt.Println("Right")
	} else if A+B == C+D {
		fmt.Println("Balanced")
	} else {
		fmt.Println("Left")
	}
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
  char a[4], b[4];
  int hi, bl, i, j;
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
    for (i = hi = bl = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
        if (b[i] == a[j]) {
          if (i == j) 
            hi++;
          else
            bl++;
        }
      }
    }
    cout << hi << ' ' << bl << endl;
  }
  return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k; 
  cin >> n >> k;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int sum = 0;
  for(int i=0;i<k;i++) sum += l[i];
  printf("%d", sum);
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> count(M, 0);
  
  for(int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for(int j = 0; j < K; j++) {
      int A;
      cin >> A;
      A--;
      count.at(A)++;
    }
  }
  
  int ans = 0;
  for(int i = 0; i < M; i++) {
    if(count.at(i) == N) {
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

const int N = 1e5 + 5;

int n;
int cnt[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		int x; cin >> x;
		if (x > n) res++;
		else cnt[x]++;
	}
	for (int i = 1; i < N; ++i) if (cnt[i]) {
		if (cnt[i] >= i) res += cnt[i] - i;
		else res += cnt[i];
	}
	cout << res << '\n';
}

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

int main(){
    int N;
    cin>>N;
    int a, i=1, A[N];
    while(cin>>a,i<=N){
        A[i]=a;
        i++;
    }

    int m,order[m];
    order[1]=0;
    while(A[1]==A[1]/2*2){
           A[1]=A[1]/2;
           order[1]++;
    }

    int minorder=order[1];
    for(int k=2;k<=N;k++){
        order[k]=0;
        while(A[k]==A[k]/2*2){
           A[k]=A[k]/2;
           order[k]++;}
        
        if(order[k]<minorder){
               minorder=order[k];
           } 
        else{
               minorder=minorder;
           }          
    }
    cout<<minorder<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
	vector <string> deck;
	vector <int> shuffle;
	string text;
	int size = 0;
	int num = 0;
	int total = 0;

	while (true) {
		cin >> text;
		if (text == "-") {
			break;
		}
		cin >> size;
		for (int i = 0; i < size; i++) {
			cin >> num;
			total += num;
		}
		deck.push_back(text);
		shuffle.push_back(total%text.size());
		total = 0;
	}
	size = deck.size();
	for (int i = 0; i < size; i++) {
		text = deck[i];
		if (shuffle[i]>0){
			text=text+text.substr(0, shuffle[i]);
			text=text.substr(shuffle[i], text.size());
		}
		cout << text << endl;
	}
}



Measured memory_bytes: 3208
/*
 * @Author: goatzyq
 * @Date: 2020-09-19 20:05:25
 * @LastEditors: goatzyq
 * @LastEditTime: 2020-09-19 20:08:36
 * @Description: abc 179 B
 */
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout << #x <<"	"<< x <<endl
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9+7;
ll qpow(ll a, ll b){
    ll ret = 1;
    while(b){
        if(b&1)ret = ret*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return ret;
}
int d[110][110];
int n;
int a[110];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i=0; i<n; ++i){
        cin >> d[i][0] >> d[i][1];
        if(d[i][0]==d[i][1])a[i]=1;
        else a[i] = 0;
    }
    for(int i=0; i<n-2; ++i){
        if(a[i]==a[i+1]&& a[i+1]==a[i+2]&& a[i]==1){
            cout <<"Yes\n";
            return 0;
        }
    }
    cout <<"No\n";
    return 0;
}


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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  vector<string> cards(3);
  cin >> cards[0] >> cards[1] >> cards[2];
  vector<int> idx(3);
  int next = 0;
  for (;;) {
    if (idx[next] == cards[next].size()) {
      printf("%c\n", next + 'A');
      return 0;
    }
    int tobe = cards[next][idx[next]++] - 'a';
    // printf("%c's turn\n", next + 'A');
    next = tobe;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int H, W;

int nx(int tx, int ty) {
  int x;
  if (ty % 2 == 1) {
    x = min(tx+1, W);
  } else {
    x = max(tx-1, 1);
  }

  return x;
}

int ny(int tx, int ty) {
  int y;
  if (ty % 2 == 1) {
    y = (tx == W) ? ty+1 : ty;
  } else {
    y = (tx == 1) ? ty+1 : ty;
  }

  return y;
}

int main() {
  cin >> H >> W;

  vector< vector<int> > a(H+1, vector<int>(W+1));

  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> a[i][j];
    }
  }

  bool flag_odd = false;
  int x = 1, y = 1, sx, sy;
  if (a[1][1] % 2 == 1) {
    flag_odd = true;
    sx = 1;
    sy = 1;
  }

  vector< vector<int> > ans(4);
  int tx, ty, cnt = 0;
  int gx, gy;
  gx = (H % 2 == 0) ? 1 : W;
  gy = H;

  while (x != gx || y != gy) {
    tx = x;
    ty = y;
    x = nx(tx, ty);
    y = ny(tx, ty);
    
    if (a[y][x] % 2 == 1) {
      if (flag_odd) {
        flag_odd = false;
        while (sx != x || sy != y) {
          tx = sx;
          ty = sy;
          sx = nx(tx, ty);
          sy = ny(tx, ty);
          ans[0].push_back(ty);
          ans[1].push_back(tx);
          ans[2].push_back(sy);
          ans[3].push_back(sx);
          cnt++;
        }
      } else {
        flag_odd = true;
        sx = x;
        sy = y;
      }
    }

  }

  cout << cnt << endl;
  rep(i, cnt) {
    cout << ans[0][i] << " ";
    cout << ans[1][i] << " ";
    cout << ans[2][i] << " ";
    cout << ans[3][i] << endl;
  }

  return 0;
}

Measured memory_bytes: 5220
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = scan.nextInt();
    int x = scan.nextInt();

    int i = 0,j,k,check = 0,cnt = 0;
    while(i <= a){
      j = 0;
      while(j <= b){
        k = 0;
        while(k <= c){
          check = 500*i + 100*j + 50*k;
          if (check == x) {
            cnt++;
          }
          k++;
        }
        j++;
      }
      i++;
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 21076
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int

int main()
{
    int n, m;
    string s[100], t[100];
    int M = 0, cnt;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> t[i];
    }
    for (int i = 0; i < n; i++)
    {
        cnt = 0;
        for (int j = 0; j < n; j++)
        {
            if (s[i] == s[j])
                cnt++;
        }
        for (int j = 0; j < m; j++)
        {
            if (s[i] == t[j])
                cnt--;
        }
        M = max(M, cnt);
    }
    cout << M << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

  
int cnt = 0;
int a[1000000];
  
void insertionSort(int a[], int n, int g){
  int i, j, key;
  
  for(i = g;i < n;i++){
    key = a[i];
    j = i - g;
    while(j >= 0 && a[j] > key){
      a[j+g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j+g] = key;
  }
}
  
void shellSort(int a[], int n){
  int m = 13; 
  int g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 165720, 797161};
  int i;
  
  cnt = 0;
  while(g[m-1] > n){
    m--;
  }
  printf("%d\n", m);
  for(i = m-1;i >= 1;i--){
    printf("%d ", g[i]);
  }
  printf("%d\n", g[0]);
  for(i = m-1;i >= 0;i--){
    insertionSort(a, n, g[i]);
  }
}
 
main(){
  int n, i;
  
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  shellSort(a, n);
  printf("%d\n", cnt);
  for(i = 0;i < n;i++){
    printf("%d\n", a[i]);
  }
  return 0 ;
}


Measured memory_bytes: 5628
#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;
struct point{
    double x,y;
};
void koch(int n,point a,point b){
    if(n==0) return ;
    point s,t,u;
    s.x=(2*a.x+b.x)/3;
    s.y=(2*a.y+b.y)/3;
    
    t.x=(2*b.x+a.x)/3;
    t.y=(2*b.y+a.y)/3;
    
    u.x=(t.x-s.x)/2-(t.y-s.y)*sqrt(3)/2+s.x;
    u.y=(t.x-s.x)*sqrt(3)/2+(t.y-s.y)/2+s.y;
    
    koch(n-1,a,s);
    printf("%.8f %.8f\n",s.x,s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n",u.x,u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n",t.x,t.y);
    koch(n-1,t,b);
}
int main(){
    point a,b;
    int n;
    scanf("%d",&n);
    
    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x,b.y);
    
    return 0;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define maxn 500010
#define mod 1000000007
int main(){
    double a,b,x;
    cin>>a>>b>>x;
    if(a*a*b/2<=x){
        x=a*a*b-x;
        x=x/a/a*2;
        double ag=atan(x/a)*180/acos(-1);
        printf("%.10lf\n",ag);
    }
    else{
        x=x/a/b*2;
        double ag=atan(b/x)*180/acos(-1);
        printf("%.10lf\n",ag);
    }
    return 0;
}

Measured memory_bytes: 384
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

inline void down(int &x,const int &y){if(x>y)x=y;}
const int maxn = 1100;
const int maxv = 5100;

int n;
struct edge{int y,nex;}a[maxn<<1]; int len,fir[maxn];
inline void ins(const int x,const int y){a[++len]=(edge){y,fir[x]};fir[x]=len;}

int f[maxn],w[maxn],g[2][maxv];
void clear(const int now){for(int i=0;i<maxv;i++) g[now][i]=inf;}
bool dp(const int x)
{
	if(!fir[x]) {f[x]=0;return true;}
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) 
		if(!dp(y))return false;
	int now=1; clear(now); g[now][0]=0;
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) 
	{
		now=!now; clear(now);
		for(int i=0;i<=w[x];i++)
		{
			if(i>=w[y]) down(g[now][i],g[!now][i-w[y]]+f[y]);
			if(i>=f[y]) down(g[now][i],g[!now][i-f[y]]+w[y]);
		}
	}
	int cc=inf;
	for(int i=0;i<=w[x];i++) down(cc,g[now][i]);
	if(cc==inf) return false;
	f[x]=cc;
	return true;
}

int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int x; scanf("%d",&x);
		ins(x,i);
	}
	for(int i=1;i<=n;i++) scanf("%d",&w[i]);
	
	if(!dp(1)) puts("IMPOSSIBLE");
	else puts("POSSIBLE");
	
	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<ii> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &b[i].first, &b[i].second);
  }
  for (int i = 0; i < n; ++i) {
    int best = 1 << 30, k = -1;
    for (int j = 0; j < m; ++j) {
      int cur = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
      if (best > cur) {
        best = cur;
        k = j;
      }
    }
    printf("%d\n", k + 1);
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1<<29;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int v[101],w[101];
ll dp[101][100001]={};
int main() {

	int n,W;
	cin>>n>>W;
	rep(i,n){
		cin>>v[i+1]>>w[i+1];
	}
	for(int i=1; i<W+1; i++){
		for(int j=1; j<n+1; j++){
			if(w[j]<=i)dp[j][i]=max(dp[j-1][i],dp[j][i-w[j]]+v[j]);
			dp[j][i]=max(dp[j][i],dp[j-1][i]);
		}
	}
	cout<<dp[n][W]<<endl;


	return 0;
}



Measured memory_bytes: 11296
using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    static void Main(string[] args) {
        
        var NC = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NC[0];
        var C = NC[1];
        
        var ST = new int[C,200001];
        var ET = new int[C,200001];
        var ans = new int[200001];
        for(int i = 0;i < N;i++){
            var STC = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var S = STC[0];
            var T = STC[1];
            var K = STC[2];
            
            if(ET[K-1,S] == 0){
                ST[K-1,S-1]++;
            }else{
                ET[K-1,S]　=　0;
            }
            
            if(ST[K-1,T-1] == 0){
                ET[K-1,T]--;
            }else{
                ST[K-1,T-1]　=　0;
            }               
        }
        
        long max = 0;
        for(int j = 0;j < C ;j++){
                ans[0] += ST[j,0]+ET[j,0];
        }
        for(int i = 1;i <= 200000;i++){
            for(int j = 0;j < C ;j++){
                ans[i] += ST[j,i]+ET[j,i];
            }
            ans[i] += ans[i-1];
            if(max < ans[i]){
                max = ans[i];
            }
        }   
        Console.WriteLine(max);
     }
     
}
     
     
                   
public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }


Measured memory_bytes: 62928
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  vector<int>vec(n+1);
  rep(i,n){
    int a;
    cin >> a;
    a--;
    vec[a]=i;
  }
  vec[n]=-1;
  int cnt=1;
  int now=vec[0];
  
  int ans=0;
  rep(i,n){
    if(now<vec[i+1]){
      cnt++;
      now=vec[i+1];
    }
    else{
      ans=max(ans,cnt);
      cnt=1;
      now=vec[i+1];
    }
  }
  ans=n-ans;
  cout << ans << endl;
  return 0;     
}


Measured memory_bytes: 1024
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;


void solve()
{
    int n, k;
    scn(n); scn(k);

    set<int> dislikes;
    set<int> aval = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    rep(i, 0, k) {
        int val; 
        scn(val);
        dislikes.insert(val);
        aval.erase(val);
    }

    vector<char> digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    bool used = 0;
    string s = to_string(n);

    rep(i, 0, s.size()) {
        int here = s[i] - '0';
        if(used) {
            auto j = aval.begin();
            if(*j < here) {
                s[i] = digit[*j];
            }
            continue;
        }
        if(dislikes.count(here)) {
            auto j = aval.upper_bound(here);
            if(j == aval.end()) {
                j = aval.begin();
                s[i] = digit[*j];
                for(int j=i-1; j>=0; j--) {
                    auto it = aval.upper_bound(s[j]);
                    if(it == aval.end()) 
                        s[i] = digit[*aval.begin()];
                    else {
                        s[i] = digit[*it]; 
                        break;
                    }
                }
            } else {
                s[i] = digit[*j];
                used = 1;
            }
        }
    }

    string org = to_string(n);

    if(s < org) {
        auto it = aval.begin();
        s += digit[*it];
    }

    cout << s << '\n';
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3708
n, a, b = map(int, input().split())
mod = int(1e+9) + 7
def extgcd(a, b):
  if b == 0:
    return 1, 0
  else:
    x, y, u, v, k, l = 1, 0, 0, 1, a, b
    while l != 0:
      x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
      k, l = l, k % l
    return x
def inved(x):
  a = extgcd(x, mod)
  return a % mod
def doubling(N, M):
  y = 1
  base = N
  while M != 0:
    if M % 2 == 1:
      y *= base
      y %= mod
    base *= base
    base %= mod
    M //= 2
  return y
S = [inved(i+1) for i in range(b)]
A = doubling(2, n)
A = (A - 1) % mod
proda, prodb = 1, 1
for i in range(a):
  proda *= ((n - i) * S[i]) % mod
  proda %= mod
for i in range(b):
  prodb *= ((n - i) * S[i]) % mod
  prodb %= mod
print((A - proda - prodb) % mod)

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

int main() {
  int B, R;
  cin >> B;
  map<string, int> m;
  for (int i = 0; i < B; i++) {
    string s;
    cin >> s;
    m[s] += 1;
  }
  
  cin >> R;
  for (int i = 0; i < R; i++) {
    string s;
    cin >> s;
    m[s] -= 1;
  }
  
  int pos = 0;
  for (auto e : m) {
    pos = max(pos, e.second);
  }
  
  cout << pos << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	
	int n;
	cin >> n;
	int m;
	cin >> m;
	cout << (n + m) % 24;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
#define pb push_back
#define mp make_pair
#define mt make_tuple
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 (a>b) { a=b; return 1; } return 0; }

int main(){
    int n;
    cin >> n;
    vi d(n);
    for(int i=0; i<n; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int ans = d[n / 2] - d[(n - 1) / 2];
    cout << ans << endl;
}

Measured memory_bytes: 640
#133

#入力　
N, D = list(map(int, input().split()))
X = []
for i in range(0,N):
    X.append(list(map(int, input().split())))


count = 0
#距離計算(X_ikとX_jk)(i < J)
for i in range(0,N - 1):
    for j in range(i + 1,N):
        distance = 0;
        for k in range(0, D):
            distance +=  (X[i][k] - X[j][k]) * (X[i][k] - X[j][k])
        for l in range(0,200):
            if(distance == l*l):
                count = count + 1

print(count)

Measured memory_bytes: 3064
(function(input) {
    var a = parse(input, ',');
    var cards = makeCards();
    for (var i = 1; i < a.length; i++) {
        var c = a[i][0];
        delete cards[c];
    }
    if (Object.keys(cards) == 0) {
        return;
    }
    console.log(Object.keys(cards).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function parse(str, sep, ter) {
    sep = sep || ' ';
    ter = ter || '\n';
    str = str.replace(/\n$/, '');
    var a = str.split(ter);
    for (var i = 0; i < a.length; i++) {
        a[i] = a[i].split(sep);
    }
    return a;
}

function makeCards() {
    var ts = ['S', 'H', 'C', 'D'];
    var a = [];
    for (var i = 0; i < ts.length; i++) {
        var t = ts[i];
        for (var j = 1; j <= 13; j++) {
            a[t + ' ' + j] = 1;
        }
    }
    return a;
}

Measured memory_bytes: 7648
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>

using namespace std;


class List{
public:
    struct Node{
        int key;
        Node* prev;
        Node* next;
    };
    Node* nil;
    int cnt;

    List(){
        nil = (Node*)malloc(sizeof(Node));
        nil -> next = nil;
        nil -> prev = nil;
        cnt = 0;
    }

    void Insert(int key){
        cnt++;
        Node *x = (Node*)malloc(sizeof(Node));
        x -> key = key;

        // nil -> 1
        //
        x -> next = nil -> next;
        nil -> next -> prev = x;
        nil -> next = x;
        x -> prev = nil;
    }

    Node* search(int key){
        Node *x = nil -> next;
        while(x -> key != key && x != nil){
            x = x -> next;
        }
        return x;
    }

    void Delete(int key){
        Node *x = this-> search(key);
        if (x == nil) return;
        x -> prev -> next = x -> next;
        x -> next -> prev = x -> prev;
        cnt--;
        free(x);
    }

    void DeleteFirst(){
        cnt--;
        Node *x = nil -> next;
        x -> prev -> next = x -> next;
        x -> next -> prev = x -> prev;
        free(x);
    }
    void DeleteLast(){
        cnt--;
        Node *x = nil -> prev;
        x -> prev -> next = x -> next;
        x -> next -> prev = x -> prev;
        free(x);
    }

    void GetAllKeys(vector<int>& keys){
        Node* x = nil -> next;
        for (int i=0; i<cnt; i++){
            keys.push_back(x -> key);
            x = x -> next;
        }
    }
};




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

    string command;
    int key;

    for (int i=0; i<n; i++){
        cin >> command;
        if (command == "insert") {
            cin >> key;
            list.Insert(key);
        }else if (command == "delete"){
            cin >> key;
            list.Delete(key);
        }else if (command == "deleteFirst") {
            list.DeleteFirst();
        }else if (command == "deleteLast") {
            list.DeleteLast();
        }
    }
    vector<int> keys;
    list.GetAllKeys(keys);
    for (int i=0; i<keys.size(); i++){
        cout << keys[i];
        if (i!=keys.size()-1) cout << " ";
    }
    cout << endl;
}




Measured memory_bytes: 34468
#include <stdio.h>
int main () {
  int minj, a[100], n, i, j, num = 0, tmp;

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

  for(i = 0 ; i < n ; i++) {
    minj = i;
    for(j = i ; j < n ; j++) {
      if(a[j] < a[minj]) {
	minj = j;
      }
    }
     if(minj != i) {
      tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
      num++;
     }
  }

  for(i = 0 ; i < n ; i++) {
    printf("%d", a[i]);
    if(i != n - 1) printf(" ");
  }
  printf("\n");
  printf("%d\n", num);

  return 0 ;
}

Measured memory_bytes: 604
from collections import defaultdict
from fractions import Fraction

INF = int(1e14)


def main():
    N, Ma, Mb = map(int, input().split())
    l = []
    for _ in range(N):
        l.append(tuple(map(int, input().split())))

    ans = INF
    dp = [[[INF] * 401 for i in range(401)] for j in range(N + 1)]
    dp[0][0][0] = 0

    max_a, max_b = 1, 1
    for i in range(N):

        for a in range(max_a, -1, -1):
            for b in range(max_b, -1, -1):
                if dp[i][a][b] != INF:
                    dp[i + 1][a + l[i][0]][b + l[i][1]] = min(dp[i + 1][a + l[i][0]][b + l[i][1]], dp[i][a][b] + l[i][2])
                    dp[i + 1][a][b] = min(dp[i + 1][a][b], dp[i][a][b])

                    max_a = max(max_a, a + l[i][0])
                    max_b = max(max_b, b + l[i][1])

    for a in range(1, len(dp[0])):
        for b in range(1, len(dp[1])):
            if a * Mb == b * Ma:
                ans = min(ans, dp[N][a][b])

    print((-1 if ans == INF else ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 61544
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(n), y(n), z(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i] >> z[i];
    }
    int ans = 0;
    for(int i = 0; i < 8; i++){
        vector<int> d(n);
        rep(j, 0, n){
            d[j] += x[j] * ((i & 1) ? 1 : -1);
            d[j] += y[j] * ((i & 2) ? 1 : -1);
            d[j] += z[j] * ((i & 4) ? 1 : -1);
        }
        sort(d.begin(), d.end());
        reverse(d.begin(), d.end());
        int tmp = 0;
        rep(j, 0, m) tmp += d[j];
        chmax(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

pair<int,int>p[200005];
int ans[200005];
int parent[200005];
int sz[200005];
int rgt[200005];
int mod=998244353;
int find_parent(int ver)
{
   if(ver==parent[ver])
      return ver;
   return parent[ver]=find_parent(parent[ver]);
}

void merge(int a,int b)
{
   a=find_parent(a);
   b=find_parent(b);
   if(a!=b)
   {
      if(sz[a]<sz[b])   
         swap(a,b);
      parent[b]=a;
      sz[a]+=sz[b];
      rgt[a]=max(rgt[a],rgt[b]);
   }
}

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
      cin>>p[i].first>>p[i].second;
   for(int i=1;i<=n;i++)
   {
      parent[i]=i;
      sz[i]=1;
      rgt[i]=i;
   }   
   p[n+1]={1e17,0};
   sort(p+1,p+n+1);
   ans[n+1]=1;
   for(int i=n;i>=1;i--)
   {
      p[i].second--;
      ans[i]=ans[i+1];
      int ini=i;
      while (p[rgt[find_parent(ini)]+1].first-p[i].first<=p[i].second)
      {
         merge(i,rgt[find_parent(ini)]+1);
         ini=rgt[find_parent(ini)];         
      }
      ans[i]+=ans[rgt[find_parent(i)]+1];      
      ans[i]%=mod;
   }
   cout<<ans[1];

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }
 

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
int arr[maxn];
int ans[maxn];
int n; 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
	for(int i=1;i<=n;i++)
	    cin >> arr[i];
	int cur = 0;
	int l = 0 , r = 1; 
	for(int i=n;i>=1;i--)
	{
		if(cur&1)
		    ans[n-r++] = arr[i];
		else 
		    ans[l++] = arr[i];
		cur++; 
	} 
	for(int i=0;i<n;i++)
	{
		if(i!=0)
		    cout << " ";
		cout << ans[i]; 
	} 
	cout << endl; 
    return 0;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public static class Solution
{
    static void ChMax(ref int cur, int next)
    {
        if (cur < next)
        {
            cur = next;
        }
    }

    public static int Solve(int N, int[] A)
    {
        var dp = new int[N, N];
        var max = 0;
        var kMax = Enumerable.Repeat(int.MinValue, N).ToArray();
        var chain = 0;

        void ChMax(int k, int l, int val)
        {
            Solution.ChMax(ref dp[k, l], val);
            Solution.ChMax(ref dp[l, k], val);
            Solution.ChMax(ref max, val);
            Solution.ChMax(ref kMax[k], val);
            Solution.ChMax(ref kMax[l], val);
        }

        for (int y = 0; y < N; y++)
        {
            for (int x = 0; x < N; x++)
            {
                dp[y, x] = int.MinValue;
            }
        }
        ChMax(A[0], A[1], 0);

        for (int i = 2; i < 3 * N - 1; i += 3)
        {
            var upList = new List<(int k, int l, int v)>();
            // k,l,p,p,p -> k,l
            if (A[i] == A[i + 1] && A[i] == A[i + 2])
            {
                chain++;
                continue;
            }

            // k,p,p,p,q -> k,q
            {
                var p = -1;
                var q = -1;
                if (A[i] == A[i + 1])
                {
                    p = A[i];
                    q = A[i + 2];
                }
                else if (A[i + 1] == A[i + 2])
                {
                    p = A[i + 1];
                    q = A[i];
                }
                else if (A[i] == A[i + 2])
                {
                    p = A[i];
                    q = A[i + 1];
                }
                if (p != -1)
                {
                    for (int k = 0; k < N; k++)
                    {
                        upList.Add((k, q, dp[p, k] + 1));
                    }
                }
            }

            for (int j = 0; j < 3; j++)
            {
                var p = A[i + j];
                var q = A[i + (j + 1) % 3];
                var r = A[i + (j + 2) % 3];
                // p,p,p,q,r -> q,r
                upList.Add((q, r, dp[p, p] + 1));

                // k,l,p,q,r -> p,q or q,r or r,p
                upList.Add((p, q, max));

                // k,l,p,q,r -> k,p or k,q or k,r
                for (int k = 0; k < N; k++)
                {
                    upList.Add((k, p, kMax[k]));
                }
            }

            foreach (var kv in upList)
            {
                ChMax(kv.k, kv.l, kv.v);
            }
        }

        var last = A.Last();
        dp[last, last]++;
        Solution.ChMax(ref max, dp[last, last]);
        chain += max;

        return chain;
    }

    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
        var chain = Solve(N, A);
        Console.WriteLine(chain);
    }
}


Measured memory_bytes: 124096
#include<iostream>
#include<cstdio>
#include<stdlib.h>
#include<string>
#include<cstring>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<math.h>
using namespace std;
int H,W,n,x,a[1000][1000];
int main()
{

    cin>>H>>W;
    cin>>n;
    int cur = 1;
    int p = 1,q = 1;
    bool flag = true;
    for (int i = 1; i <= n; i++){
        cin>>x;
        int times = 0;
        while (true){
        a[p][q] = cur;
        if (flag){
            q++;
            if (q>W) {
                q--;
                p++;
                flag = false;
            }
        }
        else{
            q--;
            if (q==0){
                q++;
                p++;
                flag = true;
            }
        }
        times++;
        if (times == x) break;
        }
        cur++;
    }
    for (int i = 1; i <= H; i++){
        for (int j = 1; j < W; j++)
            cout<<a[i][j]<<" ";
        cout<<a[i][W]<<endl;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // code
    vector<int> haiku(3), mihon = {5, 5, 7};
    rep(i, 3) cin >> haiku.at(i);
    sort(all(haiku));
    if (haiku == mihon)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
// problem: "https://atcoder.jp/contests/abc140/tasks/abc140_c"

#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;

    vector<int>V;
    int i,s,x;

    for(i=0;i!=n-1;i++)
    {
        cin>>x;
        V.push_back(x);
    }

    s = V[n-2];

    for(i=n-3;i>=0;i--)
        s += min(V[i],V[i+1]);

    s += V[0];

    cout<<s;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
    // Your code here!
    char num[210000];
    long int num_len;
    long int num_add=0;
    int i;
    
    scanf("%s",num);
    num_len = strlen(num);
    //printf("length:%d\n", num_len);
    if((num_len < 1) || (num_len > 200000)){
        printf("incorrect length\n");
        return -1;
    }
    
    for(i=0;i<num_len;i++){
        if((num[i] < '0') || (num[i] > '9')){
            printf("incorrect number:%d\n", i+1);
            return -1;
        }
        else{
            num_add = num_add + (num[i]-0x30);
            //printf("%d\n", num_add);
        }
    }
    
    if((num_add%9) == 0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    
    return 0;
    
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

map<int, int > prime_factor(int n) {
  map<int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
  int n;
  cin >> n;
  bool pairwise=true;
  vector<int> cnt(1000001,0);
  REP(i,n){
    int a;
    cin >> a;
    map<int, int> mp = prime_factor(a);
    for(auto v: mp){
      int p = v.first;
      if(cnt[p] != 0){
        pairwise=false;
      }
      cnt[p]++;
    }
  }
  if(pairwise){
    cout << "pairwise coprime" << endl;
  }else{
    bool setwise=true;
    FOR(i,2,1000001){
      if(cnt[i]==n)setwise=false;
    }
    if(setwise){
      cout << "setwise coprime" << endl;
    }else{
      cout << "not coprime" << endl;
    }
  }
}



Measured memory_bytes: 7212
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=pow(10,9)+7;
bool cmp(pair<long double, int > x, pair<long double, int> y){ return x.F<y.F && x.S<y.S; }
const ll maxn=2*1e6+10;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
ll random(ll mn, ll mx){
	return (rand() % (mx - mn + 1)) + mn; 
}
void solve(){
	
	string s;
	cin>>s;
	ll q;
	cin>>q;
	ll rs=0;
	deque<char> dq;
	for (int i=0;i<s.size();i++){
		dq.push_back(s[i]);
	}
	while(q--){
		ll t;
		cin>>t;
		if (t==1){
			rs=1-rs;
		}
		else{
			ll f;
			char c;
			cin>>f>>c;
			if (f==1){
				if (rs){
					dq.push_back(c);
				}
				else{
					dq.push_front(c);
				}
			}
			else{
				if (rs){
					dq.push_front(c);
				}
				else{
					dq.push_back(c);
				}
			}
		}	
	}
	
	vector<char> v;
	for (auto i:dq){
		v.pb(i);
	}
	if (rs){
		reverse(v.begin(), v.end());
	}
	for (auto i:v) cout<<i;
	cout<<endl;	
	
	return;
}

int main(){ 
    
    #ifndef ONLINE_JUDGE
  		//freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	//T{ solve(); }
	solve();
	
	return 0;
}

Measured memory_bytes: 1364
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	map<string,int> mope;
	set<string> st;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mope[s]++;
		st.insert( s );
	}
	int ma = -1;
	for( auto it = st.begin(); it != st.end(); ++it){
		if( mope[*it] > ma ) ma = mope[*it];
	}
	set<string> ans;
	for( auto it = st.begin(); it != st.end(); ++it){
		if( mope[*it] == ma )ans.insert(*it);
	}
	for( auto it = ans.begin(); it != ans.end(); ++it ){
		cout<<*it<<endl;
	}
	return 0;
}

Measured memory_bytes: 43904
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MOD 1000000007
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
lld l,x,y,n,m,i,z,p,s,e,q,j,k,c,d,t,a,b;string s1,s2;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin>>s1>>s2;
  s1=s1+s2;
  k=stoi(s1);
 // ck;
  //s1=to_string(a);
  //k=pow(10)
  p=sqrt(k);
  if((p*p)==k)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	const int k = 40;
	vector<ll> d(k, 0);
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < k; ++j) {
			d[j] += ((a[i]>>j) & 1);
		}
	}

	vector<vector<ll>> dp(k, vector<ll>(2, 0));
	for (int i = k - 1; i >= 0; --i) {
		// add1:= Xのiビット目を1にしたときに加算される値
		// add0:= Xのiビット目を0にしたときに加算される値
		ll add1 = (1LL<<i) * (N - d[i]);
		ll add0 = (1LL<<i) * d[i];
		if (i == k - 1) {
			if ((K>>i) & 1) {
				dp[i][1] = add1;
				dp[i][0] = add0;
			} else {
				dp[i][1] = add0;
			}
		} else {
			if ((K>>i) & 1) {
				dp[i][1] = dp[i + 1][1] + add1;
				dp[i][0] = dp[i + 1][1] + add0;
			} else {
				dp[i][1] = dp[i + 1][1] + add0;
			}
			if ((dp[i + 1][0] > 0) || (dp[i][0] > 0)) {
				dp[i][0] = max(dp[i][0], dp[i + 1][0] + max(add1, add0));
			}
		}
	}

	ll res = max(dp[0][0], dp[0][1]);
	cout << res << endl;

	return 0;
}


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


int main() {
	long long a, bn;
	string b;
	
	cin >> a;
	cin >> b;
	for (size_t c = b.find_first_of("."); c != string::npos; c = c = b.find_first_of(".")) {
		b.erase(c, 1);
	}
	a *= atoi(b.c_str());
	cout << a/100 << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>

int main(void) {
	char ST[1001];
	int i, N, W, S, E;
	scanf("%s", ST);
	N = 0; W = 0; S = 0; E = 0;
	for (i = 0; i < strlen(ST); i++) {
		if (ST[i] == 'N') { N++; }
		if (ST[i] == 'W') { W++; }
		if (ST[i] == 'S') { S++; }
		if (ST[i] == 'E') { E++; }
	}
	if ((N == 0 && S == 0) || (N > 0 && S > 0)) {
		if ((E == 0 && W == 0) || (E > 0 && W > 0)) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128