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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

struct UnionFind{
  vi data;

  UnionFind(int size){
    data.resize(size,-1);
    //rep(i, size) data[i] = -1;
  }

  bool unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x != y){
      if(data[y] < data[x]) swap(x,y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

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

  int root(int x){
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  int size(int x){
    return -data[root(x)];
  }

  void print(){
    cout << "i :\t";
    rep(i, data.size()) cout << i << "\t";
    cout << endl;
    cout << "data :\t";
    rep(i, data.size()) cout << root(i) << "\t";
    cout << endl;
  }
};

main()
{
  int n,m; cin >> n >> m;
  vi p(n), invp(n+1);
  rep(i,n){
    cin >> p[i];
    invp[p[i]] = i+1;
  }
  vector<pii> a(m); rep(i,m) cin >> a[i].fst >> a[i].snd;

  struct UnionFind uf(n+1);

  rep(i,m) uf.unite(invp[a[i].fst],invp[a[i].snd]);

  int c = 0;
  rep(i,n)
    if(uf.find(i+1,p[i])) c++;
  cout << c << endl;
}

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

int N, ans, primes[101];

void cpf(int n)
{
    for (int i = 2; i <= n; i++)
    {
        while(n % i == 0)
        {
            primes[i]++;
            n /= i;
        }
    }
}

int main()
{
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) cpf(i);

    for (int i = 1; i <= N; i++) if (primes[i] >= 74) ans++;

    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            if (i == j) continue;
            if (primes[i] >= 24 && primes[j] >= 2) ans++;
            if (primes[i] >= 14 && primes[j] >= 4) ans++;
        }
    }

    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            for (int k = j + 1; k <= N; k++)
            {
                if (i == j || i == k) continue;
                if (primes[i] >= 2 && primes[j] >= 4 && primes[k] >= 4) ans++;
            }
        }
    }

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


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

def make_divisors(n,sort=False):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    if sort:
        divisors.sort()
    return divisors

N,K = LI()

numl = [0]*(K+1)

ans = 0
for i in range(1,K+1)[::-1]:
    num = pow(math.floor(K/i),N,mod)
    for j in range(2*i,K+1,i):
        num -= numl[j]
        num %= mod
    numl[i] = num
    ans += num*i
    ans %= mod

print(ans)

Measured memory_bytes: 69512
/*input
10
5 3
5 7
8 9
1 9
9 10
8 4
7 4
6 10
7 2
*/
#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;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll INF64=8e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
ll mult(ll a,ll b){
    a%=MOD;
    b%=MOD;
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=2e5+5;
const ll maxlg=__lg(maxn)+2;
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    REP(i,n){
        ans+=(i+1)*(n-i);
    }
    REP(i,n-1){
        ll a,b;
        cin>>a>>b;
        if(a>b) swap(a,b);
        --b;
        ans-=(a)*(n-b);
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 3608
//length of the longest path in a directed acyclic graph
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9+5;

int32_t main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
   	//dp[i][j] = probability of having j heads with i coins
    int n;
    cin>>n;
    vector<double> p(n+1,0);
    for(int i = 1; i <= n; i++) cin>>p[i];
    double dp[n+1][n+1];
    memset(dp,0.0,sizeof(dp));
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= i; j++){
            if(j) dp[i][j] = dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
            else dp[i][j] = dp[i-1][j]*(1-p[i]);
        }
    } 
    double ans = 0;
    for(int i = (n+1)/2; i <= n; i++) ans += dp[n][i];
    cout<<setprecision(10)<<ans;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define int long long

struct comp{
    bool operator()(pair<int,int> a, pair<int,int> b){
        return a.second<b.second;
    }
};

bool c1(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.x.x<b.x.x;
}

bool c2(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.x.y<b.x.y;
}

int n,v[100005],ans;
pair<pair<int,int>,int> a[100005];
vector <pair<int,int>> g[100005];


multiset <pair<int,int>,comp> q;

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i].x.x >> a[i].x.y,a[i].y=i;
    sort(a+1,a+n+1,c1);
    for(int i=1;i<n;i++){
        g[a[i].y].pb({a[i+1].y,a[i+1].x.x-a[i].x.x});
        g[a[i+1].y].pb({a[i].y,a[i+1].x.x-a[i].x.x});
    }
    sort(a+1,a+n+1,c2);
    for(int i=1;i<n;i++){
        g[a[i].y].pb({a[i+1].y,a[i+1].x.y-a[i].x.y});
        g[a[i+1].y].pb({a[i].y,a[i+1].x.y-a[i].x.y});
    }

    v[1]=1;
    for(pair<int,int> i : g[1]) q.insert(i);

    while(q.size()){
        pair<int,int> t=*(q.begin());
        q.erase(q.begin());
        if(!v[t.first]){
            v[t.first]=1;
            ans+=t.second;
            for(pair<int,int> i : g[t.first]) q.insert(i);
        }
    }
    cout << ans;

}


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

