akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn._
import scala.annotation.tailrec
import scala.collection._

object Main {

  def sieve(top: Int): Iterator[Int] = {
    val topNdx = (top - 3) / 2 + 1
    val (cmpsts, sqrtLmtNdx) = (new Array[Int]((topNdx >>> 5) + 1), (Math.sqrt(top).toInt - 3) / 2)

    @inline def isCmpst(ci: Int): Boolean =
      (cmpsts(ci >>> 5) & (1 << (ci & 31))) != 0

    @inline def setCmpst(ci: Int): Unit =
      cmpsts(ci >>> 5) |= 1 << (ci & 31)

    @tailrec def forCndNdxsFrom(cndNdx: Int): Unit =
      if(cndNdx <= sqrtLmtNdx){
        if(!isCmpst(cndNdx)){
          val p = cndNdx + cndNdx + 3

          @tailrec def cullPrmCmpstsFrom(cmpstNdx: Int): Unit =
          if(cmpstNdx <= topNdx){
            setCmpst(cmpstNdx)
            cullPrmCmpstsFrom(cmpstNdx + p)
          }
          cullPrmCmpstsFrom((p * p - 3) >>> 1)
        }
        forCndNdxsFrom(cndNdx + 1)
      }

    forCndNdxsFrom(0)

    @tailrec def getNxtPrmFrom(cndNdx: Int): Int =
      if ((cndNdx > topNdx) || !isCmpst(cndNdx)) 2 * cndNdx + 3
      else getNxtPrmFrom(cndNdx + 1)

    Iterator.single(2) ++ Iterator.iterate(3)(p => getNxtPrmFrom((p - 1) >>> 1)).takeWhile(_ <= top)
  }
/*
  def sieve(top: Int): Iterator[Int] = {
    val topNdx = (top - 3) / 2
    val cmpsts = new mutable.BitSet(topNdx + 1)
    @inline def cullPrmCmpsts(prmNdx: Int) = {
      val prm = prmNdx + prmNdx + 3
       cmpsts ++= ((prm * prm - 3) >>> 1 to topNdx by prm)
    }

    (0 to (Math.sqrt(top).toInt - 3) / 2).filterNot(cmpsts).foreach(cullPrmCmpsts)
    Iterator.single(2) ++ (0 to topNdx).filterNot(cmpsts).map(2 * _ + 3)
  }
  */

  @tailrec
  def loop(s: String){
    if(s != null){
       val Array(n,_*) = s.split(" ").map(_.toInt)
       if(n<2) println(0)
       else println(sieve(n).size)
       loop(readLine)
    }
  }

  def main(args: Array[String]): Unit ={
    loop(readLine)
  }
}

