akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main()
{
    long n;
    cin >> n;
    vector<vector<pair<long, long>>> node(n);
    queue<int> qu;
    int ans[n];
    int visited[n];

    for (auto i = 0; i < n; i++)
    {
        visited[i] = 0;
    }

    for (auto i = 0; i < n - 1; i++)
    {
        pair<long, long> to;
        int from;
        cin >> from >> to.first >> to.second;
        from -= 1;
        to.first -= 1;
        node[from].push_back(to);
        pair<long, long> to2;
        to2.first = from;
        to2.second = to.second;
        node[to.first].push_back(to2);
    }

    qu.push(0);
    ans[0] = 0;

    while (!qu.empty())
    {
        int now = qu.front();
        // cout << now << "　途中経過です" << endl;
        qu.pop();
        visited[now] = 1;
        for (auto i = 0; i < node[now].size(); i++)
        {
            if (visited[node[now][i].first] != 1)
            {
                if (node[now][i].second % 2 == 0)
                {
                    ans[node[now][i].first] = ans[now];
                }
                else
                {
                    if (ans[now] == 1)
                    {
                        ans[node[now][i].first] = 0;
                    }
                    else
                    {
                        ans[node[now][i].first] = 1;
                    }
                }
                qu.push(node[now][i].first);
            }
        }
    }

    for (auto i = 0; i < n; i++)
    {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 8704
//#define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for(int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
ll N, M, Q;
ll a[51], b[51], c[51], d[51];
ll maxi = -1;

void dfs(int num, vector<int>& res) {
  if (res.size() == N) {
    ll sum = 0;
    for (int i = 0; i < Q; i++) {
      if (res[b[i]] - res[a[i]] == c[i]) {
        sum += d[i];
      }
      maxi = max(sum, maxi);
    }
    return;
  }

  for(int i = num; i <= M; i++) {
    res.pb(i);
    dfs(i, res);
    res.pop_back();
  }
}

int main() {
  fastio;
  
  cin >> N >> M >> Q;
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  vector<int> res;
  dfs(1, res);
  cout << maxi << endl;
  
  #ifdef TIMER_
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll cnt = 0, tot = 0;
    while(tot < n) {
        cnt++;
        tot += cnt;
    }
    if (tot != n) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n%lld\n", cnt + 1);
    rep(i, cnt) {
        ll ofs = (1 + i) * i / 2 + 1;
        vector<ll> v(cnt);
        ll idx = 0, cur = ofs + i;
        rep(j, i + 1) v[idx++] = ofs + j;
        rep(j, cnt - i - 1) {
            cur += i + j + 1;
            v[idx++] = cur;
        }
        printf("%lld ", cnt);
        rep(j, cnt) printf("%lld%s", v[j], (j == (cnt - 1)) ? "\n" : " ");
    }
    printf("%lld ", cnt);
    rep(i, cnt) printf("%lld%s", (1 + (i + 1)) * (i + 1) / 2, (i == (cnt - 1)) ? "\n" : " ");
    return 0;
}


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


int main()
{
    int N;
    cin >> N;
    vector<double> t(N+2, 0.0), v(N+2, 0.0);
    for(int i = 1; i <= N; i++) cin >> t[i];
    for(int i = 1; i <= N; i++) cin >> v[i];
 
 
    vector<double> l(N+2, 0.0), r(N+2, 0.0);
    for(int i = 2; i < N+2; i++) l[i] = l[i-1] + t[i-1];
    for(int i = 1; i < N+2; i++) r[i] = r[i-1] + t[i];
 
    vector<double> sv;
    for(double x = 0; x <= r[N+1]; x += 0.5) {
        double mn = 1e9+1;
        for(int i = 0; i < N+2; i++) {
            if( x < l[i] ) mn = min(mn, v[i] + (l[i] - x));
            if( l[i] <= x && x <= r[i]) mn = min(mn, v[i]);
            if( r[i] < x ) mn = min(mn, v[i] + (x - r[i]));
        }
        sv.push_back(mn);
    }
 
    double ans = 0;
    for(int i = 1; i < sv.size(); i++) {
        ans += 0.25 * (sv[i] + sv[i-1]);
    }
 
    printf("%lf", ans);
 
    return 0;
}

Measured memory_bytes: 896
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto A = RD!long;
	auto B = RD!long;
	auto C = RD!long;
	auto D = RD!long;
	auto E = RD!long;
	auto F = RD!long;

	double bestP = 0.0;
	long bestQ, bestSQ;
	foreach (ai; 0..31)
	{
		auto aq = A * ai;
		foreach (bi; 0..31)
		{
			if (ai + bi == 0) continue;

			auto bq = B * bi;
			auto wq = aq + bq;
			auto remain = F - wq * 100;
			if (remain < 0) continue;

			auto limit = min(remain, wq * E);
			long sq;
			foreach_reverse (i; 0..limit+1)
			{
				bool isDone = false;
				long s = i;
				while (s >= 0)
				{
					if (s % C == 0 || s % D == 0)
					{
						sq = i;
						isDone = true;
						break;
					}
					s -= C;
				}
				if (isDone) break;
			}
			//auto sq1   = ((limit / C) * C) + ((limit % C) / D) * D;
			//auto sq2   = ((limit / D) * D) + ((limit % D) / C) * C;
			//auto sq    = max(sq1, sq2);
			auto q     = wq * 100 + sq;
			auto p     = sq * 100.0 / q;

			if (p >= bestP)
			{
				bestP  = p;
				bestQ  = q;
				bestSQ = sq;
				stderr.writeln(remain, " ", wq * E, " ", limit);
			}
		}
	}
	
	writeln(bestQ, " ", bestSQ);
	stdout.flush();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//At coder's coins problem
using namespace std;
#define ll long long
const int mod=1e9+7;

int main(){
	int n;
	cin>>n;
	double p[n+1];
	double dp[n+1][n+1];
	memset(dp,0,sizeof dp);
	for(int i=1;i<=n;i++) cin>>p[i];
	//probability of getting 0 heads from i coins is simply (1-p[1])*(1-p[2])*....(1-p[i])
	dp[1][0]=1.0-p[1];
	for(int i=2;i<=n;i++){
		dp[i][0]=dp[i-1][0]*(1.0-p[i]);
	}
	//probability of getting exactly i heads from i coins is simply p[1]*p[2]*....p[i]
	dp[1][1]=p[1];
	for(int i=2;i<=n;i++){
		dp[i][i]=dp[i-1][i-1]*p[i];
	}
	// dp[i][j]->probability of getting j heads using the first i coins only
	// dp[i][j]=if it is head,then probability of getting j-1 heads from i-1 coins +
	//			if it is tail,then probability of getting j heads from i-1 coins
	// j>i is not possible ,i.e probability of getting j heads from i coins (ex- 3 heads from 2 coins)
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++){
			dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1.0-p[i]);
		}
	}
	double res=0;
	for(int i=n/2+1;i<=n;i++) res+=dp[n][i];
	cout<<fixed<<setprecision(10)<<res<<endl;
	return 0;
}