int main(){
  string s;

  cin>>s;

  int i;
  vector<int> a(4);

  for(i=0;i<4;i++){
    a.at(i)=(s.at(i)-'0');
  }

  int bit;
  for(bit=0;bit<(1<<3);bit++){
    // cout<<"bit "<<bit<<endl;
    int sum=a.at(0);

    for(i=0;i<3;i++){
      if(bit&(1<<2-i)){
        sum+=a.at(i+1);
      }
      else{
        sum-=a.at(i+1);
      }
    }
// cout<<"syori a"<<endl;
    if(sum==7){
      for(i=0;i<3;i++){
        cout<<a.at(i);
        if(bit&(1<<2-i))
        cout<<'+';
        else
        cout<<'-';
      }
      cout<<a.at(3)<<"=7"<<endl;
      break;
    }
    // cout<<"syori b"<<endl;
  }

}


Measured memory_bytes: 256
(n,),a,b=$<.map{|l|l.split.map &:to_i}
c,d=[a,b].map{|z|z<<F=y=z[0];(1..n).map{|i|y^y=z[i]}}
d+=m=[k=-1]
d.map{|x|k=m[k]until k<0||d[k]==x;m<<k+=1}
j=0
(2*n-1).times{|i|j=m[j]until j<0||d[j]==c[i%n];p i+=1-n,F^a[i]if n==j+=1}

Measured memory_bytes: 51864
#include <bits/stdc++.h>
 
int d, n;
 
int main() {
  scanf("%d %d", &d, &n);
  if (n == 100) {
    printf("101");
  } else {
    printf("%d", n);
  } 
  for (int i = 1; i <= d; i++) {
    printf("00");
  }
  return 0;  
}

Measured memory_bytes: 256
import math
import sys

N = input()
T = [int(i) for i in raw_input().split()]
A = [int(i) for i in raw_input().split()]

ans = 1

if(N==1 and T[0]!=A[0]):
    print '0'
    sys.exit()

for i in range(N):
#    if(i==0 or i==N-1):
#        continue
    
    if(T[i-1]!=T[i] and T[i]>A[i]):
        print '0'
        sys.exit()
    
    if(T[i-1]>T[i]):
        continue

    if(i==N-1):
        continue

    if(A[i+1]!=A[i] and A[i]>T[i]):
        print '0'
        sys.exit()
    
    if(A[i+1]>A[i]):
        continue

    if(i==0):
        continue

    if((T[i-1]!=T[i])or(A[i+1]!=A[i])):
        continue

    else:
        ans *= min(T[i],A[i])
        ans %= 1000000007

    

print ans

Measured memory_bytes: 15052
n = int(input())
ss = "abcdefghijklmnopqrstuvwxyz"
dmin = {}
for s in ss:
  dmin[s] = 51

for i in range(n):
  S = input()

  d ={}
  for s in S:
    if s not in d.keys():
      d[s] = 1
    else:
      d[s] += 1
  
  for s in ss:
    if s not in d.keys():
      dmin[s] = 0

  for s in d.keys():
    dmin[s] = min(dmin[s], d[s])
for k in dmin.keys():
  print(k*dmin[k],sep="",end="")

Measured memory_bytes: 9192
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        n: usize,
        t: [usize; n],
    }

    let lcm = t.iter().fold(1, |acc, &tt| lcm(acc, tt));
    println!("{}", lcm);
}

fn gcd(a: usize, b: usize) -> usize {
    match a {
        0 => b,
        _ => gcd(b%a, a),
    }
}

fn lcm(a: usize, b: usize) -> usize {
    let g = if a > b {
        gcd(b, a)
    } else {
        gcd(a, b)
    };
    g * (a/g) * (b/g)
}


Measured memory_bytes: 4352
x, y = list(map(int, input().split()))

c = list(map(int, input().split()))

l = set()

for _ in range(y):
    a, b = list(map(int, input().split()))
    if c[a-1] > c[b-1]:
        l.add(b-1)
    elif c[a-1] < c[b-1]:
        l.add(a-1)
    else:
        l.add(a-1)
        l.add(b-1)
l = list(l)
print(len(c) - len(l))

Measured memory_bytes: 20124
#include<stdio.h>
typedef struct{
  int k;
  char mozi;
}card;
  