Measured memory_bytes: 65784
/*
    Author:zzugzx
    Lang:C++
    Blog:blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=1e6+10;
const ll inf=0x3f3f3f3f;
const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};

ll a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n;
    cin>>n;
    ll s=0;
    for(int i=1;i<=n;i++)cin>>a[i],s^=a[i];
    for(int i=1;i<=n;i++)cout<<(s^a[i])<<' ';
    return 0;
}



Measured memory_bytes: 5208
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  lol a[n + 5];
  priority_queue<pii> nasu;
  rep(i, n){
    cin >> a[i];
  }
  sort(a, a +n);
  int b, c;
  rep(i, m){
    cin >> b >> c;
    nasu.push(mp(c, b));
  }
  lol sum = 0;
  c = nasu.top().fi;
  b = nasu.top().se;
  nasu.pop();
  rep(i, n){
    if(c >= a[i]){
      sum += c;
      b --;
      //cout << b << " ";
      if(b == 0){
        if(nasu.empty()){
          c = 0;
          b = 10e5;
        } else {
          c = nasu.top().fi;
          b = nasu.top().se;
          nasu.pop();
        }
      }
    } else {
      sum += a[i];
    }
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 2168
// 以下のライブラリを使ってみる.
// davidvc氏.
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=3125279#1
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
struct edge{
    int v; // 次の頂点.
    int w; // 距離.
    edge(int v, int w) : v(v), w(w) {}
};

vector<edge> adj[MAX];
bool visited[MAX];
int LD[MAX];

// グラフを深さ優先探索する.
// https://ja.wikipedia.org/wiki/深さ優先探索
// ※dfsの動作確認用.
// @param c: グラフの探索開始頂点.
// @param d: グラフの探索開始頂点からの距離を保存.
// @return: 特に無し.
void dfs(int c, int d) {
    // 1. 訪問済みならば, 終了.
    if(visited[c]) return;

    // 2. 訪問済みフラグ設定.
    visited[c] = true;
    
    // 3. 未訪問の頂点であれば, 距離を更新.
    LD[c] = max(LD[c], d);
    for(auto &e : adj[c]) if(!visited[e.v]) dfs(e.v, d + e.w);

}

int main(){
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    for(int i = 0, s, t, w; i < N - 1; ++i){
        scanf("%d %d %d", &s, &t, &w);
        adj[s].emplace_back(t, w);
        adj[t].emplace_back(s, w);
    }
    memset(LD, 0, sizeof(LD));
    
    // 2. 頂点の次数が, 1 のものに対して, 木の高さを計算.
    for(int r = 0; r < N; r++){
        if(adj[r].size() == 1){
            memset(visited, 0, sizeof(visited));
            dfs(r, 0);
        }
    }
    
    // 3. 出力 ～ 後処理.
    for(int r = 0; r < N; r++) printf("%d\n", LD[r]);
    return 0;
}


Measured memory_bytes: 6660
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
const int maxn = 1<<18;
int n, h, w;
set<pair<int, int>> present, cnt[10];
int sum(int i, int j) {
	if(i <= 0 || i+2>h || j <= 0 || j+2>w) return 0;
	int ans = 0;
	for(int a = 0; a < 3; a++)
		for(int b = 0; b < 3; b++)
			ans += present.count({i+a, j+b});
	return ans;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> h >> w >> n;
	for(int x, y, i = 0; i < n; i++) {
		cin >> x >> y;
		present.insert({x, y});
	}
	for(auto i : present) {
		int x = i.first, y = i.second;
		for(int a = 0; a < 3; a++)
			for(int b = 0; b < 3; b++)
				cnt[sum(x-a, y-b)].insert({x-a, y-b});
	}
	ll p0 = (h-2) * 1ll * (w - 2);
	for(int i = 1; i < 10; i++) p0 -= cnt[i].size();
	cout << p0 << '\n';
	for(int i = 1; i < 10; i++) cout << cnt[i].size() << '\n';
}


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

int main() {
	string S;
	unsigned long K;
	cin >> S >> K;
	unsigned long cnt = 0;
	char r = '1';
	for (unsigned long i = 0; i < S.length(); i++) {
		cnt++;
		if (S[i] != '1') {
			r = S[i];
			break;
		}
	}
	if (cnt <= K)
		cout << r << endl;
	else 
		cout << '1' << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a,const void *b){
  if(*(long long*)a > *(long long*)b) return 1;
  return -1;
}

int main(void){
  int N;
  scanf("%d",&N);

  long long A[N],S[N+1];
  S[0] = 0;
  for (int i = 0; i < N; i++) {
    scanf("%lld",&A[i]);
    S[i+1] = S[i]+A[i];
  }

  qsort(S,N+1,sizeof(long long),compare_int);

  long long ans = 0,cnt = 1;
  for (int i = 0; i < N; i++) {
    if(S[i] == S[i+1]){
      cnt++;
    }else{
      ans += cnt*(cnt-1)/2;
      cnt = 1;
    }
  }
  ans += cnt*(cnt-1)/2;

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

  return 0;
}

Measured memory_bytes: 4860
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
    #define ll long long
    #define db double
    #define sht short
    #define MB template <class T>
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define fur(i,x,y) for(i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fdr(i,x,y) for(i=x;i>=y;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define inf 0x3f3f3f3f
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define l2(n) (int(log2(n)))
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define fcin ios::sync_with_stdio(false)
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>=y?x:y;}
    MB T MIN(T x,T y){return x<=y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 1000011
int main(){
    int a,b;
    cin>>a>>b;
    if(b%a)cout<<b-a;
    else cout<<a+b;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s;
	string c;
	cin>>s;
	int cnt=0;
	int m=s.size();
	for(int i=1;i<m-3;i++){
		if(s[i]=='m'){
		if(s[i+1]=='e'){
		if(s[i+2]=='w'){
		cnt+=3;
		for(int j=i;j<m-3;j++){
		s[j]=s[j+3];
		}
		s[m-1]='o';
		s[m-2]='o';
		s[m-3]='o';
		i=0;
		}
		}
		}
	}
	if(s[0]=='m' && s[1]=='e' && s[2]=='w' && cnt==s.size()-3){
		cout<<"Cat"<<endl;
	}
	else{
		cout<<"Rabbit"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>

using namespace std;
typedef long long ll;
int m;
ll c[200000], d[200000], num[10] = {}, ans = 0, a;
int main() {
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld", &d[i], &c[i]);
    num[d[i]] += c[i];
    ans += c[i];
  }
  for (ll i = 1; i <= 9; i++) {
    while (num[i] >= 10) {
      ans += num[i] / 10 * i;
      num[i] = num[i] / 10 + num[i] % 10;
    }
  }
  a = 0;
  for (int i = 1; i <= 9; i++) {
    while (num[i]) {
      num[i]--;
      a += i;
      if (a >= 10) {
        ans++;
        a %= 10;
        a++;
        if (a == 10) {
          ans++;
          a = 1;
        }
      }
    }
  }
  printf("%lld\n", ans - 1);
}

Measured memory_bytes: 3328
program lisdl
  implicit none
  integer(8) :: n, a, b, h, p, s, i, j
  read(*,*) n, a, b
  if ((a+b.gt.n+1_8).or.(a*b.lt.n)) then
    write(*,'(i0)') -1
    stop
  end if
  write(*,'(i0)',advance='no') b
  do i = b-1_8, 1_8, -1_8
    write(*,'(x,i0)',advance='no') i
  end do
  h = n-a-b+1_8
  p = b+1_8
  do i = 0_8, a-2_8, 1_8
    s = min(h,b-1_8)+1_8
    h = h-s+1_8
    do j = p+s-1_8, p, -1_8
      write(*,'(x,i0)',advance='no') j
    end do
    p = p+s
  end do
  write(*,*)
  stop
end program lisdl

Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys
import math
# import numpy as np
# from functools import lru_cache

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

# sys.setrecursionlimit(10000)

#### input
A, B = map(int, input().split())
# a = list(map(int, input().split()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### function
# @lru_cache(maxsize=10000)

#### process
# if em: embed()
tmp = (A-1)
print(math.ceil((B-1)/tmp))
## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)


Measured memory_bytes: 3060
A = input()

S = 0
lis = [0] * 2019
lis[0] += 1
l = len(A)+1
d = 1

for n in reversed(A):
    S += int(n)*d
    S %= 2019
    lis[S] += 1
    d *= 10
    d %= 2019

result = 0

for n in lis:
    result += (n*(n-1)//2)


print(result)


Measured memory_bytes: 9200
/*
AizuOnline A1210
Title Die Game
*/
#include <stdio.h>
#include <string.h>