Measured memory_bytes: 70528
using System;

namespace C___Grid_Repainting_2
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var h = int.Parse (input[0]);
            var w = int.Parse (input[1]);
            var array = new string[h];
            for (var i = 0; i < h; i++)
            {
                array[i] = Console.ReadLine ();
            }
            for (var i = 1; i + 1 < h; i++)
            {
                for (var j = 1; j + 1 < w; j++)
                {
                    if (array[i][j] == '#' && array[i - 1][j] != '#' && array[i + 1][j] != '#' && array[i][j - 1] != '#' && array[i][j + 1] != '#')
                    {
                        Console.WriteLine ("No");
                        return;
                    }
                }
            }
            Console.WriteLine ("Yes");
        }
    }
}

Measured memory_bytes: 13140
import sys
import bisect

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def bis_insert(L, target, top=None, bottom=None):
    if top is None:
        top = len(L)
    if bottom is None:
        bottom = 0

    while bottom < top:
        half = (top + bottom) // 2
        if target > L[half]:
            bottom = half + 1
        else:
            top = half
    return bottom


def solve(inputs):
    L = string_to_int(inputs[0])
    L.sort()
    total_count = 0
    for i in range(len(L) - 2):
        for j in range(i + 1, len(L)-1):
            a = L[i]
            b = L[j]
            target = a + b
            # r = bis_insert(L, target)
            r = bisect.bisect_left(L, target)
            total_count += r - j - 1
    return total_count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


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