int main(){
  int i,j,n,min;
  card num[36],suit[36],temp;
   
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf(" %c%d", &num[i].mozi, &num[i].k);
    suit[i].mozi = num[i].mozi;
    suit[i].k = num[i].k;
  }
  
  for(i = 0; i < n; i++){
    for(j = n-1; j > i; j--){
      if(num[j].k < num[j-1].k){
	temp = num[j];
	num[j] = num[j-1];
	num[j-1] = temp;
      }
    }
  }
 
  for(i = 0; i < n-1; i++){
    printf("%c%d ",num[i].mozi, num[i].k);
  }
  printf("%c%d\nStable\n",num[i].mozi, num[i].k);
 
  for(i = 0; i < n-1; i++){
    min = i;
    for(j = i; j <= n-1; j++){
      if(suit[j].k < suit[min].k) min = j;
    }
    temp = suit[i];
    suit[i]=suit[min];
    suit[min]=temp;
  }
 
  for(i = 0; i < n-1; i++){
    printf("%c%d ",suit[i].mozi,suit[i].k);
  }
  printf("%c%d\n",suit[i].mozi,suit[i].k);
  
  for(i = 0; i < n; i++){
    if(suit[i].mozi != num[i].mozi) {
      printf("Not stable\n");
      break;
    }
  }
  if(i == n)printf("Stable\n");
  return 0;
}

Measured memory_bytes: 608
require 'mathn'
require 'prime'
d = gets.split.map(&:to_i).inject(:/).denominator
pfactors = []
Prime.each(Math.sqrt(d)) do |q|
    if d % q == 0
        pfactors << q
        d /= q while d % q == 0
    end
end
pfactors << d if d > 1
p pfactors.inject(:*)


Measured memory_bytes: 9536
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    T=[0]+list(map(int,input().split()))
    for i in range(n): T[i+1]+=T[i]
    V=list(map(int,input().split()))

    def f(t):
        res=INF
        res=min(res,t)
        res=min(res,-t+T[-1])
        for i in range(1,n+1):
            if(t<T[i-1]): res=min(res,-t+T[i-1]+V[i-1])
            elif(t<=T[i]): res=min(res,V[i-1])
            else: res=min(res,t-T[i]+V[i-1])
        return res

    ans=0
    for t in range(2*T[-1]): # 0.5刻みで計算
        ans+=(f(t/2)+f((t+1)/2))/4
    print(ans)
resolve()

Measured memory_bytes: 46168
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	evc, ovc := make(map[int]int), make(map[int]int)
	for i := 0; i < n/2; i++ {
		var v int
		fmt.Scanf("%d", &v)
		evc[v]++
		fmt.Scanf("%d", &v)
		ovc[v]++
	}
	if len(evc) == 1 && len(ovc) == 1 {
		var v int
		for v = range evc {
			break
		}
		if ovc[v] > 0 {
			fmt.Printf("%d\n", n/2)
			return
		}
	}
	evm, ovm := 0, 0
	evsm, ovsm := 0, 0
	var emv, omv int
	for mv, vc := range evc {
		if vc > evm {
			evsm = evm
			evm = vc
			emv = mv
		} else if vc > evsm {
			evsm = vc
		}
	}
	for mv, vc := range ovc {
		if vc > ovm {
			ovsm = ovm
			ovm = vc
			omv = mv
		} else if vc > ovsm {
			ovsm = vc
		}
	}
	if emv == omv {
		vm := ovm
		vsm := evsm
		if ovsm > vsm && ovsm > 0 {
			vm = evm
			vsm = ovsm
		}
		fmt.Printf("%d\n", n-vsm-vm)
		return
	}
	fmt.Printf("%d\n", n-evm-ovm)
}


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

int main() {
    int d;cin>>d;
    if(d==25)cout<<"Christmas"<<endl;
    else if(d==24)cout<<"Christmas Eve"<<endl;
    else if(d==23)cout<<"Christmas Eve Eve"<<endl;
    else cout<<"Christmas Eve Eve Eve"<<endl;
}

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

// Let's just be lazy in typing "typedef"
#define td typedef

// Data types
td long long ll;
td unsigned long long int ull;
td long double ld;

// Containers
td vector<int> vi;
td vector<ll> vll;
td map<int, int> mii;
td map<ll, ll> mll;
td pair<int, int> pii;
td pair<ll, ll> pll;


// Container functions
#define pb push_back
#define mp make_pair
#define n1 first // for pairs
#define n2 second
#define fill(x,v) memset(x,v,sizeof(x))

// Important Constants
#define inf (int)1e9
#define eps (ld)1e-12
#define mod (ll)(1e9 + 7)
#define endl '\n'

