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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main(){
    ll n,ans=0;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    vector<tuple<ll,ll,ll>> v(n);
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i]>>b[i];
        c[i]=a[i]+b[i];
        v[i]=make_tuple(c[i],a[i],b[i]);
    }
    sort(all(v));
    reverse(all(v));    
    
    for(int i = 0; i < n; i++)
    {
        if(i%2==0)
        {
            ans+=get<1>(v[i]);
        }
        else
        {
            ans-=get<2>(v[i]);
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
#define sbs(i,j) substr(i,j)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1e6+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

int a[55],b[55],c[55],d[55];
int main(){
    int n,m;
    cin>>n>>m;
    rep(i,1,n)
        cin>>a[i]>>b[i];
    rep(i,1,m)
        cin>>c[i]>>d[i];
    rep(i,1,n){
        int Min=INF;
        int index=0;
        rep(j,1,m){
            int dis=abs(c[j]-a[i])+abs(d[j]-b[i]);
            if(dis<Min){
                Min=dis;
                index=j;
            }
        }
        printf("%d\n",index);
    }
    getchar();
    return 0;
}

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

dic_odd = {}
dic_even = {}

for i, v in enumerate(V):
    if i % 2 == 0:
        if v in dic_even:
            dic_even[v] += 1
        else:
            dic_even[v] = 1
    else:
        if v in dic_odd:
            dic_odd[v] += 1
        else:
            dic_odd[v] = 1


odd_lst = [(k, v) for k, v in dic_odd.items()]
even_lst = [(k, v) for k, v in dic_even.items()]
odd_lst.sort(key=lambda x: x[1], reverse=True)
even_lst.sort(key=lambda x: x[1], reverse=True)

if (len(odd_lst) == len(even_lst) == 1) and (odd_lst[0][0] == even_lst[0][0]):
    print(int(N / 2))
    exit()

max_ = 0
for a, b in odd_lst:
    for x, y in even_lst:
        if a == x:
            continue
        else:
            max_ = max(b + y, max_)
            break


print(N - max_)


Measured memory_bytes: 25404
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9+7;

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  
  multiset<int> num;
  num.insert(-1);
  for( int i = 0; i < N; i++ ){
    bool fg = 0;
    auto Iter = num.lower_bound(A.at(i));
    if( Iter != num.begin() ){
      num.erase(--Iter);
    }
    num.insert(A.at(i));
  }
  cout << num.size() << endl;
  
}

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

int main(){
  int N;
  cin >> N;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if(i*j==N){
        cout << "Yes";
        return 0;
      }
    }
  }
  
  cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int BubbleSort(int);



int main(){
  int A[100],B[100],n,i,j,a,c,count,min,cnt=0;
  char C[100],D[100];

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf(" %c%d",&C[i],&A[i]);

  for(i=0;i<n;i++){
    B[i] = A[i];
    D[i] = C[i];
  }


//バブルソート
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
        a = A[j];
        c = C[j];
        A[j] = A[j-1];
        C[j] = C[j-1];
        A[j-1] = a;
        C[j-1] = c;
      }
    }
  }

  //セレクションソート

  for(i=0;i<n-1;i++){
    min = i;
    for(j=i+1;j<n;j++){
      if(B[j]<B[min]) min = j;
    }
    if(B[i]!=B[min]){
      a = B[i];
      c = D[i];
      B[i] = B[min];
      D[i] = D[min];
      B[min] = a;
      D[min] = c;
    }
  }

  for(i=0;i<n;i++) {
    if(C[i]!=D[i]) {
      cnt = 0;
      break;
    } else {
      cnt++;
    }
  }

  for(i=0;i<n;i++){
    if(i==0) printf("%c%d",C[i],A[i]);
    else printf(" %c%d",C[i],A[i]);
  }
  printf("\n");
  printf("Stable\n");

  for(i=0;i<n;i++){
    if(i==0) printf("%c%d",D[i],B[i]);
    else printf(" %c%d",D[i],B[i]);
  }
  printf("\n");
  if(cnt==0) printf("Not stable\n");
  else printf("Stable\n");






  return 0;
}



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

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