int main () {
	int n;
	cin >> n;
	vector<int> count_v1(100001,0);
	vector<int> count_v2(100001,0);
	for (int i=1; i<=n; ++i) {
		int v;
		cin >> v;
		if (i%2 == 1) {
			count_v1[v]++;
		} else {
			count_v2[v]++;
		}
	}
	auto v1_maxelement = max_element(count_v1.begin(), count_v1.end());
	auto v2_maxelement = max_element(count_v2.begin(), count_v2.end());
	int count_v1_max = *v1_maxelement;
	int count_v2_max = *v2_maxelement; 
	int reduce_count = count_v1_max + count_v2_max;
	// when max_values are the same
	{
		int v1 = distance(count_v1.begin(), v1_maxelement);
		int v2 = distance(count_v2.begin(), v2_maxelement);
		if (v1 == v2) {
			// 和が最大になるような数の選び方はどちらか
			int count_v1_max_2, count_v2_max_2;
			*v1_maxelement = 0;
			count_v1_max_2 = *max_element(count_v1.begin(), count_v1.end());
			*v2_maxelement = 0;
			count_v2_max_2 = *max_element(count_v2.begin(), count_v2.end());
			reduce_count = max(count_v1_max + count_v2_max_2, count_v1_max_2 + count_v2_max);
		}
	}
	int ans = n - reduce_count; 
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
int keta[70];

signed main(){
  int n;
  cin >> n;
  REP(i,n){
    int a;
    cin >> a;
    REP(j,63){
      keta[j] += a%2; 
      a/=2;
      //cout << a << endl;
    }
  }
  int ans = 0;
  int now_ans = 1;
  REP(j,63){
    //cout << "j=" << j << keta[j] << endl;
    int tt = now_ans * keta[j];
    tt %= MOD;
    tt *= (n-keta[j]);
    tt %= MOD;
    ans += tt;
    ans %= MOD;
    now_ans *= 2;
    now_ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;

    map<char,char> mp;
    mp['A']='T';
    mp['C']='G';
    mp['T']='A';
    mp['G']='C';



    char ch;
    cin>>ch;
    cout<<mp[ch]<<endl;


}


Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <cmath>

int main() {
    int n, x[1000], y[1000];
    std::cin >> n;
    for (int i=0;i<n;++i)
        std::cin >> x[i];
    for (int i=0;i<n;++i)
        std::cin >> y[i];
    double ans[4];
    for (int i=0;i<n;++i) {
        int abs = std::abs(x[i] - y[i]);
        ans[0] += abs;
        ans[1] += std::pow(abs, 2);
        ans[2] += std::pow(abs, 3);
        if (ans[3] < abs) ans[3] = abs;
    }
    ans[1] = std::pow(ans[1], 0.5);
    ans[2] = std::pow(ans[2], 1.0/3);
    for (int i=0;i<4;++i)
        std::cout << std::fixed << std::setprecision(6) << ans[i] << std::endl;
    return 0;
}


Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
vector <int> a[MAXN];
int n, f[MAXN], p[MAXN], s[MAXN], ans[MAXN];
void dfs(int pos, int fa) {
	f[pos] = fa;
	for (auto x : a[pos])
		if (x != fa) dfs(x, pos);
}
int find(int x) {
	if (p[x] == x) return x;
	else return p[x] = find(p[x]);
}
void work(int pos, int fa, int sum) {
	vector <int> mem;
	priority_queue <int, vector <int>, greater <int>> Heap;
	while (!Heap.empty()) Heap.pop(); Heap.push(pos);
	while (!Heap.empty() && (Heap.top() == pos || Heap.top() <= fa)) {
		int tmp = Heap.top(); Heap.pop(), sum++;
		for (auto x : a[tmp]) if (f[x] == tmp) Heap.push(x), mem.push_back(x), p[x] = (tmp == pos) ? x : tmp;
	}
	ans[pos] = sum;
	while (!Heap.empty() && (Heap.top() == pos || Heap.top() <= pos)) {
		int tmp = Heap.top(); Heap.pop(), s[find(tmp)]++;
		for (auto x : a[tmp]) if (f[x] == tmp) Heap.push(x), mem.push_back(x), p[x] = tmp;
	}
	for (auto x : mem) ans[x] = sum + s[find(x)];
	while (!Heap.empty()) {
		work(Heap.top(), pos, sum + s[find(Heap.top())]);
		Heap.pop();
	}
}
int main() {
	read(n);
	for (int i = 1; i <= n - 1; i++) {
		int x, y; read(x), read(y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1, 0);
	for (auto x : a[1])
		work(x, 1, 0);
	for (int i = 2; i <= n; i++)
		printf("%d ", ans[i]);
	return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef pair<int,int> ii;

const int IINF = INT_MAX;

struct Point3d {
  int x,y,z;
  bool operator < ( const Point3d &p ) const {
    if( z != p.z ) return z < p.z;
    if( y != p.y ) return y > p.y;
    return x > p.x;
  }
};


int a, b, C = ~(1<<31), M = (1<<16)-1;
int r() {
  a = 36969 * (a & M) + (a >> 16);
  b = 18000 * (b & M) + (b >> 16);
  return (C & ((a << 16) + b)) % 1000000;
}


const int MAX = 300010;
int m,n,A,B;
Point3d ps[MAX];


set<ii> dp[MAX];

bool check(int index,ii v){
  set<ii>::iterator it = dp[index].lower_bound(v);
  while( (*it).second < v.second ){
    if( (*it).first < v.first ) return true;
    --it;
  }
  return false;
}

void update(int index,ii v){
  set<ii>::iterator it = dp[index].lower_bound(v);
  --it;
  if( (*it).second <= v.second ) return;
  ++it;
  while( (*it).second >= v.second ) dp[index].erase(it++);
  dp[index].insert(v);
}

int LIS2D(vector<ii> &vec) {
  rep(i,(int)vec.size()+1) {
    dp[i].clear();
    dp[i].insert(ii(-1,IINF));
    dp[i].insert(ii(IINF,-1));
  }
  dp[0].insert(ii(-1,-1));
  int maxi = 0;
  rep(i,(int)vec.size()){
    int low = 0, hig = i+1;
    while( hig - low ) {
      int mid = ( low + hig ) / 2;
      if( check(mid,vec[i]) ) low = mid + 1;
      else                    hig = mid;
    }
    maxi = max(maxi,low);
    update(low,vec[i]);
  }
  return maxi + 1;
}


void compute(){
  sort(ps,ps+n+m);
  vector<ii> vec;
  rep(i,n+m) vec.push_back(ii(ps[i].y,ps[i].x));
  cout << LIS2D(vec) << endl;
}

int main(){
  while( scanf("%d %d %d %d",&m,&n,&A,&B), m|n|A|B ){
    a = A, b = B;
    rep(i,m) scanf("%d %d %d",&ps[i].x,&ps[i].y,&ps[i].z);
    rep(i,n) {
      ps[m+i].x = r();
      ps[m+i].y = r();
      ps[m+i].z = r();
    }
    compute();
  }
  return 0;
}

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

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

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

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

int main(){
    ll x;
    cin >> x;
    ll ans=0;
    ll now=100;
    while(now<x){
        ans++;
        now=(now*1.01)/1;
        if(ans>4000){
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3636
import bisect
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
b = [int(i) for i in input().split()]
b = sorted(b)
c = [int(i) for i in input().split()]
c = sorted(c)
ans = 0
for i in range(n):
    B = b[i]
    a_nums = bisect.bisect_left(a,B)
    c_nums = n - bisect.bisect_right(c,B)
    ans += a_nums * c_nums
print(ans)

Measured memory_bytes: 106724
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int N;
int X[110];
int Y[110];
int H[110];

int main(){
  cin >> N;
  rep(i, N) cin >> X[i] >> Y[i] >> H[i];

  int init;
  rep(i, N){
    if (H[i] > 0) init = i;
  }

  int h;
  int ans_x, ans_y, ans_h;
  rep(x, 101){
    rep(y, 101){
      h = H[init] + abs(X[init] - x) + abs(Y[init] - y);

      bool check = true;
      rep(i, N){
        if (H[i] > 0){
          if (h - abs(X[i] - x) - abs(Y[i] - y) != H[i]) check = false;
        }
        else {
          if (h - abs(X[i] - x) - abs(Y[i] - y) > 0) check = false;
        }
      }

      if (check){
        ans_x = x;
        ans_y = y;
        ans_h = h;
      }
    }
  }
  cout << ans_x << " " << ans_y << " " << ans_h << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>

using namespace std;

int GetGroup(int value)
{
    switch (value)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            return 0;
            
        case 4:
        case 6:
        case 9:
        case 11:
            return 1;
            
        default:
            return 2;
    }
}

int main()
{
    int H, W;
    char picture[100][100];
    
    cin >> H >> W;
    for (auto j = 0; j < H; j++)
    {
        for (auto i = 0; i < W; i++)
        {
            cin >> picture[j][i];
        }
    }
    
    for (auto i = 0; i < W + 2; i++)
    {
        printf("#");
    }
    printf("\n");
    for (auto j = 0; j < H; j++)
    {
        printf("#");
        for (auto i = 0; i < W; i++)
        {
            printf("%c", picture[j][i]);
        }
        printf("#\n");
    }
    for (auto i = 0; i < W + 2; i++)
    {
        printf("#");
    }
    printf("\n");
    
    return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a[i];
  map<ll,ll> mp;
  rep(i,n) mp[a[i]]++;
  ll ans = mp.size();
  if (ans % 2 == 0) ans--;
  cout << ans << endl;
}

Measured memory_bytes: 10220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
typedef long long int ll;
#define FOR(i,a,n) for(int i=a;i<n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end();
#define pos std::pair<int,int>
const int INF = 1LL << 30;
const int INF_ = 0 - INF;
const ll LLINF = 1LL << 60;
int main() {
	int a, b, c, d, e;
	char s,s2;
	std::cin >> s>>s2;
	if (s < s2)std::cout << "<" << std::endl;
	else if (s == s2)std::cout << "=" << std::endl;
	else std::cout << ">" << std::endl;
	return 0;
 
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()

if N == K:
    print(0)
elif N > K:
    N = N - (N // K) * K
    if K < 2 * N:
        print(abs(N - K))
    else:
        print(N)
elif K < 2 * N:
    print(abs(N - K))
else:
    print(N)

Measured memory_bytes: 38256
N = int(input())
actives = [list(map(int, input().split())) for n in range(N)]

dp = [[0 for _ in range(3)] for __ in range(N+100)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if j == k:  # i-1番目,i番目で連続して同じ活動は選択できない
                continue
            dp[i+1][k] = max(dp[i+1][k], (dp[i][j] + actives[i][k]))

print(max(dp[N]))

Measured memory_bytes: 47332
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
const int64_t INF = 1LL << 62;
int64_t dp[MAXN][2][3];

void init()
{
  for (int i = 0; i < MAXN; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        dp[i][j][k] = -INF;
      }
    }
  }
  dp[0][0][0] = 0;
}

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  init();
  if (N % 2)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < 2; j++)
      {
        for (int k = 0; k < 3; k++)
        {
          if (dp[i][j][k] == -INF)
          {
            continue;
          }
          if (j == 0)
          {
            dp[i + 1][1][k] = max(dp[i + 1][1][k], dp[i][j][k] + A[i]);
            if (k <= 1)
            {
              dp[i + 1][0][k + 1] = max(dp[i + 1][0][k + 1], dp[i][j][k]);
            }
          }
          else
          {
            dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k]);
          }
        }
      }
    }
    cout << max<int64_t>({dp[N][0][1], dp[N][1][2]}) << endl;
  }
  else
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < 2; j++)
      {
        for (int k = 0; k < 3; k++)
        {
          if (dp[i][j][k] == -INF)
          {
            continue;
          }
          if (j == 0)
          {
            dp[i + 1][1][k] = max(dp[i + 1][1][k], dp[i][j][k] + A[i]);
            if (k == 0)
            {
              dp[i + 1][0][k + 1] = max(dp[i + 1][0][k + 1], dp[i][j][k]);
            }
          }
          else
          {
            dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k]);
          }
        }
      }
    }
    cout << max<int64_t>({dp[N][0][0], dp[N][1][1]}) << endl;
  }
}