// Traversing containers
#define tr(x,itr) for( typeof(x.begin()) itr  = x.begin(); itr!= x.end(); itr++) //Use iterator to iterate from beginning of a data structure to its end
#define all(x) x.begin(),x.end() // all the elements of a DS
#define rep(i,n) for(int i=0;i<n;i++) // increasing for loop from 0 to n
#define inc(i,a,b) for(int i=a;i<=b;i++) //increasing for loop from a to b
#define dec(i,a,b) for(int i=b;i>=a;i--) //decreasing for loop from b to a
#define in(a,b)( (b).find(a) != (b).end()) // check if a is inside b
#define cases ll t;cin>>t;while(t--) // declare testcases, take input and start while loop

#define abs(x) (x<0 ? -x : x)
#define sqr(x) (x*x)

// I/O declare n and take input
#define cint(n) int n;cin>>n

// I/O optimizations
#define io1 ios::sync_with_stdio(false)
#define io2 cin.tie(NULL);cout.tie(NULL)

// Important functions
ll gcd(int a, int b){
    return b==0?a:gcd(b, a%b);
}

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

vll h, dp;

int main(){
    io1;
    io2;

    int n, x, k;
    cin >> n >> k;
    dp.assign(n, inf);
    for(int i=0;i<n;i++)cin>>x,h.pb(x);
    dp[0] = 0;
    dp[1] = abs((h[0] - h[1]));
    for(int i=2;i<n;i++){
        ll best = inf;
        for (int j = i - 1; j > -1 && j > i-k-1; j--){
            int dif = h[j] - h[i];
            best = min(best, (dp[j] + abs(dif)));
        }
        dp[i] = best;
    }
    cout << dp[n-1] << endl;
    // for(int i=0;i<n;i++)cout << dp[i] << ' ';
    return 0;
}

Measured memory_bytes: 2168
N=int(input())
l=list(map(int,input().split()))

S1=sum(l)
S2=0
diff=0
m=S1

for i in range(N-1):
    S1=S1-l[i]
    #print(S1)
    S2+=l[i]
    #print(S2)
    diff=abs(S1-S2)
    #print(diff)
    if(m>=diff):
        m=diff

print(m)


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#define MAXN 100005
using namespace std;

vector<int> G[MAXN];
int in_deg[MAXN];
int order[MAXN];

inline void add_edge(int u, int v) {
    G[u].push_back(v);
}

int main() {
    int n, m, u, v;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d%d", &u, &v);
        add_edge(u, v);
        ++in_deg[v];
    }
    typedef pair<int, int> p;
    queue<p> que;
    for (int i = 1; i <= n; ++i) {
        if (!in_deg[i]) {
            que.push(make_pair(0, i));
        }
    }
    while (!que.empty()) {
        p cur = que.front();
        order[cur.second] = cur.first;
        que.pop();
        for (auto it : G[cur.second]) {
            --in_deg[it];
            if (!in_deg[it]) que.push(make_pair(cur.first + 1, it));
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) ans = max(ans, order[i]);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+50;
int n, a[N];

void calc() {
	ll sum = accumulate(a+1,a+1+n,0ll);
	if (!sum) puts("YES"),exit(0);
	ll sz = (ll)n*(n+1)/2;
	if (sum%sz) puts("NO"),exit(0);
	a[n+1] = a[1];
	ll cnt = sum/sz;
	REP(i,1,n) {
		if ((cnt-a[i+1]+a[i])%n) puts("NO"),exit(0);
		if ((cnt-a[i+1]+a[i])<0) puts("NO"),exit(0);
	}
	int p = min_element(a+1,a+1+n)-a;
	int now = 0;
	REP(d,p,n) a[d]-=++now;
	REP(d,1,p-1) a[d]-=++now;
}
int main() {
	scanf("%d",&n);
	REP(i,1,n) scanf("%d",a+i);
	REP(i,1,20) calc();
	puts("YES");
}








Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int cc = 0;
    rep(i, a + 1)
    {
        rep(j, b + 1)
        {
            rep(k, c + 1)
            {
                if (500 * i + 100 * j + 50 * k == x)
                {
                    cc++;
                }
            }
        }
    }
    cout<<cc<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <stack>
#define endl    '\n'
using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vector<int> v(3);
    int k;
    cin >> v[0] >> v[1] >> v[2] >> k;
    int t = 0;
    int chk = 1;
    for(int i = 0; i < k; i++)
    {
        if(v[0]>= v[1] && v[1] < v[2])
        {
            v[1] *= 2;
        }
        else if (v[1] >= v[2])
        {
            v[2] *= 2;
        }
    }
    if(v[0] >= v[1] || v[1] >= v[2])
    {
        cout << "No" << "\n";
    }
    else
    {
        cout << "Yes" << "\n";
    }


    return 0;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll n, s;
vector<ll> a;
const ll M = 998244353;

/*
	dp[i][val] : L <= x1 < x2 ... xk かつ Ax1 + ... + Axk がvalになる整数列(L,x1,x2...xk)の個数
*/
ll dp[3002][3002]; 



int main(){
	cin >> n >> s;
	a.resize(n);
	
	for ( int i = 0; i < n; i++ )
		cin >> a[i];
	
	ll result = 0;
	for ( int i = 0; i < n; i++ ){
		//a[i]を使うことで数列が完成するなら、カウントする
		if ( a[i] < s ){
			if ( i != 0 )
				result = (result + dp[i-1][s-a[i]] * (n-i))%M;
		}
		else if ( a[i] == s ){
			result = (result + (i+1)*(n-i))%M;
		}
		
		// dpを計算
		for ( int j = 0; j <= s; j++ ){
			if ( i == 0 ){
				dp[i][j] = ( a[i] == j )  ? 1 : 0;
			}
			else {
				if ( j > a[i] ){
					dp[i][j] = (dp[i-1][j] + dp[i-1][j-a[i]])%M;
				}
				else if ( j == a[i] ){
					dp[i][j] = (dp[i-1][j] + (i+1))%M;
				}
				else {
					dp[i][j] = dp[i-1][j];
				}
			}
		}
	}
	
	
	cout << result << endl;
	
	return 0;
}



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

long long n, W, w[101], v[101], dp[101][100010];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	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<100010; ++j)
			dp[i][j] = 1e18;
	dp[0][0] = 0;
	for(int i=1; i<=n; ++i)
		for(int j=0; j<100010; ++j){
			dp[i][j] = dp[i-1][j];
			if(j-v[i]>=0) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
		}
	for(int i=100000; i>=0; --i)
		if(dp[n][i] <= W){
			cout << i << "\n";
			return 0;
		}
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define vi vector<int>
#define ppi pair<int,pi>
#define ld long double
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << end
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define f(i, begin, end) for (__typeof(end) i = (begin); i != (end) ; i += 1 - 2 * ((begin) > (end)))
#define nl cout<<"\n";
#define par(a,n) f(i,0,n) cout<<a[i]<<" "; nl
//void prt(int x) {cerr << x;}
#define vv(n,m) vector <vector <int> > v(n, vector <int> (m));

