akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dj[] = {0, -1, 0, 1, -1, 1, -1, 1};

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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i, 0, n) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    rep(i, 0, n-2){
        rep(j, i+1, n-1){
            if(l[i] == l[j]) continue;
            rep(k, j+1, n){
                if(l[i] == l[k] || l[j] == l[k]) continue;
                if(l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define recp(I,Y,X) {q[I].x=X;q[I].y=Y;m[Y][X]='X';I++;}
char m[1005][1005],m2[1005][1005];
typedef struct point{
	int x,y;
}POINT;
POINT sq[500],q[500],g[11];
int h,w,n,i,j,ans=0,gx,gy,cx,cy,sqn,qn;
int main(){
	char s[1005];
	scanf("%d%d%d",&h,&w,&n);
	for(i=0;i<=w+1;i++)m[0][i]=m[h+1][i]='X';
	for(i=1;i<=h;i++){
		scanf("%s",s);
		strcat(m[i]+1,s);
		for(j=1;j<=w;j++){
			if(m[i][j]=='S')g[0].y=i,g[0].x=j;
			else if(m[i][j]!='.' && m[i][j]!='X')g[m[i][j]-'0'].y=i,g[m[i][j]-'0'].x=j;
		}
		m[i][0]=m[i][w+1]='X';
	}
	memcpy(m2,m,sizeof(m));
	for(i=1;i<=n;i++){
		sq[0].x=g[i-1].x,sq[0].y=g[i-1].y;
		m[g[i-1].y][g[i-1].x]='X',gx=g[i].x,gy=g[i].y;sqn=1;
		//printf("%d %d\n",sq[0].y,sq[0].x);
		//printf("%d %d\n",gy,gx);
		while(sqn){
			qn=0;
			//printf("\n");
			for(j=0;j<sqn;j++){
				cx=sq[j].x;cy=sq[j].y;
				//printf("%d %d\n",cy,cx);
				if(cx==gx && cy==gy)goto nex;
				if(m[cy-1][cx]!='X')recp(qn,cy-1,cx);
				if(m[cy+1][cx]!='X')recp(qn,cy+1,cx);
				if(m[cy][cx-1]!='X')recp(qn,cy,cx-1);
				if(m[cy][cx+1]!='X')recp(qn,cy,cx+1);
			}
			memcpy(sq,q,sizeof(POINT)*qn);
			//printf("%d\n",qn);
			sqn=qn;
			ans++;
		}
		nex:
		memcpy(m,m2,sizeof(m2));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int K;
int V[50];
int arr[50];
int sz;
int main(){
  int i, j, k, r, res=0, tmp, x, y;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(V[Lj4PdHRW]);
    }
  }
  for(x=0;x<K+1;x++){
    for(y=0;y<K+1;y++){
      if(x+y <= N && x+y <= K){
        sz = 0;
        for(i=0;i<x;i++){
          arr[sz++] = V[i];
        }
        for(i=0;i<y;i++){
          arr[sz++] = V[N-1-i];
        }
        sort(arr, arr+sz);
        r =min_L(K - x - y, sz);
        {
          int Q5VJL1cS, e98WHCEY;
          if(sz==0){
            e98WHCEY = 0;
          }
          else{
            e98WHCEY = arr[0];
            for(Q5VJL1cS=1;Q5VJL1cS<sz;Q5VJL1cS++){
              e98WHCEY += arr[Q5VJL1cS];
            }
          }
          tmp =e98WHCEY;
        }
        for(i=0;i<r;i++){
          if(arr[i] < 0){
            tmp -= arr[i];
          }
        }
        chmax(res, tmp);
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// int N, K, V[50];
// int arr[50], sz;
// 
// {
//   int i, j, k, r;
//   int x, y;
//   int res = 0, tmp;
// 
//   rd(N,K,V(N));
// 
//   rep(x,K+1) rep(y,K+1) if(x+y <= N && x+y <= K){
//     sz = 0;
//     rep(i,x) arr[sz++] = V[i];
//     rep(i,y) arr[sz++] = V[N-1-i];
//     sort(arr, arr+sz);
// 
//     r = min(K - x - y, sz);
//     tmp = sum(arr(sz));
//     rep(i,r) if(arr[i] < 0) tmp -= arr[i];
// 
//     res >?= tmp;
//   }
// 
//   wt(res);
// }


Measured memory_bytes: 256
<?php
[$N] = ints();
$gcd = gcd(360,$N);
echo 360 / $gcd;

function str(){return trim(fgets(STDIN));}
function ints($n = false){
  if($n===false){
    return array_map('intval',explode(' ',trim(fgets(STDIN))));
  }else{$ret = [];for($i = 0; $i < $n; $i++)foreach(array_map('intval',explode(' ',trim(fgets(STDIN)))) as $j => $v)$ret[$j][] = $v;return $ret;}
}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$M = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      if($both == 0){
        $G[$a][] = $b;
      }elseif($both == 1){
        $G[$a][] = $b;
        $G[$b][] = $a;
      }else{
        $G[$b][] = $a;
      }
    }else{
      list($a, $b, $d) = $values;
      if($both == 0){
        $G[$a][] = [$b, $d];
      }elseif($both == 1){
        $G[$a][] = [$b, $d];
        $G[$b][] = [$a, $d];
      }else{
        $G[$b][] = [$a, $d];
      }
    }
  }
  return $G;
}

Measured memory_bytes: 16372
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#define rep(i, a, n) for(int i = int(a);i < int(n);++i)
#define repe(i, a, n) for(int i = int(a);i <= int(n);++i)
#define repr(i, a, n) for(int i = int(a);i > int(n);--i)
#define reper(i, a, n) for(int i = int(a);i >= int(n);--i)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using namespace std;


int main(){
	int n[3];
	int K;
	cin >> n[0] >> n[1] >> n[2];
	cin >> K;
	sort(&n[0], &n[3]);
	cout << n[0]+n[1]+n[2]*(int)pow(2, K) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>


using namespace std;

int main(){
    string n; cin >> n;
    char a = n[0];
    char b = n[1];
    int ai = 1,bi = 1;
    int i = 2;

    if(a == b){
        b = n[2];
        ai = 2;
        bi = 1;
        i = 3;
    }

    for(i; i < 4; i++){
        if(a == n[i]) ai++;
        else if(b == n[i])bi++;
    }

    if(ai == 2 && bi == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



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

	rep(i, 1, s.size()) {
		if (s[i - 1] == s[i]) {
			cout << i << " " << i + 1 << endl;
			return 0;
		}
	}

	rep(i, 2, s.size()) {
		if (s[i - 2] == s[i]) {
			cout << i - 1 <<" " <<i+1 << endl;
			return 0;
		}
	}

	cout << "-1 -1" << endl;




	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)
	{
		cout<<"bust"<<endl;
		return 0;
	}
	else
	{
	cout<<"win"<<endl;
	return 0;
}
	 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
    int t;
    while(b>0){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}

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

int main(){
    ll b,l=0,r=0,n,o=0,o1=0;
    string s,t,u;
    cin>>s;
    ll h[s.size()]={};
    n=s.size();
    for(ll i=0;i<n-1;i++){
        if(s[i]=='R'){
            r++;
        }
        
        if(s[i]=='R'&&s[i+1]=='L'){
            h[i]=r;
            l=i+1;
            o++;
            r=0;
        }
        if(s[i]=='L'){
            if(o!=0)h[l]++;
        }
    }
    
    for(ll i=0;i<n-1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            o1++;
            if(o==o1)h[i+1]++;
        }
    }
    
    cout<<endl;
    for(ll i=0;i<n-1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            
            if(h[i]%2==h[i+1]%2){
                   b=(h[i]+h[i+1])/2;
                h[i]=b;
                h[i+1]=b;
            }
            else{
                ll hi=0,hi1=0;
                if(h[i]>h[i+1]){
                    if(h[i]%2==1)hi++;
                    if(h[i]%2==0)hi1++;          
                }
                if(h[i]<h[i+1]){
                    if(h[i+1]%2==1)hi1++;
                    if(h[i+1]%2==0)hi++;    
                }
                b=(h[i]+h[i+1])/2; 
                h[i]=b+hi;
                h[i+1]=b+hi1;
                
            }
            i++;
        }
    }
    for(ll i=0;i<n;i++){
        cout<<h[i];
        if(i!=n-1)cout<<" ";
    }
}



Measured memory_bytes: 1408
N = int(input())
S = [input() for i in range(N)]
L = [[],[],[],[],[]]
for i in S:
    if i[0]=="M":
        L[0].append(i)
    elif i[0]=="A":
        L[1].append(i)
    elif i[0]=="R":
        L[2].append(i)
    elif i[0]=="C":
        L[3].append(i)
    elif i[0]=="H":
        L[4].append(i)
import itertools
a = [i for i in range(5)]
T = list(itertools.combinations(a,3))
M = 0
for k in T:
    M += len(L[k[0]])*len(L[k[1]])*len(L[k[2]])
print(M)


Measured memory_bytes: 10852
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

lcm = (N * M) // gcd(N, M)
gcd = gcd(N, M)

for i in range(gcd):
    if S[i * N // gcd] != T[i * M // gcd]:
        print(-1)
        exit()

print(lcm)


Measured memory_bytes: 5344
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, a, b = rm()
ans = 0
for i in range(1, n+1):
    s = sum(map(int, str(i)))
    if a <= s <= b:
        ans += i
print(ans)












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

vector<int> dp;
vector<vector<int>> e;

int f(int x) {
  if(dp[x] != -1) return dp[x];
  int r = 0;
  if(e[x].size())
    for(auto p : e[x]) r = max(r, f(p) + 1);
  else
    r = 0;
  dp[x] = r;
  return r;
}

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  dp = vector<int>(n, -1);
  e = vector<vector<int>>(n);
  for(int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    e[--x].push_back(--y);
  }
  int o = 0;
  for(int i = 0; i < n; i++)
    if(dp[i] == -1) o = max(o, f(i));
  printf("%d\n", o);
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
ll freq[300005];
int main()
{
    int n, k;
    cin >> n >> k;
    int i;
    for (i = n; i >= 1; i--)
    {
        freq[i % k]++;
    }
    ll ans = 0;
    int d = freq[0];
    // case 0
    ans += freq[0];
    for (i = 1; i <= d; i++)
    {
        ans += (freq[0] - 1LL) * 3LL;
        ans += (freq[0] - 1LL) * (freq[0] - 1LL) * 3LL;
        freq[0]--;
    }
    // n % 2 == 0
    if (k % 2 == 0)
    {
        ans += freq[k / 2];
        d = freq[k / 2];
        for (i = 1; i <= d; i++)
        {
            ans += (freq[k / 2] - 1LL) * 3LL;
            ans += (freq[k / 2] - 1LL) * (freq[k / 2] - 1LL) * 3LL;
            freq[k / 2]--;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include    <stdio.h>

int main(void)
{
  int w, h, x, y, r;

  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
  if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
    puts("No");
  } else {
    puts("Yes");
  }
  
  return 0;
}

Measured memory_bytes: 584
#include<iostream>
using namespace std;
int main()
{
    int n,c1,c2,c3,c4;
    cin>>n;
    c1=n%10;n/=10;
    c2=n%10;n/=10;
    c3=n%10;n/=10;
    c4=n%10;n/=10;
    if( ( (c1==c2) && (c2==c3) ) || ( (c2==c3)&&(c3==c4) ))cout<<"Yes";
        else cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
ll n,m,a[100005],gc,tw=1,lc;
bool flg=0;
ll gcd(ll x,ll y){
    if(!y) return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    if(!x) return y;
    return x/gcd(x,y)*y;
}
int main()
{
    fastio;
    cin>>n>>m;
    rep(i,1,n) {
        cin>>a[i];
        gc=gcd(gc,a[i]);
    }
    if(!gc) gc=1;
    while(gc%2==0) tw*=2,gc>>=1;
    
    rep(i,1,n)
    if(a[i]/tw%2==0) flg=1;
    if(flg){cout<<"0\n";return 0;}
    rep(i,1,n){
        lc=lcm(lc,a[i]);
        if(lc>2*m) {cout<<"0\n";return 0;}
    }
    lc/=2;
    cout<<(m+lc)/lc/2<<'\n';
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define long long long
#define ull unsigned long long
#define up(i,a,b) for (int i=a; i<=b; i++)
#define down(i,a,b) for (int i=a; i>=b; i--)
#define endl '\n'
#define pb push_back
#define X first
#define Y second
#define II pair<int, int>
#define III pair<int, pair<int, int> >
#define V vector
#define debug(X) cerr<< #X << " = " <<X << endl
#define debug2(X,Y) cerr<< #X << " = " <<X << ","<<#Y<<" = "<<Y<<endl
#define show(X,a,b) {cerr << #X << " = "; up(__,a,b) cerr << X[__] << ' '; cerr << endl;}
#define gc getchar
#define pc putchar

using namespace std;

inline void read(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for (;((c<48 || c>57) && c != '-') ;c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}
inline void writeln(int x){

         char buffor[21];
         register int i=0;
         int neg=0; if (x<0) {neg=1; x= -x;}
         do{
               buffor[i++]=(x%10)+'0';
               x/=10;
            } while(x);
           i--;
           if (neg) pc('-');
           while(i>=0) pc(buffor[i--]);
           pc('\n');
       }
long a,b;
void input()
{
    cin>>a>>b;
}
int getbit(long x,int k)
{
    return (x>>k)& 1;
}
long setbit(long x,int k)
{
	return x^ (1LL<<k);
}
void solve()
{
	if (a==b)
	{
		cout<<1; return;
	};

	int dif= -1;
    down(bit,59,0)
     if (getbit(a,bit)!= getbit(b,bit))
     {
		dif= bit; break;
	 }
	 else
	 {
	 	if (getbit(a,bit))
		{
			a= setbit(a,bit); b= setbit(b,bit);
		}
	 }

	 long t= 1LL<<dif;
     long res= t-a; //debug(res);

     int k= -1;
     down(bit,dif-1,0)
      if (getbit(b,bit))
	  {
	  	k= bit; break;
	  }

	 long r1= t+ ( 1LL<<(k+1) )-1;
	 long l2= t+ a;
	 long r2= (1LL<<(dif+1)) -1;

	 if (l2> r1) res+= r1-t+1+ r2-l2+1;
	 else res+= r2-t+1;

	 cout<<res;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);// don't use when interactive
    #define TASK "tmp"
  //  freopen(TASK".inp","r",stdin);
   // freopen(TASK".out","w",stdout);

    input();
    solve();

    return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin >> s >> t;
    cout << t << s;
    
    
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <cstring>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repe(i,x) for (edge *i=fst[x]; i; i=i->nxt)
using namespace std;

int n,p[200100],root,f[200100];
bool cyc[200100];
struct edge
{
    int v;
    edge *nxt;
} pool[200100],*tp=pool,*fst[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

int mex(int x,bool type)
{
    static bool flag[200100];
    repe(i,x)
        if (type || !cyc[i->v])
            flag[f[i->v]]=1;
    int ret=0;
    for (; flag[ret]; ++ret);
    repe(i,x)
        if (type || !cyc[i->v])
            flag[f[i->v]]=0;
    return ret;
}

void dfs(int x)
{
    repe(i,x)
        if (!cyc[i->v])
            dfs(i->v);
    f[x]=mex(x,0);
}

int main()
{
    n=getint();
    repu(i,1,n)
    {
        p[i]=getint();
        *tp=(edge){i,fst[p[i]]},fst[p[i]]=tp++;
    }
    root=1;
    for (; !cyc[root]; cyc[root]=1,root=p[root]);
    memset(cyc,0,sizeof(cyc));
    for (; !cyc[root]; cyc[root]=1,root=p[root]);
    repu(i,1,n)
        if (cyc[i])
            dfs(i);
    for (int i=p[p[root]]; i!=p[root]; f[i]=mex(i,1),i=p[i]);
    if (f[root]!=f[p[root]])
    {
        puts("POSSIBLE");
        return 0;
    }
    ++f[p[root]];
    for (int i=p[p[root]]; i!=p[root]; f[i]=mex(i,1),i=p[i]);
    puts(f[root]+1==f[p[root]]?"POSSIBLE":"IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 6528
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input())
ans = 0
for a in range(1, n+1):
    for b in range(1, n+1):
        for c in range(1, n+1):
            ans += gcd_list([a, b, c])
print(ans)

Measured memory_bytes: 69704
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
char s[101];
int i,k;
int main(void){
    scanf("%s",s);
    for (i = 0; i < strlen(s) / 2; i++)
    {
        if (s[i] != s[strlen(s)-i-1])
        {
            k++;
        }
    }
    printf("%d\n",k);
    return 0;
}

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


int puteree(int puterea)
{
    int P = 1;
    while (puterea)
    {
        P = P * 10;
        puterea--;
    }
    return P;
}
int main()
{
    int n;
    cin >> n;
    int y = floor(log10(n));
    int sum = 0;
    for (int i = 1; i <= y; i++)
    {
        if (i % 2 == 1)
        {
            int putere = puteree(i-1);
            int inmultit = 9 * putere;
            sum += inmultit;
        }
    }
    if (y % 2 == 0)
    {
        int z = puteree(y);
        sum += n - z + 1;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int m1, m2, o1;

    while (cin >> m1 >> m2 >> o1) {
        bool card[11];
        int sum = m1 + m2;
        int min_c, max_c;


        min_c = max_c = 0;
        for (int i = 1; i <= 10; i++)
            card[i] = false;
        card[m1] = card[m2] = card[o1] = true;

        for (int i = 1; i <= 10; i++) {
            if (!card[i] && i + sum <= 20)
                min_c++;
            else if (!card[i] && i + sum > 20)
                max_c++;
        }

        if ((double)min_c++ / (max_c + min_c) >= 0.5)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1156
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n  , a[maxN] , dp[maxN] , k;
void solve(){
	cin>> n >> k;
	for(ll i=0;i<n ; i++)cin>>a[i];
	for(ll i=1;i<n ;i++){
		dp[i]=inf;
		for(ll j=1;j<=k; j++){
			if(i-j>=0)
				dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]));
		}
	}	
	cout<<dp[n-1]<<endl;
}
int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll N;
    cin >> N;
    vector<vector<ll>> dp;
    vector<vector<ll>> A(N,vector<ll>(N));
    rep(i,N){
        rep(j,N){
            cin >> A[i][j];
        }
    }
    dp = A;

    rep(k,N){
        rep(i,N){
            rep(j,N){
                chmin(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    bool ok;
    ll ans = 0;
    rep(i,N){
        rep3(j,1+i,N){
            if(dp[i][j] == A[i][j]){
                ok = 0;
                rep(k,N){
                    if(dp[i][k]+dp[k][j]==A[i][j] && i!=k && j!=k){
                        ok = 1;
                    }
                }
                if(!ok){
                    ans+=A[i][j];
                }
            }else{
                cout << -1 <<endl;
                return 0;
            }
        }
    }
    
    cout << ans <<endl;
    
    return 0;
    

}


Measured memory_bytes: 5036
// inputに入力データ全体が入る
function Main(input) {
	input = input.split("\n"); // 1行目がinput[0], 2行目がinput[1], …に入る
	// ここに処理を書く
    ss = input[0].split(" ");
	// console.logは標準出力に1行出力します (自動的に最後に改行が入ります)
	console.log(ss[0][0] + ss[1][0] + ss[2][0]);
}
 
// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

/*
// inputに入力データ全体が入る
function Main(input) {
    console.log(input);
	input = input.split("\n"); // 1行目がinput[0], 2行目がinput[1], …に入る
	// ここに処理を書く
	var result = input[1];
    console.log(result);
	var score = 0;
	for (var i = 0; i < result.length; i++) {
		if (result[i] == "A") score += 4;
		else if (result[i] == "B") score += 3;
		else if (result[i] == "C") score += 2;
		else if (result[i] == "D") score += 1;
	}
	// console.logは標準出力に1行出力します (自動的に最後に改行が入ります)
	console.log(score / result.length);
}
 
// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
console.log("test");
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
*/


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

using namespace std;

template <class T> inline bool chmax(T &a, T b) { /* {{{ */
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} /* }}} */

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> WS(N), VS(N);
  for (int i = 0; i < N; i++) {
    cin >> WS[i] >> VS[i];
  }
  vector<vector<long long>> dp(N + 5, vector<long long>(W + 5));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j + WS[i] <= W) {
        chmax(dp[i + 1][j + WS[i]], dp[i][j] + VS[i]);
      }
    }
  }
  cout << dp[N][W] << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 83328
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  cin>>n;
  int a[n];
  int b[n+1]={0};
  for(int i=0;i<n-1;++i)
  {
    cin>>a[i];
  	b[a[i]]++;
  }
  for(int i=1;i<=n;++i)
    cout<<b[i]<<"\n";
}

Measured memory_bytes: 5188
class Program
{
    static void Main(string[] args)
    {
        string line = System.Console.ReadLine().Trim();

        string[] Data = line.Split(' ');
        long N = long.Parse(Data[0]);
        long M = long.Parse(Data[1]);


        if(N*2 <= M)
        {
            long x = N + (M - N * 2L) / 4L;
            System.Console.WriteLine(x);
        }
        else
        {
            long x = M / 2L;
            System.Console.WriteLine(x);
        }             
    }
}

Measured memory_bytes: 13140
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((b*10+c)%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

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

using namespace std;

bool vis[100005];
int now[100005];

struct Per {
  int *num,n;
  Per() {}
  Per(int a):n(a) {num=new int[n+1];}
  Per inv() {
  	Per b(n);
  	for(int i=1;i<=n;i++) b.num[num[i]]=i;
  	return b;
  }
  Per operator * (Per b) {
  	Per c(n);
  	for(int i=1;i<=n;i++) c.num[i]=num[b.num[i]];
  	return c;
  }
  Per operator ^ (int k) {
  	Per b(n);
  	for(int i=1;i<=n;i++) vis[i]=0;
  	for(int i=1;i<=n;i++)
  	  if (!vis[i]) {
  	  	  int x=i,cnt=0;
  	  	  do {
  	  	  	now[++cnt]=x;
  	  	  	vis[x]=1;
  	  	  	x=num[x];
		  } while (x!=i);
		  for(int j=1;j<=cnt;j++) b.num[now[j]]=now[(j+k-1)%cnt+1];
		}
	return b;
  }
};

Per fir[7];

int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  fir[1]=Per(n);
  fir[2]=Per(n);
  for(int i=1;i<=n;i++) scanf("%d",&fir[1].num[i]);
  for(int i=1;i<=n;i++) scanf("%d",&fir[2].num[i]);
  for(int i=3;i<=6;i++) fir[i]=fir[i-1]*fir[i-2].inv();
  Per a=fir[2]*fir[1].inv()*fir[2].inv()*fir[1];
  Per ans=(a^((k-1)/6))*fir[(k-1)%6+1]*(a.inv()^((k-1)/6));
  for(int i=1;i<=n;i++) printf("%d ",ans.num[i]);
  printf("\n");
  return 0;
}

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

using namespace std;

char s[30];
int n,ans;
bool f;

int main()
{
    scanf("%s",s); n=strlen(s); f=true;
    ans=s[0]-'0'+(n-1)*9;
    for (int i=1;i<n;i++) if (s[i]!='9') f=false;
    if (!f) ans--;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define MOD 1000000007
#define pb push_back
#define Long long long 
using namespace std;
stack<int> S;
	int R,C,N,a,b,c,d;
bool isBound(int x, int y){
	if((x==0 || x == C) || (y==0 || y == R) )  return true;
	return false;
}
typedef pair<int,int> ii;
vector<ii> v;
int count(int x, int y){
	int c = C+1;
	int r = R+1;	
	if(y==0) return x;
	if(x==C) return c+y;	
	if(y==R) return r+c+(c-x);
//	cout << "return  " << c+r+c+r-y;
	if(x==0) return c+r+c+r-y;		
}

main(){
	cin >> R >> C >> N;
	For(i,1,N){
		scanf("%d%d",&b,&a);		
		scanf("%d%d",&d,&c);
		if(isBound(a,b) && isBound(c,d)){
//			cout << "push " << count(a,b) << " . " << a << " " << b << endl;
//			cout << "push " << count(c,d) << " . " << c << " " << d << endl;
			v.pb(ii(count(a,b),i));
			v.pb(ii(count(c,d),i));
		}
	}
	sort(v.begin(),v.end());		
	for(int i=0;i<v.size();i++){
//		cout << v[i] << " " ;
		if(S.empty()){
			S.push(v[i].second);
		}	else	if(S.top()==v[i].second){
			S.pop();
		}	else	{
			S.push(v[i].second);
		}
	}
	if(S.empty()){
		cout << "YES";
	}	else	{
		cout << "NO";
	}
}

Measured memory_bytes: 2420
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def f(a,b,x):
	return floor((a*x)/b) - a*floor(x/b)

def solve(a,b,n):
	x = b-1
	if(b > n):
		x = n
	return floor(a*x/b)


a,b,n = list(map(int, stdin.readline().rstrip().split()))
ans = solve(a,b,n)
print(ans)



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

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

  long long N = __gcd(A, B);
  int ans = 0;

  for (long long i = 2; i * i <= N; i++) {
    int f = 0;
    while (N % i == 0) N /= i, f = 1;
    if (f) ans++;
  }
  if (N != 1) ans++;

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

Measured memory_bytes: 256
import math

N = int(input())
S = int(input())

def f(B, N):
    X, res = N, 0
    while 0 < X:
        res += X % B
        X //= B
    return res


if N == S:
    print(N + 1)
    exit()

i = 2
while i * i <= N:
    if f(i, N) == S:
        print(i)
        exit()
    i += 1

sqrtN = math.floor(math.sqrt(N))
i = 1
ans = []
while i * i < N:
    if (N - S) % i != 0:
        i += 1
        continue
    b = (N - S) // i + 1
    if sqrtN < b and f(b, N) == S:
        ans.append(b)
    i += 1

print(-1 if len(ans) == 0 else min(ans))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MOD 1000000007
int num_ways(int **mat,int n,int m){
    bool canMove = 1;

    
    for(int i=1;i<n;i++)
        mat[i][0] = (mat[i-1][0] & mat[i][0]);
    
    for(int i=1;i<m;i++){
        mat[0][i] = (mat[0][i-1] & mat[0][i]);
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            mat[i][j] = mat[i][j]==0?0: (mat[i-1][j]%MOD+mat[i][j-1]%MOD)%MOD;
        }
    }
    return mat[n-1][m-1];
}
int main(){
    int n,m;
    cin>>n>>m;
    int **mat = new int*[n];
    for(int i=0;i<n;i++)
        mat[i] = new int[m];
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<m;j++){
            mat[i][j] =  (s[j] == '.');
        }
    }
    cout<<num_ways(mat,n,m)<<endl;
    for(int i=0;i<n;i++)
        delete[]mat[i];
    delete[] mat;   
}

Measured memory_bytes: 7460
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    sc.nextLine();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (x >= a[i]) {
        ans++;
        x -= a[i];      
      }
    }
    if (n == ans && x > 0)
      ans--;
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 100010
ll l[N], r[N];
multiset<ll> ls, rs;
ll lo, ro;
ll n;

int main(){
	INIT;
	cin>>n;
	rep(i, n) cin>>l[i]>>r[i];
	ls.insert(l[0]);
	rs.insert(r[0]);
	ll res = 0;
	REP(i, 1, n){
		lo -= r[i]-l[i];
		auto itl = ls.end(); --itl;
		auto itr = rs.begin();
		if(l[i]<*itl+lo){
			ll x = *itl+lo;
			res += abs(l[i]-x);
			ls.erase(itl);
			rs.insert(x-ro);
			ls.insert(l[i]-lo);
			ls.insert(l[i]-lo);
		} else if(l[i]>*itr+ro){
			ll x = *itr+ro;
			res += abs(l[i]-x);
			rs.erase(itr);
			ls.insert(x-lo);
			rs.insert(l[i]-ro);
			rs.insert(l[i]-ro);
		} else {
			ls.insert(l[i]-lo);
			rs.insert(l[i]-ro);
		}
		/*
		{
			cerr<<"ls"<<endl;
			for(auto x: ls) cerr<<x+lo<<" "; cerr<<endl;
			cerr<<"rs"<<endl;
			for(auto x: rs) cerr<<x+ro<<" "; cerr<<endl;
		}
		*/
		itl = ls.end(); --itl;
		//cerr<<l[i]<<" "<<*itl+lo<<" "<<lo<<endl;
		//res += abs(l[i]-(*itl+lo));
		ro += r[i]-l[i];
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define all(x)          (x).begin(),(x).end()
#define sz(v)               ((int)((v).size()))

int H,W,h,w;
int grid[501][501];

bool ok()
{
	int s = 0;
	for(int i = 0 ; i < H ; ++i)
	{
		for(int j = 0 ; j < W ; ++j)
		{
			s += grid[i][j];
		}

	}
	return s >= 0;
}


// worst case we will have w * h - w negative cells and
// and h positive cells
// we want the positive sum to be less than (h * w - w) but large as possible
// use (w * h - w) - 1
// use w*(h-1)
int main()
{

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> H >> W >> h >> w;
	if(H % h == 0 && W % w == 0)
	{
		cout << "No" << "\n";
	}
	else
	{

		if(H % h != 0)
		{
			for(int i = 0 ; i < H ; ++i)
			{
				for(int j = 0 ; j < W ; ++j)
				{
					if(i % h == 0)
						grid[i][j] = 1000*(h - 1) - 1;
					else grid[i][j] = -1000;
				}
			}
		}
		else
		{
			for(int i = 0 ; i < H ; ++i)
			{
				for(int j = 0 ; j < W ; ++j)
				{
					if(j % w == 0)
						grid[i][j] = 1000*(w - 1) - 1;
					else grid[i][j] = -1000;
				}
			}
		}
		if(!ok()) cout << "No" << "\n";
		else
		{
			cout << "Yes" << "\n";
			for(int i = 0 ; i < H ; ++i)
			{
				for(int j = 0 ; j < W ; ++j)
				{
					cout << grid[i][j] << " ";
				}
				cout << "\n";
			}
		}
	}



}


Measured memory_bytes: 2816
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: Java8 (OpenJDK 1.8.0)
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int n,k;
		int cnt = 0;
		ArrayList<Integer> h;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		h = new ArrayList<Integer>();

		for (int i = 0; i < n; ++i){
			h.add(sc.nextInt());
			if(h.get(i) >= k)	++cnt;
		}
		out.println(cnt);
	}
}


Measured memory_bytes: 60644
A, B, C = map(int, input().split())
flag = 0

if A+B+C == 17:
  if abs(A-B) == 0 and C == 7:
    flag = 1
  elif abs(A-B) == 2 and C == 5:
    flag = 1
  
if flag == 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long

signed main()
{

    rootdada;
    int n;
    cin>>n;
    int a[n-1];
    rep(i,0,n-1)
        cin>>a[i];
    int b[n];
    b[0]=a[0];
    rep(i,0,n-1)
    {
        if(a[i]==max(a[i],b[i]))
            b[i+1]=a[i];
        else
        {
            b[i+1]=a[i];
            b[i]=a[i];
        }
        
    }
    int sum=0;
    rep(i,0,n)
        sum+=b[i];
    cout<<sum<<endl;
    
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n=int(input())
s=[list(map(int, input().split())) for _ in range(n)]
a=0
for i in range(n-1):
    for j in range(i+1,n):
        a+=((s[i][0]-s[j][0])**2+((s[i][1]-s[j][1])**2))**(1/2)
print(2*a/n)


Measured memory_bytes: 38384
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let S = (0..<3).map{_ in readLine()!.toArray()}
var cnt = [Int](repeating: 0, count: 3)
var player = 0
while true {
    if cnt[player] == S[player].count {
        print(["A","B","C"][player])
        break
    } else {
        cnt[player] += 1
        player = ["a":0,"b":1,"c":2][S[player][cnt[player]-1]]!
    }
}


Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<deque<int>> A, B;
	vector<int> used;
	queue<int> Q;
	
	cin>>N;
	
	A.resize(N,deque<int>(N-1));
	B.resize(N+2,deque<int>(N+2));
	used.resize(N+1,0);
	
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N-1; j++){
			cin>>A[i][j];
		}
		Q.push(i);
	}
	
	
	int con = 0;
	for(int d = 1; ; d++){
		bool flag = false;
		
		while(!Q.empty()){
			int i = Q.front(); 
			if(used[i] == d) break;
			Q.pop();
			
			if(A[i].size() == 0) continue;
			int a = i;
			int b = A[i].front()-1;
			
			B[a][b] = true;
			
			if(B[a][b] && B[b][a]){
				used[a] = d;
				used[b] = d;
				A[a].pop_front();
				A[b].pop_front();
				if(A[a].size() == 0)con++;
				if(A[b].size() == 0)con++;
				
				flag = true;
				Q.push(a);
				Q.push(b);
			}
		}
		
		if(con == N){
			cout<<d<<endl;
			return 0;
		}
		if(!flag) break;
	}
	
	cout<<-1<<endl;
	
	return 0;
}

Measured memory_bytes: 17280
H,W,N = map(int, input().split())
y,x = map(int, input().split())
S = input()
T = input()

y,x = y-1, x-1
xmin, xmax, ymin, ymax = 0,W-1, 0,H-1
S = S[::-1]
T = T[::-1]

d = {
  'L': (1,0),
  'R': (-1,0),
  'U': (0,1),
  'D': (0,-1),
}
 
for i in range(N):
  dx,dy = d[T[i]]
  xmin = xmin + dx if dx < 0 else xmin
  xmax = xmax + dx if dx > 0 else xmax
  ymin = ymin + dy if dy < 0 else ymin
  ymax = ymax + dy if dy > 0 else ymax

  if xmin < 0: xmin = 0
  if xmax >= W: xmax = W-1
  if ymin < 0: ymin = 0
  if ymax >= H: ymax = H-1

  dx,dy = d[S[i]]
  xmin = xmin + dx if dx > 0 else xmin
  xmax = xmax + dx if dx < 0 else xmax
  ymin = ymin + dy if dy > 0 else ymin
  ymax = ymax + dy if dy < 0 else ymax
  
  #print(i,xmin,xmax,ymin,ymax)
  if xmin > xmax or ymin > ymax:
    print("NO")
    #print(xmin,x,xmax)
    #print(ymin,y,ymax)
    exit(0)

if xmin <= x <= xmax and ymin <= y <= ymax:
  print("YES")
else:
  print("NO")
#print(xmin,x,xmax)
#print(ymin,y,ymax)

Measured memory_bytes: 9832
n=int(input())
inf=10**15;d=[inf]*n;d[0]=0
node=[[]for _ in range(n)]
for i in range(n):
	x=list(map(int,input().split()))
	for j in range(x[1]):
		node[i].append((x[j*2+2],x[j*2+3]))
dis=[[inf]*n for _ in range(n)]
for i in range(n):
	dis[i][i]=0
for i in range(n):
	for x in node[i]:
		dis[i][x[0]]=x[1]
s=[False]*n
while True:
	min_cost=inf
	for i in range(n):
		if s[i]==0 and d[i]<min_cost:
			min_cost=d[i]
			u=i
	if min_cost==inf:
		break
	s[u]=True
	for i in range(n):
		if s[i]==False and dis[u][i]!=inf:
			if d[u]+dis[u][i]<d[i]:
				d[i]=d[u]+dis[u][i]		
for i in range(n):
	print(i,d[i])


Measured memory_bytes: 6208
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

char s[200010];
int a[130];

int main()
{
	scanf("%s",s+1);int n=strlen(s+1);
	ll ans=ll(n)*(n-1)/2+1;
	for (int i=1;i<=n;i++)
		ans-=(a[s[i]]++);
	cout<<ans<<endl; 
	return 0;
}



Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut arr:Vec<usize> = (0..n).map(|_| read()).collect();
    let mut ans = 0;
    loop {
        if arr.iter().filter(|&&x| x % 2 != 0).count() != 0 {
            break;
        }
        arr = arr.iter().map(|x| x / 2).collect();
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2092