Measured memory_bytes: 14292
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

int main(){
  int N; cin>>N;
  vector<pair<string,int> > pairs(N),tpairs;
  vector<int> num(N);
  for(int i=0;i<N;i++){
    string a;int b; cin>>a>>b; 
    pairs[i]=make_pair(a,b);
    num[i]=b;
  }

  sort(pairs.begin(),pairs.end());

  for(int i=0;i<N;i++){
    tpairs.push_back(make_pair(pairs[i].first,pairs[i].second));
    if(pairs[i].first!=pairs[(i<N-1?i+1:i)].first||i==N-1){
      reverse(tpairs.begin(),tpairs.end());
      for(int j=0;j<tpairs.size();j++){
        for(int k=0;k<N;k++){
          if(num[k]==tpairs[j].second){
            cout<<k+1<<endl;
            break;
          }
        }
      }
      tpairs.clear();
    }
  }

  return 0;
}


Measured memory_bytes: 256
def main():
    import numpy as np
    n, k = map(int, input().split())
    H = list(map(int, input().split()))
    s = np.array(sorted(set(H+[0])), dtype=np.int64)
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    dp = np.full((k+1, l), 10**13, dtype=np.int64)
    dp2 = np.zeros((k+1, l), dtype=np.int64)
    dp[0, 0] = 0

    for h in H:
        dh = d[h]
        dp2 = np.zeros((k+1, l), dtype=np.int64)
        dp2[0] = np.full(l, 10**13, dtype=np.int64)
        dp2[1:, :] = dp[:-1, :]
        temp = np.min(
            dp + np.concatenate([(h-s)[:dh], np.zeros(l-dh, dtype=np.int64)]), axis=1)
        dp2[:, dh] = np.minimum(dp2[:, dh], temp[:])
        dp = dp2
    print(np.min(dp))