#define er(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... brgs>
void err(istream_iterator<string> it, T a, brgs... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);	
}
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
typedef pair<int,int> pii;
typedef vector<pii> vpii;
const int mod = 1000000007;
const int N = 3e5;

int kadane(int*a, int n);
bool isPrime(int n);
int mpow(int a, int b);


void solve(){
    int n;
    cin>>n;
    int a[n];
    f(i,0,n) cin>>a[i];
    int q;
    cin>>q;
    map<int,int> mp;
    f(i,0,n) mp[a[i]]++;
    int s=0;
    f(i,0,n) s+=a[i];
    while(q--){
      int b,c;
      cin>>b>>c;
      int x=mp[b];
      mp[b]=0;
      mp[c]+=x;
      s=s-b*x+c*x;
      //tr(it,mp) cout<<it->F<<" "<<it->S<<endl;
      //nl
      cout<<s<<endl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    solve();
        
}

int mpow(int a, int b){ /* pow(a, b) % m */
  int m=mod;
  int x=1;
  while (b>0){
    if (b&1){
      x=(x * a) % m;
    }
    a=(a*a) % m; /* compute the next power of 2 */
    b>>=1; /* this is equivalent to b = floor(b / 2) */
  }
  return x;
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
} 

int kadane(int*a, int n){
    int max_so_far = INT_MIN, max_ending_here = 0;
    f(i,0,n){
        max_ending_here+=a[i];
        max_so_far = max(max_so_far, max_ending_here);
        if(max_ending_here<0) max_ending_here=0;
    }
    return max_so_far;
}

Measured memory_bytes: 10316
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int x,ans=0;
	cin>>x;
	while(x>100){
		double KK=x/101.0*100.0;
		double CKK=ceil(KK);
		x=(int)(CKK);
		ans++;
	}
	cout<<ans;
	return 0;
}

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

