akhauriyash/Code-Regression huggingface dataset:
#include<iostream>    
#include<cstdio>  
#include<stdio.h>  
#include<cstring>    
#include<cstdio>    
#include<climits>    
#include<cmath>   
#include<vector>  
#include <bitset>  
#include<algorithm>    
#include <queue>  
#include<map>  
using namespace std;

long long int MAX,MIN,i,n,m,x,y,z,ans1,ans2,ans3,ans4;
int main()
{
	cin>>n>>m;
	if(n%3==0||m%3==0)
	{
		cout<<0<<endl;
		return 0;
	}
	ans1=n;
	ans2=m;
	ans3=ans4=9999999;
	for(i=1;i<=n;i++)
	{
		x=i*m;
		if(m%2!=0)
		{
			y=(n-i)*(m/2+1);
			z=(n-i)*(m/2);
		}
		else
		{
			y=z=(n-i)*(m/2);
		}
		MAX=max(z,max(x,y));
		MIN=min(z,min(x,y));
		ans3=min(MAX-MIN,ans3);
	}
	for(i=1;i<=m;i++)
	{
		x=i*n;
		if(n%2!=0)
		{
			z=(m-i)*(n/2+1);
			y=(m-i)*(n/2);
		}
		else
		{
			y=z=(m-i)*(n/2);
		}
		MAX=max(x,max(y,z));
		MIN=min(x,min(y,z));
		ans4=min(MAX-MIN,ans4);
	}
	cout<<min(min(ans1,ans2),min(ans3,ans4))<<endl;	
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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 lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<lint, char> pa;

lint N, K, A;
vector<lint> to[100000];
lint ans = 0;

lint dfs(lint curr, lint prv) {
	lint maxv = 0;
	for (lint v : to[curr]) {
		if (v == prv) continue;
		chmax(maxv, dfs(v, curr) + 1);
	}
	if (maxv == K - 1 && prv != 0) {
		ans++;
		return -1;
	}
	return maxv;
}

int main() {
	cin >> N >> K;
	cin >> A;
	if (A != 1) ans++;
	REP(i, N - 1) {
		cin >> A; A--;
		to[A].push_back(i + 1);
	}
	dfs(0, 0);
	cout << ans << endk;
}

Measured memory_bytes: 13728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int m, n;
  m = A % K;
  n = K - m;
  if(A + n <= B || m == 0){
  cout << "OK" << endl;
  }else{
  cout << "NG" << endl;
  }
}

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sd pop_back

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

ll p,q,r,n,m,ans;
char b;
string s,t,u;

int main(){
  ios::sync_with_stdio(false);
  cin>>s>>t>>u;
  b='a';
  reverse(all(s));
  reverse(all(t));
  reverse(all(u));
  while(1){
    if(b=='a'){
      if(s.size()==0){
        dump('A');
        return 0;
      }
      b=s.back();
      s.sd();
    }
    else if(b=='b'){
      if(t.size()==0){
        dump('B');
        return 0;
      }
      b=t.back();
      t.sd();
    }
    else if(b=='c'){
      if(u.size()==0){
        dump('C');
        return 0;
      }
      b=u.back();
      u.sd();
    }
  }
}

Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    int n = 0, h = 0, suma = 0;
    cin >> h >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        suma += a[i];
    }
    cout << (h > suma ? "No" : "Yes") << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 640
n=int(input())
s=list(input())
m=2*n
mod=10**9+7

if s[0]=="W" or s[m-1]=="W":
    print(0)
    exit()

rl=["L"]
for i in range(1,m):
    if s[i-1]==s[i]:
        if rl[i-1]=="R":
            rl.append("L")
        else: 
            rl.append("R")
    else:
        if rl[i-1]=="L":
            rl.append("L")
        else: 
            rl.append("R")
if rl[m-1]=="L":
    print(0)
    exit()
nl=0
for i in range(m):
    if rl[i]=="L":
        nl+=1
if nl!=n:
    print(0)
    exit()
    
ans=1
li=0
ri=0
for i in range(m):
    if rl[i]=="L":
        li+=1
    else:
      if li-ri<0:
          ans=0
      ans*=li-ri
      ans=ans%mod
      ri+=1
    if i>=1 and i<=n:
        ans*=i
        ans=ans%mod
print(ans)

Measured memory_bytes: 6336
#if 0
2020.01.30

每行放一个颜色即可构造 n = k 的方案。
如果 k 为 4 的倍数，每行相间放两个颜色即可构造 n = k / 2 的方案。
但是如果 k 不是 4 的倍数的时候这个构造方法就不使用了，
任何一行如果只放一个颜色，由于其相邻的行是相间的，不符合要求。

从斜行方向考虑，每斜行放一个颜色同样可以构造 n = k 的方案。
同样如果 k 为 4 的倍数，每斜行相间放两个颜色即可构造 n = k / 2 的方案。
而这个构造方式很优秀，把一斜行换成只填一种颜色仍然合法，
因为两斜行的相交部分本来就是相邻两个块。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
} read;

