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

int main(){
int n;
cin>>n;
long long  a[n]={0};
long long sum1=0,sum2=0;
long long t=0;
long long min=300000000000;
for(int i=1;i<=n;i++)  {
cin>>a[i];
sum1+=a[i];
}
for(int j=n;j>1;j--){
	sum1-=a[j];
	sum2+=a[j];
	 t=abs(sum1-sum2);
	 if(t<min)  min=t;
}
cout<<min;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		 try{

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

			 System.out.printf("%d\n", x*x*x);

		 }catch(IOException e){
			 e.printStackTrace();
		 }
	}
}


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

using namespace std;

int main() {
	int n,count=0;
	cin >>n;
    vector<int> w(n);

	for (int i = 0; i < n; i++)
	{
		cin >> w.at(i);
		count += w.at(i);
	}  
//  cout<<count<<endl;

	int ans=100000,s;

	for (int i = 0; i < n; i++)
	{
	s=0;
		for (int j = 0; j < i+1; j++)
		{
			s+= w.at(j);
		}
        
//        cout << s<< endl; 

		if(std::abs(count-2*s)<ans){
          ans=std::abs(count-2*s);
        }		
	}
	cout << ans<<endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;

int main()
{
	int a,b;
	int ans=0;
	
	cin>>a>>b;
	if(a*b==15)
		cout<<"*"<<endl;
	else if(a+b==15)
		cout<<"+"<<endl;
	else
		cout<<"x"<<endl;
	
	return 0;
}

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

map<long long, int> prime_factorize(long long x){
  map<long long, int> ret;
  for(long long i = 2; i * i <= x; i++){
    while(x % i == 0){
      ret[i]++;
      x /= i;
    }
  }
  if(x != 1){
    ret[x]++;
  }
  return ret;
}

int main(){
  long long N, P;
  cin >> N >> P;

  auto prime_factorization = prime_factorize(P);
  long long ans = 1;
  for(auto x: prime_factorization){
    for(int i = 0; i < x.second / N; i++){
      ans *= x.first;
    }
    //cout << x.first << ' ' << x.second << endl;
  }
  cout << ans << endl;
}



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

using std::cout;
using std::endl;
using std::cin;

std::vector<int64_t> v(100010, 1000000010);

int main()
{
    int64_t N, C, K, cnt = 0;
    cin >> N >> C >> K;
    for (int64_t i = 0; i < N; ++i)
    {
        cin >> v[i];
    }
    std::sort(v.begin(), v.end());
    int64_t i = 0, j;
    while (i < N)
    {
        for (j = 0; v[i + j] <= v[i] + K && j < C; ++j)
        {
            ;
        }
        i += j;
        ++cnt;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[3005][3005][5];
ll v[3005][3005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, C, K;
    cin >> R >> C >> K;
    rep(i,K){
        int r, c;
        ll val;
        cin >> r >> c >> val;
        --r; --c;
        v[r][c] = val;
    }
    ll ans = 0;
    rep(i,R)rep(j,C){
        rep(k,4){
            chmax(dp[i][j+1][k], dp[i][j][k]);
            chmax(dp[i][j+1][k+1], dp[i][j][k] + v[i][j]);
            chmax(dp[i+1][j][0], dp[i][j][k]);
            if(k < 3) chmax(dp[i+1][j][0], dp[i][j][k] + v[i][j]);
            chmax(ans, dp[i][j][k]);
            if(k < 3) chmax(ans, dp[i][j][k] + v[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 426020
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  bool f = false;
  for (int j = a.size(); j >=0; j-=2) {
    if (j%2 == 1 && f == false) {
      f = true;
      a.pop_back();
    }
    string b = a.substr(0, a.size()/2);
    string c = a.substr(a.size()/2, a.size()-1);
    if (b == c && f) {
      cout << j << endl;
      break;
    }
    a.pop_back();
    a.pop_back();
    f = true;
  }
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <iostream>
using namespace std;

int main()
{
  int n,m;
  int pre;
  int a[100001]={};

  cin >> n >> pre;
  a[0] = pre;
  m = 1;

  for(int i=1;i<n;i++){
    int tmp;
    cin >> tmp;
    if(tmp != pre){
      a[m] = tmp;
      m++;
      pre = tmp;
    }
  }

  int ans = 0;
  int i = 0;
  while(1){
    if(i>=m){
      break;
    }
    else if(i>= m-2){
      ans++;
      break;
    }
    if(a[i+1] - a[i] > 0){
      ans++;
      while( a[i+1] - a[i] > 0){
        i++;
        if(i == m-1)
          break;
      }
      i++;
    }
    else{
      ans++;
      while( a[i+1] - a[i] < 0){
        i++;
        if(i == m-1)
          break;
      }
      i++;
    }
  }

  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
char s[15],s1[14],s2[15];
int main()
{
    scanf("%s",s);
    scanf("%s",s1);
    scanf("%s",s2);
    printf("%c%c%c\n",s[0] - 32,s1[0] - 32,s2[0] - 32);
}

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

template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
 
inline double calc(int x, int r, double v, double e, double f) {
	if(x >= r) return 1.0 / (v - e * (x - r));
	return 1.0 / (v - f * (r - x));
}
 
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);
 
	for(int n; cin >> n && n;) {
		vector<int> a(n + 1, 0);
		for(int i = 1; i <= n; ++i) {
			cin >> a[i];
		}
 
		double b;
		cin >> b;
 
		int r;
		double v, e, f;
		cin >> r >> v >> e >> f;
 
		vector<vector<double>> dp(n + 1, vector<double>(n + 1, INT_MAX));
		dp[0][0] = 0.0;
 
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j <= i; ++j) {
				chmin(dp[i][i], dp[i][j] + b);
 
				double next_cost = 0.0;
				for(int x = a[i]; x < a[i + 1]; ++x) {
					next_cost += calc(x - a[j], r, v, e, f);
				}

				chmin(dp[i + 1][j], dp[i][j] + next_cost);
			}
		}
 
		cout << *min_element(dp[n].begin(), dp[n].end()) << endl;
	}
 
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;cin>>s;cin>>t;
  bool is_possible=true; ll pos=0;
  vector<char> v(26,' '),v_(26,' ');
  rep(i,s.length()) {
    pos=t[i]-'a';
    if(v[pos]==' ') v[pos]=s[i];
    if(v[pos]!=' '&&v[pos]!=s[i]) {is_possible=false;break;}
  }
  if (is_possible) {
    rep(i,t.length()) {
      pos=s[i]-'a';
      if(v_[pos]==' ') v_[pos]=t[i];
      if(v_[pos]!=' '&&v_[pos]!=t[i]) {is_possible=false;break;}
    }
  }
  print(is_possible?"Yes":"No");
  return 0;
}


Measured memory_bytes: 916
def main():
    p = [0] + list(map(int, input().split()))
    cnt = 0
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i]):
            cnt += 1
    print(cnt)

def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def unite(x, y):
    root_x = root(x)
    if root_x != root(y):
        parent[root_x] = y

def same(x, y):
    return root(x) == root(y)

if __name__ == "__main__":
    n, m = map(int, input().split())
    parent = list(range(n+1))
    main()

Measured memory_bytes: 130228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    sort(b.begin(), b.end());

    map<ll, int> mp;
    for (int i = 0; i <= n; i++) {
        mp[b[i]]++;
    }

    ll r = 0;
    for (auto& p : mp) {
        r += (ll)p.second * (p.second - 1) / 2;
    }

    cout << r << endl;

    return 0;
}

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

int main() {
  
  int K, X;
  cin >> K >> X;

  vector<int> ans(K * 2 - 1);
  
  ans.at(0) = X - K + 1;
  for (int i = 1; i < ans.size(); i++) {
     ans.at(i) = ans.at(i - 1) + 1;
   }

  cout << ans.at(0);
  for (int i = 1; i < ans.size(); i++) {
     cout << " ";
     cout << ans.at(i);
   }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

ll vec[200003];
ll osum[200003];
ll esum[200003];

ll oro[200003];
ll ero[200003];

ll dp[200003][3];

int n;
ll go(int o, int pp) {
    if (o > n) return -(ll)1e17;
    if (o == n) {
        if (pp == 2) return vec[o];
        else return -(ll)1e17;
    }
    if (dp[o][pp] > -(ll)1e18) return dp[o][pp];

    ll ret = -(ll)1e17;
    if (pp < 2) ret = max(ret, go(o + 3, pp + 1));
    ret = max(ret, go(o + 2, pp));

    return dp[o][pp] = ret + vec[o];
}

int main() {
    memset(dp, -0x3f, sizeof(dp));
    scanf("%d", &n);

    for (int i = 1; i <= n + 2; i++) {
        if (i < n + 1) scanf("%lld", &vec[i]);

        osum[i] = osum[i - 1];
        esum[i] = esum[i - 1];
        oro[i] = oro[i - 1];
        ero[i] = ero[i - 1];

        if (i < n + 1) {
            if (i % 2) osum[i] += vec[i], oro[i]++;
            else esum[i] += vec[i], ero[i]++;
        }
    }

    ll ans = -1e18;
    for (int i = 1; i <= n; i++) {
        if (oro[i - 1] + oro[n] - oro[i] == n / 2)
            ans = max(ans, osum[i - 1] + osum[n] - osum[i]);

        if (oro[i - 1] + ero[n] - ero[i] == n / 2)
            ans = max(ans, osum[i - 1] + esum[n] - esum[i]);

        if (ero[i - 1] + oro[n] - oro[i] == n / 2)
            ans = max(ans, esum[i - 1] + osum[n] - osum[i]);

        if (ero[i - 1] + ero[n] - ero[i] == n / 2)
            ans = max(ans, esum[i - 1] + esum[n] - esum[i]);


        ////
        if (oro[i - 1] + oro[n] - oro[i + 1] == n / 2)
            ans = max(ans, osum[i - 1] + osum[n] - osum[i + 1]);

        if (oro[i - 1] + ero[n] - ero[i + 1] == n / 2)
            ans = max(ans, osum[i - 1] + esum[n] - esum[i + 1]);

        if (ero[i - 1] + oro[n] - oro[i + 1] == n / 2)
            ans = max(ans, esum[i - 1] + osum[n] - osum[i + 1]);

        if (ero[i - 1] + ero[n] - ero[i + 1] == n / 2)
            ans = max(ans, esum[i - 1] + esum[n] - esum[i + 1]);
    }

    printf("%lld", max(ans, go(1, 0)));
}

Measured memory_bytes: 22560
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N, K; cin >> N >> K;
  vector<LL> A(N); cin >> A;

  LL vmin = 1e18;
  for (int i = 0; i < (1 << N); ++i) {
    bitset<15> b(i);
    if (b.count() < K) continue;

    LL prev_a = 0;
    LL cost = 0;
    for (int j = 0; j < N; ++j) {
      if (!b.test(j)) {
        prev_a = max(prev_a, A[j]);
        continue;
      }

      if (A[j] > prev_a) {
        prev_a = A[j];
      } else {
        cost += prev_a + 1 - A[j];
        ++prev_a;
      }
    }
    vmin = min(vmin, cost);
  }
  cout << vmin << endl;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
INF = float('inf')
def dijkstra(s, n, adj):
    dist = [INF] * n
    hq = [(0, s)]
    dist[s] = 0
    seen = [False] * n
    while hq:
        v = heappop(hq)[1]
        seen[v] = True
        for to, cost in adj[v]:
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                heappush(hq, (dist[to], to))
    return dist

v, e, r = map(int, input().split())
adj = [[] for _ in range(v)]
for i in range(e):
    s, t, d = map(int,input().split())
    adj[s].append((t, d))

ans = dijkstra(r, v, adj)
for i in ans:
    if i == float('inf'):
        print('INF')
    else:
        print(i)


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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  ll mod = 1e9+7;
  
  int n, m;
  cin >> n >> m;
  vector<int> stair(n+1);
  rep(i, m) {
    int at;
    cin >> at;
    stair[at] = 1; //1なら壊れている
  }
  vector<ll> dp(n+1);
  dp[0] = 1;
  for(int i = 0; i < n; ++i) {
    for(int j = i+1; j <= min(n, i+2); ++j) {
      if(stair[j] == 0) {
        dp[j] += dp[i];
        dp[j] %= mod;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 4532
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str;
	while((str=input.readLine())!=null)
	    {
		String str_ary[]=str.split(",");
		int a[]=new int[5];
		for(int i=0;i<5;i++)
		    {
			a[i]=Integer.parseInt(str_ary[i]);
		    }
		for(int i=0;i<5;i++)
		    {
			int mini=a[i],x=i;
			for(int j=i;j<5;j++)
			    {
				if(mini>a[j])
				    {
					mini=a[j];
					x=j;
				    }
				
			    }
			int tmp=a[i];
			a[i]=mini;
			a[x]=tmp;
		    }
		
		int count=0;
		for(int i=0;i<5;i++)
		    {
			for(int j=i;j<5;j++)
			    {
				if(a[i]==a[j] && i!=j)
				    {
					count++;
					
				    }
			    }
			
		    }
		if(((a[0]+1==a[1]) && (a[1]+1)==a[2]) && (a[2]+1==a[3]) && (a[3]+1==a[4]))System.out.println("straight");
		else if((a[0]==1) && (a[1]==10) && (a[2]==11) && (a[3]==12) && (a[4]==13))System.out.println("straight");
	else if(count==1)System.out.println("one pair");
	else if(count==2)System.out.println("two pair");
	else if(count==3)System.out.println("three card");
	else if(count==4)System.out.println("full house");
	else if(count==6)System.out.println("four card");
	else System.out.println("null");
	    }
    }
}

Measured memory_bytes: 16924
#include <stdio.h>
#include <math.h>

int main(){
    int h,w,a;
    int i;
    double j;
    while(scanf("%d %d",&h,&w)){
        int mh=0,mw=0;
        if(h==0 && w==0)break;
        a = h*h + w*w;
        for(i=h+1;i<sqrt(a);i++){ 
            j=sqrt(a - i*i);
            if(i<j&&ceil(j) == floor(j)){ 
                mh = i;
                mw = j;
                break;
            }
        }//end of for(i=h+1...)
        
        if(!mh&&!mw){
            while(!mh){
                a++;
                for(i=1;i<sqrt(a);i++){
                    j=sqrt(a - i*i);
                    if(i>=j)continue;
                    if(ceil(j) == floor(j)){
                        mh = i;
                        mw = j;
                        break;
                    }
                }
            }
        }//end_of_if(!mh&&!mw)
        
        printf("%d %d\n",mh,mw);
    }
    return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void E();

int main()
{
	E();
	fflush(stdout);
	return 0;
}

static void E()
{
	int N;
	getint(N);

	LLONG all = 0;
	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
		all = all ^ ai[i];
	}

	std::string ans;
	for (int i = 0; i < N; i++) {
		char tmp[64] = { 0 };
		sprintf(tmp, "%lld", all ^ ai[i]);
		if (ans.length()) {
			ans += " ";
		}
		ans += tmp;
	}
	printf("%s\n", ans.c_str());
}


Measured memory_bytes: 8760
#include <iostream>
using namespace std;
int main(void){
   int x,y;
   cin >> x >> y;
   
   while( x != 0 || y != 0 ){
       if(x > y){
           cout << y << " " << x << endl;
       }
       else{
           cout << x << " " << y << endl;
       }
       cin >> x >> y;
   }

}



Measured memory_bytes: 3084
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize;n],
    }

    let sum: usize = a.iter().sum();
    let choice = a.iter().filter(|&&x| sum <= x * 4 * m).count();
    println!("{}", if m <= choice { "Yes" } else { "No" });
}


Measured memory_bytes: 2160
#include <stdio.h>

int main() {
  int ss;
  scanf("%d", &ss);
  int h = ss / 3600;
  int m = (ss - (h * 3600)) / 60;
  int s = ss % 60;
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a,b;
    cin>>n>>a>>b;
    if((b-a)%2==0){
        cout << ((b-a)/2)<<endl;
    }
    else{
        ll maki=n-b+1;
        ll niko=a;
        ll x=a+maki;
        ll y=b-niko;
        cout <<(min((n-x)/2+maki,(y-1)/2+niko))<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < (int) n; ++i)
#define ford(i, n) for (int i = ((int) n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

int n;
int a[MAXN];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, n) {
		scanf("%d", &a[i]);
	}
	return 1;
}