int main() {
int n1,n2;
int n3,n4;

//int *num=new int[N+1];
//string *name=new string[N+1];
cin >> n1 >> n2;
cin >> n3 >> n4;

if(n3>n1)
cout << 1 << endl;
else
cout << 0 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include "string.h"
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int countMax = 0;
	int count = 0;
	int index = 1;
	for(int i = 1;i <= N;i++){
		int j = i;
		while(j > 1 and j % 2 == 0){
			count += 1;
			j = j / 2;
		}
		if(countMax < count){
			countMax = count;
			index = i;
		}
		count = 0;
	}
	cout << index << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int A;
  cin >> A;
 
  int a = A / 1000;
  int b = (A % 1000) / 100;
  int c = (A % 100) / 10;
  int d = (A % 10) / 1;
  
  if (a == b && b == c) cout << "Yes" << endl;
  else if (b == c && c == d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> Ls(N);
  for(int i=0; i<N; i++){ cin >> Ls.at(i); }
  sort(Ls.begin(), Ls.end());
  
  int sum=0;
  for(int i=0; i<(N-1); i++){
    sum += Ls.at(i);
  }
  
  if(Ls.at(N-1) < sum){ cout << "Yes" << endl; }
  else{ cout << "No" << endl; }

}


Measured memory_bytes: 256
n = int(input())
c,s,f = [0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
    c[i],s[i],f[i] = map(int,input().split())


def solve(c,s,f,i,cnt,n):
    if i == n-1:
        return print(cnt)
    else:
        if cnt < s[i]:
            cnt = s[i]
        loss = (cnt-s[i])%f[i]
        if loss == 0:
            return solve(c,s,f,i+1,cnt+c[i],n)
        else:
            return solve(c,s,f,i+1,cnt+c[i]+(f[i]-loss),n)

for i in range(n):
    solve(c,s,f,i,0,n)

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

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}

int main() {
  long long n,k,X,sum=0,a=0,b=0,c=0,d=0,ans=0;
  long long MOD = 1000000007;
  long long INF = 1LL << 60;
  string S="";
  cin >> n >> X;
  vector<long long> x(n);
    for (int i=0;i<n;i++){
      cin >> x[i];
    }
    ans = 0;
    for (long long i=0;i<n;i++){
      ans = gcd(abs(x[i]-X),ans);
    }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

vector<vector<int> > to;
vector<P> id;
map<P,int> mp;
vector<bool> visit;

struct Edge {
    int to, id;
};

vector<vector<Edge> > g;
vector<int> ans;

void dfs(int v, int pc = -1, int p = -1) {
    int c = 1;
    rep(i, g[v].size()) {
        int u = g[v][i].to;
        int ei = g[v][i].id;
        if (u == p) continue;
        if (c == pc) ++c;
        ans[ei] = c;
        dfs(u, c, v); ++c;
    }
}

int main() {
    int n;
    cin >> n;
    ans.resize(n);
    g.resize(n);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].pb(Edge{b,i});
        g[b].pb(Edge{a,i});
    }
    dfs(0);
    
    int mx = 0;
    rep(i,n) mx = max(mx, (int)g[i].size());
    cout << mx << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}