//Global data section
int N;
int top,north,west;
int nexttop,nextnorth,nextwest;
char buf[10];
char *d="NSWE";
//
main()
{
        int i,nextnum,dir;

        while(EOF!=scanf("%d",&N) && N)
        {
                top=1;north=2;west=3;
                for(i=0;i<N;i++)
                {
                        scanf("%s\n",buf);
                        dir=strchr(d,toupper(buf[0]))-d;
                        switch(dir)
                        {
                        case 0:
                                nexttop=7-north;
                                nextnorth=top;
                                nextwest=west;
                                break;
                        case 1:
                                nexttop=north;
                                nextnorth=7-top;
                                nextwest=west;
                                break;
                        case 2:
                                nexttop=7-west;
                                nextwest=top;
                                nextnorth=north;
                                break;
                        case 3: //dir:east w->t t->e
                                nexttop=west;
                                nextwest=7-top;
                                nextnorth=north;
                                break;
                                
                        }
                        top=nexttop;
                        north=nextnorth;
                        west = nextwest;
                }
                printf("%d\n",top);
        }
return(0);
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 105
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;

int arr[M];

int main()
{
	int n, left = 0, right = 0;
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
		right += arr[i];
	}
	int diff = right;
	for(int i = 0; i < n; i++) {
		left += arr[i];
		right-= arr[i];
		int tmp = abs(left-right);
		if(tmp < diff) diff = tmp;
	}
	cout << diff << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll k;
    scanf("%lld",&k);
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    printf("%lld\n",a[k-1]);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define F first
#define S second
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int d,n,no=0;
    cin>>d>>n;
    for(int i=1; i<=1e8; i++)
    {
        int cnt=0;
        int temp=i;
        while(temp%100==0)
        {
            cnt++;
            temp/=100;
        }
        if(cnt==d)
            no++;
        if(no==n)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    
    int n = s.length();
    int ans, count = 0;
    rep(i, n){
        if(i%2==0){
            if(s.at(i) != '0') count++;
        } else {
            if(s.at(i) != '1') count++;
        }
    }
    ans = min(count, n-count);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}

/////////////////////////////////////////////////////

int main(){
    string s;cin>>s;
    int len=s.size();
    if(len==1){
        cout<<1<<endl;
    }else if(len%2==0){
        int pos=len/2-1;
        int count=0;
        while(pos>=0){
            if(s[pos]==s[len-pos-1]){
                count++;
                pos--;
            }else break;
        }
        cout<<len/2+count<<endl;
    }else{
        int pos=len/2-1;
        int count=0;
        if(s[pos]==s[pos+1]&&s[pos+1]==s[pos+2])count++;
        pos--;
        if(count)while(pos>=0){
            if(s[pos]==s[len-pos-1]){
                count++;
                pos--;
            }else break;
        }
        cout<<len/2+1+count;
    }
    
    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 n, a, b;
  cin >> n >> a >> b;
  a--;
  b--;
  if ((b - a) % 2 == 0) {
    cout << (b - a) / 2 << endl;
  } else {
    int64 t1 = (b + a + 1) / 2;
    int64 t2 = (n - 1 - b + 1 + n - 1 - a) / 2;
    cout << min(t1, t2) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

const int MOD = 1000000007;

signed main(){

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

  int ans = 1;
  vector<int> h(n, 0);
  h[0] = 3;
  for(int i = 0; i < n; i++){
    ans = (ans * h[a[i]]) % MOD;
    h[a[i]]--;
    h[a[i]+1]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

string s;

int main(){
  cin >> s;
  s.at(3) = '8';
  cout << s <<endl;
}

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), v(d);
	vector<int> last(n);
	rep(i, d) {
		cin >> t[i];
		t[i]--;
	}
	
	ll ans = 0;
	rep(i, d) {
		ans += s[i][t[i]];
		last[t[i]] = i+1;
		rep(j, n) {
			ans -= c[j] * (i+1-last[j]);
		}
		cout << ans << endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3652
import string
S = input()

tmp = sum((c == 'C') * 1 for c in S[2:-1])
flag = True
for c in S[:2] + S[-2:]:
    if c in string.ascii_uppercase:
        if c != 'A' and c != 'C':
            flag = False
            break

if S[0] == "A" and tmp == 1 and flag:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3828
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 100000
int A[MAXN+5];

int main(){
    int N=read();
    for(int i=1;i<=N;i++)
        A[i]=read();
    for(int i=N-1;i>=1;i--){
        if(A[i]>A[i+1]+1)
            return printf("No"),0;
        else if(A[i]==A[i+1]+1)
            A[i]--;
    }
    printf("Yes");
}


Measured memory_bytes: 512
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var ans = 0;
  for(var i = 0; i < s.length; i++){
    if(s[i] === "x")ans++;
  }
  return ans>7?"NO":"YES";
}

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

int main(void) {
    string str;
    cin >> str;

    int cnt = 0;
    for(auto it : str) {
        if(it == 'C' && cnt == 0)cnt++;
        if(it == 'F' && cnt == 1) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef vector<int> vi;

int n;

vi solve(vi& a) {
	vp cnt; //num, count
	REP(i, n) {
		bool f = true;
		REP(j, cnt.size()) {
			if (a[i] == cnt[j].first) {
				cnt[j].second++;
				f = false;
			}
		}
		if (f) cnt.push_back(pii(a[i], 1));
	}
	
	vi res(n);
	REP(i, n) {
		REP(j, cnt.size()) if (a[i] == cnt[j].first)
			res[i] = cnt[j].second;
	}
	
	return res;
}

bool check(const vi& a, const vi& b) {
	bool f = true;
	REP(i, n) if (a[i] != b[i]) f = false;
	return f;
}

int main() {
	while (cin >> n, n) {
		vi s1(n), s2;
		REP(i, n) scanf("%d", &s1[i]);
		
		int ans = 0;
		while (true) {
			s2 = solve(s1);
			if (check(s1, s2)) break;
			s1 = s2;
			ans++;
		}
		cout << ans << endl;
		REP(i, n - 1) printf("%d ", s1[i]);
		printf("%d\n", s1[n - 1]);
	}
	return 0;
}

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

const int N = 702;

int adj[N][N];
bool vis[N];
int color[N];
set<int> s[N];

int sz[2];
bool dfs(int node,int c,int n) {
    vis[node] = true;
    color[node] = c;
    ++sz[c];
    for(int i=1;i<=n;++i) {
        if(adj[node][i]==0) {
            continue;
        }
        if(i==node) {
            continue;
        }
        if(vis[i]) {
            if(color[i]==c) {
                return false;
            }
        }
        else {
            if(!dfs(i,c^1,n)) {
                return false;
            }
        }
    }
    return true;
}

int dp[N][N];

int solveDp(vector<pair<int,int> >&v,int ind,int sz,int n) {
    if(ind == v.size()) {
        int r = n - sz;
        return (sz*(sz-1))/2 + (r*(r-1))/2;
    }
    int &ret = dp[ind][sz];
    if(ret!=-1) {
        return ret;
    }
    ret = min( solveDp(v,ind+1,sz+ v[ind].first,n),solveDp(v,ind+1,sz+v[ind].second,n));
    return ret;
}

void solve() {
    memset(dp,-1,sizeof(dp));
    int n,m;
    scanf("%d%d",&n,&m);
    memset(adj,1,sizeof(adj));
    for(int i=1;i<=n;++i) {
        adj[i][i] = 0;
    }
    for(int i=0;i<m;++i) {
        int a,b;
        scanf("%d%d",&a,&b);
        adj[a][b] = adj[b][a] = 0;
    }
    vector<pair<int,int> > v;
    for(int i=1;i<=n;++i) {
        if(!vis[i]) {
            memset(sz,0,sizeof(sz));
            if(!dfs(i,0,n)) {
                printf("-1\n");
                return;
            }
            v.push_back(make_pair(sz[0],sz[1]));
        }
    }
    printf("%d\n", solveDp(v,0,0,n));
}

int main() {
   //freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 4224
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    using namespace std ;
    int main(){
        int N,A;
        cin>>N>>A;
        while(N>=500)N=N-500;
        if(N<=A)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0 ;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
ll a[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+1+n,greater<ll>());
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
        q.push(a[i]);
        if(i==1)
            continue;
        q.push(a[i]);
    }

    ll ans=0;
    for(int i=1;i<n;i++)
    {
        ll max1=q.top();
        q.pop();
        ans+=max1;
    }
    cout<<ans<<'\n';






}


Measured memory_bytes: 6896
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N, K; cin >> N >> K;
	vector<pair<long long,int>> d(N);
	vector<pair<long long,int>> ans;
	vector<int> x(N+1, 0);
	long long s = 0, c = 0;
	for (int i = 0; i < N; i++) {
		int a; long long b;
		cin >> a >> b; d[i].first = -b; d[i].second = a;
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < K; i++) {
		ans.push_back({ d[i].first,d[i].second});
		if (x[d[i].second] == 0)c++;
		x[d[i].second]++;
		s -= d[i].first;
		
	}
	long long res = s + c * c;
	for (int i = K; i < N; i++) {
		if (x[d[i].second] != 0)continue;
		for (auto j = K - 1; j >= 0; j--) {
			if (x[ans[j].second] > 1) {
				x[ans[j].second]--; swap(ans[j], ans[K - 1]); break;
			}
			if (j == 0) {
				cout << res << endl; return 0;
			}
		}
		
		s += ans[K - 1].first;
		ans.pop_back();
		ans.push_back({ d[i].first,d[i].second});
		x[d[i].second]++;
		s -= d[i].first;
		c++;
		res = max(s + c * c, res);
	}
	cout << res << endl;
	
}



Measured memory_bytes: 4340
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if((a*b)%2 == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG(x) cout << "> " << #x << ": " << x << endl;

typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
const int inf = 1e9+7;
const ll longinf = 1LL<<60;

// Start Coding...

void solve() {
    int N;
    cin >> N;
    string P_str = "", Q_str = "", standard = "";
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        P_str += to_string(a);
    }
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        Q_str += to_string(a);
    }
    int idx1 = -1, idx2 = -1;
    standard = P_str;
    sort(standard.begin(), standard.end());
    int counter = 1;
    do {
        if (standard == P_str) idx1 = counter;
        if (standard == Q_str) idx2 = counter;
        if (idx1 != -1 && idx2 != -1) break;
        counter++;
    } while (next_permutation(standard.begin(), standard.end()));
    cout << abs(idx1 - idx2) << endl;
    return;
}

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

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){


    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a>b*2){
        ans=a-b*2;
    }  
    cout<<ans<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    A_arr = list(map(int,_in[1].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    A_arr.sort(reverse=True)
    vote = sum(A_arr)
    TF = 'Yes' if A_arr[M-1] >= vote/(4*M) else 'No'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Measured memory_bytes: 38384
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<string>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define MEM(a,b) memset(a,b,sizeof(a))
#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 800010
#define MOD 1000000009
#define EPS 1e-3
using namespace std;
int num[100010];

int main() {
    int n;
    W(~scanf("%d",&n)) {
        MEM(num,0);
        UP(i,0,n) {
            scanf("%d",&num[i]);
        }
        sort(num,num+n,greater<int>());
        LL ans=0;
        bool can1=false,can2=false;
        int m1=0,n1=0;
        int m2=0,n2=0;
        UP(i,0,n) {
            if(!can1) {
                if(num[i]==m1) {
                    n1++;
                    if(n1==2) {
                        can1=true;
                    }
                } else {
                    m1=num[i];
                    n1=1;
                }
            } else if(!can2) {
                if(num[i]==m2) {
                    n2++;
                    if(n2==2) {
                        can2=true;
                    }
                } else {
                    m2=num[i];
                    n2=1;
                }
            }else{
                break;
            }
        }
//        cout<<m1<<" "<<m2<<endl;
        ans=(LL)m1*m2;
        if(!can1||!can2) {
            puts("0");
        } else {
            printf("%lld\n",ans);
        }
    }
}


Measured memory_bytes: 640
/*  -*- coding: utf-8 -*-
 *
 * 1627.cc: Playoff by all the teams
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 9;
const int MAX_M = MAX_N * (MAX_N - 1) / 2;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int wns[MAX_N], lns[MAX_N], h, cnt;
bool mts[MAX_N][MAX_N];
pii ps[MAX_M];

/* subroutines */

void rec(int u) {
  if (u < 0) {
    cnt++;
    return;
  }

  int &x = ps[u].first, &y = ps[u].second;

  if (wns[x] < h && lns[y] < h) {
    wns[x]++, lns[y]++;
    rec(u - 1);
    wns[x]--, lns[y]--;
  }
  if (wns[y] < h && lns[x] < h) {
    wns[y]++, lns[x]++;
    rec(u - 1);
    wns[y]--, lns[x]--;
  }
}

/* main */

int main() {
  for (int n; scanf("%d", &n) == 1 && n > 0;) {
    memset(wns, 0, sizeof(wns));
    memset(lns, 0, sizeof(lns));
    memset(mts, false, sizeof(mts));

    int m;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      x--, y--;
      wns[x]++, lns[y]++;
      mts[x][y] = mts[y][x] = true;
    }

    h = (n - 1) / 2;
    bool ok = true;
    for (int i = 0; ok && i < n; i++)
      ok = (wns[i] <= h && lns[i] <= h);
    if (! ok) {
      puts("0");
      continue;
    }

    int l = 0;
    for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
	if (! mts[i][j])
	  ps[l++] = pii(i, j);
    //printf("l=%d\n", l);

    cnt = 0;
    rec(l - 1);
    printf("%d\n", cnt);
  }
  return 0;
}



Measured memory_bytes: 3192
N=int(input())
x,y,h=[],[],[]
for i in range(N):
  X,Y,H=map(int,input().split())
  x.append(X)
  y.append(Y)
  h.append(H)
MAX=101
for posX in range(MAX):
  for posY in range(MAX):
    needH=-1
    for i in range(N):
      if h[i]>0:
        tmp=h[i]+abs(posX-x[i])+abs(posY-y[i])
        if needH == -1:
          needH=tmp
        elif needH != tmp:
          needH=-2
          break
    if needH==-2:
      continue
    for i in range(N):
      if h[i] == 0:
        dist=abs(posY-y[i])+abs(posX-x[i])
        if needH > dist:
          needH=-2
          break
    if needH == -2:
      continue
    print(posX,posY,needH)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
  public static void main (String[] args) {
    Scanner sc =new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    int[] a = new int[w];
    for(int i=0;i<w;i++){
      a[i]=i+1;
    }
    for(int i=0;i<n;i++){
      String line = sc.next();
      String[] ml =line.split(",");
      int m = Integer.parseInt(ml[0]) -1;
      int l = Integer.parseInt(ml[1]) -1;
      int k = a[m];
      a[m] = a[l];
      a[l] = k;
    }
    for(int i=0;i<w;i++)
      System.out.println(a[i]);
      sc.close();
  }
}


Measured memory_bytes: 26008
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a[] = new int[n];
		
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		
		int max=a[0];
		for(int j=1;j<n;j++){
			max = Math.max(max, a[j]);
		} 
		
		int min = a[0];
		for(int k=1;k<n;k++){
			min = Math.min(min, a[k]);
		}
		
		long sum = 0;
		for(int l=0;l<n;l++){
			sum = sum + a[l];
		}
		
		System.out.println(min + " " + max + " " + sum);

	}

}



Measured memory_bytes: 42356
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

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

    int x = 0;
    int ans = 999;
    for (int i = 0; i < s.length(); i++) {
        x = x * 10 % 1000 + s[i] - '0';

        if (i >= 2) {
            ans = min(ans, abs(x - 753));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <functional>
#include <map>
#include <set>
#include <cmath>
using namespace std;
 
#define INT_MAX 2147483647
 

// DP !!
int main() {
    int n;
    cin >> n;
    vector<vector<int>> a(n);

    for (int i = 0; i < n; i++) {
        a[i].resize(3);
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }

    vector<vector<int>> dp(n);
    for (int i = 0; i < n; i++) {
        dp[i].resize(3);
    }

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];

    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = a[i][j] + max(dp[i-1][(j + 1) % 3], dp[i-1][(j + 2) % 3]);
        }
    }

    int best = dp[n-1][0];
    best = max(dp[n-1][1], best);
    best = max(dp[n-1][2], best);

    cout << best << endl;
    return 0;
}