main()


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ull MOD = 1000000007;

int main() {
	int N, M, K;
	cin >> N >> M >> K;

	vector <int> A(M, 0);
	vector <int> B(M, 0);

	vector <vector<int>> tomo(N, vector <int>());
	for (int ii = 0; ii < M; ++ii){
		int A, B;
		cin >> A >> B;
		A--; B--;
		tomo[A].push_back(B);
		tomo[B].push_back(A);
	}

	vector <vector<int>> block(N, vector <int>());
	for (int ii = 0; ii < K; ++ii){
		int A, B;
		cin >> A >> B;
		A--; B--;
		block[A].push_back(B);
		block[B].push_back(A);
	}

	//友達候補をクラスタ毎に数える（ただし，直接友達とブロックを省いていない）
	vector <int> pot(N, 0);
	vector <int> visit(N, 0);
	int visitNum = 1;
	for (int ii = 0; ii < N; ++ii){
		if (visit[ii] > 0){
			continue;
		}
		visit[ii] = visitNum;

		queue<int> q;
		queue<int> r;
		int cnt = 0;
		for (int jj = 0; jj < tomo[ii].size(); ++jj){
			q.push(tomo[ii][jj]);
			r.push(tomo[ii][jj]);
		}

		while(!q.empty()) {
			int index = q.front();
			q.pop();
			if (visit[index] > 0){
				continue;
			}

			visit[index] = visitNum;
			cnt++;
			for (int kk = 0; kk < tomo[index].size(); ++kk){
				q.push(tomo[index][kk]);
				r.push(tomo[index][kk]);
			}
		}

		while(!r.empty()) {
			int index = r.front();
			r.pop();
			pot[index] = cnt;
		}

		visitNum++;
	}

	vector <int> ans(N, 0);
	for (int ii = 0; ii < N; ++ii){
		ans[ii] = pot[ii] - tomo[ii].size();
		for (int jj = 0; jj < block[ii].size(); ++jj){
			int index = block[ii][jj];
			if (visit[ii] == visit[index]){
				ans[ii]--;
			}
		}
	}

	for (int ii = 0; ii < N; ++ii){
		cout << ans[ii] << " ";
	}

	return 0;
}


Measured memory_bytes: 14072
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a[100],b[100],c=0;
bool r,ft[100][100];
string s,sa;

struct UF{
    
    vector<int> par;
    
    UF(int num):par(num){
        for(int i=0;i<num;i++)par[i]=i;
    }
    
    void reset(){
        for(int i=0;i<par.size();i++)par[i]=i;
    }
    
    int root(int tar){
        
        while(par[tar]!=tar){
            tar=par[tar];
        }
        return tar;
    }
    
    bool same(int tarx,int tary){
        return root(tarx)==root(tary);
        
    }
    
