akhauriyash/Code-Regression huggingface dataset:
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define double long double
#define mp make_pair
#define pb push_back
#define er erase
#define cl clear
#define sw swap
#define br break
#define ct continue
#define rt return
#define xx exit(0)
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#define x first
#define y second
#define fo(i,a,b) for(int i=a;i<b;i++)
using namespace std;
struct st{
    
};
bool cmp(){
    return 1;
}
int go(){
    return 0;
}
void recur(){
    
}
void solve(){
    int h,w,m;
    cin>>h>>w>>m;
    int a[h+1],b[w+1];
    for (int i=0; i<=h; i++) a[i]=0;
    for (int i=0; i<=w; i++) b[i]=0;
    map <pair <int,int>,bool> mp;
    for (int i=0; i<m; i++){
        int p,q;
        cin>>p>>q;
        mp[{p,q}]=1;
        a[p]++;
        b[q]++;
    }
    int ma=0,mb=0;
    vector <int> vec,wec;
    for (int i=1; i<=h; i++){
        if (a[i]>ma){
            vec.cl();
            vec.pb(i);
            ma=a[i];
        } else if (a[i]==ma){
            vec.pb(i);
        }
    }
    for (int i=1; i<=w; i++){
        if (b[i]>mb){
            wec.cl();
            wec.pb(i);
            mb=b[i];
        } else if (b[i]==mb){
            wec.pb(i);
        }
    }
    //cout<<endl<<endl<<endl;
    for (auto&i:vec){
        for (auto&j:wec){
            if (!mp[{i,j}]){
                cout<<ma+mb;
                rt;
            }
            //cout<<i<<' '<<j<<endl;
        }
    }
    cout<<ma+mb-1;
    
    
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    fo(i,0,t) solve();
}

Measured memory_bytes: 35044
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