Measured memory_bytes: 11136
/*
TASK: <Task>
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define EPS 1e-9
#define ALL(x) (x).begin(),(x).end()
#define mp(x,y) make_pair((x),(y))
#define pb(x) push_back((x))
#define FOR(i,st,ed) for(int (i)=(st);(i)<(ed);(i)++)
typedef pair<int,int> PII;
typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long LL;

int N,M,T;
string s[5];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("xxx.in","r",stdin);
    //freopen("xxx.out","w",stdout);
    int i,j,k;
    cin >> N >> s[0] >> s[1];
    long long ans=1;
    k=0;
    for(i=0;i<N;i++)
    {
        if(s[0][i]==s[1][i])
        {
            if(k==0)
                ans*=3,k=1;
            else if(k==1)
                ans*=2,k=1;
            else if(k==2)
                ans*=1,k=1;
        }
        else
        {
            i++;
            if(k==0)
                ans*=6,k=2;
            else if(k==1)
                ans*=2,k=2;
            else if(k==2)
                ans*=3,k=2;
        }
        ans%=1000000007;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
using namespace std;


int main()
{
    int a;
	long long int b,c,d,e;
	cin>>a>>b>>c;
	for(int i=0;i<a-1;i++)
    {
        cin>>d>>e;
        long long int k;
        k=max(b/d,c/e);
        while((d*k)<(b)||(e*k)<(c))
        {
            ++k;
        }
        b=k*d;
        c=k*e;
    }
    cout<< b+c <<endl;
	return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse2,avx,avx2,fma")

const long long MOD = 998244353;

long long inv[10000005];
long long invFact[10000005];
long long fact[10000005];

long long powmod(long long a, long long b){
    long long x = 1;
    long long y = a;
    while(b){
        if(b&1){ x = (x*y)%MOD; }
        y = (y*y)%MOD;
        b >>= 1;
    }
    return x;
}

inline long long ncr(long long a, long long b){
    return fact[a]*((invFact[a-b]*invFact[b])%MOD)%MOD;
}

int main(){
    int N;
    scanf("%d", &N);

    inv[1] = 1;
    for(int i = 2; i <= N; i ++){
        inv[i] = inv[MOD%i]*(MOD-MOD/i)%MOD;
    }

    fact[0] = 1;
    invFact[0] = 1;
    for(int i = 1; i <= N; i ++){
        fact[i] = (fact[i-1]*i)%MOD;
        invFact[i] = (invFact[i-1]*inv[i])%MOD;
    }

    long long tempPow2 = 1;
    long long ans = 0;
    for(int i = N; i > (N>>1); i --){
        ans += tempPow2*ncr(N, i)%MOD;

        tempPow2 += tempPow2;
        if(tempPow2 >= MOD){tempPow2 -= MOD;}
    }
    //printf("ans(%d)=%lld\n", N, ans);
    ans = (ans+ans)%MOD;
    long long finalAns = (powmod(3, N)-ans+MOD)%MOD;

    printf("%lld", finalAns);
    return 0;
}


Measured memory_bytes: 234624
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int D = sc.nextInt();
    int G = sc.nextInt();
    int[] p = new int[D];
    int[] c = new int[D];
    int count = 0;

    for (int i =0; i < D; i++) {
      p[i] = sc.nextInt();
      c[i] = sc.nextInt();
      count += p[i];
    }

    int[] dp = new int[count+1];
    int point = 0;

    for (int i = 0; i < D; i++) {
      for (int j = point; j >= 0; j--) {
        for (int k = 0; k < p[i]; k++) {
          int tmp = dp[j] + (1 + i) * 100 * (k + 1);
          if (k == p[i]-1) {
            tmp += c[i];
          }

          if (tmp > dp[j+k+1]) {
            dp[j+k+1] = tmp;
          }
        }
      }
      point += p[i];
    }

    int ans = count;

    for (int i = 0; i <= count; i++) {
      if (dp[i] >= G) {
        ans = i;
        break;
      }
    }

    System.out.println(ans);
  }
}


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

int main(){
    int h, w;
    cin >> h >> w;
    string field[h+1];
    for(int i = 0; i < h; i++) cin >> field[i];

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

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(field[i][j] == '#') continue;

            int num = 0;
            for(int k = 0; k < 8; k++){
                int numi = i + dx[k];
                int numj = j + dy[k];

                if(numi < 0 || numi >= h) continue;
                if(numj < 0 || numj >= w) continue;

                if(field[numi][numj] == '#') num++;
            }
            field[i][j] = char(num + '0');
        }
    }

    for(int i = 0; i < h; i++) cout << field[i] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int n; cin >> n;
    vector<pair<int, int>> red(n), blue(n);
    rep(i, n) cin >> red[i].first >> red[i].second;
    rep(i, n) cin >> blue[i].first >> blue[i].second;
    sort(all(red), [](pair<int, int> a, pair<int, int> b) {
        return a.second > b.second;
    });
    sort(all(blue));
    int ans = 0;
    rep(i, n) {
        int s = red.size();
        rep(j, s) {
            if(red[j].second < blue[i].second && red[j].first < blue[i].first) {
                ans++;
                red.erase(red.begin() + j);
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
import copy
from collections import deque
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
route = [[0, 0]]
visited = copy.deepcopy(s)
visited[0][0] = '#'
q = deque([[0, 0, route]])
score = -1

while q:
    y, x, route = q.popleft()
    r = copy.deepcopy(route)
    if [y, x] == [H-1, W-1]:
        score = sum(len(l) for l in s) - (sum(l.count('#') for l in s) + len(route))
        break
    if y > 0 and visited[y-1][x] == '.':
        visited[y-1][x] = '#'
        r.append([y-1, x])
        q.append([y-1, x, r])
        r = copy.deepcopy(route)
    if y < H-1 and visited[y+1][x] == '.':
        visited[y+1][x] = '#'
        r.append([y+1, x])
        q.append([y+1, x, r])
        r = copy.deepcopy(route)
    if x > 0 and visited[y][x-1] == '.':
        visited[y][x-1] = '#'
        r.append([y, x-1])
        q.append([y, x-1, r])
        r = copy.deepcopy(route)
    if x < W-1 and visited[y][x+1] == '.':
        visited[y][x+1] = '#'
        r.append([y, x+1])
        q.append([y, x+1, r])
        r = copy.deepcopy(route)

print(score)

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

using namespace std;

constexpr int N = 3e5 + 10;
constexpr int MOD = 1e9 + 7;

long long n, m, k;
string gender, s;

void bin (int b, int e) {
    if (b + 1 == e) {
        cout << b << '\n';
        cout.flush();
        return;
    }
    int mid = (b + e) >> 1;
    cout << mid << '\n';
    cout.flush();
    cin >> s;
    if (s == "Vacant")
        return;
    if (mid & 1) {
        if (s != gender)
            bin (mid, e);
        else
            bin (b, mid);
        return;
    }
    else {
        if (s != gender)
            bin (b, mid);
        else
            bin (mid, e);
        return;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    cout << 0 << '\n';
    cout.flush();
    cin >> gender;
    if (gender == "Vacant")
        return 0;
    bin (1, n);
    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;
int x[100000];
signed main(){
	int a,b,ans=INT_MAX;
	cin>>a>>b;
	f(i,a){
		cin>>x[i];
	}
	sort(x,x+a);
	for(int i=b-1;i<a;i++){
		ans=min(ans,x[i]-x[i-b+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();

    // input
    let n: usize = read(&mut stdin_lock, &mut buf, b' ');
    let k: usize = read(&mut stdin_lock, &mut buf, b'\n');
    let mut hv = vec![0usize; n];
    for i in 0..n - 1 {
        hv[i] = read(&mut stdin_lock, &mut buf, b' ');
    }
    hv[n - 1] = read(&mut stdin_lock, &mut buf, b'\n');

    hv.sort_by(|a, b| b.cmp(&a));

    let mut ans = 0;
    for i in k..n {
        ans += hv[i];
    }
    println!("{}", ans);
}


Measured memory_bytes: 6524
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
  int a, b;
  cin >> a >> b;
  if(0 < a){
    cout << "Positive" << endl;
    return 0;
  }
  if(a <= 0 && 0 <= b){
    cout << "Zero" << endl;
    return 0;
  }
  int n = -a + b + 1;
  if(n % 2 == 0) cout << "Positive" << endl;
  else cout << "Negative" << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var N int
	if scanner.Scan() {
		N, _ = strconv.Atoi(scanner.Text())
	}
	m := map[int]int{}
	for i := 1; i < N; i++ {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		m[a]++
	}

	for i := 1; i < N+1; i++ {
		v, is := m[i]
		if is {
			fmt.Println(v)
		} else {
			fmt.Println(0)
		}
	}

}


Measured memory_bytes: 13076
#include <iostream>
#include <algorithm>

using namespace std;

#define maxN 100010
#define stdCache -1
typedef long long ll;

int n;
int h[maxN];
ll cache[maxN];

ll pos(ll x) {
    return x < 0 ? -x : x;
}

ll dp(int i) {
    if (cache[i] != stdCache) return cache[i];
    if (i == n-1) return 0;
    if (i >= n) return 999999999;
    return cache[i] = min(pos(h[i]-h[i+1]) + dp(i+1), pos(h[i]-h[i+2]) + dp(i+2));
}

int main() {
    cin >> n;
    for (int i = 0; i<n; i++) {
        cin >> h[i];
        cache[i] = stdCache;
    }
    h[n] = 999999999;
    h[n+1] = 999999999;
    cout << dp(0) << endl;
    return 0;
}

Measured memory_bytes: 2944