int cnt[MAXN];

int solve() {
	memset (cnt, 0, sizeof cnt);
	forn(i, n) {
		++cnt[abs(i - (n - i - 1))];
	}

	forn(i, n) {
		--cnt[a[i]];
	}

	forn(i, n) {
		if  (cnt[i]) {
			return 0;
		}
	}

	int ans = 1;
	forn(i, n / 2) {
		ans = ans * 2ll % MOD;
	}

	return ans;
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		printf("%d\n", solve());
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:TYPE();}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:TYPE();}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=100005;

int n,rt;
vector<int> G[MAXN];
char a[MAXN];
int q[MAXN],deg[MAXN];
int b[MAXN],f[MAXN],ans;
bool vis[MAXN];
void dfs(int u,int pa)
{
	int fir=0,sec=0;
	for(auto v:G[u])
	{
		if(v==pa || vis[v])continue;
		dfs(v,u);
		if(f[v]>fir)sec=fir,fir=f[v];
		else if(f[v]>sec)sec=f[v];
	}
	f[u]=b[u]+fir;
	chkmax(ans,fir+sec+b[u]);
}

int main()
{
	int x,y;
	readint(n);
	for(int i=1;i<n;++i)readint(x),readint(y),G[x].pb(y),G[y].pb(x),++deg[x],++deg[y];
	scanf("%s",a+1);
	int front=1,rear=0;
	for(int i=1;i<=n;++i)if(deg[i]==1 && a[i]=='B')q[++rear]=i,vis[i]=1;
	while(front<=rear)
	{
		x=q[front++];
		for(auto y:G[x])
		{
			if(vis[y])continue;
			--deg[y];
			if(deg[y]==1 && a[y]=='B')q[++rear]=y,vis[y]=1;
		}
	}
	if(rear==n)return 0*printf("0\n");
	int sum=-2;
	for(int i=1;i<=n;++i)
		if(!vis[i])
		{
			b[i]=(a[i]=='W')^(deg[i]&1);
			sum+=2+b[i];
			if(!rt)rt=i;
		}
	dfs(rt,-1);
	printf("%d\n",abs(sum-ans*2)); 
	return 0;
}

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