    bool allsame(){
        bool r=true;
        for(int i=1;i<par.size();i++)r=r and same(i-1,i);
        return r;
    }
    
    void unite(int tarx,int tary){
        int rx=root(tarx);
        int ry=root(tary);
        if(rx!=ry)par[rx]=ry;
    }
    
};



int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    UF unif(n);
    for(int d=0;d<m;d++){
        unif.reset();
        for(int i=0;i<m;i++){
            if(i==d)continue;
            unif.unite(a[i],b[i]);
        }
        
        if(!unif.allsame()){
            c++;
        }
    }
    
    C c E;
    
}

Measured memory_bytes: 256
N = int(input())
*A, = list(map(int, input().split()))
count = 0


def merge(a, left, mid, right):
    global count
    la = a[left:mid] + [float("inf")]
    ra = a[mid:right] + [float("inf")]

    i, j = 0, 0
    for k in range(left, right):
        count += 1
        if la[i] <= ra[j]:
            a[k] = la[i]
            i += 1
        else:
            a[k] = ra[j]
            j += 1


def merge_sort(a, left, right):
    if left + 1 < right:
        mid = int((left + right) / 2)
        merge_sort(a, left, mid)
        merge_sort(a, mid, right)
        merge(a, left, mid, right)

merge_sort(A, 0, N)
print(*A)
print(count)