void solve() {
    int N; cin >> N;
    ll dp[110000][3];
    ll luck[110000][3];
    rep(i, N) rep(j, 3) cin >> luck[i][j];

    
    for (int i = 0; i < N; ++i){
        for (int j = 0; j < 3; ++j){
            for (int k = 0; k < 3; ++k){
                if( j == k) continue;
                chmax(dp[i+1][k], dp[i][j] + luck[i][k]);
            }
        }
    }

    ll res = 0;
    rep(i, 3) chmax(res, dp[N][i]);

    cout << res << "\n";
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

int main() {
  int A,B;
  int n[5];
  int buf;
  int count; //回文数の数
  cin >> A >> B;
  
  //初期化
  count = 0;
  for (int i=A;i<=B;i++) {
	//各桁の値を抽出
    buf = i;
    for (int j=0;j<5;j++){
      n[j] = buf%10;
      buf /= 10;
    }
    //回文数か判定
    if (n[0]==n[4] && n[1]==n[3]) {
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())
h = [int(i) for i in input().split()]
ans = 0

def f(h):
    global ans
    if len(h) == 0:
        return 
    v = [[]]
    for i in h:
        if i != 0:
            v[-1].append(i)
        else:
            v.append([])
    n = []
    for i in v:
        if len(i) == 0:
            continue
        j = min(i)
        ans += j
        n += [k - j for k in i]
        n += [0]
    f(n)

f(h)
print(ans)

Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: u64
    }

    println!("{}", 180 * (n - 2));
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, k);

    int ans = 0;
    if (!k) {
        std::cout << n * n << std::endl;
        return 0;
    }

    for (int b = k + 1; b <= n; b++) {
        int ress = b - k;
        //ans += (ress * (n / b)) + ((n % b) ? max((n % b) - k + 1, 0LL) : 0LL);
        ans += (ress * (n / b)) + ((n % b) ? max((n % b) - k + 1, 0LL) : 0LL);
        //cout << b << " : " << (ress * (n / b)) << " " << ((n % b) ? max((n % b) - k + 1, 0LL) : 0LL) << endl;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long

int main(){
    ll i, a, b; 
    scanf("%lld %lld", &a, &b);
    for(i=0;i<1001;i++){
        if(i*8/100==a&&i/10==b){
            printf("%lld", i);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[110100];
ll diff[110100];
int main(){
    int N;
    cin >> N;
    ll asum = 0;
    ll ok = true;
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
        asum += a;
    }

    ll n = N*(N+1LL)/2;
    if(asum % n != 0) ok = false;
    ll K = asum / n;


    ll difsum = 0;
    REP(i,N-1){
        diff[i] = A[i+1] - A[i] - K;
        if(diff[i] > 0) ok = false;
        if(diff[i] % N != 0) ok = false;
        difsum += -diff[i]/N;
    }
    diff[N-1] = A[0] - A[N-1] - K;
    difsum += -diff[N-1]/N;

    if(difsum != K) ok = false;

    //ll sum = 0;
    //for(int k = 0; k < N; k++){
    //    if(diff[k] == 0) continue;
    //    if(diff[k] > 0 || diff[k] % N != 0){
    //        ok = false;
    //        break;
    //    } 
    //    sum += -diff[k] / N;
    //}


    if(ok)
        cout << "YES" << endl;
    else{
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;
	
	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i-1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

void dfs(int from) {
	int c = 1;
	for (auto t : tree[from]) {
		c = c != color[from] ? c : c + 1;
		color[t] = c;
		colorMap[make_pair(from, t)] = c;
		m = max(c, m);
		dfs(t);
		c++;
	}
}

int dp[105][4][2];

int main() {
	string S;
	cin >> S;
	int N = S.size();
	int K;
	cin >> K;
	vector<int>n(N);
	for (int i = 0; i < N;++i) {
		n[i] = (int)S[i] - 48;
	}

	dp[0][0][0] = 1;
	for (int i = 0; i < N;++i) {
		for (int j = 0; j <= K; ++j) {
			for (int k = 0; k < 2; ++k) {
				int target = n[i];
				for (int d = 0; d < 10; ++d) {
					int ni = i + 1; int nj = j; int nk = k;
					if (d != 0) nj++;
					if (K < nj) continue;
					if (nk == 0) {
						if (target < d)continue;
						if (d < target)nk = 1;
					}
					dp[ni][nj][nk] += dp[i][j][k];
				}
			}
		}
	}
	
	int ans = dp[N][K][0] + dp[N][K][1];
	cout  << ans << endl;
}



Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		Long A = sc.nextLong() - 1;
      Long B = sc.nextLong();
      Long C = sc.nextLong();
      Long D = sc.nextLong();
      Long CDkaburi = lcm(C,D);
      
      
      Long AC = A / C;//1
      Long AD = A / D;//1
      Long ACD = A / CDkaburi;//0
      Long Awarenai = A - (AC + AD) + ACD;//8
      
      Long BC = B / C;//6
      Long BD = B / D;//5
      Long BCD = B / CDkaburi;//0
      Long Bwarenai = B - (BC + BD) + BCD;
      System.out.println(Bwarenai - Awarenai);
	}
 private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> C(13, 0);
	C[0] = 1;
	vector<int> A(N + 1);
	int res = -1;
	A[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i + 1];
		C[A[i + 1]]++;
	}
	for (int i = 0; i <= 12; i++) {
		if (C[i] >= 3) {
			res = 0;
		}
	}
	if (C[12] >= 2) {
		res = 0;
	}
	if (C[0] >= 2) {
		res = 0;
	}
	int k;
	int t;
	N++;
	vector<int>x;
	vector<int> y;
	if (res != 0) {
		A.clear();
		for (int i = 0; i <= 12; i++) {
			if (C[i] == 2) {
				y.push_back(i);
				y.push_back(24 - i);
			}
		}
		for (int i = 0; i <= 12; i++) {
			if (C[i] == 1) {
				A.push_back(i);
			}
		}
		N = A.size();
		//cerr << N << endl;
		for (int i = 0; i < (int)(1 << N); i++) {
			k = i;
			x = y;
			for (int j = 0; j < N; j++) {
				if (k % 2 == 1) {
					x.push_back(A[j]);
				}
				else {
					x.push_back(24 - A[j]);
				}
				k /= 2;
			}
			t = 10000;
			sort(x.begin(), x.end());
			for (int j = 0; j < (int)x.size() - 1; j++) {
				t = min(t, x[j + 1] - x[j]);
			}
			t = min(t, x.back() - x[0]);
			t = min(t, 24 - x.back() + x[0]);
			res = max(res, t);
			/*if (res == 5) {
				for (int j = 0; j < (int)x.size(); j++) {
					cerr << x[j] << " ";
				}
				cerr << endl;
			}*/
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
double dp[100][100];
double tk[100][100];
int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;if(!n)return 0;
        for(int i=0;i<n;++i){
            for(int j=0;j<n;++j){
                cin>>tk[i][j];
            }
        }
        for(int i=0;i<100;++i){
            fill(dp[i],dp[i]+100,0);
        }
        for(int i=0;i<n;++i){
            dp[0][i]=1;
        }
        for(int i=1;i<m;++i){
            for(int j=0;j<n;++j){
                for(int k=0;k<n;++k){
                    double buf;
                    buf=dp[i-1][j]*tk[j][k];
                    dp[i][k]=max(dp[i][k],buf);
                }
            }
        }
        double ans=0;
        for(int i=0;i<n;++i){
            ans=max(ans,dp[m-1][i]);
        }
        printf("%.2lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>

char taro[1000][200],hanako[1000][100];

int main(void){
    int i,j,k,l,n,pointt = 0,pointh = 0;

    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%s",&taro[i][0]);
        scanf("%s",&hanako[i][0]);
    }
    for(i = 0;i < n;i++){
        j = 0;k = 1;
        while(1){
            if(taro[i][j] > hanako[i][j] || (taro[i][j] != '\0' && hanako[i][j] == '\0')){k = 2;break;}
            if(taro[i][j] < hanako[i][j] || (taro[i][j] == '\0' && hanako[i][j] != '\0')){k = 3;break;}
            if(taro[i][j] == '\0')break;
            j++;
        }
        if(k == 1){pointt++;pointh++;}
        else if(k == 2)pointt+=3;
        else pointh+=3;
    }
    printf("%d %d\n",pointt,pointh);
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>

int main(int argc, char **argv){
    int N;
    std::cin >> N;

    std::vector<long long> A(N+1), B(N);

    for(int i = 0; i < N+1; i++){
        std::cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        std::cin >> B.at(i);
    }

    long long atacked = 0;
    long long rest = 0;
    for(int i = 0; i < N; i++){
        long long monstor = A.at(i);
        long long atack_power = B.at(i) + rest;
        if(monstor >= atack_power){
            //std::cout << "atack: " << atack_power << std::endl;
            atacked += atack_power;
            rest = 0;
        }else{
            //std::cout << "atack: " << monstor << std::endl;
            atacked += monstor;
            if(rest >= monstor){
                rest = B.at(i);
            }else{
                rest = B.at(i) - (monstor - rest);
            }
        }
    }
    atacked += std::min(rest, A.at(N));

    std::cout << atacked << std::endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> avec(n);
  vector<ll> bvec(m);
  vector<ll> asum(n+1, 0);
  vector<ll> bsum(m+1, 0);
  rep(i, n) {
    cin >> avec[i];
    asum[i+1] = asum[i] + avec[i];
  }
  rep(i, m) {
    cin >> bvec[i];
    bsum[i+1] = bsum[i] + bvec[i];
  }
  ll ans = 0;
  rep(i, n+1) {
    if (asum[i] > k) continue;
    ll l = 0;
    ll r = m;
    while(l <= r) {
      ll med = (l + r) / 2;
      ll temp = asum[i] + bsum[med];
      if (temp > k) {
        r = med - 1;
      } else {
        ans = max(ans, i+med);
        l = med + 1;
      }
    }
  }
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 9604
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		double r=sc.nextDouble();
		double pi=Math.PI;
		double area=r*r*pi;
		double length=2*r*pi;
		System.out.printf("%f %f",area,length);
	}
}

Measured memory_bytes: 28044
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split("");

		long R = 0;
		long G = 0;
		long B = 0;

		for (int i = 0; i < n; i++) {
			if (str[i].equals("R")) {
				R++;
			} else if (str[i].equals("G")) {
				G++;
			} else {
				B++;
			}
		}
		long no = 0;

		for (int i = 0; i < n - 2; i++) {
			String first = str[i];

			for (int j = i + 1; j < n - 1; j++) {
				if (str[j].equals(first)) {
					continue;
				}
				String second = str[j];
				int k = j + j - i;

				if (k < n && !str[k].equals(first) && !str[k].equals(second)) {
					no++;
				}
			}
		}

		long ans = R * G * B - no;
		System.out.println(ans);
	}
}

Measured memory_bytes: 34428
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    cout << N * N * N << endl;
    return 0;
};


Measured memory_bytes: 256
// abc131_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
typedef long long ll;
using namespace std;

int main() {
    int n, m, ans = 0;
    cin >> n;
    m = n;
    for(int i = 0; m != 0; i++) {
        ans += m % 10;
        m /= 10;
    }
    if(n % ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int cnt[26];
int main(){
	int h,w;
	lol(i,26)cnt[i]=0;
	cin>>h>>w;
	lol(i,h){
		lol(j,w){
			char z;
			cin>>z;
			cnt[z-'a']++;
		}
	}
	int d4=(h/2)*(w/2);
	int d2=0;
	if(h%2==1)d2+=w/2;
	if(w%2==1)d2+=h/2;
	int d1=0;
	if(h%2==1&&w%2==1)d1=1;
	bool ok=true;
	lol(i,26){
		while(d4){
			if(cnt[i]>=4){
				cnt[i]-=4;
			}
			else break;
			d4--;
		}
		while(d2){
			if(cnt[i]>=2){
				cnt[i]-=2;
			}
			else break;
			d2--;
		}
		if(cnt[i]==1){
			if(d1==1){
				cnt[i]=0;
				d1--;
			}
		}
		if(cnt[i]>0)ok=false;
	}
	if(ok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int N ;
void dfs(string S , char mx){
	if(S.length() == N ){
      cout << S << endl;
    }
  else{
    for(char c = 'a' ; c <= mx ; c++){
		dfs(S+c ,((c==mx)? (char)(mx+1) : mx ) );
    }
  }
}
  int main() {
	cin >> N ;
    dfs("",'a') ;
    return 0 ;
  }

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

int main() {
  string S;
  cin >> S;
  for (int i=0; i<(int)S.size(); i++) {
    if (S[i]=='1') {
      cout << '9';
    }
    else {
      cout << '1';
    }
  }
  cout << endl;
}


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

class Cube{
public:
  int f[6];
  Cube(){}
  void roll_z(){ roll(1,2,4,3);}
  void roll_y(){ roll(0,2,5,3);}
  void roll_x(){ roll(0,1,5,4);}
  void roll(int i,int j,int k,int l){
    int t=f[i]; f[i]=f[j]; f[j]=f[k]; f[k]=f[l]; f[l]=t;
  }
};

bool eq(Cube c1, Cube c2 ){
  for(int i=0;i<6;i++)
    if(c1.f[i] != c2.f[i])return false;
  return true;
}

bool equal( Cube c1, Cube c2 ){
  for(int i=0;i<6;i++){
    for(int j=0;j<4;j++){
      if( eq(c1,c2) )return true;
      c1.roll_z();
    }
    if(i%2 == 0)c1.roll_y();
    else c1.roll_x();
  }
  return false;
}

Cube C[100]; int n;

bool check(){
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++) if( equal(C[i],C[j]) )return false;
  return true;
}

int main(){
  cin>>n;
  for(int j=0;j<n;j++)
    for(int i=0;i<6;i++)cin>>C[j].f[i];

  if( check() )cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



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

using namespace std;

int N;
int feliz[100000][3];
int pd[100000][3];

int mam(int i, int ant){
    int aux = 0;

    if (i == N){
        return 0;
    }

    if (ant == -1 || pd[i][ant] == -1){
        for (int j = 0; j < 3; j++){
            if (j != ant)
                aux = max(aux, feliz[i][j] + mam(i + 1, j));
        }
        return pd[i][ant] = aux;
    }

    return pd[i][ant];
}

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

    memset(pd, -1, sizeof(int) * N * 3);

    for (int i = 0; i < N; i++){
        scanf("%d %d %d", &feliz[i][0], &feliz[i][1], &feliz[i][2]);
    }

    printf("%d\n", mam(0, -1));

    return 0;
}

Measured memory_bytes: 10368
import sys
n,m,x,y = map(int,input().split())
xs = list(map(int,input().split()))
ys = list(map(int,input().split()))

i = x+1
while(i<=y):
    f = True
    for j in xs:
        if j >= i:
            f = False
    for j in ys:
        if j < i:
            f = False
    if f:
        print("No War")
        sys.exit()
    i += 1

print("War")

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N, A, B = map(int, input().split())
h = [0] * N
for i in range(N): h[i] = int(input())
h.sort()

def check(x):
  t = [h[i] - x * B for i in range(N)]
  for i in range(N):
    if t[i] > 0:
      x -= -(-t[i] // (A - B))
      if x < 0: return False
  return x >= 0

ok = 10 ** 9
ng = 0
while ok - ng > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(ok)

Measured memory_bytes: 179032
import Control.Monad
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

getInt = readInt <$> BS.getLine
getIntListN n = map readInt <$> replicateM (fromIntegral n) BS.getLine

play table n as count = do
  let index = as ! n
  if index == 2
    then return count
    else do
      entry <- VUM.read table (index - 1)
      if entry == -1
        then do
          VUM.write table (index - 1) 1
          play table index as (count + 1)
        else return (-1)

main = do
  n <- getInt
  as <- getIntListN n
  let as' = listArray (1, length as) as
  table <- VUM.replicate n (-1) :: IO (VUM.IOVector Int)
  result <- play table 1 as' 1
  print result


Measured memory_bytes: 28412
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

long gcd( long a, long b )
{
    if (a < b) {
      return gcd(b, a);
    } else if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

  long n, k;
  cin >> n >> k;

  cout << n-k+1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	string s1, s2;
	cin >> s1 >> s2;

	if (s2 == s1) {
		cout << "Yes" << endl;
		return 0;
	}
	for (int i = 0; i < s1.length();i++) {
		string s3;
		s3= s1.substr(i + 1, s1.length() - 1) + s1.substr(0, i+1);
		if (s3 == s2) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define md 1000000007
#define inf 1e18
#define rep(i,a,b) for(int i=a;i<b;++i)
using namespace std;
#define M 1000010


int32_t main(){
	
	
	int n;cin>>n;
	int a[n];
	rep(i,0,n)cin>>a[i];
	int ans=0,mx=0;
	rep(i,0,n){
		if(a[i]<mx)ans+=mx-a[i];
		mx=max(mx,a[i]);
	}
	cout<<ans;
	
	
	
	
    return 0;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, m, x;
    cin >> n >> m >> x;
    int a[m];
    int b[n + 1] = {};
    rep(i, m) { cin >> a[i]; }
    // コスト表を作る
    for (int i = 0; i < m; i++) {
        b[a[i]] = 1;
    }

    // check
    // rep(i, n + 1) { cout << b[i] << " "; }

    // 処理
    int sumX = 0;
    int minV = INF;
    for (int i = 0; i <= x; i++) {
        sumX += b[i];
    }
    int sumY = 0;
    for (int i = x; i <= n; i++) {
        sumY += b[i];
    }

    // check
    // cout << sumX << " " << sumY << endl;

    // 出力
    cout << min(sumX, sumY) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,ans=0; cin >> X;
  
  while(X>=500) {
    X -= 500;
    ans += 1000;
  }
  while(X>=5) {
    X -= 5;
    ans += 5;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


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;
}

int main () {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    
   
    sort(a.begin(),a.end());
    vector<bool> dp(a[n-1]+1,true);
    bool flag = false;
    REP(i, n){
        ll k = a[n-1] / a[i];
        if(i < n-1){
            if(a[i] == a[i+1]){
                dp[a[i]] = false;
            }
        }
        FOR(j,2, k + 1){
            dp[a[i] * j] = false;
        }
    }
    ll ans = 0;
    REP(i,n){
        if(dp[a[i]]){
            ans += 1;
        }
    }
    cout << ans << endl;

}






Measured memory_bytes: 4760
import math
from decimal import *
import random

n = int(input())
arr = list(map(int, input().split()))
cnt = 0
pref  = [0 for i in range(n)]
for i in range(n):
    cnt+=arr[i]
    pref[i] = cnt
ans = 0
for i in range(n):
    ans= (ans+(pref[n-1]-pref[i])*arr[i])%(int(1e9)+7)
print(ans)


Measured memory_bytes: 122092
// Best practice

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <functional> // for less 

#define int         long long
#define pb          emplace_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> pbds; 

#define fbo find_by_order
#define ook order_of_key

signed main() {
   tezz
   
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n>=3200){
        cout << s;
    }
    else{
        cout << "red";
    }
   
   return 0;
}


Measured memory_bytes: 256
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const NK = inp.shift().split(' ').map(n => Number(n))
  inp = inp[0].split(' ').map(n => Number(n))
    .filter(n => n >= NK[1])
  console.log(inp.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A_B_Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            int lValue = int.Parse(strs[0]);
            int rValue = int.Parse(strs[1]);
            DivisionCalculate problem = new DivisionCalculate(lValue, rValue);

            Console.WriteLine(
                problem.GetDivisionToInt() + " " +
                problem.GetModuloToInt() + " " +
                problem.GetDivisionToDouble().ToString("F5"));
        }
    }

    public class DivisionCalculate
    {
        private int lValue;
        private int rValue;

        public DivisionCalculate(int lValue, int rValue)
        {
            this.lValue = lValue;
            this.rValue = rValue;
        }

        public int GetDivisionToInt() {
            return lValue / rValue;
        }

        public int GetModuloToInt()
        {
            return lValue % rValue;
        }

        public double GetDivisionToDouble()
        {
            return lValue / (double)rValue;
        }
    }
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
#include <math.h>
#include <string>
using namespace std;
string s[1000];
long long p[1000],pos[1000];
int ss(string a, string b){
	int k=min(a.size(),b.size());
	if (a==b) return 0;
	for (int i=0;i<k;i++)
		if (a[i]>b[i]) return 1;
		else if (a[i]<b[i]) return 2;
	if (a.size()>b.size()) return 1;
	else return 2;
	return 0;
}
int main(){
	long long n;
	cin>>n;
	for (int i=1;i<=n;i++) pos[i-1]=i;
	for (int i=0;i<n;i++) cin>>s[i]>>p[i];
	for (int i=0;i<n-1;i++)
		for (int j=i+1;j<n;j++)
			if ((ss(s[i],s[j])==1) || (ss(s[i],s[j])==0 && p[i]<p[j])){
				swap(s[i],s[j]);
				swap(p[i],p[j]);
				swap(pos[i],pos[j]);
			}
   	for (int i=0;i<n;i++) cout<<pos[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

vector<pair<long long, long long> > prime_factorize(long long n) {
	vector<pair<long long, long long> > res;
	for (long long p = 2; p * p <= n; ++p) {
		if (n % p != 0) continue;
		int num = 0;
		while (n % p == 0) { ++num; n /= p; }
		res.push_back(make_pair(p, num));
	}
	if (n != 1) res.push_back(make_pair(n, 1));
	return res;
}

// 最大公約数を求める
long long GCD(long long x, long long y) {
	return y ? GCD(y, x%y) : x;
}

int main() {
	long long A, B;
	cin >> A >> B;
	long long G = GCD(A, B);
	auto pf = prime_factorize(G);
	cout << pf.size() + 1 << endl;
	return 0;
}


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

int main(){
    string divide[4] = {"dream", "dreamer", "erase", "eraser"};
    string ans;
    cin >> ans;
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < 4; i++) reverse(divide[i].begin(),divide[i].end());

    bool can = false;
    bool can2 = false;
    for(int i = 0; i < ans.size();){
        for(int a = 0; a < 4; a++){
            if(ans.substr(i, divide[a].size())== divide[a]){
                i += divide[a].size();
                can2 = true;
                break;
            } else {
                can2 = false;
            }
        }
        if(!can2){
            break;
        }
        if(ans.size() == i) can = true;
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

const int mod = 1e9 + 7;

int main() {
	cin.tie(0);
	int n;
	cin >> n;
	
	vector<int> cnt(n);
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		cnt[t]++;
	}
	
	vector<int> foo(n);
	for (int i = 0; i < n; i++) {
		foo[abs(i - (n - 1 - i))]++;
	}

	int ans = 1;
	for (int i = 0; i < n; i++) {
		if (cnt[i] != foo[i]) {
			ans = 0;
		}
		if (cnt[i] == 2) {
			ans *= 2;
			ans %= mod;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(i=a;i<n;i++)
#define test(a) cout << "*" << a << endl;
int main(){
  int n,k;
  
  cin >> n >> k;
  
  if(n%k==0)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  
}

Measured memory_bytes: 256
from heapq import heapify, heappop, heappush

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

N,M = map(int,input().split())
A = list(map(int,input().split()))
if N == M +1:
  print(0)
  exit()
Cost = []
for i in range(N):
  heappush(Cost,[A[i],i]) #コスト、IDという順で保存。
uf = UnionFind(N)
for i in range(M):
  a,b = map(int,input().split())
  #a-=1;b-=1 #既に0index
  uf.union(a,b)
ans = 0
L = [[] for _ in range(N-M)]
dic = {}
num = 0
for i in range(N):
  par = uf.find(i)
  if par not in dic:
    dic[par] = num
    heappush(L[dic[par]],[A[i],i])
    num +=1
  else:
    heappush(L[dic[par]],[A[i],i])
#print(L)
Selected = set([])
for x in L:
  ans += x[0][0] #最小のコスト
  Selected.add(x[0][1]) #頂点
#print(Selected)
ima = N-M
while ima < 2*(N-M-1) and Cost:
  cost, ID = heappop(Cost)
  if ID in Selected:
    continue
  else:
    ans += cost
    ima += 1
if ima < 2*(N-M-1):
  print("Impossible")
else:
  print(ans)
  


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

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    vector<int> vec(101);
    rep(i,101){
        if(a%i==0&&b%i==0){
            vec.at(i)=i;
            //cout<<vec.at(i);
        }
    }
    sort(vec.begin(),vec.end());
    cout<<vec.at(vec.size()-c)<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, p, prime[1000009], s[1000009];
int main() {
	fill(prime + 2, prime + 1000000, 1);
	for (int i = 2; i < 1000; i++) {
		if (!prime[i]) continue;
		for (int j = i * i; j < 1000000; j += i) prime[j] = 0;
	}
	for (int i = 2; i < 1000009; i++) s[i] = s[i - 1] + prime[i];
	while (cin >> n, n) {
		int ret = 0;
		for (int i = 0; i < n; i++) {
			cin >> p >> m;
			ret += s[min(p + m, 1000000)] - s[max(p - m - 1, 0)] - 1;
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 10820
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
#define int long long 
int nod(int a,int b){
  while(a != 0 && b != 0){
  	if(a > b){
  	  a %= b;
  	}else{
  	  b %= a;
  	}
  }
  return a + b;
}
signed main(){
  int a,b;
  cin >> a >> b;
  cout << (a * b) / nod(a,b);
  return 0;
} 


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

typedef long long int ll;
typedef long long unsigned int ull;
typedef long double ld;
typedef vector<int> vr;
typedef pair<int, int> pr;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
#define endl "\n"
//cout << fixed << setprecision(2);

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin >> s;
    string r = s;
    reverse(r.begin(), r.end());
    //cout << "s " << s << endl;
    //cout << "r " << r << endl;
    int len = s.size();
    for(int i = 0; i < len; i++){
        if(r[i] == 'b'){
            r[i] = 'd';
        }
        else if(r[i] == 'd'){
            r[i] = 'b';
        }
        else if(r[i] == 'p'){
            r[i] = 'q';
        }
        else if(r[i] == 'q'){
            r[i] = 'p';
        }
    }

    //cout << "s " << s << endl;
    //cout << "r " << r << endl;
    if(s == r){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}



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

int N, M;
vector<int> G[10];
bool visited[10];
int ans = 0;

void dfs(int v, int cnt) {
    if (cnt == N-1) {
        ans++;
        return;
    }
    
    for (int i = 0; i < G[v].size(); i++) {
        if (!visited[G[v][i]]) {
            visited[G[v][i]] = true;
            dfs(G[v][i], cnt+1);
            visited[G[v][i]] = false;
        }
    }
    return;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    memset(visited, false, sizeof(visited));
    visited[1] = true;

    dfs(1, 0);

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


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

int main(){
  int N;
  cin>>N;
  vector<int64_t> p(N);
  vector<int64_t> q(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
    q[i]=p[i];
    if(i>0){
      p[i]+=p[i-1];
    }
  }
  for(int i=N-1;i>0;i--){
    q[i-1]+=q[i];
  } 
  int64_t Z=167167167167167167;
  for(int i=2;i<N-1;i++){
    int l1=0,r1=i-1;
    while(r1-l1>1){
      int D=(l1+r1)/2;
      if(p[D]*2>p[i-1]){
        r1=D;
      }
      else{
        l1=D;
      }
    }
    int64_t A=p[i-1],B=min(abs(p[i-1]-p[l1]*2),abs(p[i-1]-2*p[r1]));
    int l2=i,r2=N-1;
    while(r2-l2>1){
      int D=(l2+r2)/2;
      if(q[D]*2>q[i]){
        l2=D;
      }
      else{
        r2=D;
      }
    }
    int64_t E=q[i],F=min(abs(q[i]-q[l2]*2),abs(q[i]-2*q[r2]));
    Z=min(Z,max(E+F,A+B)-min(E-F,A-B));
  }
  Z/=2;
  cout<<Z<<endl;
    
}

Measured memory_bytes: 6424