int memo[20][20][4][16];
char data[20][20];
int W,H;
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};

char chg(char c){
	string table = "<>^v";
	return table.find(c);
}
int dfs(int x,int y,int d,int m){
	x = (x+W) % W ;
	y = (y+H) % H ;
	
	if(memo[x][y][d][m]) return 0;
	else memo[x][y][d][m] = true;
	
	char c = data[y][x];
	if(c=='_'){
		d = m ? 0 : 1;
	}else if( c == '|'){
		d = m ? 2 : 3;
	}else if( c == '?'){
		for(int i = 0 ; i < 4 ; i++){
			if( dfs(x+dx[i],y+dy[i],i,m) ) return 1;
		}		
		return 0;
	}else if(c == '.'){
		
	}else if(c == '@'){
		return 1;
	}else if('0' <= c && c <= '9'){
		m = c - '0';
	}else if(c == '+'){
		m = (m+1) % 16;
	}else if(c == '-'){
		m = (m+15) % 16;
	}else{
		d = chg(c);
	}
	return dfs(x+dx[d],y+dy[d],d,m);
}
int main(){
	cin >> H >> W;
	for(int i = 0 ; i < H; i++)
		for(int j = 0 ; j < W ; j++)
			cin >> data[i][j];
	cout << (dfs(0,0,1,0)?"YES":"NO") << endl;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<ctime>
#include<string.h>
using namespace std;
int dp[100010];
int l[100010];
int r[100010];
int main(){
	memset(dp,0,sizeof(dp));
	int n,m;
	cin>>n>>m;
	string s;
	cin>>s;
	for(int i=0;i<m;i++)cin>>l[i]>>r[i];
	for(int i=1;i<s.size();i++){
		if(s[i]=='C'&&s[i-1]=='A'){
			dp[i]=dp[i-1]+1;
		}
		else{
			dp[i]=dp[i-1];
		}
	}
	for(int i=0;i<m;i++){
		cout<<abs(dp[l[i]-1]-dp[r[i]-1])<<endl;
	}
	return 0;
}

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (2000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N),C(N);
  rep(i,N)cin >> A[i];
  rep(i,N)cin >> B[i];
  rep(i,N)cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));

  ll ans = 0;
  rep(i,N){
    //B[i]より小さいA[i]の個数と、より大きいC[i]の個数を調べます
    ll a,c,ok,ng;
    
    ok = -1;ng=N;
    while(ng-ok>1){
      int mid = (ok+ng)/2;
      if(A[mid]<B[i]){
        ok = mid;
      }else{
        ng = mid;
      }
    }
    a = ok+1;

    ok = N;ng=-1;
    while(ok-ng>1){
      int mid = (ok+ng)/2;
      if(C[mid]>B[i]){
        ok = mid;
      }else{
        ng = mid;
      }
      //cout << ok << " " << ng << endl;
    }
    c = N-ok;

    ans += a*c;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

struct type{int id,len;} x,y;
bool operator < (type a,type b) {return a.len>b.len;}

int n,i,j,k,l,Find,len;
char ask[129],a[129],st[63][129],ch;
priority_queue<type> heap;

int turn(char ch) {if (ch>='a' && ch<='z') return ch-'a'+1; if (ch>='A' && ch<='Z') return ch-'A'+27;return ch-'0'+53;}
void Ask()
{
	int i;
	
//	if (len==128)
//	{
//		Find=127;
//		return;
//	}
	
	printf("? ");
	fo(i,1,len) putchar(ask[i]);putchar('\n');
	fflush(stdout);
	scanf("%d",&Find);
}

void merge(int x,int y,int n,int m)
{
	int i,j,k,l,Len=0;
	
	j=1;
	fo(i,1,m)
	{
		if (j<=n)
		{
			do{
				a[++Len]=st[x][j];len=Len;
				memcpy(ask,a,Len+1);
				fo(k,i,m) ask[++len]=st[y][k];
				Ask();
				++j;
			}while (Find==(::n)-m-(j-1) && j<=n);
			
			if (Find!=(::n)-m-(j-1)) --j,--Len;
		}
		a[++Len]=st[y][i];
	}
	while (j<=n) a[++Len]=st[x][j++];
	
	memcpy(st[x],a,n+m+1);
}

int main()
{
	#ifdef file
	freopen("d.in","r",stdin);
	#endif
	
	len=128;
//	fo(ch,'a','c') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	fo(ch,'a','z') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	fo(ch,'A','Z') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	fo(ch,'0','9') {memset(ask,ch,129); Ask();n+=128-Find; if (Find<128) {memset(st[turn(ch)],ch,129-Find); heap.push({turn(ch),128-Find});}}
	
	while (heap.size()>1)
	{
		x=heap.top();heap.pop();
		y=heap.top();heap.pop();
		
		merge(x.id,y.id,x.len,y.len);
		heap.push({x.id,x.len+y.len});
	}
	
	x=heap.top();
	printf("! ");
	fo(i,1,x.len) putchar(st[x.id][i]);putchar('\n');
	fflush(stdout);
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

Measured memory_bytes: 3796
#include <iostream>

using namespace std;

int main(){
  int m, f, r;

  while(1){
    cin >> m >> f >> r;

    if(m == -1 && f == -1 && r == -1){ break; }
    else {
      if(m == -1 || f == -1 || m+f < 30){ cout << "F"; }
      else if(80 <= m+f){ cout << "A"; }
      else if(65 <= m+f && m+f < 80){ cout << "B"; }
      else if(50 <= m+f && m+f < 65){ cout << "C"; }
      else if(30 <= m+f && m+f < 50){
	if(r >= 50){ cout << "C"; }
	else { cout << "D";}
      }
      else { cout << "F"; }
    }
    cout << endl;
  }

  return 0;
}



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

int main() {
  ll L,R;
  cin >> L >> R;
  ll ans = 2019;
  for(int i=L;i<R && i<=L+2019;i++){
    for(int j=i+1;j<=R && j<=L+2019;j++){
      ll i0 = i%2019;
      ll j0 = j%2019;
      ll tmp = (i0*j0)%2019;
      if(ans > tmp){
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	ar := make([]int, n)
	for i := range ar {
		fmt.Scan(&ar[i])
	}
	sort.Ints(ar)
	ans := 0
	for i := 0; i < k; i++ {
		ans += ar[n-1-i]
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define All(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}



int main() {
    double N;
    cin >> N;
    //sort(ALL(A));
    printf("%lf\n",(N-((int)N/2))/N);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k,n,a[2][101],v,j,t=0,t1=0;
    char c[2][101];
    //char s[200];
    char ch;
    string s;
    cin>>n;
    
    for (int i=0; i<n; i++){
    	cin>>c[0][i]>>a[0][i];
    	c[1][i]=c[0][i];
    	a[1][i]=a[0][i];
	}
	for (int i=0; i<n; i++)
	   for (int j=n-1; j>=i+1; j--){
	   	   if (a[1][j]<a[1][j-1]){
	   	   	  v=a[1][j];
	   	   	  a[1][j]=a[1][j-1];
	   	   	  a[1][j-1]=v;
	   	   	  ch=c[1][j];
	   	   	  c[1][j]=c[1][j-1];
	   	   	  c[1][j-1]=ch;
			}
	   }
	cout<<c[1][0]<<a[1][0];
	for (int i=1; i<n; i++)
	    cout<<' '<<c[1][i]<<a[1][i];
	cout<<endl;
	cout<<"Stable"<<endl;
    for (int i=0; i<n; i++){
    	k=i;
    	for (int j=i+1; j<n; j++)
    		if (a[0][j]<a[0][k])
    		   k=j;
        if (a[0][k]<a[0][i]){
        	t++;
        	v=a[0][k];
        	a[0][k]=a[0][i];
        	a[0][i]=v;
        	ch=c[0][k];
        	c[0][k]=c[0][i];
        	c[0][i]=ch;
		}
	}
	cout<<c[0][0]<<a[0][0];
	for (int i=1; i<n; i++)
	    cout<<' '<<c[0][i]<<a[0][i];
	cout<<endl;
	int f=1;
	for (int i=0; i<n; i++){
		if (c[0][i]!=c[1][i]){
		    f=0;
		    cout<<"Not stable"<<endl;
		    break;
		}
	}
	if (f)
	   cout<<"Stable"<<endl;
    return 0;
} 


Measured memory_bytes: 3100
n,m = map(int,input().split())

AB = [list(map(int,input().split())) for _ in range(m)]

def search(UF,loc):
    if UF[loc] == loc:
        return UF[loc]
    else:
        UF[loc] = search(UF,UF[loc])
        return UF[loc]

import math

def Comb(a,b):#aCbを返す
    if a>= b:
        return int(math.factorial(a)/(math.factorial(b)*math.factorial(a-b)))
    else:
        return 0

UF = [_ for _ in range(n+1)]
size = [1]*(n+1)

Ans = [0]
for a,b in AB[::-1]:
    t1 = search(UF,a)
    t2 = search(UF,b)
    if t1 != t2:
        UF[max(t1,t2)] = min(t1,t2)
        Ans.append(Ans[-1]+size[max(t1,t2)]*size[min(t1,t2)])
        size[min(t1,t2)] += size[max(t1,t2)]
    else:
        UF[max(t1,t2)] = UF[min(t1,t2)]
        Ans.append(Ans[-1])
maxi = Comb(n,2)

for ans in Ans[-2::-1]:
        print(maxi-ans)

Measured memory_bytes: 37464
L,R = map(int,input().split())
 
ans = 2019
m = []
l = R-L+1
if l < 2019:
	for i in range(L,R+1):
		m.append(i%2019)
else:
	for i in range(L,L+2019):
		m.append(i%2019)

for i in range(len(m)):
	for j in range(i+1,len(m)):
		tmp = (m[i]*m[j])%2019
		if ans> tmp:
			ans = tmp
		if tmp == 0:
			break				
print(ans)

Measured memory_bytes: 3064
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1362",problemID = "B",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time,random
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    k = inp()
    a,b = invr()
    if a <= math.ceil(a / k) * k <= b:
        print("OK")
    else:
        print("NG")
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def log_two(n): 
    return(math.log(n) / math.log(2))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Measured memory_bytes: 76868
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace CsProgramSpace
{
    public partial class Pencil
    {

        partial class Program
        {
            static void Main(string[] args)
            {
                long x, y;
                long[] a = Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();
                x = a[0];y = a[1];
                long mod;
                if(x>y)
                {
                    while(true)
                    {
                        
                        mod = x % y;
                        if (mod == 0)
                        {
                            break;
                        }
                        x = y;
                        y = mod;
                    }
                }
                else
                {
                    long t;
                    t = x;
                    x = y;
                    y = t;
                    while (true)
                    {
                        mod = x % y;
                        if (mod == 0)
                        {
                            break;
                        }
                        x = y;
                        y = mod;
                    }
                }
                Console.WriteLine(y);
            }
        }
    }
}


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

const int INF = 1000000;

int main() {
	ll N;
	cin >> N;
	stack<ll> div;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			div.push(i);
			div.push(N / i);
		}
	}
	ll a, b;
	a = div.top(); div.pop();
	b = div.top();
	cout << a + b - 2;
}





Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.readline())

s = set()
for i in range(1, N):
    a = N - i
    b = i
    if a == b:
        continue
    s.add((max(a, b), min(a, b)))
a = len(s)
print(a)


Measured memory_bytes: 76752
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
#define ll long long
#define INF 1000000007
using P=pair<int,int>;
int main(){
    string n;
    cin>>n;
    char a,b;
    a=n[0];
    for(int i=1;i<4;i++){
        if(n[i]!=a)b=n[i];
    }
    int k=0,l=0;
    for(int i=0;i<4;i++){
        if(n[i]==a)k++;
        if(n[i]==b)l++;
    }
    if(k==2&&l==2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
#include<algorithm>
using namespace std;
const int inf=2147483647;
char s[5010],t[5010];
int n;
int p1[5010],p2[5010],n1,n2;
int res;
void work(char*s,char*t){
	int i,j,u;
	n1=0;
	for(i=0;i<=n;i++){
		if(s[i]!=s[i+1])p1[++n1]=i;
	}
	n2=0;
	if(s[1]!=t[1])p2[++n2]=0;
	for(i=0;i<=n;i++){
		if(t[i]!=t[i+1])p2[++n2]=i;
	}
	if(s[1]==t[n])p2[++n2]=n;
	for(i=1;i<=n2;i+=2){
		u=0;
		for(j=i;j>0;j--)u+=p2[j];
		if(n2-i<n1-1){
			for(j=2;j<=n1;j++)u+=abs(p1[j]-p2[min(n2,i+j-1)]);
		}else{
			for(j=1;j<=n2-i;j++)u+=abs(p1[min(n1,j+1)]-p2[i+j]);
		}
		res=min(res,u);
	}
}
int main(){
	scanf("%d%s%s",&n,s+1,t+1);
	s[0]=s[1]^1;
	s[n+1]=s[n]^1;
	t[0]=t[1]^1;
	t[n+1]=t[n]^1;
	res=inf;
	work(s,t);
	work(t,s);
	printf("%d",res);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<time.h>
#define pi acos(-1.0)
using namespace std;
int main()
{
//	long long begin_time=clock();
//	int t;
///	scanf("%d",&t);
//	while(t--)
	//{
		int n,i,j,flag=0,x=0,y=0,ma=0,mi=0x3f3f3f3f;
	//	char s[];
	//	int a[],b[];
	    scanf("%d",&n);
	    if(n%10==3)
	    printf("bon\n");
	    else if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
	    printf("hon\n");
	    else
	    printf("pon\n");
//	} 
//	long long end_time=clock();
//	printf("time=%lldms\n",end_time-begin_time);
}


Measured memory_bytes: 3764
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
cin>>n;
if(n==1){
    cout<<1<<"\n";
    cout<<0<<"\n";
    return 0;
}
if(n==2){
    cout<<2<<"\n";
    cout<<0<<"\n";
    cout<<11<<"\n";
    return 0;
}
V<string> s;
for(int i=2;i<=n;i++){
    string t(i,'0');
    t[0]='1';t[i-1]='1';
    s.emplace_back(t);
}
cout<<s.size()<<"\n";
for(int i=0;i<n-1;i++){
    cout<<s[i]<<"\n";
}
}


Measured memory_bytes: 3300
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,a,b;
    cin>>n>>a>>b;

    if(!a)
    {
        cout<<0;
        return;
    }

    int ans=(n/(a+b))*a;
    n%=(a+b);

    ans+=min(n,a);

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
#include<utility>
#include<list>
using namespace std;
using ll = long long;

int main(){
  string str;
  cin >> str;
  if(str[2]==str[3]&&str[4]==str[5])
    cout << "Yes";
  else
    cout << "No";
  return 0;
}

Measured memory_bytes: 256
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;


void solve(long long N){
    cout << N * N * N << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 36
 
int main(void){
  int n,i,j,min,k,f;
  char a[N][3],ba[N][3],ch[N][3],sw[1][4];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",a[i]);
  }
 
  for(i=0;i<n;i++){
    strcpy(ba[i],a[i]);
  }
  for(i=0;i<n;i++){
    strcpy(ch[i],a[i]);
  }
 
  //バブルソート開始
  for(i=0;i<n;i++){
    for(j=n-1;j>=i+1;j--){
      if(ba[j][1]<ba[j-1][1]){
    strncpy(sw[0],ba[j],3);
    strncpy(ba[j],ba[j-1],3);
    strncpy(ba[j-1],sw[0],3);
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%s",ba[i]);
    if(i!=n-1){
      printf(" ");
    }
  }
  printf("\n");
  //バブルソート終了
 
  //判定
    printf("Stable\n");
  //判定終了
 
 
  //選択ソート開始
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++)if(ch[j][1]<ch[min][1])min=j;
    if(min!=i){
      strncpy(sw[0],ch[min],3);
      strncpy(ch[min],ch[i],3);
      strncpy(ch[i],sw[0],3);
    }
  }
  for(i=0;i<n;i++){
    printf("%s",ch[i]);
    if(i!=n-1){
      printf(" ");
    }
  }
  printf("\n");
  //選択ソート終了
 
  //判定
  f=0;
  for(i=0;i<n;i++){
    if(ba[i][1]==ch[i][1]&&ba[i][0]!=ch[i][0]){
        printf("Not stable\n");
        f=1;
		break;
      }
    }
  if(f==0){
    printf("Stable\n");
  }
  //判定終了
 
  return 0;
   
}

Measured memory_bytes: 620
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  
  if(s.substr(0,n/2)==s.substr(n/2,n)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
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; }

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string n; cin >> n;
    if(n[0] == n[2]) cout << "Yes" << endl;
    else cout <<  "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
    //    #include <boost/multiprecision/cpp_int.hpp>
        #include<functional>
 //     #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define  mp make_pair
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

        class Point{
        	public:
        	double x,y;
        	Point(double x=0,double y=0):x(x),y(y) {}
        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
        	Point operator * (double a) {return Point(x*a,y*a);}
        	Point operator / (double a) {return Point(x/a,y/a);}
        	double absv() {return sqrt(norm());}
        	double norm() {return x*x+y*y;}
        	bool operator < (const Point &p) const{
        		return x != p.x ? x<p.x: y<p.y;
        	}
        	bool operator == (const Point &p) const{
        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
        	}
        };
        typedef Point Vector;

        struct Segment{
        Point p1,p2;
        };

    double hen(Vector a){
    if(fabs(a.x)<EPS && a.y>0) return acos(0);
    else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
    else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
    else if(fabs(a.y)<EPS && a.x>0) return 0.0;
    else if(a.y>0) return acos(a.x/a.absv());
    else return 2*acos(0)+acos(-a.x/a.absv());

    }

        double dot(Vector a,Vector b){
        	return a.x*b.x+a.y*b.y;
        }
        double cross(Vector a,Vector b){
        	return a.x*b.y-a.y*b.x;
        }
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------

int t[100002];

signed main(){
string s;
	cin>>s;
	for(int i=0;i<4;i++) cout<<s[i];
	cout<<" ";
	for(int i=4;i<12;i++) cout<<s[i];
	
	cout<<endl;
	
	return 0;
}

//printf("%.10f\n",ans);


Measured memory_bytes: 384