Measured memory_bytes: 61652
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll A;
    cin >> A;
    ll mini = INF;
    while(A > 100){
        mini = min(mini, abs(A % 1000 - 753) );
        A /= 10;
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
// Facts.cpp
#include <iostream>
#include <vector>
using namespace std;

class Facts
{
public:
    long long mod = 1000000007;
    int n_max = 1;
    vector<long long int>  fact{1, 1};
    vector<long long int>  inv{1, 1};
    vector<long long int>  factinv{1, 1};

    Facts();
    Facts(int64_t mod);
    int64_t cmb(int n, int r);
    void setup_table(int t);
};

Facts::Facts(int64_t m){
  mod = m;
}

int64_t Facts::cmb(int n, int r){
  if(r < 0 || n < r) return 0;
  if(n_max < n) setup_table(n);
  return fact[n] * (factinv[r] * factinv[n-r] % mod) % mod;
}

void Facts::setup_table(int t){
  for(int i=n_max+1; i<=t; i++){
    fact.push_back( fact.back() * i % mod );
    inv.push_back( -inv[mod % i] * (mod / i) % mod );
    factinv.push_back( factinv.back() * inv.back() % mod );
  }
  n_max = t;
}

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

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main(){
  
  int64_t mod = 998244353;
  
  int64_t n, m, k;
  cin >> n >> m >> k;
  
  int64_t ans = 0, t;
  Facts f = Facts(mod);
  t = m * modpow(m-1, n-1-k, mod) % mod;
  
  for(int i=k; i>=0; i--){
    ans += f.cmb(n-1, i) * t % mod;
    ans %= mod;
    t = t * (m-1) % mod;
  }
  
  if(ans < 0) ans += mod;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 8092
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

int main(){
	ll n;cin>>n;
	ll ans=INF;
	for(ll i=1;i*i<=n;i++){
		if(n%i!=0)continue;
		ll j=n/i;
		ans=min(ans,i+j-2);
	}
	cout<<ans<<endl;
}


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

int main(){
    int rooms[5][4][11],n;
    
    for(int i=1; i<=4; i++)
        for(int j=1; j<=3; j++)
            for(int k=1; k<=10; k++) rooms[i][j][k]=0;
                
    cin>>n;
    for(int i=0; i<n; i++){
        int b,f,r,v;
        cin>>b>>f>>r>>v;
        rooms[b][f][r]+=v;
    }
    
    for(int b=1; b<=4; b++){
        if(b>1) cout<<"####################"<<"\n";
        for(int f=1; f<=3; f++){
            for(int r=1; r<=10; r++){
                cout<<" "<<rooms[b][f][r];
            }
            cout<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3088
from sys import stdin

day = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]

s = stdin.readline().rstrip()

if s != "SUN":
    a = day[day.index(s):]
    for i in a[::-1]:
        day.insert(0, i)
    print(day.index("SUN"))
else:
    print(7)

Measured memory_bytes: 2940
import java.util.Scanner;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    int X=sc.nextInt();
    int A=sc.nextInt();
    if (X<A)
      System.out.println("0");
    else
       System.out.println("10");
  }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int h, w, a, b; cin>>h>>w>>a>>b;
    int c=(h/a)*(w/b);
    cout<<h*w-a*b*c<<endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) {
        b[i] = a[i];
    }
    sort(b.begin(), b.end());

    rep(i,n) {
        if (a[i] == b[n-1]) cout << b[n-2] << endl;
        else cout << b[n-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 4816
#include<iostream>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	if(a==1) a+=13;
	if(b==1) b+=13;
	
	if(a>b) cout<<"Alice"<<endl;
	else if(a<b) cout<<"Bob"<<endl;
	else cout<<"Draw"<<endl;
	
	return 0;	
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b, n1, n2;  //??£?¨?//
	
	scanf("%d %d", &a, &b);
	//scanf("%d", &b);  //a??¨b?????\???//
	
	n1 = a * b;      //n1???a?????????b//
	n2 = 2 * a + 2 * b;  //n2???2*a+2*b//
	
	printf("%d %d\n", n1, n2);   //n1??¨n2?????????
	
	return 0;
}

Measured memory_bytes: 2708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
set<long long > ss;
long long n;
void solve(long long i){
    //cout << i << endl;
    long long tmp =n;
    while(tmp!=1){
        if((tmp-1)%i==0){
        ss.insert(i);
            return ;
        }
        if(tmp%i)
            return;
        tmp=tmp/i;
    }
    ss.insert(i);
}
int main()
{
    cin >> n;
    for(long long i=1;i*i<=n;i++){
        if((n-1)%i==0)
        {
            ss.insert(i);
            ss.insert((n-1)/i);
        }
        if(n%i==0){
            solve(i);
            solve(n/i);
        }
    }

    cout << ss.size()-1 << endl;
    return 0;
}


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

int a[20], n;

bool f(int i, int m)
{
    if (m == 0)
        return true;
    if (i == n)
        return false;
    bool ans = f(i + 1, m) || f(i + 1, m - a[i]);
    return ans;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int m;
        cin >> m;
        if (f(0, m))
            cout << "yes\n";
        else
            cout << "no\n";
    }
    return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

//population count
//?????£?????????bit?????°?????°??????
int popcount(int x) {
	int ret = 0;
	//?????????????????£?????????bit????????????
	while (x) {
		x &= x - 1;
		ret++;
	}
	return ret;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N; cin >> N&&N;) {
		int K; cin >> K;
		unordered_set<string> st;
		vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
		for (int mask = 1; mask < (1 << N); mask++) {
			if (popcount(mask) != K)continue;
			vector<int> base;
			rep(i, 0, N) {
				if ((mask >> i) & 1) {
					base.emplace_back(v[i]);
				}
			}
			sort(all(base));
			do {
				string tmp = "";
				rep(i, 0, K) {
					tmp += to_string(base[i]);
				}
				st.insert(tmp);
			} while (next_permutation(all(base)));
		}
		cout << st.size() << endl;
	}
	return 0;
}

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

const int MAXN = 100005;

int N;
long long a[MAXN], b[MAXN];

int main() {

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

    long long add = 0;
    for (int i = N-1; i >= 0; i--) {
        add += (b[i] - ((a[i] + add) % b[i])) % b[i];
    }

    printf("%lld\n", add);

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;


static unsigned long long MAX = 1000000000000000000;

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

  unsigned long long result = 1;
  vector<unsigned long long> A(N);
  for (int i = 0; i < N; i++) {
    unsigned long long a;
    cin >> a;
    if (a == 0L) {
      cout << "0" << endl;
      return 0;
    }
    A[i] = a;
  }
  for (int i = 0; i < N; i++) {
    unsigned long long a = A[i];
    unsigned long long max = ceil((double) MAX / result);
    // cout << max << endl;
    if (a > max) {
      // 
      // cout << result * a << endl;
      // cout << a << endl;
      cout << "-1" << endl;
      return 0;
    }
    if ((result * a) > MAX) {
      cout << "-1" << endl;
      return 0;
    }
    result *= a;
  }

  // cout << ((result > MAX) ? "-1" : to_string(result)) << endl;
  cout << to_string(result) << endl;

  return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define Int long long
#define rep(i, n) for(Int i = 0; i < n; i++)
#define in(params) cin >> params;
#define p(params) cout << params << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    Int A, B, K;
    in(A >> B >> K);

    vector<Int> arr;
    for (Int i = 1; i <= min(A, B); i++)
    {
        if ((A % i) == 0 && (B % i) == 0) {
            arr.push_back(i);
        }
    }

    sort(arr.begin(), arr.end(), greater<int>());
    p(arr[K - 1]);

    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  set<int> st[] {
    {1,3,5,7,8,10,12},
      {4,6,9,11},
	{2}
  };
  int x, y;
  cin >> x >> y;
  rep(i, 3) {
    if(st[i].count(x) && st[i].count(y)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;


  return 0;
}


Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    int g,Max=0,p;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&p);
        if(i==0){
            g=p;
        } else {
            g=__gcd(g,p);
        }
        Max=max(Max,p);
    }
    if(k%g==0&&k<=Max){
        cout<<"POSSIBLE";
    } else {
        cout<<"IMPOSSIBLE";
	}
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

typedef pair<int,int> pairi;

int h,w,n;
char map[1002][1002];
int visited[1002][1002];

int x,y;

main(){
  scanf("%d%d%d", &h, &w, &n);

  for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
      map[i][j] = 'X';
      if(i == 0 || i == h+1 || j == 0 || j == w+1) continue;
      scanf(" %c", &map[i][j]);
      if(map[i][j] == 'S') x = i, y = j;
    }
  }

  queue<pairi> q;
  pairi c;
      
  char target;

  int r = 0;

  for(int i=0;i<n;i++){
    target = '1'+i;

    q = queue<pairi>();
    memset(visited, 0, sizeof(visited));

    q.push(pairi(x,y));
    visited[x][y] = 1;

    while(!q.empty()){
      c = q.front();
      x = c.first;
      y = c.second;
      q.pop();

      if(map[x][y] == target){
	r += visited[x][y]-1;
	break;
      }

      if(map[x+1][y] != 'X' && visited[x+1][y] == 0){
	q.push(pairi(x+1,y));
	visited[x+1][y] = visited[x][y]+1;
      }

      if(map[x-1][y] != 'X' && visited[x-1][y] == 0){
	q.push(pairi(x-1,y));
	visited[x-1][y] = visited[x][y]+1;
      }

      if(map[x][y+1] != 'X' && visited[x][y+1] == 0){
	q.push(pairi(x,y+1));
	visited[x][y+1] = visited[x][y]+1;
      }

      if(map[x][y-1] != 'X' && visited[x][y-1] == 0){
	q.push(pairi(x,y-1));
	visited[x][y-1] = visited[x][y]+1;
      }
    }
  }

  printf("%d\n", r);
}

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n;
ll a[300000], b[300000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  priority_queue<pair<ll, int>> pq;
  for (int i = 0; i < n; i++)
    if (b[i] > a[i])
      pq.push({b[i], i});
  ll o = 0;
  while (!pq.empty()) {
    auto p = pq.top();
    pq.pop();
    int i = p.second;
    ll c = (b[i] - a[i]) / (b[(i + 1) % n] + b[(i - 1 + n) % n]);
    o += c;
    b[i] -= c * (b[(i + 1) % n] + b[(i - 1 + n) % n]);
    if (c == 0 || b[i] < a[i]) {
      cout << -1 << "\n";
      return 0;
    }
    if (b[i] > a[i])
      pq.push({b[i], i});
  }
  cout << o << "\n";
}