Measured memory_bytes: 8320
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
INT_MIN=-10**13
import bisect as B
###############################################################################\
n,m=INPUT()
A=INPUT()
A.sort()
for _ in range(m):
    B.insort(A,A.pop()//2)
print(sum(A))


Measured memory_bytes: 85964
#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>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
#define INF 1e30
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N, M, Q, H, W, L, R, K, X, A, B, C, Z;
ll ans;
string S;
bool D[10];
ll x[100000000];
ll y[100000000];
ll nowcost = 1;
ll twopow[202020];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
ll m[100][100];
ll DP[1000001];
int main() {
	cin>>N;
	cout<<(1+N)*N/2;
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;

    vector<bool> d(10, true);
    rep(i, k) {
        int a;
        cin >> a;
        d[a] = false;
    }

    for (int i = n; i <= n * 10; ++i) {
        string s = to_string(i);

        bool flag = true;
        for (auto c : s) {
            if (!d[c - '0']) {
                flag = false;
                break;
            }
        }

        if (flag) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
# Problem C - Grid Repainting 2

# input
H, W = map(int, input().split())
board = [[0]*W for i in range(H)]
for i in range(H):
    s_list = list(input())
    for j in range(W):
        board[i][j] = s_list[j]

# initialization
is_ok = True

# check
for i in range(H):
    for j in range(W):
        s = board[i][j]
        if s=='.':
            continue

        # right
        if j+1<W:
            if s=='#' and board[i][j+1]=='#':
                continue

        # left
        if j-1>=0:
            if s=='#' and board[i][j-1]=='#':
                continue

        # up
        if i-1>=0:
            if s=='#' and board[i-1][j]=='#':
                continue

        # down
        if i+1<H:
            if s=='#' and board[i+1][j]=='#':
                continue

        is_ok = False
        break

# output
if is_ok:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
    #define ll long long 
    #define MAXN 10010
     
    using namespace std;
     
    int n, m, d;
    bool f[MAXN];
    int a[MAXN][MAXN];
    ll t;
    string s;
     
    bool check() {
    	for (int i = 1; i <= n; i++) {
    		if (a[i][0] != n) return false;
    	}
    	return true;
    }
     
    int main() {
    	scanf("%d", &n);
    	for (int i = 1; i <= n; i++) {
    		for (int j = 1; j <= n - 1; j++) {
    			scanf("%d", &a[i][j]);
    		} 
    		a[i][0] = 1;
    	}
    	while (1) {
    		if (check()) {
    			printf("%d\n", d);
    			return 0;
    		}
    		memset(f, false, sizeof(f));
    		d++;
    //		cout << "Day: "<< d << endl;
    		bool tf = false;
    		for (int i = 1; i <= n; i++) {
    			if (f[i] || a[i][0] == n) continue;
    			int x = a[i][a[i][0]];
    			int y = a[x][a[x][0]];
    //			cout << i << " and " << y << " "<< x << endl;
    //			cout << f[i] << f[x] << endl;
    			if (!f[i] && !f[x] && y == i) {
    //				cout << "YTES" << endl;
    				tf = true;
    				a[i][0]++;
    				a[x][0]++;
    				f[i] = true;
    				f[x] = true;
    			}
    		}
    		if (!tf) {
    			cout << "-1" << endl;
    			return 0;
    		}
    	}
    //	cout << "Error" << endl;
    	return 0;
    }


Measured memory_bytes: 39552
main = do
  n <- readLn
  bs <- map read.words<$>getLine
  putStr.unlines.map show $ solve n bs

solve n bs
  | head ans == -1 = [-1]
  | otherwise = ans
  where
  ans = reverse.go n.reverse$bs
  go _ [] = []
  go n bs
    | del == -1 = [-1]
    | otherwise = del : go (n-1) remaining
    where
    del = find n bs
    remaining = take (n-del) bs ++ drop (n-del+1) bs
    find _ [] = -1
    find i (b:bs)
      | i == b = i
      | otherwise = find (i-1) bs

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

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define mn 1000000

using namespace std;

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n,m;

    cin>>n>>m;

    ll niza[n];
    ll zbirovi[n];

    map<ll,ll> mapa;

    ll res = 0;
    mapa[0]=1;
    for (ll i = 0; i<n; i++) {
        cin>>niza[i];

        if (i != 0) zbirovi[i] = zbirovi[i-1]+niza[i];
        else zbirovi[i] = niza[i];

        zbirovi[i] %= m;

        res += mapa[zbirovi[i]];

        mapa[zbirovi[i]]++;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int k;
    cin>>k;
    cin>>s;
    if(s.length()<=k){
    cout<<s<<"\n";}
    else{
    for(int i=0;i<k;i++)
    cout<<s[i];
    cout<<"..."<<"\n";}
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>

int serch(int ,int );

int n,A[20];

int main ()
{
  int i,q,m;

  scanf("%d",&n);
  for(i = 0;i < n;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&q);
  for(i = 0;i < q;i++)
    {
      scanf("%d",&m);
      if(serch(0,m)) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}
int serch(int a,int b)
{
  int ab;
  if(b == 0) return 1;
  if(a >= n) return 0;

  ab = serch(a + 1,b - A[a]) || serch(a + 1,b);
  return ab;
}
  
  
  
  



Measured memory_bytes: 2108
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    int nt = 0,nx = 0,ny = 0;
    cin >> N;
    for(int i = 0;i < N;i++){
        int t,x,y;
        cin >> t >> x >> y;
        int dx = abs(x - nx),dy = abs(y - ny);
        if(t - nt < dx + dy || ((t - nt) - (dx + dy)&1)){
            cout << "No" << endl;
            return 0;
        }
        nt = t,nx = x,ny = y;
    }
    cout << "Yes" << endl;
}

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

ans = 10**10

for i in range(N):
    a = 0
    while True:
        if A[i] % 2 != 0:
            break
        A[i] /= 2
        a += 1
    ans = min(a,ans)
print(ans)


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

int t[102][102], tt[102][102];
int ans[102][102];

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 0, 0, 1};

bool solve(int bit){
  memcpy(t, tt, sizeof(tt));
  memset(ans, 0, sizeof(ans));

  for(int i = 0; i < 10; i++){
    if(bit & (1 << i)){
      ans[0][i] = true;

      for(int j = 0; j < 4; j++){
        int nx = i + dx[j];
        int ny = dy[j];
        if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
        t[ny][nx] = !t[ny][nx];
      }
    }
  }

  for(int i = 1; i < 10; i++){
    for(int j = 0; j < 10; j++){
      if(t[i - 1][j]){
        ans[i][j] = true;

        for(int k = 0; k < 4; k++){
          int nx = j + dx[k];
          int ny = i + dy[k];
          if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
          t[ny][nx] = !t[ny][nx];
        }
      }
    }
  }

  for(int i = 0; i < 10; i++){
    if(t[9][i]){
      return false;
    }
  }

  return true;
}

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

  while(T--){
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < 10; j++){
        cin >> tt[i][j];
      }
    }

    for(int bit = 0; bit < (1 << 10); bit++){
      bool flg = solve(bit);

      if(flg){
        for(int i = 0; i < 10; i++){
          for(int j = 0; j < 10; j++){
            if(j != 0) cout << " ";
            cout << ans[i][j];
          }
          cout << endl;
        }

        break;
      }
    }
  }
}