const int maxn = 500;
int a[maxn][maxn];

int main() {
	int k = read;
	int n = (k + 3) >> 2 << 1;

	if(k == 1) {
		puts("1");
		puts("1");
		return 0;
	}

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

	for(int i = 0; i < n; i ++) {
		int x = ++ c;
		if(x > k)
			x = a[i][0];
		for(int j = 1; j < n; j += 2)
			a[(i + j) % n][j] = x;
	}

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


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

public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        long x = long.Parse(input[0]);
        long y = long.Parse(input[1]);
        long a = 1000000007;
        x *= a;
        y = x%y;
        if(y==0){
            WriteLine("-1");
        }else{
            WriteLine(x);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l[10];
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; ++i)
        cin >> l[i], sum += l[i];

    sort(l, l + n);
    if (sum - l[n - 1] > l[n - 1])
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 256
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
void makeit(int a[])
{
    int i,j;
    for(i=12;i>=0;i--)
    {
        if(a[i]>=10)
        {
            a[i]=a[i]-10;
            a[i-1]++;
        }
        else
            break;
    }
    for(i=0;;i++)
        if(a[i]!=0)
            break;
    int f=0;
    for(j=i+1;j<13;j++)
    {
        if(abs(a[j]-a[j-1])>1)
        {
            if(a[j]>a[j-1])
            {
                a[j-1]++;
                a[j]=a[j-1]-1;
            }
            else
            {
                a[j]=a[j-1]-1;
            }
            f=1;
            j=j+1;
            while(j<13)
            {
                a[j]=max(a[j-1]-1,0);
                j++;
            }
            break;
        }
    }
    if(f)
        makeit(a);
    return ;
}
int main()
{
    ll n,k;
    cin>>n;
    if(n<9)
        cout<<n;
    else
    {
        int a[13]={0},i;
        a[12]=9;
        for(i=10;i<=n;i++)
        {
            a[12]++;
            makeit(a);
        }
        for(i=0;;i++)
        {
            if(a[i]!=0)
                break;
        }
        for(;i<13;i++)
            cout<<a[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void) {
    int a,b;
    int c;
    int count;
    while(!feof(stdin)) {
        scanf("%d %d",&a,&b);
        while(!feof(stdin) && getchar()!='\n');
        if(feof(stdin))break;
        c=a+b;
        if(c<0)c=-c;
        for(count=0;c>0;count++)c/=10;
        if(a+b==0)count=1;
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int N;
    cin >> N;
    int i = 1;
    for ( ; i <= 9; i++) {
        if (N <= 111 * i) {
            break;
        }
    }
    cout << i * 111 << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    double a,b,x;
    cin>>a>>b>>x;
    double ans;
    if(x<=a*a*b*0.5){
        ans=atan2(b,2*x/(a*b))*180/M_PI;
    }
    else{
        double y=a*a*b-x;
        ans=atan2(2*y/(a*a),a)*180/M_PI;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
A=list(map(int, input().split()))

c=1
path=[]
d={}
l=0
while l<=k:
    if c in d:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print(path[k])


Measured memory_bytes: 32376
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
struct PersistentUnionFind {

    int global_time;
    vector < vector < int > > rank;
    vector < vector < int > > time;
    vector < vector < int > > parent;

    PersistentUnionFind(int n) : rank(n), time(n), parent(n) {
        for (int i = 0; i < n; i++) {
            rank[i].push_back(1);
            time[i].push_back(0);
            parent[i].push_back(i);
        }
        global_time = 0;
    }

    bool unite(int x, int y) {
        global_time++;
        x = root(x, global_time); 
        y = root(y, global_time);
        if (x != y) {
            if (rank[y] > rank[x]) swap(x, y);
            int r = rank[x].back() + rank[y].back();
            rank[x].push_back(r);
            rank[y].push_back(r);
            time[x].push_back(global_time);
            time[y].push_back(global_time);
            parent[x].push_back(x);
            parent[y].push_back(x);
        }
        return x != y;
    }

    bool same(int x, int y, int t) {
        return root(x, t) == root(y, t);
    }

    int root(int x, int t) {
        if (parent[x].back() == x) return x;
        if (time[x].back() > t) return x;
        return root(parent[x].back(), t);
    }

    int size(int x, int t) {
        int v = root(x, t);
        int i = *lower_bound(time[v].begin(), time[v].end(), t);
        return rank[v][i];
    }

    bool same(int x, int y) { return same(x, y, global_time); }
    int  root(int x) { return root(x, global_time); }
    int  size(int x) { return size(x, global_time); }

};

int main(){
 
    int N,K,L; cin>>N>>K>>L;
    PersistentUnionFind inst1(200010);
    PersistentUnionFind inst2(200010);
    REP(i,K){
        int p,q; cin>>p>>q;
        inst1.unite(p,q);
    }
    REP(i,L){
        int r,s; cin>>r>>s;
        inst2.unite(r,s);
    }
    
    map<int,vector<int> > same_g;
    for(int i=1;i<=N;i++){
        same_g[inst1.root(i)].push_back(i);
    }
    
    int ans[200010]={};
    FOREACH(i,same_g){
        vector<int> t=i->second;
        map<int,int> root;
        REP(j,t.size()){
            int r=inst2.root(t[j]);
            if(root.find(r)==root.end())root[r]=1;
            else root[r]++;
        }
        REP(j,t.size())ans[t[j]]=root[inst2.root(t[j])];
    }
    
    for(int i=1;i<N;i++){
        cout<<ans[i]<<" ";
    }
    cout<<ans[N]<<endl;
    
    return 0;
}

Measured memory_bytes: 87296
num = int(input())
difficulty = [int(i) for i in input().split()]
difficulty.sort()
K = 0
if difficulty[int(num/2)] != difficulty[int(num/2 - 1)]:
    K = difficulty[int(num/2)] - difficulty[int(num/2 - 1)]
else:
    K = 0
print (K)

Measured memory_bytes: 14428
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl;
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	int n; cin >> n;
	rep(i, n) {
		vector<vector<pair<int, bool>>> a(9, vector<pair<int, bool>>(9));
		rep(i, 9)rep(j, 9)cin >> a[i][j].first;

		//yoko
		rep(i, 9) {
			rep(j, 8)FOR(k, j + 1, 9) {
				if (a[i][j].first == a[i][k].first) {
					a[i][j].second = true; a[i][k].second = true;
				}
			}
		}

		//tate
		rep(i, 9) {
			rep(j, 8)FOR(k, j + 1, 9) {
				if (a[j][i].first == a[k][i].first) {
					a[j][i].second = true; a[k][i].second = true;
				}
			}
		}

		//3x3
		for (int i = 0; i < 9; i += 3)for (int i2 = 0; i2 < 9; i2 += 3) {
			FOR(j, i, i + 3)FOR(j2, i2, i2 + 3) {
				FOR(k, i, i + 3)FOR(k2, i2, i2 + 3) {
					if ((j != k || j2 != k2) && a[j][j2].first == a[k][k2].first) {
						a[j][j2].second = true; a[k][k2].second = true;
					}
				}
			}
		}

		rep(i, 9) {
			rep(j, 9) {
				printf(a[i][j].second ? "*" : " ");
				cout << a[i][j].first;
			}
			puts("");
		}
		if (i != n - 1)puts("");
	}
}


Measured memory_bytes: 3160
x, y, z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort_by{|e| -e}
b = gets.split.map(&:to_i).sort_by{|e| -e}
c = gets.split.map(&:to_i).sort_by{|e| -e}

M = 1 << 35
@h = Array.new(k+1, M)
@l = 0

def enque(v)
    i = @l += 1
    @h[i] = v

    while i > 1 && @h[i] < @h[i/2]
        @h[i], @h[i/2] = @h[i/2], @h[i]
        i /= 2
    end
end

def deque
    x = @h[1]
    @h[1] = @h[@l]
    @h[@l] = M
    @l -= 1
    i = 1

    while i * 2 <= @l
        j = @h[i*2] < @h[i*2+1] ? i*2 : i*2+1
        break if @h[i] <= @h[j]
        @h[i], @h[j] = @h[j], @h[i]
        i = j
    end

    x
end

x.times do |s|
    y.times do |t|
        z.times do |u|
            v = a[s] + b[t] + c[u]
            break u if @l == k && v <= @h[1]
            deque if @l == k
            enque(v)
        end == 0 and break t
    end == 0 and break
end

w = []
k.times {w << deque}
puts w.reverse


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

int main() {
    int a[3][3];
    bool s[3][3];
    int i, j;
    for(i = 0; i < 3; i++) {
        for(j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    for(i = 0; i < 3; i++) {
        for(j = 0; j < 3; j++) {
            s[i][j] = false;
        }
    }
    int n;
    cin >> n;
    int b[n];
    int k;
    for(i = 0; i < n; i++) {
        cin >> b[i];
        for(j = 0; j < 3; j++) {
            for(k = 0; k < 3; k++) {
                if (b[i] == a[j][k]) {
                    s[j][k] = true;
                }
            }
        }
    }

    string ans = "No";
    for(i = 0; i < 3; i++) {
        bool tmp = true;
        for(j = 0; j < 3; j++) {
            if (s[i][j] == false) {
                tmp = false;
            }
        }
        if (tmp) {
            ans = "Yes";
        }
    }
    for(i = 0; i < 3; i++) {
        bool tmp = true;
        for(j = 0; j < 3; j++) {
            if (s[j][i] == false) {
                tmp = false;
            }
        }
        if (tmp) {
            ans = "Yes";
        }
    }
    if (s[0][0] == true && s[1][1] == true && s[2][2] == true) {
        ans = "Yes";
    }
    if (s[0][2] == true && s[1][1] == true && s[2][0] == true) {
        ans = "Yes";
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define lli long long 
using namespace std;

typedef vector<lli> vi;

lli mincost(int* h,lli* cost, lli n)
{
    if(n<=1 || cost[n]!=INT_MAX)
    {
        return cost[n];
    }
    
    lli a=mincost(h,cost,n-1);
    lli b=mincost(h,cost,n-2);
    cost[n]=min(a+(abs(h[n]-h[n-1])) , b+(abs(h[n]-h[n-2])));
    
    return cost[n];
    
  
}



int main() {
	lli n;
	cin>>n;
	//vi h(n+1,0);
	int* h=new int[n+1];
	
	for(lli i=1;i<=n;i++)
	{
	    cin>>h[i];
	}
	
	
	h[0]=INT_MAX;
	lli* cost=new lli[n+1];
	//memset(cost,-1,sizeof(cost));
	for(int i=0;i<=n;i++)
	{
	    cost[i]=INT_MAX;
	}
	
	cost[0] = cost[1] = 0;
	lli ans=mincost(h,cost,n);
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
 int main() {
int x,a,b;
   string s;
   string t;
   cin >> s >>t;
   reverse(t.begin(), t.end());
//   cout << s;
//   cout << t;
   if(s==t) cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
   
   }
   


Measured memory_bytes: 256
a = []
a.append(input().split())
a.append(input().split())
a.append(input().split())
n = int(input())

for i in range(n):
  b = input()
  for j in range(3):
    for k in range(3):
      if a[j][k] == b:
        a[j][k] = "0"
        break
    else:
      continue
    break

for i in range(3):
  if a[i][0] == a[i][1] == a[i][2] == "0":
    print("Yes")
    exit()
  if a[0][i] == a[1][i] == a[2][i] == "0":
    print("Yes")
    exit()

if a[0][0] == a[1][1] == a[2][2] == "0":
  print("Yes")
  exit()
if a[0][2] == a[1][1] == a[2][0] == "0":
  print("Yes")
  exit()

print("No")

Measured memory_bytes: 9108
import math
from typing import List
from functools import reduce

def least_common_multiple(x: int, y: int) -> int:
    return x * y // math.gcd(x, y)


def least_common_multiple_of_numbers(numbers: List[int]) -> int:
    if len(numbers) == 1:
        return numbers[0]

    # while len(numbers) != 1:
    #     new_nums = []
    #     for i in range(len(numbers) // 2):
    #         new_nums.append(least_common_multiple(numbers[2*i], numbers[2*i+1]))
    #     if len(numbers) % 2 != 0:
    #         new_nums.append(numbers[-1])
    #     numbers = new_nums
    # return numbers

    return reduce(least_common_multiple, numbers)


def main():
    m = int(input())
    numbers = list(map(int, input().split()))
    gcm = least_common_multiple_of_numbers(numbers)
    print(gcm)
    return


main()


Measured memory_bytes: 7216
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n;
const int mxn = 1e6+5;

vector<int> spf;
vector<bool> prime;
void seive(){
    prime = vector<bool>(mxn, true);
    for(int i = 2; i*i < mxn; ++i){
        if(prime[i]){
            for(int j = i*i; j < mxn; j += i){
                prime[j] = false;
            }
        }
    }

    spf = vector<int>(mxn);
    spf[1] = 1; 
    for (int i=2; i<mxn; i++){
        spf[i] = i; 
    }
  
    for (int i=4; i<mxn; i+=2){
        spf[i] = 2;
    }
  
    for (int i=3; i*i<mxn; i++){ 
        if (spf[i] == i){ 
            for (int j=i*i; j<mxn; j+=i){
                if (spf[j]==j){
                        spf[j] = i; 
                }
            }
        } 
    } 
}

vector<int> factor(int x){
    vector<int> ans;
    while(x != 1){
        ans.push_back(spf[x]);
        x /= spf[x];
    }
    return ans;
}

void solve(){
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];

    seive();

    vector<int> primecnt(mxn, 0);
    for(int i = 0; i < n; ++i){
        vector<int> fact = factor(a[i]);
        for(int j : fact) ++primecnt[j];
    }

    bool pairwise = true;
    for(int i = 0; i < n; ++i){
        vector<int> fact = factor(a[i]);
        for(int j : fact) --primecnt[j];

        bool share = false;
        for(int j : fact){
            if(primecnt[j]) share = true;
        }
        if(share) pairwise = false;

        for(int j : fact) ++primecnt[j];
    }

    if(pairwise){
        cout << "pairwise coprime\n";
    }
    else{
        int g = a[0];
        for(int i = 1; i < n; ++i){
            g = __gcd(g, a[i]);
        }
        if(g==1){
            cout << "setwise coprime\n";
        }
        else{
            cout << "not coprime\n";
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 14964
n=int(input())
a=list(map(int,input().split()))
s_lst=[0]
for i,aa in enumerate(a):
  s_lst.append(s_lst[i]+aa) # len(s_lst): n+1
s_all=s_lst[-1]
ans=float("inf")
for i in range(1,len(s_lst)-1):
  ans=min(ans,abs(2*s_lst[i]-s_all))
print(ans)


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

int main(void){
	int a,b,c,d;
	std::vector<int> num;

	while(std::cin >> a >> b >> c >> d){
		num.push_back(a);
		num.push_back(b);
		num.push_back(c);
		num.push_back(d);
	}
	
	int hit,blow;
	for(int i = 0; i < (int)num.size(); i += 8){
		hit = 0, blow = 0;
		for(int j = 0; j < 4; ++j){
			for(int k = -j; k < -j+4; ++k){
				if(k == 0){
					if(num[i+j+4] == num[i+j+k]){
						++hit;
					}
				}else{
					if(num[i+j+4] == num[i+j+k]){
						++blow;
					}
				}
			}
		}
		std::cout << hit << " " << blow << std::endl;
	}

	return 0;
}

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

int main(){
    int n;cin >> n;
    int p[n];
    int max = 0;
    int sum = 0;

    for (int i=0;i<n;i++){
        cin >> p[i];
        sum += p[i];
        if (max < p[i]) {
            max = p[i];
        }
    }

    cout << sum - max /2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

 
int N;
vector<pair<char, int>> v;
int idx;

int solve() {
  int d = v[idx].first; char c = v[idx].second;
  idx ++;
  if(isdigit(c)) {
    return c - '0';
  } else {
    int ret = c == '*';
    while(idx < N && d < v[idx].first) {
      if(c == '*')
        ret *= solve();
      if(c == '+')
        ret += solve();
    }
    return ret;
  }
}

int main() {
   
  while(cin >> N && N) {
    v.clear();
    rep(i, N) {
      string s; cin >> s;
      v.push_back({s.size() - 1, s.back()});
    }
     
    idx = 0;
    cout << solve() << endl;
  }
   
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

using namespace std;

int main(){

    int n;
    cin>>n;

   
    cout<<n*n*n<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>
#include <iterator>
using namespace std;

namespace {

}

int main()
{
	int r = 0, g = 0, b = 0;

	cin >> r >> g >> b;

	int num = r * 100 + g * 10 + b;

	if (num % 4 == 0){
		cout << "YES" << endl;
		return 0;
	}

	cout << "NO" << endl;


	return 0;
}

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

const int MAX = 1000005;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		vector<int> s(MAX);
		rep(i, n) {
			int h1, m1, s1;
			int h2, m2, s2;
			scanf("%d:%d:%d", &h1, &m1, &s1);
			scanf("%d:%d:%d", &h2, &m2, &s2);
			int t1 = h1 * 60 * 60 + m1 * 60 + s1;
			int t2 = h2 * 60 * 60 + m2 * 60 + s2;
			s[t1]++;
			s[t2]--;
		}
		rep(i, MAX) s[i + 1] += s[i];
		int mx = 0;
		rep(i, MAX) mx = max(mx, s[i]);
		cout << mx << endl;
	}
	return 0;
}


Measured memory_bytes: 7064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

namespace {

}

int main()
{
	long long A = 0, B = 0, C = 0;
	long long sum = 0;

	cin >> A >> B >> C;

	bool isFound = false;
	for (int i = 1; i < 100; ++i){
		sum = i * A;
		if ((sum % B) == C){
			isFound = true;
			break;
		}
	}

	if (isFound){
		cout << "YES";
	}
	else {
		cout << "NO";
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define REP(i,n) for(int i=0; i<n;i++)
int main()
{
    int A[3],B[3],C[3],D[3];
    char num[5]={'*'};
    char op[3];
    op[0]='+'; op[1]='-';
    
    scanf("%s",num);
    A[0]= num[0]-48; B[0]= num[1]-48; C[0]= num[2]-48; D[0]= num[3]-48;
    A[1] = -A[0]; B[1]= -B[0]; C[1]= -C[0]; D[1]= -D[0];
    
    REP(i,2)
    {
        REP(j,2)
        {
            REP(k,2)
            {
                if(A[0]+B[i]+C[j]+D[k]==7)
                {
                    printf("%d%c%d%c%d%c%d=7\n",A[0],op[i],B[0],op[j],C[0],op[k],D[0]);
                    return 0;
                }
                
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 128
import itertools
import math

N = int(input())

L = []

for i in range(N):
  X, Y = map(int, input().split())
  L.append([X,Y])

itl_L = list(itertools.permutations(L))

lens = 0

for elem in itl_L:
  #print("==")
  for i in range(len(elem)-1):
    #print(elem)
    length = math.sqrt((elem[i][0]-elem[i+1][0])**2 +
                       (elem[i][1]-elem[i+1][1])**2
                      )
    #print(length)
    lens += length
print(lens/len(itl_L))


Measured memory_bytes: 47468
import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    for(i in map.indices) {
        val line = StringBuilder()
        for(j in map[i].indices) {
            if(map[i][j] == '#') {
                line.append("#")
                continue
            }
            var cnt = 0
            for(k in (i-1..i+1)) {
                if(k < 0 || k >= h) {
                    continue
                }
                for(l in (j-1..j+1)) {
                    if(l < 0 || l >= w) {
                        continue
                    }
                    if(k == i && l == j) {
                        continue
                    }
                    if(map[k][l] == '#') {
                        cnt++
                    }
                }
            }
            line.append(cnt)
        }
        println(line.toString())
    }
}


Measured memory_bytes: 37928
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
const int INF = 0x7fffffff;
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;

  int n;
  cin >> n;

  vector<int> a(n);
  a[0] = 0;
  for(ii=1;ii<n;ii++){
    cin >> a[ii] ;
  }
  vector<int> buka(n);

  for(ii=1;ii<n;ii++){
    buka[a[ii]-1]++;
  }

  for(ii=0;ii<n;ii++){
    cout << buka[ii] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[100010];
ll a[100010];//a[i]=[0,i)でのACの数
int main(){
	ll n,q;
	scanf("%lld%lld",&n,&q);
	scanf(" %s",s);
	char pre=' ';
	rep(i,0,n){
		if(pre=='A'&&s[i]=='C')a[i+1]=a[i]+1;
		else a[i+1]=a[i];
		pre=s[i];
	}
//	rep(i,0,n+1)printf("%lld",a[i]);
	
	while(q--){
		ll l,r;
		scanf("%lld%lld",&l,&r);
		l--,r--;
		printf("%lld\n",a[r+1]-a[l]-(l-1>=0&&s[l-1]=='A'&&s[l]=='C'));
	}
}

Measured memory_bytes: 1664
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll n,m,in;
	cin >> n >> m;
	priority_queue<ll> price;
	REP(i,n){
		cin >> in;
		price.push(in);
	}
	
	ll goods;
	REP(i,m){
		goods = price.top();
		price.pop();
		price.push(goods/2);
	}
	
	ll ans=0;
	while(!price.empty()){
		ans += price.top();
		price.pop();
	}
	cout << ans << endl;
	
	
	
	return 0;
}

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

struct card{char suit, value;};

void bubblesort(struct card a[], int n){
  rep(i, n){
    for(int j=n-1; j>i; j--){
      if(a[j].value<a[j-1].value){
        card t=a[j];
        a[j]=a[j-1];
        a[j-1]=t;
      }
    }
  }
}

void selectionsort(struct card a[], int n){
  rep(i, n){
    int minj=i;
    for(int j=i; j<n; j++){
      if(a[j].value<a[minj].value){
        minj=j;
      }
    }
    card t=a[i];
    a[i]=a[minj];
    a[minj]=t;
  }
}

void print(struct card a[], int n){
  rep(i, n){
    if(i>0)cout << " ";
    cout << a[i].suit << a[i].value;
  }
  cout << endl;
}

bool isstable(struct card c1[], struct card c2[], int n){
  rep(i, n){
    if(c1[i].suit!=c2[i].suit)return false;
  }
  return true;
}

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

  card c1[100], c2[100];
  int n;
  char ch;

  cin >> n;
  rep(i, n)cin >> c1[i].suit >> c1[i].value;
  rep(i, n)c2[i]=c1[i];

  bubblesort(c1, n);
  selectionsort(c2, n);

  print(c1, n);
  cout << "Stable" << endl;
  print(c2, n);
  if(isstable(c1, c2, n))cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}


Measured memory_bytes: 3216
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::cmp::{max, min, Ordering};

const MOD: u64 = 1000000007;

fn main() {
    let mut cin = Input::new();

    let mut K: usize = 0;
    let mut S: String = String::from("");

    cin = cin >> &mut K >> &mut S;

    if S.len() <= K {
        println!("{}", S);
    } else {
        S = (&S[0..K]).to_string();
        print!("{}", S);
        println!("...");
    }
}

struct Input {
    data: Vec<String>,
}

impl Input {
    pub fn new() -> Input {
        Input{data: Vec::new()}
    }

    fn read(&mut self) {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        self.data = line.split_whitespace().rev().map(|s| s.parse::<String>().unwrap()).collect::<Vec<_>>();
    }

    pub fn get<T: core::str::FromStr>(&mut self) -> T {
        if self.data.len() == 0 {
            self.read();
        }
        return self.data.pop().unwrap().parse::<T>().ok().unwrap();
    }
}

impl<T: core::str::FromStr> std::ops::Shr<&mut T> for Input {
    type Output = Input;

    fn shr(mut self, rhs: &mut T) -> Input {
        *rhs = self.get::<T>();
        return self;
    }
}


Measured memory_bytes: 2112
ans = 0


def main():
    N, M, Q = map(int, input().split())
    a = [0] * Q
    b = [0] * Q
    c = [0] * Q
    d = [0] * Q
    for i in range(Q):
        a[i], b[i], c[i], d[i] = map(int, input().split())

    A = [1] * N

    def check(A, i):
        global ans
        if i + 1 == N:
            ans = max(point_check(A), ans)
            return
        for j in range(A[i], M+1):
            A[i+1] = j
            check(A, i + 1)

    def point_check(arr):
        pt = 0
        for i in range(Q):
            if arr[b[i]-1] - arr[a[i]-1] == c[i]:
                pt += d[i]
        return pt

    for i in range(1, M + 1):
        A[0] = i
        check(A, 0)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9248
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
unordered_map<LL,int> mp;
unordered_set<LL> p2,p1;
int n;
LL val[100005];
int pr[N],pcnt,ccnt;
LL cube[N];
bool vis[N];
void pre(){
	for(int i=2;i<N;i++)
		if(vis[i]==false){
			pr[++pcnt]=i;p2.insert(i*1LL*i);p1.insert(i);
			cube[pcnt]=i*1LL*i*i;
			if(i<=2155) ccnt=pcnt;
			for(int j=i+i;j<N;j+=i) vis[j]=true;
		}
}
LL op(LL v){
	LL ret=1;
	for(int i=1;i<=ccnt&&pr[i]<=v;i++){
		if(v%pr[i]==0){
			v/=pr[i];ret*=pr[i];
			if(v%pr[i]==0) v/=pr[i];
			else ret*=pr[i];
			if(ret>1e10) return -1;
		}
	}
	if(v==1) return ret;
	if(p1.find(v)!=p1.end()) return ret*v*v;
	if(p2.find(v)!=p2.end()) return ret*(int)(sqrt((long double)v)+0.5);
	return -1;
}
int main(){
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&val[i]);
		for(int j=1;j<=pcnt&&cube[j]<=val[i];j++)
			while(val[i]%cube[j]==0) val[i]/=cube[j];
		mp[val[i]]++;
	}
	sort(val+1,val+n+1);
	n=unique(val+1,val+n+1)-val-1;
	int ans=0;
	for(int i=1;i<=n;i++){
		if(val[i]==1) {ans++;continue;}
		long long opz=op(val[i]);
		if(opz==-1)
			ans+=mp[val[i]];
		else if(mp[val[i]]>mp[opz]||(mp[val[i]]==mp[opz]&&val[i]>=opz))
			ans+=mp[val[i]];
		
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9288
// stones

#include <iostream>
using namespace std;

int main()
{
    long long n, k;
    long long stones[102];
    bool dp[100003];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> stones[i];
    }
    fill(dp, dp + k + 1, true);
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (i - stones[j] >= 0 && dp[i - stones[j]])
                dp[i] = false;
        }
    }
    if (dp[k])
        cout << "Second" << endl;
    else
        cout << "First" << endl;
}

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

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

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

  sort( card.begin(), card.end() );
  reverse( card.begin(), card.end() );

  int a = 0;
  int b = 0;

  for ( int i = 0; 2 * i < N; i++ ){
    a += card.at( 2 * i  );
  }

  for ( int i = 0; 2 * i + 1 < N; i++){
    b += card.at( 2 * i + 1 );
  }

  cout << a - b << endl;

}

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

#define INF 999999999

using namespace std;

// input
int n;
string s1,s2;

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

    cin >> n;
    cin >> s1;
    cin >> s2;

    ll ans = 3;

    int index = 0;

    while(index < n){
        // tate
        if(s1[index] == s2[index]){
            index += 1;
            if(index < n && s1[index] == s2[index]){

                ans = ans * 2 % 1000000007;
            }
        }
        // yoko
        else{
            index += 2;
            if(index < n && s1[index] != s2[index]){
                ans = ans * 3 % 1000000007;
            }
            else{
                ans = ans * 2 % 1000000007;
            }
        }

    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int INF=1000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;


int main() {
	int n,m;
	int a,b=-1;
	cin>>n>>m;
	rep(i,1,100001){
		if(m%i==0){
			if(m/i>n)a=i;
			if(i>=n&&b==-1)b=m/i;
		}
	}
	cout<<max(a,b)<<endl;
	return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


int main(){
  int n, a;
  cin >> n;
  unordered_map<int, int> amap; // 数値, 個数
  ll total = 0;
  rep(i, n) {
    cin >> a;
    amap[a]++;
    total += a;
  }
  int q, b, c;
  cin >> q;
  vector<ll> ret;
  rep(i,q) {
    cin >> b >> c;
    if (amap.find(b) != amap.end()) {
      int num = amap[b];
      if (num > 0) {
        total += (c-b) * num;
        amap[c] += amap[b];
        amap[b] = 0;
      }
    }
    ret.push_back(total);
  }

  // 答え
  rep(i,q) {
    cout << ret[i] << endl;
  }

  return 0;
}


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

int main()
{

        int N, M;
        cin >> N >> M;

        int a;
        int b;

        bool A[N];
        bool B[N];
        for (int i = 0; i < N; ++i) {
                A[i] = false;
                B[i] = false;
        }
        for (int i = 0; i < M; i++) {
                cin >> a >> b;
                if (a == 1 && b == N) {
                        continue;
                }
                if (a == 1) {
                        A[b-1] = true;
                }
                if (b == N) {
                        B[a-1] = true;
                }
        }

        for (int i = 0; i < N; ++i) {

                if (A[i] == true) {

                        if (B[i] == true) {

                                cout << "POSSIBLE" << endl;
                                return 0;
                        }
                }
        }
        cout << "IMPOSSIBLE" << endl;


}


Measured memory_bytes: 640
// starter code
# include<bits/stdc++.h>
using namespace std;
int main(){
// taking input into an array
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++){
       cin >> arr[i];
  }
  // sorting the array
  sort(arr, arr+n);
  float ans = arr[0];
  for(int i = 1; i < n; i++){
  	ans = (ans+arr[i])/2;
  }
  // displaying the output
  cout << ans <<'\n';

	return 0;
}


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

#define int long long

int t, a, b, c, d;

int gcd(int x, int y) {
	return (!y) ? x : gcd(y, x % y);
}

int solve(int a, int b, int c, int d) {
	if(d < b) return 0;
	if(a < b) return 0;
	if(a <= c) a += d;
	if(c >= b) return 1;
	int now = d - b;
	a = a % b;
	if(a > c) return 0;
	if(gcd(d - b, b) == b) {
		return 1;
	}
	int G = gcd(d - b, b);
	a = a % G;
	now = (c - a) / G;
	a += now * G;
	if(a <= c) a += G;
	if(b <= a) return 1;
	return 0;
}

main(void) {
	for(cin >> t; t --; ) {
		cin >> a >> b >> c >> d;
		cout << (solve(a, b, c, d) ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 256
//IncubatorMan
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
#define All(x) (x).begin(),(x).end()
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

void solve(){
    long double A,B,H,M;
    cin>>A>>B>>H>>M;
    long double angM = M*6.00;
    long double angH = H*30.00 + .50 * M;
    long double ang = abs(angM-angH);
    long double T = abs(180.00 - ang);
     T = (T*2*acos(0.0) )/ 180.00;
    long double lom = A* sin(T);
    lom = lom * lom;
    long double vumi = A * cos(T) + B;
    vumi = vumi * vumi;
    long double ans = sqrtl(lom + vumi);
    cout<<fixed<<setprecision(15);
    cout<<ans<<endl;

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
        int test=1;
        //read(test);
        //cin>>test;
        while(test--){
            solve();
        }
    return 0;
}

Measured memory_bytes: 4172
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll s, w;
    cin >> s >> w;
    cout << (s > w ? "safe" : "unsafe");
}

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

int main() {
  long double n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int count = 0;
  long double sum = 0;
  rep(i,n) sum += a[i];
  long double cri = sum / (4 * m); 
  rep(i,n) {
    if (a[i] >= cri) count++;
  }
  
  if (count >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  //cout << count << endl;
  
  return 0;
}

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

int main() {
	// your code goes here
	long long int a,b;
	char ch;
	cin>>a>>ch>>b;
	if(ch=='+')
	{
		cout<<a+b<<endl;
	}
	else if(ch=='-')
	{
		cout<<a-b<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
N, Y = [int(i) for i in input().split()]

ans = []
for i in range(N+1):
    for j in range(N+1-i):
        if 10000*i + 5000*j + 1000*(N-i-j) == Y:
            print(i, j, N-i-j)
            sys.exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
//g++でビルド

#include "bits/stdc++.h"

using namespace std;

int a, b, c;
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> a >> b>>c;



    int result = min(b/a, c);
    cout << result << endl;
}

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

using namespace std;

const int N = 2e5 + 5;

int cnt[N];

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int v;
    scanf("%d", &v);
    cnt[v]++;
  }
  vector<int> all;
  for (int i = 0; i < N; i++) {
    if (cnt[i]) {
      all.push_back(cnt[i]);
    }
  }
  sort(all.begin(), all.end());
  reverse(all.begin(), all.end());
  int ans = 0;
  for (int i = k; i < all.size(); i++) ans += all[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2168