akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl '\n'
 
void solve(){
    int l,r,d;
    int c = 0;
    cin>>l>>r>>d;
    for(int i = 1;i<=100;i++){
        int x = i * d;
        if(x >= l && x <= r)c++;
    }
    cout<<c;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
    while(t--){
        solve();
    }
	return 0;
}


Measured memory_bytes: 3644
// https://atcoder.jp/contests/abc068/tasks/arc079_a

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, M, a, b;
vector<set<ll>> g;
string r;

int main()
{
  set<ll> s;
  cin >> N >> M;

  REP(i, N)
  {
    g.push_back(s);
  }

  REP(i, M)
  {
    cin >> a >> b;
    if (a == 1 || b == N)
      g[a - 1].insert(b - 1);
  }

  r = "IMPOSSIBLE";
  for (auto &i : g[0])
  {
    if (0 < g[i].count(N - 1))
      r = "POSSIBLE";
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 20328
import sys
S=input()
N=len(S)
if S[:N//2]==S[N//2+1:][::-1]:
  if N==3:
    print("Yes")
  elif (N//2)%2==1:
    if S[:(N//2)//2]==S[(N//2)//2+1:N//2][::-1] and S[N//2+1:-(N//2)//2]==S[-(N//2)//2+1:][::-1]:
      print("Yes")
    else:
#      sys.stderr.write("2\n")
      print("No")
  else:
    if S[:(N//2)//2]==S[(N//2)//2:N//2][::-1] and S[N//2+1:-(N//2)//2]==S[-(N//2)//2:][::-1]:
      print("Yes")
    else:
      print("No")
else:
#  sys.stderr.write("1\n")
  print("No")



Measured memory_bytes: 9156
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

#define MOD 1000000007

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll comb(int n, int r) {
  ll val = 1;
  ll din = 1;
  repi(a, n-r+1, n+1) val = (val * a) % MOD;
  repi(a, 1, r+1) din = (din * a) % MOD;
  val = (modinv(din, MOD) * val) % MOD;
  return val;
}

ll f_sum(ll m, ll n){
  ll val = 0;
  repi(i, 1, m+1)
    val = (val + i * i + (m-i+1) * (m-i+1)) % MOD;
  val = (val * n * n) % MOD;
  return val;
}

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

  ll ans = (f_sum(N, M) + f_sum(M, N) - M*N*(2*M*N+M+N)) % MOD;
  if(ans < 0) ans += MOD;
  ans = (ans * comb(K, 2)) % MOD;
  ans = (ans * comb(M*N, K)) % MOD;
  ans = (modinv(2*M*N*(M*N-1) % MOD, MOD) * ans) % MOD;

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


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

int main(){

    int N, M; cin >> N >> M;
    int k[M];
    int s[10][10];
    bool p[M];
    for(int i = 0; i < M; i += 1){
        cin >> k[i];
        for(int j = 0; j < k[i]; j+=1){
            cin >> s[i][j];
        }
    }

    for(int i = 0; i < M; i++){cin >> p[i];}

    bool swch[N];
    bool check;
    int cnt = 0;

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

        check = 1;

        for(int j = 0; j < N; j++){
            swch[j] = i & (1 << j);
        }

        for(int h = 0; h < M; h++){

            bool tmp = 0;
            for(int l = 0; l < k[h]; l++){
                tmp = tmp^swch[s[h][l]-1];
            }

            check = check & (!(p[h]^tmp));
        }

        if(check){cnt++;}
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll g=(c*d)/__gcd(c,d);
	ll ans=(b-a+1);
	ll a1=(b/c)-(a-1)/c;
	ll a2=(b/d)-(a-1)/d;
	ll a3=(b/g)-(a-1)/g;
	// telll(a1,a2,a3);
	cout<<ans-a1-a2+a3;
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int A[5000100];
int L[2500100];
int R[2500100];
int INFTY = 999999999;
int k;
int cnt;
void merge(int left, int mid, int right){
  int i,j;
  int n1 = mid - left;
  int n2 = right - mid;
  for (i = 0;i <= n1-1;i++)
    L[i] = A[left + i];
  
  for (i = 0;i <= n2-1;i++){
    R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  }
  i = 0;
  j = 0;

  for (k = left;k <= right-1;k++){
    cnt++;
    if (L[i] <= R[j])
      A[k] = L[i++];
    
    else 
      A[k] = R[j++];
  }
}

void mergeSort(int left, int right){
  if (left+1 < right){
    int mid = (left + right)/2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int main(){
  int i,a,b,n;

  scanf("%d",&a);
  for(i=0;i<a;i++)
    scanf("%d",&A[i]);
  
  
    mergeSort(0,a);

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


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll n;
	cin>>n;
	string s[n];
	map<string,ll> wow;
	floop(i,0,n)
	{
		cin>>s[i];
		wow[s[i]]++;
	}
	cout<<"AC x "<<wow["AC"]<<"\n";
	cout<<"WA x "<<wow["WA"]<<"\n";
	cout<<"TLE x "<<wow["TLE"]<<"\n";
	cout<<"RE x "<<wow["RE"]<<"\n";
	return 0;
}

Measured memory_bytes: 6752
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int h, w;
int n;
const int maxN = 105;
int a[maxN * maxN];
int ans[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> h >> w >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector < pair < int, int > > ord;
    for (int i = 1; i <= h; i++) {
        if (i % 2) for (int j = 1; j <= w; j++) ord.emplace_back(i, j);
        else {
            for (int j = w; j >= 1; j--) ord.emplace_back(i, j);
        }
    }
    int sm = 0;
    for (int i = 1; i <= n; i++) {
        for (int v = sm; v < sm + a[i]; v++) {
            ans[ord[v].first][ord[v].second] = i;
        }
        sm += a[i];
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) cout << ans[i][j] << " ";
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
  int n,a[25],i,ans,f;
  while(1){
    scanf("%d",&n);
    if(!n)break;
    ans=32;
    for(i=0;i<n;i++)
      scanf("%d",&a[i]);
    f=0;
    while(1){
      for(i=0;i<n;i++){
	ans-=(ans-1)%5;
	if(ans<0)ans=0;
	printf("%d\n",ans);
	if(!ans){
	  f=1;
	  break;
	}
	ans-=a[i];
	if(ans<0)ans=0;
	printf("%d\n",ans);
	if(!ans){
	  f=1;
	  break;
	}
      }
      if(f)break;
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep( i, n ) for (ll i = 0; i < ( ll )(n); i++)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair< int , int > P;
typedef tuple<int, int, int> T;



int main(){
    string s,t;
    cin>>s>>t;
    for(int i =0;i<s.size();i++){
        if(s[i]!=t[i]) {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}

Measured memory_bytes: 3624
from decimal import *

n,k=map(int,input().split())

def count_beki(n,k):
  count=0
  while n<k:
    count+=1
    n=n*2
  return count
  

win=Decimal(0)
base_k=Decimal(1)/Decimal(n)
for i in range(1,n+1):
  if i < k:
    beki=count_beki(i,k)
    unq_k=(Decimal(1)/Decimal(2))**beki
    win+=base_k*unq_k
  else:
    win+=base_k

print(round(win,12))


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

int main () {
	
	int n=0, q=0, val=0, i=0;
	multiset <int> si;

	scanf("%d", &n);

	for (i=0; i<n; i++) {
		scanf("%d", &val);
		si.insert(val);
	}

	scanf("%d", &q);

	bool flag=1;
	for (i=0; i<q; i++) {
		scanf("%d", &val);
		auto it = si.find(val);
		if(it != si.end()) si.erase(it);
		else flag=0;
	}

	if (flag) printf("YES\n");
	else printf("NO\n");



	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
const double PI = acos(-1.0);

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

    
    int ct[26];
    mem(ct, 0);

    int h, w;
    cin >> h >> w;
    REP(i,h*w){
        char tmp;
        cin >> tmp;
        FOR(j, 'a', 'z'+1){
            if(tmp == (char)j) ct[j-(int)'a']++;
        }
    }
    int count = 0;
    REP(i, 26){
        count += (ct[i] / 4);
        ct[i] = ct[i]%4;
    }
    if(count < (h-(h%2))*(w-(w%2))/4){
        cout << "No" << "\n";
        return 0;
    }
    int rem = (h%2)*w + (w%2)*h - (count - (h-(h%2))*(w-(w%2))/4)*4;
    bool flag = true;
    if(h%2 && w%2){
        rem--;
        flag = false;
    }
    REP(i,26){
        rem -= ct[i];
        if(ct[i]%2){
            if(flag){
                cout << "No" << "\n";
                return 0;
            }else{
                flag = true;
            }
        }
    }
    cout << (rem == 0 ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
https://atcoder.jp/contests/agc047/editorial/43を参考にpythonで実装
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"



def main():
    n = int(ipt())
    sts = []
    nax = 10**6+5
    child = [[0]*26 for _ in range(nax)]
    is_end = [False]*nax
    paths = [[] for i in range(n)]
    nxt = 1

    for who in range(n):
        s = input()[::-1]
        sts.append(s)
        node = 0
        for ch in s:
            paths[who].append(node)
            nm = ord(ch)-ord("a")
            if child[node][nm] == 0:
                child[node][nm] = nxt
                nxt += 1
            node = child[node][nm]
        is_end[node] = True

    ans = 0
    for who in range(n):
        s = sts[who]
        suffix = set()
        for i in range(len(s)-1,-1,-1):
            suffix.add(s[i])
            node = paths[who][i]
            for ch in suffix:
                ans += is_end[child[node][ord(ch)-ord("a")]]

    print(ans-n)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 437088
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b;
   cin >> a >> b;
   if (a < b) {
      rep(i, 0, b) { cout << a; }
      cout << endl;
   } else if (a > b) {
      rep(i, 0, a) { cout << b; }
      cout << endl;
   } else {
      rep(i, 0, a) { cout << a; }
      cout << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<deq[n-1]<<endl;
}


Measured memory_bytes: 256
/*
    Problem 73
    https://atcoder.jp/contests/abc145/tasks/abc145_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int mod = 1000000007;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
/* global variables */
/* function */
struct combination {
    // vector size : n + 1
    vector<mint> fact, ifact;
    // precaliculation O(n)
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        // 0! = 1;
        fact[0] = 1;
        // 1! = 0! * 1 ... n! = (n-1)! * n
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
        // 1/n! = n!^(-1)
        ifact[n] = fact[n].inv();
        // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    // combination O(1)
    // nCk = n! / (k! * (n-k)!)
    //     = n! * k!^(-1) * (n-k)!^(-1)
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
/* main */
int main(){
    int X, Y;
    cin >> X >> Y;
    if (X > Y) swap(X, Y);
    combination C = combination(1000000);
    int n = Y - X;
    int nY = Y - 2 * n, nX = X - n;
    if (nY < 0 || nY % 3 != 0) {
        cout << 0 << '\n';
        return 0;
    }
    int m = nY / 3;
    mint ans = C((m + n) + m, m);
    cout << ans.x << '\n';
}


Measured memory_bytes: 15872
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_num, count)
      break
  sride += 1
  count = 0
print(max_num)


Measured memory_bytes: 42380
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n>=30)
    {
        cout<<"Yes"<<"\n";
    }
    else
    {
        cout<<"No"<<"\n";
    }
    return 0;
}




Measured memory_bytes: 3556
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 600005;
pair<int,int> b[N];
int n, a[N];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=0;i<(1 << n);++i)	{
		cin >> a[i];
		b[i].first = a[0];
	}
	for (int m = 1; m < (1 << n); ++m){
		for (int s= m; s; s = (s-1) & m){
			if (b[m].first < a[s]) {
				b[m].second = b[m].first;
				b[m].first = a[s];
			}
			else if (b[m].second < a[s]) b[m].second = a[s];
		}
	}
	int ans = 0;
	for(int m=1;m<(1 << n);++m) {
		ans = max(ans, b[m].first + b[m].second);
		cout << ans << '\n';
	}
}

Measured memory_bytes: 6740
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> V;
typedef pair<ll,ll> P;
typedef map<ll,ll> M;

#define REP(i,n) for(ll (i) = 0; (i) < (n); ++(i))


int main(){
    V h(6);
    V w(6);
    map<P,ll> m;
    REP(i,6){
        cin >> h[i] >> w[i];
        if(h[i] > w[i])swap(h[i], w[i]);
        m[make_pair(h[i],w[i])]++;
    }
    bool flag = true;
    for(auto x : m){
        if(x.second % 2)
            flag = false;
    }
    if(!flag){
        cout << "no" << endl;
        return 0;
    }
    vector<P> p;
    for(auto x : m){
        REP(i, x.second / 2)
            p.push_back(x.first);
    }
    sort(p.begin(), p.end());

    flag = (
                p[0].first == p[1].first &&
                min(p[0].second, p[1].second) == p[2].first &&
                max(p[0].second, p[1].second) == p[2].second
            );

    cout << (flag ? "yes" : "no" ) << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

ll n, m;
ll q;

ll a[100010];
ll t;

vl v, x;

set<ll> ss[100010];

bool used[100010];

int no(){
  puts( "No" );
  return 0;
}

int main(){

  scanf( "%lld %lld" , &n , &m );
  scanf( "%lld" , &q );
  REP( i , q ) scanf( "%lld" , &a[i] );
  
  for( ll i = m; i >= 1; i-- ) v.pb( i );
  REP( i , q ) v.pb( a[i] );

  REP( i , q ) ss[ a[i] ].insert( i );

  for( ll i = SZ(v)-1; i >= 0; i-- ){
    if( !used[v[i]] ){
      used[ v[i] ] = true;
      x.pb( v[i] );
      if( i >= m ){
	assert( ss[ v[i] ].find( i-m ) != ss[ v[i] ].end() );
	ss[ v[i] ].erase( ss[ v[i] ].find( i-m ) );
      }
    }
  }
  
  for( ll i = SZ(x)-2; i >= 0; i-- ){
    if( x[i] > x[i+1] ){
      t = i+1;
      break;
    }
  }
  
  if( t * n  > q ) return no();

  REP( i , n-1 ){
    ll cur = q;
    REP( j , t ){
      auto ite = ss[ x[j] ].lower_bound( cur );
      if( ite == ss[ x[j] ].begin() ) return no();
      ite--;
      cur = *ite;
      ss[ x[j] ].erase( ite );
    }
  }

  puts( "Yes" );
  
  return 0;
}


Measured memory_bytes: 13808
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static int[] minSegment;
	private static int[] maxSegment;

	private static int n;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		List<Integer> values = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			values.add(sc.nextInt());
		}

		Collections.sort(values);

		makeSegment(values);
		int minVal = Integer.MAX_VALUE;
		for(int i = 0; i + k -1 < n; i++) {
			int dif = getMaxVal(i, i + k -1) - getMinVal(i, i + k - 1);
			minVal = Math.min(minVal, dif);
		}

		System.out.println(minVal);

	}

	private static void makeSegment(List<Integer> values) {
		n = 1;
		while(n < values.size()) {
			n *= 2;
		}

		int segLen = 2 * n - 1;

		minSegment = new int[segLen];
		for(int j = 0; j < segLen; j++) {
			minSegment[j] = Integer.MAX_VALUE;
		}
		maxSegment = new int[segLen];

		for(int j = 0; j < values.size(); j++) {
			int segIdx = n + j - 1;
			updateSegment(segIdx, values.get(j));
		}

	}

	private static void updateSegment(int idx, int val) {

		minSegment[idx] = val;
		maxSegment[idx] = val;

		while(idx > 0) {
			idx = (idx-1)/2;
			minSegment[idx] = Math.min(minSegment[2*idx + 1], minSegment[2*idx + 2]);
			maxSegment[idx] = Math.max(maxSegment[2*idx + 1], maxSegment[2*idx + 2]);
		}
	}

	private static int getMinVal(int l, int r) {
		int minVal = Integer.MAX_VALUE;

		l = n + l - 1;
		r = n + r - 1;

		if(l % 2 == 0) {
			minVal = minSegment[l];
			l++;
		}
		if(r % 2 != 0) {
			minVal = Math.min(minVal, minSegment[r]);
			r--;
		}

		while(l<r) {
			l = (l-1)/2;
			r = (r-1)/2;

			if(l % 2 == 0) {
				minVal = Math.min(minVal, minSegment[l]);
				l++;
			}
			if(r % 2 != 0) {
				minVal = Math.min(minVal, minSegment[r]);
				r--;
			}
		}

		return minVal;
	}

	private static int getMaxVal(int l, int r) {
		int maxVal = 0;

		l = n + l - 1;
		r = n + r - 1;

		if(l % 2 == 0) {
			maxVal = maxSegment[l];
			l++;
		}
		if(r % 2 != 0) {
			maxVal = Math.max(maxVal, maxSegment[r]);
			r--;
		}

		while(l<r) {
			l = (l-1)/2;
			r = (r-1)/2;

			if(l % 2 == 0) {
				maxVal = Math.max(maxVal, maxSegment[l]);
				l++;
			}
			if(r % 2 != 0) {
				maxVal = Math.max(maxVal, maxSegment[r]);
				r--;
			}
		}

		return maxVal;
	}
}



Measured memory_bytes: 60496
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];

int main(void){
    int N; 
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    
    for(int i=0; i<100010; i++) dp[i] = INF;
    dp[0] = 0;
    
    for(int i=0; i<N; i++){
        chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
        if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[N-1] << endl;
    
}


Measured memory_bytes: 1792
N,K=map(int,input().split())
b=list(map(int,input().split()))
b.sort()
a=[]
for i in range(N):
    if b[i]<K:
        a.append(b[i])
N=len(a)
ans=0
#print(bin((1<<K)>>1))
C=[1]
n=1
for i in range(N):
    n=n|n<<a[i]
    n%=(1<<K)
    C.append(n)
#print(C)
    #print(bin(n))
if N<=10:
    for i in range(N):
        n=C[i]
        for j in range(i+1,N):
            n=n|n<<a[j]
            n%=(1<<K)
        if n < (1<<K)>>a[i]:
            ans+=1
        else:
            break
    print(ans)
else:
    a+=[10**9]
    H=N
    L=0
    
    while abs(H-L)>4:
        Mid=(H+L)//2
        #print(H,Mid,L)
        n=1
        for i in range(N):
            if i==Mid:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[Mid]:    
            H=Mid
        else:
            L=Mid
    #print(H,L)        
    for j in range(max(0,L-5),N):
        n=1
        for i in range(N):
            if i==j:
                continue
            else:
                n=n|n<<a[i]
                n%=(1<<K)
        if n >= (1<<K)>>a[j]: 
            print(j)
            exit()
    print(N)

Measured memory_bytes: 46572
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
var abs = x=>x>0?x:-x;
function min(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]<val)val = rest[i];return val}
function max(){var rest = arguments,val=rest[0];for(var i=1;i<rest.length;i++)if(rest[i]>val)val = rest[i];return val}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
 
function Main(input){
	var input = input.split('\n');
	var s = input[0];
	var t = input[1];
	var x = s.length;
	var y = s;
	for(var i = 0; i < x+1; i++){
		y = y[x-1] + y.slice(0,-1);
		if(t === y){
			console.log('Yes');
			return 0;
		}
	}
	console.log('No');	
}

Measured memory_bytes: 21064
n=int(input())
A=list(map(int,input().split()))
r=set()
def f(s,k):
    if k>=0:
        global r
        r.add(s)
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])


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

typedef long long LL;
typedef unsigned long long uLL;

#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
#define MP(x, y) std::make_pair(x, y)
#define DE(x) cerr << x << endl;
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define GO cerr << "GO" << endl;

using namespace std;

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}
inline int read() 
{
    register int x = 0; register int f = 1; register char c;
    while (!isdigit(c = getchar())) if (c == '-') f = -1;
    while (x = (x << 1) + (x << 3) + (c xor 48), isdigit(c = getchar()));
    return x * f;
}
template<class T> inline void write(T x) 
{
    static char stk[30]; static int top = 0;
    if (x < 0) { x = -x, putchar('-'); }
    while (stk[++top] = x % 10 xor 48, x /= 10, x);
    while (putchar(stk[top--]), top);
}
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

const int maxN = 1000;
const int mod = 1e9 + 7;

void pls(int &x, int y)
{
	x += y;
	if (x >= mod) x -= mod;
	if (x < 0) x += mod;
}

int n, K, to[maxN], sum[maxN];
int dp[maxN][maxN], g[maxN];

int main() 
{
	cin >> n >> K;
	for (int i = 1; i <= K; ++i)
	{
		int u, v;
		cin >> u >> v;
		to[u] = v;
		to[v] = u;
		sum[u]++;
		sum[v]++;
	}
	n <<= 1;
	for (int i = 1; i <= n; ++i)
		sum[i] += sum[i - 1];
	g[0] = 1;
	for (int i = 2; i <= n; i += 2) 
		g[i] = 1ll * (i - 1) * g[i - 2] % mod;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = i + 1; j <= n; j += 2)
		{
			bool flag = 0;
			for (int k = i; k <= j; ++k)
				if (to[k] and (to[k] < i || to[k] > j))
				{
					flag = 1;
					break;
				}
			if (flag)
				continue;
			dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
			for (int l = i + 1; l < j; l += 2)
				pls(dp[i][j], -1ll * dp[i][l] * g[j - l- sum[j] + sum[l]] % mod);
		}
	}
	K <<= 1;
	int ans(0);
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; j += 2)
			pls(ans, 1ll * dp[i][j] * g[n - (j - i + 1) - (K - (sum[j] - sum[i - 1]))] % mod);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
while True:
    m, f, r = map(int, input().split())
    
    if m == -1 and f == -1 and r == -1:
        break
    else:
        pass
    
    if m == -1 or f == -1:
        print("F")
    else:
        if m + f >= 80:
            print("A")
        elif 65 <= m + f < 80:
            print("B")
        elif 50 <= m + f < 65:
            print("C")
        elif 30 <= m + f < 50:
            if r >= 50:
                print("C")
            else:
                print("D")
        elif m + f < 30:
            print("F")



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1<<15)+5;
int n,m;
int dp[maxn][16];
int mp[16][16],val[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		mp[v][u]=mp[u][v]=w;
	}
	memset(dp,-1,sizeof(dp));
	int all=(1<<n)-1;
	dp[1][1]=0;
	for(int s=0;s<=all;s++)
	{
		for(int i=1;i<=n;i++)
		if(s&(1<<i-1))
		{
			for(int j=i+1;j<=n;j++)
			if(s&(1<<j-1))val[s]+=mp[i][j];
		}
		for(int i=1;i<=n;i++)
		if(s&(1<<i-1))
		{
			for(int s0=s;s0;s0=(s0-1)&s)if(((s^s0)&(1<<i-1))&&dp[s^s0][i]!=-1)dp[s][i]=max(dp[s^s0][i]+val[s0|(1<<i-1)],dp[s][i]);
			for(int j=1;j<=n;j++)if((s&(1<<j-1))&&j!=i&&mp[j][i]&&dp[s^(1<<i-1)][j]!=-1)dp[s][i]=max(dp[s][i],dp[s^(1<<i-1)][j]+mp[j][i]);	
		}
	}
	printf("%d\n",val[all]-dp[all][n]);
}

Measured memory_bytes: 2432
#include <stdio.h>
int main(void)
{
    int cnt,x,i;
    scanf("%d",&x);
    while(1)
    {
        cnt = 0;
        for(i = 2; i < x; i++)
        {
            if(x % i == 0)
                cnt++;
        }
        if (cnt == 0)
            break;
        else
            x++;
    }
    printf("%d\n",x);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int w[100];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> w[i];
	
	int ans = 11451419;
	rep(i, n) {
		int s1 = 0;
		int s2 = 0;
		for (j = 0; j < i; j++) s1 += w[j];
		for (j = i; j < n; j++) s2 += w[j];
		ans = min(ans, abs(s1 - s2));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



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

  Int n;
  cin>>n;
  map<Int,Int> A, B;
  Int cntA = 0, cntB = 0;
  for(Int i=0;i<n;i++){
    Int num;
    cin>>num;
    if(i % 2 == 0) A[num]++, cntA++;
    else B[num]++, cntB++;
  }

  vector<P> X, Y;
  for(auto p:A) X.push_back(P(p.second, p.first));
  for(auto p:B) Y.push_back(P(p.second, p.first));
  sort(X.begin(), X.end(), greater<P>());
  sort(Y.begin(), Y.end(), greater<P>());

  auto calc = [&](Int a, Int b) {
    return (cntA - a) + (cntB - b);
  };

  Int ans = INF;
  for(Int i=0;i<10;i++)
    for(Int j=0;j<10;j++){
      if(i >=(Int)X.size() || j >= (Int)Y.size()) continue;
      if(X[i].second == Y[j].second) continue;
      Min(ans, calc(X[i].first, Y[j].first));
    }

  if(ans == INF) Min(ans, n/2);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8824
#include<stdio.h>
#include<string.h>
int main(){
    int e,d;
    char s[101];
    char c[101];
    scanf("%d",&e);
    scanf("%s",s);
    d=strlen(s);
   //d++;
    strncpy(c,s,e);
    c[e]='\0';
    if(d>e)printf("%s...\n",c);
    else printf("%s\n",s);
    
    return 0;
    
}

Measured memory_bytes: 1736
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

N = int(input())
L = [list(map(int, input().split())) for i in range(N)]

A, B = 1, 1
for x,y in L:
    n = max(0-(-A//x), 0-(-B//y))
    A, B = n*x, n*y

print(A+B)

Measured memory_bytes: 12184
#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

// #define fisier 1

using namespace std;

typedef long long ll;

const int mod = 1000000007;
const double dancila = 3.14159265359; // PI 
const double eps = 1e-9;

ll n, w, W[102], V[102];

ll dp[102][100002]; // dp[i][j] = max value if we filled the knapsack with some of the first i items, weight = j
int main()
{

    #ifdef fisier
        ifstream f("input.in");
        ofstream g("output.out");
    #endif

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

	
	cin >> n >> w;
	for(int i = 1; i <= n; ++i)
		cin >> W[i] >> V[i];
	
	for(int i = 0; i < n; ++i)
		for(int j = 0; j <= w; ++j)
		{
			if(j + W[i+1] <= w)
				dp[i+1][j + W[i+1]] = max(dp[i+1][j + W[i+1]], dp[i][j] + V[i+1]);
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
		}
		
	ll ans = 0;
	for(int j = 0; j <= w; ++j)
		ans = max(ans, dp[n][j]);
	cout << ans;
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    int count=0;
    set<int> s;
    set<int>::iterator ite; 
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        ite =s.find(a);
        if(ite == s.end()){
            s.insert(a);
            count++;
        }else{
            s.erase(a);
            count--;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 4864
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int N_MAX = 100000;
const int M_MAX = 100000;
const int Q_MAX = 100000;
const int D_MAX = 10;

typedef pair<int, int> P;

int N, M;
int Q;
int v[Q_MAX];
int d[Q_MAX];
int c[Q_MAX];

vector<int> G[N_MAX];
bool memo[N_MAX][D_MAX + 1];
int color[N_MAX];

void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}

void rec(int v, int d, int c) {
  if (memo[v][d]) return;
  memo[v][d] = true;
  if (color[v] == 0) color[v] = c;
  if (d == 0) return;
  REP(i, G[v].size()) rec(G[v][i], d - 1, c);
}

void solve() {
  for(int i = Q - 1; i >= 0; i--) {
    rec(v[i] - 1, d[i], c[i]);
  }
  REP(i, N) printf("%d\n", color[i]);
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) {
    int a, b;
    scanf("%d%d", &a, &b);
    add_edge(a - 1, b - 1);
  }
  scanf("%d", &Q);
  REP(i, Q) scanf("%d%d%d", v + i, d + i, c + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) <= (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;          using vi  = vector<int>;
using unit= unsigned;           using vl  = vector<ll>;
using ull = unsigned long long; using vvi = vector<vi>;
using P   = pair<int,int>;      using vvl = vector<vl>;
                                using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>string join(const v(T)&v){ stringstream s; rep(i,0,sz(v))s<<' '<<v[i]; return s.str().substr(1); }
template<class T>istream &operator>>(istream&i, v(T)&v){ fore(x,v){ i >> v; } return i; }
template<class T>ostream &operator<<(ostream&o, const v(T)&v){ o<<"["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const deque<T>&v){ o<<"deq["; fore(x,v)o<<x<<","; o<<"]"; return o; }
template<class T>ostream &operator<<(ostream&o, const set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_set<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T>ostream &operator<<(ostream&o, const unordered_multiset<T>&v){ o<<"{"; fore(x,v)o<<x<<","; o<<"}"; return o; }
template<class T1,class T2>ostream &operator<<(ostream &o, const pair<T1,T2>&p){ o<<"("<<p.fi<<","<<p.se<<")"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class TK,class TV>ostream &operator<<(ostream &o, const unordered_map<TK,TV>&m){ o<<"{"; fore(x,m)o<<x.fi<<"=>"<<x.se<<","; o<<"}"; return o; }
template<class T>void YES(T c){ if(c) cout<<"YES"<<endl; else cout<<"NO"<<endl; }
template<class T>void Yes(T c){ if(c) cout<<"Yes"<< endl; else cout<<"No"<<endl; }
template<class T>void POSS(T c){ if(c) cout<<"POSSIBLE"<<endl; else cout<<"IMPOSSIBLE"<<endl; }
template<class T>void Poss(T c){ if(c) cout<<"Possible"<<endl; else cout<<"Impossible"<<endl; }
template<class T>void chmax(T &a, const T &b){ if(a<b) a=b; }
template<class T>void chmin(T &a, const T &b){ if(b<a) a=b; }
template<class T>T gcd(T a, T b){ return (b==0) ? a : gcd(b,a%b); }
template<class T>T lcm(T a, T b){ return a * (b / gcd(a,b)); }
const double  EPS = 1e-10;
const double  PI  = acos(-1.0);
const int     INF = INT_MAX / 2;
const ll      INFL= 1LL << 60;
const int dx[] = { -1, 0, 1, 0 , -1,-1, 1, 1 };
const int dy[] = {  0, 1, 0,-1 , -1, 1,-1, 1 };

void _main() {
  int A, B;
  cin >> A >> B;

  int d = abs(A-B);
  if (d&1) puts("IMPOSSIBLE");
  else cout << (min(A,B) + d/2) << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	map<ll, int> ct;
	int a, ok=1;
	rep(i, n){
		cin >> a;
		ct[a]++;
		if(ct[a]>1) ok=0;
	}
	cout <<(ok? "YES":"NO")<<"\n";
	return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  int m[3][3]={};
  m[0][0]=a;m[0][1]=b;m[1][1]=c;m[2][0]=a+b-c;m[1][2]=2*a+b-2*c;
  REP(i,101){
    if(a+b+i==2*i+2*a+2*b-3*c){
        m[0][2]=i;
        m[1][0]=i-a+c;
        m[2][1]=a-c+i;
        m[2][2]=b-c+i;
        break;
    }
  }
  REP(i,3){
    REP(j,3){
      cout<<m[i][j];
      if(j<2)cout<<' ';
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

vector<bool> seive(int ma){
    vector<bool> is_prime(ma+1,1);
    for(int i=2;i<=ma;i++){
        if(is_prime[i]){
            for(int j=2*i;j<=ma;j+=i) is_prime[j] = 0;
        }
    }
    return is_prime;
}

int main(){
    const int ma = 100001;
    vector<bool> is_prime = seive(ma);
    vector<int> a(is_prime.size()+1,0);
    for(int i=2;i<=ma;i++){
        if(is_prime[i] && is_prime[(i+1)/2] && i!=0){
            a[i] = a[i-1] + 1;
        }else{
            a[i] = a[i-1];
        }
    }/*
    rep(i,101){
        cout << i << " " << a[i] << endl;
    }*/
    int q;
    cin >> q;
    while(q--){
        int l,r;
        cin >> l >> r;
        l--;
        cout << a[r] - a[l] - (l==0? 1 : 0)<< endl;
    }
}

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

const int N_MAX = 200005;
int A[N_MAX];

int main(){
    int K;
    int n;
    cin >> K >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int sho = 0;
    for(int i = 1; i < n; i++){
        int l = A[i] - A[i-1];
        sho = max(sho, l);
    }
    int l = (K + A[0]) - A[n-1];
    sho = max(sho,l);
    cout << K - sho << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "E"
int x[100001], l;
int f[100001][21];
int ans[100001];
int n, q, a, b;
priority_queue <pair <int, int> , vector <pair <int, int> >, greater<pair <int, int> > > query[100001];
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    FOR(i, 1, n) read(x[i]);
    read(l);
    read(q);
    FOR(i, 1, q){
        read(a);
        read(b);
        if(a>b) swap(a, b);
        query[a].push(mp(b, i));
    }
    f[n][0]=n;
    DFOR(i, n-1, 1){
        f[i][0]=f[i+1][0];
        while(x[f[i][0]]-x[i]>l) f[i][0]--;
    }
    if(f[1][0]<n) for(int j=1;;j++){
        FOR(i, 1, n) f[i][j]=f[f[i][j-1]][j-1];
        if(f[1][j]==n) break;
    }
    pair <int, int> p;
    FOR(i, 1, n){
        int j=0, r=1;
        while(!query[i].empty()){
            p=query[i].top();
            query[i].pop();
            while(f[i][j]<p.first){
                r<<=1;
                j++;
            }
            if(j==0) ans[p.second]++;
            else{
                ans[p.second]+=r>>1;
                query[f[i][j-1]].push(p);
            }
        }
    }
    FOR(i, 1, q) writeln(ans[i]);
}

Measured memory_bytes: 24704
(let* ((n (read))
       (m (read))
       (arr (make-array (list 2 (1+ n)) :element-type 'bit :initial-element 0)))
  (loop :repeat m :do (let* ((a (read))
                             (b (read)))
                        (cond ((= a 1) (setf (aref arr 0 b) 1))
                              ((= b n) (setf (aref arr 1 a) 1)))))
  (if (loop :for k :from 0 :upto n :never (and (= (aref arr 0 k) 1) (= (aref arr 1 k) 1)))
      (princ "IMPOSSIBLE")
      (princ "POSSIBLE")))

Measured memory_bytes: 57704
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main()
{
	int a, b, c, d, n, judg = 0, sub = 0, Ans = 0, i, j, k;
	int A[3];	
		cin >> A[0] >> A[1] >> A[2] >> n;
		for (i = 0; i < 2; i++) {
			for (j = i + 1; j < 3; j++) {
				if (A[i] < A[j]) {
					sub = A[i];
					A[i] = A[j];
					A[j] = sub;
				}
			}
		}
		for (i = 0; i <= 3000; i++) {
			if (A[0]*i > n)
				break;
			for (j = 0; j <= 3000; j++) {
				if (A[0] * i + A[1] * j > n)
					break;
				if ((n - (A[0] * i + A[1] * j)) % A[2] == 0) {
					Ans += 1;
				}
			}
		}
		cout << Ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int ctoi(char c){
  switch(c){
      case '0': return 0;
      case '1': return 1;
      case '2': return 2;
      case '3': return 3;
      case '4': return 4;
      case '5': return 5;
      case '6': return 6;
      case '7': return 7;
      case '8': return 8;
      case '9': return 9;
      default : return -1;
  }
}

void dfs(int index, int sum, vector<char> ops, vector<char> &D) {
  if(index == 3 && sum == 7) {
    cout << D[0] << ops[0] << D[1] << ops[1] << D[2] << ops[2] << D[3] << "=7" << endl;
    exit(0);
  }

  if(index == 3) {
    return;
  }

  index++;
  int plusSum = sum + ctoi(D[index]);
  vector<char> plusOps = ops;
  plusOps.pb('+');
  dfs(index, plusSum, plusOps, D);

  int minusSum = sum - ctoi(D[index]);
  vector<char> minusOps = ops;
  minusOps.pb('-');
  dfs(index, minusSum, minusOps, D);
}

int main() {
  string digits;
  cin >> digits;
  vector<char> ops;
  vector<char> D;
  rep(i, 4) {
    D.pb(digits[i]);
  }
  dfs(0, ctoi(D[0]), ops, D);
}


Measured memory_bytes: 256