Measured memory_bytes: 1256
#include <iostream>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int r,t;
    cin>> r >> t;
    if(r%100==0&&t%30==0)cout << r/100+(t/30)*5<<endl;
    else if(r%100==0) cout << r/100+(t/30)*5<<" "<<r/100+(t/30)*5+5<<endl;
    else if(t%30==0) cout << r/100+(t/30)*5<<" "<<r/100+(t/30)*5+1<<endl;
    else cout << r/100+(t/30)*5<< " "<<r/100+(t/30)*5+1<<" "<<r/100+(t/30)*5+5<<" "<<r/100+(t/30)*5+6<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a>k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

template <typename T>
istream& operator>>(istream& is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size()-1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0){
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    vll a(n);
    cin >> a;
    ll dp[50][2];
    REP(i, 50)
    {
        dp[i][0] = LONG_LONG_MIN;
        dp[i][1] = LONG_LONG_MIN;
    }
    dp[0][0] = 0;
    vint ktwo;
    for (ll now = k; now > 0; now >>= 1)
    {
        int keta = now & 1;
        ktwo.push_back(keta);
    }
    if (k == 0) ktwo.push_back(0);
    int sz = ktwo.size();
    for (int now = sz; now <= 50;++now)
    {
        ll now0 = 0;
        REP(m, n)
        {
            now0 += (0 ^ (((1LL << now) & a[m]) >> now)) << now;
        }
        dp[0][0] += now0;
    }
    REP(i, sz)
    {
        int now = sz - 1 - i;
        REP(j,2){
            for (int l = 0; l <= (j ? 1 : ktwo[now]);++l)
            {
                ll now0 = 0;
                REP(m, n)
                {
                    now0 += (l ^ (((1LL << now) & a[m]) >> now)) << now;
                }
                dp[i + 1][j || (l < ktwo[now])] = max(dp[i + 1][j || (l < ktwo[now])], dp[i][j] + now0);
            }
        }
    }
    cout << max(dp[sz][0], dp[sz][1]) << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
 
int main()
{
   int n,a,b;
   scanf("%d %d %d",&n,&a,&b);
   if(n == 1 ){
       if( a == b)
           printf("1");
        else
            printf("0");
   } 
   else{
       if(a > b ) 
         printf("0");
       else
         printf("%lld",(long long)(b-a)*(n-2)+1);
   
   }
    return 0;
}
    

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := scanStrings(1)
	str := arr[0]
	if str[0] >= "a"[0] {
		fmt.Print("a")
	} else {
		fmt.Print("A")
	}

}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


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

int main(){
    int n, m;
    cin >> n >> m;
    
    vector<int> k(m);
    vector<vector<int>> s(m);
    vector<int> p(n);
    
    rep(i, m){
        cin >> k[i];
        s[i].resize(k[i]);
        rep(j, k[i]){
            cin >> s[i][j];
            s[i][j];
        }
    }
    rep(i, m)cin >> p[i];
    
    
    int ans = 0;
    rep(i, 1<<n){
        int cnt1 = 0;
        rep(j, m){
            int cnt2 = 0;
            rep(l, k[j]){
                if(i & 1<<(s[j][l]-1))cnt2++;
            }
            if(cnt2%2==p[j])cnt1++;
        }
        if(cnt1==m)ans++;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;


int main(){
    string s;
    cin>>s;
    if(s.size()%2 == 1)
        puts("No");
    else{
        for(int i = 0; i < s.size(); i++){
            if(i % 2 == 0 and s[i] != 'h')
                return puts("No"), 0;
            if(i%2 == 1 and s[i] != 'i')
                return puts("No"), 0;
        }
        puts("Yes");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, s, sum = 0, min = 101;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        sum += s;
        if (s % 10 != 0) if (s < min) min = s;
        
    }
    if (min == 101) cout << 0;
    else if (sum % 10 != 0) cout << sum;
    else cout << sum - min;
    return 0;
}


Measured memory_bytes: 256