#define MOD 1000000007
#define MAX 1000005
long long int fac[MAX], finv[MAX], inv[MAX];
void MOD_COM_init(){
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for(int i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long int MOD_pow(long long int a, long long int n){
    long long int res = 1;
    while(n>0){
        if(n&1){
            res = res*a % MOD;
        }
        a = a*a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    scanf("%d", &n);
    lld a[n];
    rep(i, 0, n){
        scanf("%lld", &a[i]);
    }
    MOD_COM_init();
    lld t[1000001] = {0};
    rep(i, 0, n){
        lld cnt, buf;
        buf = a[i];
        cnt = 0;
        while(buf % 2 == 0){
            buf /= 2;
            cnt++;
        }
        if(cnt > t[2]){
            t[2] = cnt;
        }
        for(int j=3; j*j<=buf; j+=2){
            cnt = 0;
            while(buf % j == 0){
                cnt++;
                buf /= j;
            }
            if(cnt > t[j]){
                t[j] = cnt;
            }
        }
        if(buf > 1){
            if(t[buf] == 0){
                t[buf] = 1;
            }
        }
    }
    lld x = 1;
    rep(i, 0, 1000001){
        if(t[i] != 0){
            x *= MOD_pow((lld)i, t[i]);
            x %= MOD;
        }
    }
    lld ans = 0;
    rep(i, 0, n){
        ans += x * inv[a[i]] % MOD;
        ans %= MOD;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 31488
#include <stdio.h>
int main()
{
	int N[4];
	int g = 0;
	scanf("%d %d %d %d", &N[0], &N[1], &N[2], &N[3]);
	
	if(N[0] ==1 || N[1] ==1 || N[2] ==1 || N[3] ==1) g++;
	if(N[0] ==4 || N[1] ==4 || N[2] ==4 || N[3] ==4) g++;
	if(N[0] ==7 || N[1] ==7 || N[2] ==7 || N[3] ==7) g++;
	if(N[0] ==9 || N[1] ==9 || N[2] ==9 || N[3] ==9) g++;
	
	if(g == 4) printf("YES");
	else printf("NO");
	
	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define END(x) cout << x << endl; exit(0);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, minimum, maximum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int calc(ll n) {
    ll c = 0;
    for (k = 1; k <= n; k++) {
        if (n % k == 0) c++;
    }
    return c;
}

int main() {
    cin >> n;
    ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (i % 2 == 0) continue;
        ans += calc(i) == 8;
    }
    MSG(ans)
}


Measured memory_bytes: 256
use std::cmp::min;
use std::io::Read;

fn main() {
    let mut buff = String::new();
    std::io::stdin().read_to_string(&mut buff).unwrap();
    let mut iter = buff.split_whitespace();

    let a = iter.next().unwrap().parse::<i32>().unwrap();
    let b = iter.next().unwrap().parse::<i32>().unwrap();
    let c = iter.next().unwrap().parse::<i32>().unwrap();
    let d = iter.next().unwrap().parse::<i32>().unwrap();
    println!("{}", min(a, b) + min(c, d));
}


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

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

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

    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    ll g = gcd(n, m);
    ll L = max(n, m) / g * min(n, m);

    ll ans = L;
    REP(i, g) {
        if (s[i * n / g] != t[i * m / g]) {
            ans = -1;
            break ;
        }
    }

    cout << ans << '\n';
    return 0;
}


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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n, k; cin >> n >> k;
	ll x[n], y[n], t = 0;
	Rep(i, n){
		cin >> x[i];
		y[i] = max(t, x[i]);
	}
	Rep(i, n-1){
		x[i+1] += x[i];
		y[i+1] += y[i];
	}
	ll ans = 0;
	Rep(i, n-k+1){
		if(i == 0){
			ans = max(ans, max(t, x[k-1]) + y[n-1] - y[k-1]);
		}else if(i == n - k){
			ans = max(ans, max(t, x[n-1] - x[n-k-1]) + y[i-1]);
		}else{
			ans = max(ans, max(t, x[k+i-1] - x[i-1]) + y[n-1] - y[k+i-1] + y[i-1]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int main() {
  int x; cin >>x;
  int ans = (x / 500) * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout <<ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
vector<i64> A;

vector<i64> sum;

int main() {
  cin >> N;
  A.resize(N + 1);
  sum.resize(N + 1);
  rep(i,1,N) cin >> A[i];
  rep(i,1,N) sum[i] = sum[i - 1] + A[i];

  i64 ans = 1e18;

  rep(i,2,N - 2) {
    {
      int j = lower_bound(begin(sum) + 1, end(sum), sum[i] / 2) - begin(sum);
      int k = lower_bound(begin(sum) + 1, end(sum), (sum[N] + sum[i]) / 2) - begin(sum);
      for(int cc = max(0, j - 1);cc <= min(i - 1, j + 1);cc++) {
        for(int dd = max(i + 1, k - 1);dd <= min(N, k + 1);dd++) {
          vector<i64> vec = { sum[cc], sum[i] - sum[cc], sum[dd] - sum[i], sum[N] - sum[dd] };
          sort(all(vec));
          ans = min(ans , vec.back() - vec.front());
        }
      }
    }
  }

  cout << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  int s[N];
  int sum = 0;
  for(int i=0;i<N;i++){
    cin >> s[i];
    sum += s[i];
  }
  if(sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }
  sort(s,s+N);

  for(int i=0;i<N; i++){
    if( (sum-s[i]) % 10 != 0){
      cout << sum-s[i] << endl;
      return 0;
    }
  }

  cout << 0 << endl;

}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val n = readInt
  val a = readLine.split(" ").map(_.toInt)

  println(a.mkString(" "))
  var j = 0
  for(i<-1 until a.length) {
    val key = a(i)
    j = i-1
    while( j >= 0 && a(j) > key ) {
      a(j+1) = a(j)
      j -= 1
    }
    a(j+1) = key

    println(a.mkString(" "))
  }
}

Measured memory_bytes: 45560
#include<stdio.h>
#include<string.h>
 
typedef struct p{
  char name[100];
  int time;
}Process;
 
Process Que[100000];
int head, tail, n;
 
void enqueue(Process x){
  Que[tail] = x;
  tail = (tail + 1)%100000;
}
 
Process dequeue(){
  Process x = Que[head];
  head = (head + 1)%100000;
  return x;
}
 
int main(void){
  int i, n, q, e=0;
  scanf("%d %d\n", &n, &q);
  for (i=0;i<n;i++){
      Process que;
      scanf("%s %d", que.name, &que.time);
      enqueue(que);
  }

  while (head != tail){
      Process pro = dequeue();
      if (pro.time <= q){
          e += pro.time;
          printf("%s %d\n", pro.name, e);
      }
      else{
          e += q;
          pro.time -= q;
          enqueue(pro);
      }
  }
}

Measured memory_bytes: 11824
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,x,ans = 0;
    cin >> n >> x;
    vector<ll> sum(n + 1,0),a(n);
    cin >> a[0];
    rep1(i, n){
        cin >> a[i];
        sum[i - 1] = a[i] + a[i - 1];
    }
    rep0(i,n){
        if (sum[i] > x) {
            ans += (sum[i] - x);
            if (sum[i] - x > a[i + 1]) {
                sum[i + 1] -= a[i + 1];
            }else{
                sum[i + 1] -= (sum[i] - x);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

namespace{
   constexpr int g1 = 1000 * 1000 * 1000, si = 1001 * 1002, si_log = 8 + 10, mod = static_cast<int>(1e9) + 7;
   constexpr long double eps = 1.0e-9;
   int n, m;
   char ar[si];
}

int64_t sol() {
   int64_t ret = 0 * numeric_limits<int64_t>::max();
   return ret;
}

int main() {
   ios_base::sync_with_stdio(0); cin.tie(0);
   
   while (1 == scanf("%d", &n))
   {
      memset(ar, 0, sizeof ar);
      //for (int i = 0; i <= n; i++)  { gr[i].clear(); }
      //for (int i = 1; i < n; i++) {
      //   int a, b; cin >> a >> b; gr[a].push_back(b); gr[b].push_back(a);
      //}
      auto s =0
         //sol()
      ;
      
      for (int i = 0; i < n; i++)
      {
         int x, y; scanf("%d%d", &x, &y);
         for (int j = x; j <= y; j++) ar[j] = 1;
      }

      for (int i = 0; i <= 100*1000; i++)
         s += ar[i];
      //cout << (s ? "Yes": "No") << '\n';
      cout << s << '\n';
#ifndef _DEBUG
      break;
#endif
   }
   return 0;
}

Measured memory_bytes: 1280
import sys
input = sys.stdin.readline
from operator import itemgetter
from collections import deque

class Unionfindtree:
    def __init__(self, number):
        self.par = [i for i in range(number)]
        self.rank = [0] * (number)

    def find(self, x):  # 親を探す
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):  # x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] < self.rank[py]:
            self.par[px] = py
        else:
            self.par[py] = px
        if self.rank[px] == self.rank[py]:
            self.rank[px] += 1

    def connect(self, x, y):  # 親が同じかみる
        return self.find(x) == self.find(y)


N,M=map(int,input().split())
table=[[int(i) for i in input().split()]for i in range(M)]
Q=int(input())
query=[[int(i) for i in input().split()]for i in range(Q)]
table = sorted(table,key=itemgetter(2))
if N<3:
    for a,b in query:
        print(0)
    sys.exit()
T=Unionfindtree(N)
sear=Unionfindtree(2*N-1)
ans=0
value=[0]*(N+N-1)
dp=[[0]*(2*N-1) for i in range(16)]
table2=[[] for i in range(2*N-1)]
s=0
for i in range(M):
    a,b,c=table[i]
    a,b=a-1,b-1
    if not T.connect(a,b):
        ans+=c
        T.union(a,b)
        value[s+N]=c
        le=a
        ri=b
        for j in range(s+N,N-1,-1):
            if sear.connect(a,j):
                le=j
                break
        for j in range(s+N,N-1,-1):
            if sear.connect(b,j):
                ri=j
                break
        table2[s+N].append(le)
        table2[s+N].append(ri)
        sear.union(le,s+N)
        sear.union(ri,s+N)
        s+=1
    if s==N-1:
        break

H=deque()
H.append((0,2*N-2))
depth=[-1]*(2*N-1)
depth[2*N-2]=0
while H:
    dep,pt=H.popleft()
    for p in table2[pt]:
        H.append((dep+1,p))
        depth[p]=dep+1
        dp[0][p]=pt
#print(table2)
#print(depth,dp[0])

for k in range(1,16):
    for x in range(2*N-1):
        dp[k][x]=dp[k-1][dp[k-1][x]]
def LCA(s,t):
    if depth[s]>depth[t]:
        s,t=t,s
    for k in range(16):
        if ((depth[t]-depth[s] )>>k) & 1:
            t = dp[k][t]
    if s==t:
        return s
    for k in range(15,-1,-1):
        if dp[k][s]!=dp[k][t]:
            s=dp[k][s]
            t=dp[k][t]
    return dp[0][s]

for s,t in query:
    s,t=s-1,t-1
    pa=LCA(s,t)
    #print(pa,value[pa])
    print(ans-value[pa])





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

using namespace std;

int main()
{
    string s;
    cin >> s;

    int len = s.size();

    vector<int> t(len + 1);
    vector<int> bucket(2019, 0);

    int i,j,dig = 1;
    t[len] = 0;
    bucket[0] = 1;
    for (i = len - 1; i >= 0; i--)
    {
        t.at(i) = t.at(i + 1) + dig * (s.at(i) - '0');
        dig *= 10;
        dig %= 2019;
        t[i] %= 2019;
        bucket[t[i]]++;
    }
    
    long long ans = 0;
    for (i = 0; i < 2019; i++)
    {
        ans += bucket[i] * (bucket[i] - 1) / 2; 
    }

    cout << ans << endl;
}

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

int main(){
	int n, m, k, s, p;
	if(scanf("%d %d ",&n, &m)==EOF){return 0;}
	
	int lightbutton[m][n];
	memset(lightbutton, 0, sizeof(int)*m*n); //一応sizeof(lightbutton)でも良い？
	for(int i = 0; i<m; i++){
		if(scanf("%d",&k)==EOF){return 0;}
		for(int j = 0; j < k; j++){
			if(scanf("%d",&s)==EOF){return 0;}
			lightbutton[i][s-1] = 1;
		}
	}

	int condition[m];
	for (int i = 0; i<m; i++){
		if(scanf("%d",&p)==EOF){return 0;}
		condition[i] = p;
	}
	
	/*
	printf("\n");
	for(int i = 0; i<m; i++){
		for(int j = 0; j < n; j++){
			printf("%d ", lightbutton[i][j]);
		}
		printf("\n");
	}*/
	
	
	int count =0;
	int ng = 0;
	int onswitch;
	
	for (int bit = 0; bit < (1 << n); bit++){
		for(int i = 0; i<m; i++){
			//各電灯を見る
			onswitch = 0;
			//掛け算の計算
			for(int j = 0; j < n; j++){
				if((bit &(1 << j)) && lightbutton[i][j]==1){
					onswitch++; 
				}
			}
			//printf("colimn %d:onswitch(bit:%d):%d\n", i, bit, onswitch); 
			if(condition[i] != onswitch %2){ng = 1; break;}
		}
		if(ng == 0){count++;} //printf("OK:%d\n", bit); 
		else{ ng = 0;} //printf("NG:%d\n", bit);
		
	}


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



Measured memory_bytes: 1676
a ,b ,c = map(int,input().split())
if a == b == c and a % 2 == 0:
    ans = -1
else:
    ans = 0
    while True:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            break
        na = a
        nb = b
        nc = c
        a = (nb + nc)//2
        b = (na + nc)//2
        c = (na + nb)//2
        ans += 1
print(ans)

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

int main() {
  int H, W;
  cin >> H >> W;
  
  //waku-ue
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    
    vector<char> A(W);
    for (int j = 0; j < W; j++)
      cin >> A.at(j);
    
    cout << "#";
    for (int j = 0; j < W; j++)
      cout << A.at(j);
    cout << "#";
    cout << endl;
  }
  
  //waku-shita
  for (int i = 0; i < W + 2; i++)
    cout << "#";
  
}
    
    

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int main() {

	FAST;

	int x, n;
	cin >> x >> n;
	vector <int> a(n + 1);
	vector <bool> yes(105);
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
		yes[a[i]] = true;
	}
	int minn = 105, ans = 105;
	for (int i = 0; i <= 101; i ++) {
		if (!yes[i]) {
			if (minn > abs(i - x)) {
				minn = abs(i - x);
				ans = i;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i = 0 ; i <m ; i++){
    cin >> b.at(i);
  }
  
  vector<vector<int>> a(n, vector<int>(m));
  for(int i = 0; i<n ;i++){
    for(int j = 0; j<m ; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  int Ans =0;
  
  for(int i = 0; i<n ;i++){
    int s = 0;
    for(int j = 0; j<m ; j++){
      s += a.at(i).at(j) * b.at(j) ;
    }
    if( s + c > 0) {
      Ans++;
    }
  }
  
  cout << Ans << endl;
}

  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i<n; i++)
#define rep1(i, n) for (int i = 1; i<n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    vector<vector<int>> b(3, vector<int>(3));
    
    rep(i,3)rep(j,3) cin >> b[i][j];
    cin >> N;
    
    vector<int> r(N);
    rep(i, N) cin >> r[i];
    rep(i,3)rep(j,3)rep(k, N){
        if(b[i][j] == r[k]){
            b[i][j] = 0;
            break;
        }
    }
    
    
    int cnt = 0;
    rep(i, 3){
        //cout << b[i][0] << b[i][1] << b[i][2];
        if(b[i][0] + b[i][1] + b[i][2] == 0){
            puts("Yes");
            cnt++;
            break;
        }
    }
    
    if (cnt == 0){
        rep(j, 3){
            //cout << b[0][j] << b[1][j] << b[2][j];
            if(b[0][j] + b[1][j] + b[2][j] == 0){
                puts("Yes");
                cnt++;
                break;
            }
        }
    }
    
    if (cnt == 0){
        
        if (b[0][0] + b[1][1] + b[2][2] == 0){
            puts("Yes");
            cnt++;
        }
        else if (b[2][0] + b[1][1] + b[0][2] == 0){
            puts("Yes");
            cnt++;
        }
        
        //else puts("No");
    }
    
    if (cnt == 0) puts("No");
        
    //cout << N/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n, total;
int a[21], b, c[21];

int main(){

	cin >> n;
	rep(i, n)cin >> a[i];
	rep(i, n){
		cin >> b;
		total += b;
	}
	rep(i, n - 1)cin >> c[i];

	rep(i, n - 1){
		if (a[i] + 1 == a[i + 1])total += c[a[i] - 1];
	}

	cout << total << endl;

	return 0;
}



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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


const int MAX = 1510000;
int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

void Main()
{

	int x,y; cin >> x >> y;
	if(x>y){
		int tmp = x;
		x = y;
		y = tmp;
	}


	if((x+y) % 3 != 0){
		cout << 0 << endl;
		return;
	}

	int a = (x+y)/3;
	int b = x-a;

	if(a > x || a > y){
		cout << 0 << endl;
		return;
	}

	//dump(a)
	//dump(b)

    COMinit();

    // 計算例
    cout << COM(a, b) << endl;
	//cout << (aa / bb)%MOD << endl;






	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 35712
#include<bits/stdc++.h>
using namespace std;
vector<unsigned long> v;

void tap(unsigned long k, unsigned long p){
    if(k > 3234566667)return;
    v.push_back(k);
    for(unsigned long i{max(p, 1UL) - 1}, j{min(p, 8UL) + 1}; i <= j; ++i)tap(10 * k + i, i);
}

int main(){
    for(unsigned long i{1}; i <= 9; ++i)tap(i, i);
    sort(v.begin(), v.end());
    unsigned long K;
    cin >> K;
    cout << v[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Train {
	ll t;
	int is_in;
	Train(ll _t, int _is_in) :t(_t), is_in(_is_in) {}
	bool operator< (const Train& tr) {
		if (t == tr.t) {
			return is_in < tr.is_in;
		}
		else {
			return t < tr.t;
		}
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	while (1) {
		string s;
		getline(cin, s);
		if (s == ".") break;
		bool flag = true;
		stack<char> st;
		for (ll i = 0; i < s.size(); i++) {
			if (s[i] == '(') {
				st.push('(');
			}
			if (s[i] == ')') {
				if (st.empty() || st.top() != '(') {
					flag = false;
					break;
				}
				st.pop();
			}
			if (s[i] == '[') {
				st.push('[');
			}
			if (s[i] == ']') {
				if (st.empty() || st.top() != '[') {
					flag = false;
					break;
				}
				st.pop();
			}
		}
		if (!st.empty()) flag = false;
		if (flag) puts("yes");
		else puts("no");
	}
	return 0;
}


Measured memory_bytes: 3168
n = int(input())
xys = []
for i in range(n):
    x, y = list(map(int, input().split(' ')))
    xys.append((x, y))
# 全部の組み合わせを足して割った数と同じ？
temp = 0.0
for i in range(n):
    for j in range(n):
        temp += (((xys[i][0] - xys[j][0]) ** 2 + (xys[i][1] - xys[j][1]) ** 2) ** 0.5)
print(temp / n)

Measured memory_bytes: 9312
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int A,B;

int main(){
    cin>>A>>B;

    if(A*B%2==1){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>


using namespace std;

short heap_index[10000];

struct Info{
	Info(){
		to=0;
		weight = 0;
	}
	Info(short arg_to,int arg_weight){
		to = arg_to;
		weight = arg_weight;
	}
	short to;
	int weight;
};

class InfoPQ{
public:
	InfoPQ(){
		array = new Info[10000];
		n = 0;
	}
	void push(Info arg_info){
		array[n] = arg_info;
		int tmp = n;
		while(tmp != 0 && array[tmp].weight < array[(tmp-1)/2].weight){
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
		n++;
	}

	bool isEmpty(){
		return n == 0;
	}

	void writeHeapIndex(){
		for(int i=0;i<n;i++){
			heap_index[array[i].to] = i;
		}
	}

	void update(short update_index,int new_weight){
		array[heap_index[update_index]].weight = new_weight;
		int tmp = heap_index[update_index];
		while(tmp != 0 && array[tmp].weight < array[(tmp-1)/2].weight){
			std::swap(heap_index[array[tmp].to],heap_index[array[(tmp-1)/2].to]);
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
	}

	Info pop(){
		Info ret = array[0];
		n--;
		heap_index[array[n].to] = 0;
		std::swap(array[0],array[n]);
		int tmp = 0;
		while(2*tmp+1 <= n-1){
			if(2*tmp+2 <= n-1){
				if(array[2*tmp+2].weight < array[tmp].weight && array[2*tmp+2].weight <= array[2*tmp+1].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+2].to]);
					std::swap(array[2*tmp+2],array[tmp]);
					tmp = 2*tmp+2;
				}else if(array[2*tmp+1].weight < array[tmp].weight && array[2*tmp+1].weight <= array[2*tmp+2].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+1].to]);
					std::swap(array[2*tmp+1],array[tmp]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}else{
				if(array[tmp].weight > array[2*tmp+1].weight){
					std::swap(heap_index[array[tmp].to],heap_index[array[2*tmp+1].to]);
					std::swap(array[tmp],array[2*tmp+1]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}
		}
		return ret;
	}

private:
	Info* array;
	int n;
};



int main(){
	int n,count=0,tmp,left_node,right_node,dist;
	scanf("%d",&n);
	vector<Info> V[n];
	Info catcher;
	InfoPQ A;

	int P[n],zero_dist[n];

	for(int i=0;i<n;i++){
		P[i]=0;
		zero_dist[i] = 10000001;
	}
	zero_dist[0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		if(left_node == 0){
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				zero_dist[right_node] = dist;
			}
		}else{
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				V[left_node].push_back(Info(right_node,dist));
			}
		}
	}

	for(short k=1;k<n;k++){
		A.push(Info(k,zero_dist[k]));
	}

	A.writeHeapIndex();

	while(count<n-1){

		catcher = A.pop();
		P[catcher.to]=1;
		count++;

		for(int k=0;k<V[catcher.to].size();k++){
			if(zero_dist[V[catcher.to][k].to] > catcher.weight+V[catcher.to][k].weight){
				zero_dist[V[catcher.to][k].to] = catcher.weight+V[catcher.to][k].weight;
				A.update(V[catcher.to][k].to,catcher.weight+V[catcher.to][k].weight);
			}
		}
	}

	for(int i=0;i<n;i++){
		printf("%d %d\n",i,zero_dist[i]);
	}

    return 0;
}

Measured memory_bytes: 7324
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


int main() {
    // freopen("input.txt","r",stdin);
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n, k;
    cin >> n >> k;
    vl a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    set<ll> kek;
    for (ll i = 0; i < k; ++i) {
        kek.insert(a[i]);
    }

    ll sorted = 0;
    ll curr = 0;
    vb s(n);
    for (ll i = 0; i + 1 < n; ++i) {
        if (a[i] < a[i + 1]) {
            ++curr;
            if (curr >= k - 1) {
                ++sorted;
                s[i + 1] = true;
            }
        } else {
            curr = 0;
        }
    }

    ll ans = 1;
    bool flag = s[k - 1];
    for (ll i = k; i < n; ++i) {
        bool eq = (a[i] > *kek.rbegin() && a[i - k] == *kek.begin());
        if (!eq) {
            if (!(s[i] && flag)) {
                ++ans;
            }
            flag |= s[i];
        }

        kek.erase(a[i - k]);
        kek.insert(a[i]);
    }
    
    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    ll h,w; cin >> h >> w;
    ll ans = 0;
    if((h*w) % 2 == 0) ans = h*w/2;
    else ans = (h*w+1)/2;
    if(h == 1 || w == 1) ans = 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int leng = int.Parse(ReadLine());
        string input = ReadLine();
        int max = 0;
        int temp = 0;
        for(int i=0;i<leng;i++){
            if(input[i] == 'I'){
                temp++;
                max = Max(temp,max);
            }else if(input[i] == 'D'){
                temp--;
            }
        }
        WriteLine(max);
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int rec(vector<string> s, int top, int bot, int lev) {
    if (s[top][lev] >= '0' && s[top][lev] <= '9') return s[top][lev]-'0';
    
    vector<int> a;
    int y = top;
    int x = lev+1;
    while (y+1 <= bot && x < s[y+1].size() && s[y+1][x] != ' ') {
        y++;
        if (s[y][x] >= '0' && s[y][x] <= '9') {
            a.push_back(s[y][x]-'0');
        }
        else if (s[y][x] == '+' || s[y][x] == '*') {
            int b = y;
            while (b+1 <= bot && s[b+1][x] == '.') b++;
            a.push_back(rec(s,y,b,x));
            y = b;
        }
    }
    
    //printf("top=%d bot=%d lev=%d | ",top,bot,lev);
    //for (int i = 0; i < a.size(); i++) cout << a[i] << " "; cout << endl;
    
    int sum = 0;
    if (s[top][lev] == '+') for (int i = 0; i < a.size(); i++) sum += a[i];
    else if (s[top][lev] == '*') {
        sum = 1;
        for (int i = 0; i < a.size(); i++) sum *= a[i];
    }
    return sum;
}

int main(void){
    int n;
    while (cin>>n && n) {
        vector<string> s(n);
        for (int i = 0; i < n; i++) cin >> s[i];
        cout << rec(s, 0, n-1, 0) << endl;
    }
}

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

int main(){
  int n,x,l;
  int d=0;
  int count=1;
  cin>>n>>x;
  for(int i=1;i<=n;i++){
    cin>>l;
      d+=l;
      if(d<=x) count++;
  }
  
  cout<<count<<endl;
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll a,b;
    cin>>a>>b;
    if(a<10&&b<10)cout<<a*b<<endl;
    else cout<<-1<<endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>

using namespace std;

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int cost;
    if (N > K) {
        cost = K * X + (N - K) * Y;
    } else {
        cost = N * X;
    }
    cout << cost << endl;
    return 0;
}

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

int main() {
    int k, n;
    cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h, h + n);
    int ans = 1e9;
    for (int i = 0; i + k - 1 < n; i++) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            string S = Console.ReadLine();
            for (int i = 0; i < S.Length; i++)
            {
                char c = S[i];
                if (c == '1') c = '9';
                else if (c == '9')
                    c = '1';
                Console.Write(c);
            }
            Console.WriteLine();
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11092
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

count = 0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      count += 1 if x == 500*i + 100*j + 50*k
    end
  end
end
printf("%d\n",count)

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s,p;

int main()
{
    ft
    int i,j,n,m,l,r,a[3];
    for(i=0;i<3;i++)
    {
        cin>>a[i];
    }
    sort(a,a+3);
    if((a[0]==a[1] && a[2]!=a[0]) || (a[1]==a[2] && a[0]!=a[1]))
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{	
    ll n;
    cin >> n;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];
    ll min_cnt = 0;
    ll max_cnt = 0;
    int bit = 0b00000000;
    bool less_than_3200 = true;

    REP(i, n){
        for(int rate = 0; rate < 3200; rate += 400){
            if(rate <= v[i] && v[i] < rate + 400){
                less_than_3200 = false;
                int loop_cnt = (rate / 400) + 1;
                    if(!(bit & (1 << loop_cnt - 1))){
                        min_cnt++;
                        max_cnt++;
                    }
                bit = bit | (1 << loop_cnt - 1);
                //cout << bitset<8>(bit) << endl;
            }   
        }
        if(v[i] >= 3200) max_cnt++;
    }
    if(less_than_3200) min_cnt = 1;
    cout << min_cnt << " " << max_cnt << endl;
}


Measured memory_bytes: 3632
n = int(input())
h_list = list(map(int, input().split()))
if n == 1:
    print(h_list[0])
elif n == 2:
    print(abs(h_list[1]-h_list[0]))
else:
    dp1 = 0
    dp2 = abs(h_list[1]-h_list[0])
    dp3 = 0
    for i in range(2, n):
        if abs(h_list[i]-h_list[i-1]) + dp2 >= abs(h_list[i]-h_list[i-2]) + dp1:
            dp3 = abs(h_list[i]-h_list[i-2]) + dp1
        else:
            dp3 = abs(h_list[i]-h_list[i-1]) + dp2
        dp1 = dp2
        dp2 = dp3
    print(dp2)

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

bool is_match(int n, int m, vector<string> a, vector<string> b) {
    for (int i = 0; i < n-m+1; i++) {
        vector<size_t> vi;
        for (int j = 0; j < n-m+1; j++) {
            size_t idx = a[i].find(b[0], j);
            if (idx != string::npos) vi.push_back(idx);
            else break;
        }
        
        if (m == 1 and !vi.empty()) return true;
        
        for (auto& idx : vi) {
            for (int j = 1; j < m; j++) {
                if (a[i+j].find(b[j], idx) != idx) break;
                if (j == m-1) return true;
            }
        }
    }
    return false;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> a(n);
    for(auto& e : a) cin >> e;
    vector<string> b(m);
    for(auto& e : b) cin >> e;
    
    cout << (is_match(n, m, a, b) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n, a;
    cin >> n >> a;
    while(n>=500){
        n = n - 500;
    }
    if(n<=a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int min(int x, int y)
{
	return (x < y)?x:y;
}
int main()
{
	int n, k,s=0;
	int i, j, x[105] = {0};
	cin >> n >> k;
	for (i = 0; i < n; i++)
		cin >> x[i];
	for (i = 0; i < n; i++)
		s += 2*min(x[i], k - x[i]);
	cout << s << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e30)
#define PI (acos(-1))
int n;
ll a[300001];
priority_queue<int, vector<int>, greater<int>> que;
priority_queue<int> que2;
int main() {
    cin >> n;
    for (int i=0;i<3*n;i++) cin >> a[i];
    // 前半の和を求める(i個とった時)
    ll sum[2*n] = {};
    for (int i=0;i<n;i++) {
        que.push(a[i]);
        sum[0] += a[i];
    }
    for (int i=n;i<2*n;i++) {
        // cout << "sum " << i-n << " " << sum[i-n] << endl;
        que.push(a[i]);
        sum[i-n+1] = sum[i-n] + a[i] - que.top();
        que.pop();
    }
    // 後半の和を求める(後ろからi個とった時)
    ll sum2[2*n] = {};
    for (int i=2*n;i<3*n;i++) {
        que2.push(a[i]);
        sum2[0] += a[i];
    }
    for (int i=2*n-1;i>=n;i--) {
        // cout << "sum2 " << 2+n-i-1 << " " << sum2[2*n-i-1] << endl;
        que2.push(a[i]);
        sum2[2*n-i] = sum2[2*n-i-1] + a[i] - que2.top();
        que2.pop();
    }
    // 最大値を求める
    ll ans = -INF;
    for (int i=0;i<=n;i++) ans = max(ans, sum[i] - sum2[n-i]);
    cout << ans << endl;
}

Measured memory_bytes: 6904
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using namespace std;
signed main() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++) {
        if (A.at(i) == 0) {
            cout << 0 << endl;
          return 0;
        }
    }
    Bint sum = 1;
    int ABC = 0;
    for (int i = 0; i < N; i++) {
        if (A.at(i) == 0) {
            break;
        }
        sum *= A.at(i);
        if (sum > 1000000000000000000) {
            ABC += 2;
            break;
        }
    }
    if (ABC == 2) {
        cout << "-1" << endl;
    }
    else {
        cout << sum << endl;
    }
}

Measured memory_bytes: 4092
# -*- coding:utf-8 -*-
S=input()
if S=="SUN":
    print(7)
elif S=="MON":
    print(6)
elif S=="TUE":
    print(5)
elif S=="WED":
    print(4)
elif S=="THU":
    print(3)
elif S=="FRI":
    print(2)
else:
    print(1)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main() {
   string b;
   cin >> b;
   if(b == "A"){
       cout << "T" << endl;
   }else if(b == "T"){
       cout << "A" << endl;
   }else if(b == "G"){
       cout << "C" << endl;
   }else{
       cout << "G" << endl;
   }
}

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

int main()
{
	int n;
    cin>>n;
	vector<int> d(n);
	rep(i,n) cin>>d[i];

	sort(d.begin(),d.end());
	int a=d[n/2-1],b=d[n/2];
	cout<<b-a<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//fixed<<setprecision(15);
signed main(){
    string s; cin >> s;
    for(int bit=0; bit<(1<<3); bit++){
        int tmp=s[0]-'0';
        rep(i,3){
            if(bit&(1<<i)){
                tmp+=s[i+1]-'0';
            }else{
                tmp-=s[i+1]-'0';
            }
        }
        if(tmp==7){
            rep(i,3){
                cout<<s[i]<<((bit&(1<<i))?'+':'-');
            }
            cout<<s[3]<<"=7"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
B = list(map(int, input().split()))
A = [0] * N

A[0] = B[0]
for i in range(1, N-1):
    A[i] = min(B[i], B[i-1])
A[N-1] = B[-1]

print(sum(A))


Measured memory_bytes: 3060