Measured memory_bytes: 10096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    VI as;
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        as.push_back(a - (i + 1));
    }
    
    sort(as.begin(), as.end());
    long mid;
    if (n % 2 == 0) {
        mid = (as[n / 2 - 1] + as[n / 2]) / 2;
    } else {
        mid = as[n / 2];
    }
    long ans = 0;
    for (auto a: as) {
        ans += abs(mid - a);
    }
    
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

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

int main(void){
	int n;
	while(cin>>n,n){
		vector<int> v(n);
		rep(i,n)cin>>v[i];
		int cnt = 0;
		rep(i,n){
			for(int j = 0; j+1 < n-i; j++){
      	if(v[j] > v[j+1]){ 
      		swap(v[j],v[j+1]); 
      		cnt++;
      	}
      }
		}		

		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
using System;

namespace A___T_or_T
{
    class Program
    {
        static void Main(string[] args)
        {
            var NAB = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];

            Console.WriteLine(Math.Min(N * A, B));
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, m, i, j, k, x, y, v, ans;
	cin >> n >> m >> k;
	vector<vector<long long>> vv(n + 1, vector<long long>(m + 1, 0));
	for (i = 0; i < k; i++) {
		cin >> x >> y >> v;
		vv[x][y] = v;
	}

	vector<vector<long long>> dp(m + 1, vector<long long>(4, 0)), dp2;

	for (i = 1; i <= n; i++) {
		swap(dp, dp2);
		dp.assign(m + 1, vector<long long>(4, 0));

		for (j = 1; j <= m; j++) {
			x = max(max(dp2[j][0], dp2[j][1]), max(dp2[j][2], dp2[j][3]));
			dp[j][0] = max(dp[j][0], x); 
			dp[j][1] = max(dp[j][1], x + vv[i][j]);
			dp[j][1] = max(dp[j][1], dp[j][0] + vv[i][j]);

			if (j < m) {
				for (k = 0; k <= 3; k++) {
					dp[j + 1][k] = max(dp[j + 1][k], dp[j][k]);
					if (k < 3) dp[j + 1][k + 1] = max(dp[j + 1][k + 1], dp[j][k] + vv[i][j + 1]);
				}
			}
		}
	}

	ans = max(max(dp[m][0], dp[m][1]), max(dp[m][2], dp[m][3]));

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 74012
from itertools import accumulate
while 1:
    n=int(input())
    if n==0:
        break
    timeline=[0 for i in range(86401)]
    for i in range(n):
        a,b=input().split()
        a=list(map(int,a.split(':')))
        b=list(map(int,b.split(':')))
        a=a[0]*3600+a[1]*60+a[2]
        b=b[0]*3600+b[1]*60+b[2]
        timeline[a]+=1
        timeline[b]-=1
    print(max(accumulate(timeline)))


Measured memory_bytes: 6972
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    BC = [[0, 0] for _ in range(M)]
    for i in range(M):
        BC[i][0], BC[i][1] = map(int, input().split())
    BC.sort(key=lambda x: x[1], reverse=True)

    D = []
    cnt = 0
    for i in range(M):
        cnt += BC[i][0]
        if cnt > N:
            D.extend([BC[i][1]] * (BC[i][0] - (cnt - N)))
            break
        else:
            D.extend([BC[i][1]] * BC[i][0])

    A.extend(D)
    A.sort()
    ans = sum(A[-N:])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 26652