akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define vmax 10000
constexpr ll inf = 100000000000000;
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/

int main(){
  int n;
  cin>>n;
  if(n%2==0){
    cout<<n<<endl;
  }else{
    cout<<2*n<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N,A,B;
    cin>>N>>A>>B;
    if (N*A>B)
    {
        cout<<B;
    }
    else if(N*A<B)
    {
        cout<<N*A;
    }
    else if(N*A==B)
    {
        cout<<B;
    }
}

Measured memory_bytes: 3616
s = int(input())

def func(n):
    if n%2 == 0:
        return int(n / 2)
    else:
        return 3 * n + 1

a = [s]
i = 0
flg = 1
while(flg):
    a.append(func(a[i]))
    #print(a)
    for k in range(len(a)):
        for l in range(1, len(a)-k): 
            if a[k] == a[k+l]:
                print(k+l+1)
                flg = 0
                break
        if flg == 0:
            break
        
    i += 1

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    unsigned long long sum=0,n;
    cin>>n;
    for(long long i=1;i<n/2&&(n-i)/i>i;i++)
    {
        //printf("1\n");
        if((n-i)%i==0) sum+=(n-i)/i;
    }
    cout<<sum<<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++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int k;cin>>k;
  vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout<<vec[k-1]<<endl;
}

Measured memory_bytes: 3600
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[] rect=new int[2];
int[] circle=new int[3];
for(int i=0; i<rect.length+circle.length; i++){
if(i<2){
rect[i]=scan.nextInt();
}else{
circle[i-2]=scan.nextInt();
}
}
if(circle[0]<=0||circle[1]<=0||circle[0]-circle[2]<0||circle[1]-circle[2]<0){
System.out.println("No");
}
else if(circle[0]+circle[2]>rect[0]||circle[1]+circle[2]>rect[1]){
System.out.println("No");
}else{
System.out.println("Yes");
}
}
}  

Measured memory_bytes: 26300
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
typedef struct {
	int num,
		t;
}SPORT;
void sort(int, SPORT[]);
int main() {
	int n, m, s, i, j;
	SPORT d[100000];
	for (; ~fscanf(stdin, "%d", &n), n;P(d, d[0].num),P(d, d[1].num),P(d, d[n - 2].num)) {
		for (i = 0; i < n; i++) {
			fscanf(stdin, "%d", &d[i].num);
			j = 3;
			fscanf(stdin, "%d%d", &m, &s);
			d[i].t = m * 60 + s;
			while(j--) fscanf(stdin, "%d%d", &m, &s),d[i].t += m * 60 + s;
		}
		sort(n, d);
		
	}

	return 0;
}

void sort(int n, SPORT d[]){
	int i,j;
	SPORT tmp;
	for (i = 0; i < n - 1; i++)
		for (j = i + 1; j < n; j++)
			if (d[i].t > d[j].t) tmp = d[i], d[i] = d[j], d[j] = tmp;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
using namespace std;
long long s;
const long long t=1000000000LL;
int main()
{
	scanf("%lld",&s);
	printf("%lld 0 %lld %lld 0 %lld",s/t,s/t+(bool)(s%t),t,s%t);
	return 0;
}

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, D;
vector<int> v[10];

double dist(vector<int> &v1, vector<int> &v2)
{
    double ret = 0.;
    int d = v1.size();
    REP(i, d){
        double x = abs(v1[i] - v2[i]);
        ret += x*x;
    }
    return sqrt(ret);
}

void solve()
{
    int ans = 0;
    REP(i, N){
        FOR(j, i+1, N){
            double d = dist(v[i], v[j]);
            double df = floor(d);
            if(df == d) ans++;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> D;
    REP(i, N){
        REP(j, D){
            int x;
            cin >> x;
            v[i].pb(x);
        }
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
N = gets.chomp.to_i  #曲数
a, b = N.times.map{gets.split.map(&:to_s)}.transpose  #配列生成
S  = gets.chomp.to_s  #曲名

num = 0

while num < N do
  if a[num] == S then
    num = num + 1  #寝たのは次の曲から
    break;
  end
  num = num + 1
end

ans = 0
while num < N do
  ans = ans + (b[num]).to_i
  num = num + 1
end
puts ans

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


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

   /* AC x 10
   WA x 0
   TLE x 0
   RE x 0*/
   int op1 ,op2,op3,op4 ;
   op1 = op2 = op3 = op4 = 0;
    while(n --)
    {
        string s;
        cin>>s;

        if(s == "AC")
          op1++;
        else if(s == "WA")
          op2++;
        else if(s == "TLE")
          op3++;
        else if(s == "RE")
          op4++;
    }

    cout<<"AC x "<<op1;
    cout<<"\nWA x "<<op2;
    cout<<"\nTLE x "<<op3;
    cout<<"\nRE x "<<op4;
    
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int a,b;
	char c;
	cin >> a >> c >> b;
	if(c == '+'){
		cout << a + b << endl;
	}
	else if(c == '-'){
		cout << a - b << endl;
	}
	
	return 0;
}

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

void init(){

}

void solve(){
    int A[N], n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    A[0]--;
    for(int i = 1; i < n; i++){
        if(A[i] > A[i-1]) A[i]--;
        if(A[i] < A[i-1]){
            printf("No\n");
            return;
        }
    }
    printf("Yes\n");
}

int main(){
    int test_cases_number = 1;
//    scanf("%d", &test_cases_number);
    for(int i = 0; i < test_cases_number; i++)
        solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    	long long h1,h2,m1,m2,k,sum=0;
    	cin>>h1>>m1>>h2>>m2>>k;
    	if(m1-m2<=0)
    	sum=abs(h1-h2)*60;
    	else
    	sum=(abs(h1-h2)-1)*60;
      	if(h1>h2 && h1<24 && h2>=0){
          if(m1-m2<0)
          sum=abs(24*60-sum);
      else
        sum=abs(23*60-sum);
        }
		if(m1-m2<=0)
    	sum+=abs(m1-m2);
		else
		sum+=abs(60-(m1-m2));
     
    	cout<<sum-k<<endl;
      return(0);
    }

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  int A[N];
  int B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  int ans = 999999;
  for (int bit = 0; bit < (1 << N); bit++) {
    vector<int> U;
    bool T = true;
    for (int i = 1; i <= 50; i++) {
      int even = 0;
      int odd = 0;
      vector<int> e;
      vector<int> o;
      for (int j = 0; j < N; j++) {
        if ((1 << j) & bit) {
          if (A[j] == i) {
            if (j % 2 == 0) {
              even++;
              e.push_back(j);
            } else {
              odd++;
              o.push_back(j);
            }
          }
        } else {
          if (B[j] == i) {
            if (j % 2 == 0) {
              odd++;
              o.push_back(j);
            } else {
              even++;
              e.push_back(j);
            }
          }
        }
      }

      int sz = o.size() + e.size();
      if (U.size() % 2 == 0) {
        if (odd == even) {
          for (int i = 0; i < sz; i++) {
            if (i % 2 == 0) {
              U.push_back(e[i/2]);
            } else {
              U.push_back(o[i/2]);
            }
          }
        } else if (odd + 1 == even) {
          for (int i = 0; i < sz; i++) {
            if (i % 2 == 0) {
              U.push_back(e[i/2]);
            } else {
              U.push_back(o[i/2]);
            }
          }
        } else {
          T = false;
          break;
        }
      } else {
        if (odd == even) {
          for (int i = 0; i < sz; i++) {
            if (i % 2 == 0) {
              U.push_back(o[i/2]);
            } else {
              U.push_back(e[i/2]);
            }
          }
        } else if (odd == even + 1) {
          for (int i = 0; i < sz; i++) {
            if (i % 2 == 0) {
              U.push_back(o[i/2]);
            } else {
              U.push_back(e[i/2]);
            }
          }
        } else {
          T = false;
          break;
        }
      } 
    }
    
    if (T) {
      int res = 0;
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
          if (i < j && U[i] > U[j]) {
            res++;
          }
        }
      }
      ans = min(ans,res);
    }
  }

  if (ans == 999999) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v[x - 1] = i + 1;
    }
    for (auto&& x : v) {
        cout << x << " ";
    }
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
const ll mod = 1e9+7;

void dfs(vector<vector<int>>& adj, int src, vector<bool>& vis, stack<int>& st){
    vis[src]=true;
    for(auto j:adj[src]){
        if(!vis[j])dfs(adj, j, vis, st);
    }
    st.push(src);
}

void solve(){
    int n,m;cin>>n>>m;
    vector<vector<int>> adj(n);
    vector<int> in(n,0);
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        adj[x-1].push_back(y-1);
        in[y-1]++;
    }
    queue<int> st;
    vector<int> dist(n, -mod);
    for(int i=0;i<n;i++){
        if(in[i]==0){
            st.push(i);
            dist[i]=0;
        }
    }
    while(!st.empty()){
        int src = st.front();st.pop();
        for(auto j:adj[src]){
            if(dist[j]< dist[src]+1){
                dist[j]=dist[src]+1;
            }
            in[j]--;
            if(in[j]==0){
                st.push(j);
            }
        }
    }
    cout<<*max_element(dist.begin(), dist.end());
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input1.txt","r",stdin);
        freopen("output1.txt", "w", stdout);
    #endif
    int t;
    t=1;
    // cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 9408
//# define FLAG
///delet....................................
# include   <bits/stdc++.h>
using namespace std;
# define    pb                      push_back
# define    mp                      make_pair
# define    IOS                     ios::sync_with_stdio(false)
# define    mem(a,b)                memset(a,b,sizeof(a))
# define    FO(i,n,a)               for(int i=n; i>=a; --i)
# define    FOR(i,a,n)              for(int i=a; i<=n; ++i)
# define    MAX(a,b)                (a)>(b)?(a):(b)
# define    MIN(a,b)                (a)<(b)?(a):(b)
# define    lowbit(x)               ((x)&(-x))
# define    LINF                    0xfcfcfcfcfcfcfcf
# define    INF                     0x3f3f3f3f
# define    MOD                     1000000007
# define    eps                     0.00000001
# define    pi                      3.141592653
# define    ee                      2.718281828459
# define    hr                      ptc('\n')
# define    kb                      ptc(' ')
# define    bug                     puts("H");
# pragma    comment(linker,"/STACK:1024000000,1024000000")
typedef     pair<int,int>           PII;
typedef     vector<int>             VI;
typedef     long long               LL;
typedef     unsigned long long      ULL;
inline char gtc() {
    static char buf[100000],*p1=buf-1,*p2=buf-1;
    return p1==p2&&(p2=(p1=buf-1)+fread(buf,1,100000,stdin),p1==p2)?EOF:*++p1;
}
static char bufout[2000000],*chout=bufout-1;
inline void ptc(char ch) {
    *++chout=ch;
}
# define    Template                LL
inline Template read() {
    char ch=gtc();
    while(!(ch>='0'&&ch<='9'||ch=='-'))ch=gtc();
    Template sum=0,flag=(ch=='-'?(ch=gtc()):0);
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return flag?-sum:sum;
}
inline void out(Template x) {
    if(x<0)ptc('-'),x=-x;
    if(x>9)out(x/10);
    ptc(x%10+'0');
}
inline void write() {
    fwrite(bufout,1,chout-bufout+1,stdout);
}
///coding...................................

int main() {
    IOS;
#ifdef FLAG
    //freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    char a[1000];
    cin>>a;
    int len=strlen(a);
    for(int i=0;i<len-8;++i)cout<<a[i];
    return 0;
}










///delete FLAG..............................




Measured memory_bytes: 256
#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);
};

const lint BLimit = 10000;

bool solve(lint X, lint t, lint& out)
{
    lint y = X / t;
    lint k1 = 5, k2 = 10 * t, k3 = 10 * t * t, k4 = 5 * t * t * t;
    lint k5 = t * t * t * t;
    FOR(B, -BLimit, BLimit + 1) {
        lint term = k1 * B * B * B * B + k2 * B * B * B;
        term += k3 * B * B + k4 * B + k5;
        if (term == y) {
            out = B;
            return true;
        }
    }

    return false;
}

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

    // Actual program code starts here.
    int X;
    cin >> X;
    for (int t = 1;t <= X / t; t++)
        if (X % t == 0) {
            lint B;
            if (solve(X, t, B)) {
                cout << (B + t) << " " << B << endl;
                return 0;
            }
            if (solve(X, X / t, B)) {
                cout << (B + X / t) << " " << B << endl;
                return 0;
            }
        }

    return 0;
};


Measured memory_bytes: 3640
n,x,y=map(int,input().split())
ans=[0]*(n-1)
for i in range(1,n):
    for j in range(i+1,1+n):
        d=min(j-i,abs(x-i)+abs(y-j)+1)
        ans[d-1]+=1

for i in ans:
    print(i)

Measured memory_bytes: 46172
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
MOD = 1000000007
def POW(x, y): return pow(x, y, MOD)
def INV(x, m=MOD): return pow(x, m - 2, m)
def DIV(x, y, m=MOD): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL = LI()

res = INTMAX
for s in range(1, N):
    res = min(res,abs(sum(INL[:s])-sum(INL[s:])))
print(res)


Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

int main() {
	int N;
	long long ans;
	char S1[53], S2[53];
	int p[52], j;

	scanf("%d", &N);
	scanf("%s %s", S1, S2);
	
	j = 0;
	for (int i = 0; i < N; i++) {
		if (S1[i] == S1[i + 1]) {
			p[j] = 1; /*横*/
			j++; i++;
		}
		else {
			p[j] = 0; /*縦*/
			j++;
		}
	}

	ans = 1;
	for (int i = 0; i < j; i++) {
		if (i == 0 && p[i] == 0) { ans = 3; }
		if (i == 0 && p[i] == 1) { ans = 6; }
		if (i > 0 && p[i] == 0 && p[i - 1] == 0) { ans = (ans * 2) % 1000000007; }
		if (i > 0 && p[i] == 0 && p[i - 1] == 1) { ans = ans; }
		if (i > 0 && p[i] == 1 && p[i - 1] == 0) { ans = (ans * 2) % 1000000007; }
		if (i > 0 && p[i] == 1 && p[i - 1] == 1) { ans = (ans * 3) % 1000000007; }
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
import math

n = int(input())
arraya = list(map(int,input().split()))
numsa = [i+1 for i in range(n)]
arrayb = list(map(int,input().split()))
numsb = [i+1 for i in range(n)]

cnta = 1
for i in range(n):
  num = arraya[i]
  mae = numsa.index(num)
  ushiro = math.factorial(n-(i+1))
  cnta += mae*ushiro
  numsa.remove(num)
  
cntb = 1
for i in range(n):
  num = arrayb[i]
  mae = numsb.index(num)
  ushiro = math.factorial(n-(i+1))
  cntb += mae*ushiro
  numsb.remove(num)
  
print(abs(cnta-cntb))

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

signed main(void)
{
	long long n, m, ans;
	cin >> n >> m;
	m /= 2;
	ans = 0;
	ans = min(n, m);
	m -= ans;
	if (m > 0)
		ans += m / 2;
	cout << ans << endl;
	return 0;
}


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

void solve(stack<int> box[]){
    int x; cin >> x;
    switch(x){
        case 0:
            int t0, y; cin >> t0 >> y;
            box[t0].push(y);
            break;
        case 1:
            int t1; cin >> t1;
            if(!box[t1].empty()) cout << box[t1].top() << endl;
            break;
        case 2:
            int t2; cin >> t2;
            if(!box[t2].empty()) box[t2].pop();
            break;
        default: cout << "ERROR" << endl;
    }
}

int main(){
    int n, q; cin >> n >> q;
    stack<int> box[n];
    while(q--){
        solve(box);
    }
    return 0;
}


Measured memory_bytes: 4372
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <bitset>

using namespace std;

typedef long long LL;
typedef bitset<200002> BS;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	BS a, r;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		if (x) {
			a[i] = true;
		}
	}
	for (int i = n; i >= 1; --i) {
		bool c = a[i];
		for (int j = i + i; j <= n; j += i) {
			c ^= r[j];
		}
		r[i] = c;
	}
	vector<int> res;
	for (int i = 1; i <= n; ++i) {
		if (r[i]) {
			res.push_back(i);
		}
	}
	cout << res.size() << endl;
	if (res.size()) {
		for (int i = 0; i < (int)res.size(); ++i) {
			if (i) cout << " ";
			cout << res[i];
		}
		cout << endl;
	}
	return 0;
}	


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

const int INF = 1e9;
const int MAX_K = 1<<12;

struct P{
    int v,w;
    P(){}
    P(int v, int w):v(v),w(w){}
};
bool operator<(const P &a, const P &b){return a.w<b.w;}
P operator+(const P &a, const P &b){return {a.v+b.v,a.w+b.w};}
ostream &operator<<(ostream &os, const P &a){
    return os<<"("<<a.w<<","<<a.v<<")";
}

vector<P> S[MAX_K];

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin>>N;
    vector<P> nodes(N);
    rep(i,N){
        int v,w; cin>>v>>w;
        nodes[i] = P(v,w);
    }
    S[0].pb(P(0,0));
    int K = min(MAX_K,N+1);
    FOR(i,1,K-1){
        int p = i/2;
        for(P e:S[p]){
            S[i].pb(e);
            S[i].pb(e+nodes[i-1]);
        }
        sort(all(S[i]));
        int M = S[i].size();
        int m=1;
        FOR(j,1,M-1){
            if (S[i][m-1].v < S[i][j].v){
                S[i][m++] = S[i][j];
            }
        }
        S[i].erase(S[i].begin()+m, S[i].end());
    }
    // for(P e:nodes){
    //     cout<<e<<" ";
    // }cout<<endl;
    // rep(v,K){
    //     for(P e:S[v]){
    //         cout<<e<<" ";
    //     }cout<<endl;
    // }

    int Q; cin>>Q;
    while(Q--){
        int v,L; cin>>v>>L;
        vector<P> ps;
        ps.pb(P(0,0));
        while(v>=K){
            int M = ps.size();
            rep(i,M){
                ps.pb(ps[i]+nodes[v-1]);
            }
            v>>=1;
        }
        int ans=0;
        for(P e:ps){
            if (L<e.w) continue;
            auto itr = upper_bound(all(S[v]), P(0,L-e.w)); itr--;
            chmax(ans,e.v+itr->v);
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 91516
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 2019;

//繰り返し二乗法
ll ex(ll x,ll n){
    if(n==0)return 1;
    else if(n%2==1)return ex(x,n-1)*x%mod;
    else return ex(x*x%mod,n/2)%mod;
};

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int dp[n+1];
    dp[n] = 0;
    map<int,int> mp;
    ll ans = 0;
    for(int i = n-1; i >= 0; i--){
        dp[i] = dp[i+1]+(s[i]-'0')*ex(10,n-i-1);
        if(dp[i] < 0) dp[i] += mod;
        dp[i] %= mod;
    }
    for(int i = 0; i < n; i++) mp[dp[i]]++;

    for(auto p:mp){
        ans += p.second*(p.second-1)/2;
    }
    ans += mp[0];
    cout << ans << endl;
}

Measured memory_bytes: 4508
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,i;
	cin>>s;
	for(int t=0;;t++)
	{
		n=n+2;
		for(i=0;i<(s.size()-n)/2;i++)
		{
			if(s[i]!=s[i+(s.size()-n)/2])
			{
				//cout<<t<<" "<<i<<" "<<s[i]<<s[i+(s.size()-n)/2-1]<<endl;
				break;
			}
		}
		if(i==(s.size()-n)/2)
		{
			cout<<s.size()-n;
			return 0;
		}
	}
} 


Measured memory_bytes: 256
import sys
s = sys.stdin.read()
s = s.lower()
ans = [0] * 26
n = [chr(i) for i in range(97, 123)]
for i in range(len(s)):
    if s[i] in n:
        ans[n.index(s[i])] += 1

for i in range(len(ans)):
    print(n[i], ":", ans[i])


Measured memory_bytes: 5576
#include "bits/stdc++.h"
// #include <boost/multi_array.hpp>
// #include <boost/optional.hpp>
// #include <boost/range/irange.hpp>
// #include <boost/range/algorithm.hpp>
// #include <boost/range/adaptors.hpp>

// namespace adaptor = boost::adaptors;

using ll = long long;
using i64 = int64_t;

void Main()
{
   int N;
   int ans = 0;
   int ba = 0, bs = 0, ae = 0;
   std::string s;
   std::cin >> N;
   for (int i = 0; i < N; i++)
   {
      std::cin >> s;
      if (s[0] == 'B')
      {
         if (s[s.length() - 1] == 'A')
            ba++;
         else
            bs++;
      }
      else if (s[s.length() - 1] == 'A')
         ae++;
      for (int j = 0; j < s.length() - 1; j++)
      {
         if (s.compare(j, 2, "AB") == 0)
         {
            ans++;
         }
      }
   }
   if (ba != 0)
   {
      ans += ba - 1;
      if (ae != 0)
      {
         ae--;
         ans++;
      }
      if (bs != 0)
      {
         bs--;
         ans++;
      }
      ans += std::min(ae, bs);
   }
   else
      ans += std::min(ae, bs);
   std::cout << ans << std::endl;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	public void profit() {
		int num = sc.nextInt();
		int[] store = new int[num];
		for (int i = 0; i < num; i++) {
			store[i] = sc.nextInt();
		}
		
		int min = store[0];
		int max = -Integer.MAX_VALUE;
		
		for (int i = 1; i < num; i++) {
			max = Math.max(max, store[i] - min);
			min = Math.min(min, store[i]);
		}
		System.out.println(max);
	}

	
	
	public static void main(String[] args) {
		new Main().profit();
	}
}


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

typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  ll a;
  cin >> n >> m;
  priority_queue<ll> que;
  for (int i = 0; i < n; i++) {
    cin >> a;
    que.push(a);
  }
  for (int i = 0; i < m; i++) {
    a = que.top();
    que.pop();
    que.push(a/2);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += que.top();
    que.pop();
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;

#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vl p(a), q(b), r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    rep(i,x) r.push_back(p[i]);
    rep(i,y) r.push_back(q[i]);
    sort(r.rbegin(), r.rend());
    ll ans = 0;
    rep(i,x+y) ans += r[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6512
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        ans -= b
        AB.append(a+b)
    AB.sort()

    for i in range(N):
        if i % 2 == 0:
            ans += AB.pop()
        else:
            AB.pop()
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 46812
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = 1e18;
#define endl "\n"
#define fr first
#define sc second
#define f (i, L, R) for (int i = L; i < R; i++)
#define F(i, t) for (typeof(t.begin()) i = t.begin(); i != t.end(); i++)
void solve()
{
    char x;
    cin >> x;
    // cout << (int)x << endl;
    if (x > 96)
        cout << 'a' << endl;
    else
        cout << "A" << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  map<int,int>mp0,mp1;
  rep(i,0,n){
    ll a;cin>>a;
    if(i%2==0)mp0[a]++;
    else mp1[a]++;
  }

  priority_queue<P>pq0,pq1;
  map<int,int>::iterator i0=mp0.begin();
  map<int,int>::iterator i1=mp1.begin();
  for(;i0!=mp0.end();i0++){
    pq0.push(make_pair(i0->second,i0->first));
  }
  for(;i1!=mp1.end();i1++){
    pq1.push(make_pair(i1->second,i1->first));
  }

  P t0=pq0.top();pq0.pop();
  P t1=pq1.top();pq1.pop();
  int ans=0;
  if(t0.second!=t1.second)ans+=(n/2-t0.first)+(n/2-t1.first);
  else{
    int next0=pq0.top().first,next1=pq1.top().first;
    int res1=(n/2-t0.first)+(n/2-(pq1.empty()?0:next1));
    int res2=(n/2-(pq0.empty()?0:next0))+(n/2-t1.first);
    ans=min(res1,res2);
  }

  out(ans);

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	int n, fir, sec, res = 0;
	cin >> n;
	list<vector<int>> red;
	list<vector<int>> blue;
	for ( int i = 0 ; i < n ; i++ ){
		cin >> fir >> sec;
		red.push_back({0, fir, sec});
	}
	red.sort();
	for ( int i = 0 ; i < n ; i++ ){
		cin >> fir >> sec;
		blue.push_back({0, fir, sec});
	}
	while ( ! blue.empty() ){
		for ( auto it = red.begin() ; it != red.end() ; it++ ) {
			(*it)[0] = 0;	
		}
		for ( auto itb = blue.begin() ; itb != blue.end() ; itb++ ) {
			(*itb)[0] = 0;
			for ( auto itr = red.begin() ; itr != red.end() ; itr++ ) {
				if ( (*itr)[1] < (*itb)[1] && (*itr)[2] < (*itb)[2] ){
					(*itr)[0]++;
					(*itb)[0]++;
				}
			}
		}
		red.sort();
		blue.sort();
		vector<int> b = blue.front();
		blue.pop_front();
		if ( b[0] > 0 ){
			res++;
			auto it = red.begin();
			while ( !((*it)[1] < b[1] && (*it)[2] < b[2]) )
				it++;
			red.erase(it);
		}
	}
	cout << res << "\n";

	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n,&s)

	ss := strings.Split(s,"")

	tmp := ""
	count := 0
	for _,s := range ss {
		if s == tmp {
			continue
		} else {
			tmp = s
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 2944
#include <stdio.h>
int main(){    
int i, n;    
int arr[100];    
scanf("%d", &n);    
for(i=0;i<n;i++){        
scanf(" %d", &arr[i]);    }   
 for(i=0;i<n;i++){       
 if(i)printf(" ");        
printf("%d", arr[n-i-1]);    }    
printf("\n");    
return 0;
}


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

int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = min(abs(n % k - k), n % k);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

#define repAll(n) (n).begin(), (n).end()
#define repConAll(n) (n).cbegin(), (n).cend()

using namespace std;

namespace {
	const set<int> setStandard{ 3, 5, 7 };
}

int DFS(long long tmpN, set<int>numbers, int N)
{
	if (tmpN > N){
		return 0;
	}
	int countAll = 0;
	if (numbers == setStandard){
		countAll = 1;
	}
	
	for (const auto elem : setStandard){
		set<int> numbers2(numbers);
		numbers2.insert(elem);
		countAll += DFS(tmpN * 10 + elem, numbers2, N);
	}

	return countAll;
}

int Work5_core(int N)
{
	set<int> numbers;
	return DFS(0, numbers, N);
}

int main()
{
	int N(0);
	cin >> N;

	int result = Work5_core(N);

	cout << result;

	return 0;
}

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

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

  int s = 0;
  for (auto c : x) {
    if (c == 'S')
      ++s;
    if (c == 'T' && s > 0)
      --s;
  }

  cout << 2 * s << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL );
  ll h,w,m;
  cin>>h>>w>>m;
  ll arr1[h+1]={0},arr2[w+1]={0};

  map<pair<ll,ll>,ll> mp3;
  for(ll i=0;i<m;i++)
  {
    ll a,b;
    cin>>a>>b;
    arr1[a]++;
    arr2[b]++;
    mp3[{a,b}]++;
  }
  ll ans1=INT_MIN,x,y,ans2=INT_MIN,sum=0;
  for(int i=1;i<=h;i++)
  {
    ans1=max(ans1,arr1[i]);
  }
  for(int j=1;j<=w;j++)
  {
    ans2=max(ans2,arr2[j]);
  }
  vector<ll> v1,v2;
  for(int i=1;i<=h;i++)
  {
    if(ans1==arr1[i])
    {
      v1.pb(i);
    }
  }
  for(int i=1;i<=w;i++)
  {
    if(ans2==arr2[i])
    {
      v2.pb(i);
    }
  }
  ll ans=INT_MIN,flag=0;
  for(int i=0;i<v1.size();i++)
  {
    for(int j=0;j<v2.size();j++)
    {
      sum=0;
      if(!mp3[{v1[i],v2[j]}])
      {
        sum+=arr1[v1[i]]+arr2[v2[j]];
        ans=max(ans,sum);
        flag=1;
        break;
      }
      sum+=arr1[v1[i]]+arr2[v2[j]]-mp3[{v1[i],v2[j]}];
      ans=max(ans,sum);
    }
    if(flag)
    break;
  }
  cout<<ans<<endl;
}


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

int main()
{   
    int n,l;
    cin>>n>>l;
    vector <string> s(n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++)
    {
        cout<<s[i];
    }   
    
    return 0;
}

Measured memory_bytes: 256
S = str(input())
S_list = [i for i in S]
target = ["0", "1"]

an1 = []
an2 = []

an1_suu = 0
an2_suu = 0

for j in range(len(S_list)):
    if j % 2 == 0:
        an1.append(target[0])
        an2.append(target[1])
    else:
        an1.append(target[1])
        an2.append(target[0])
    if S_list[j] == an1[j]:
        an1_suu += 1
    elif S_list[j] == an2[j]:
        an2_suu += 1
        
print(min(an1_suu, an2_suu))

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

using namespace std;

typedef long long ll;

#define p(x) cout << x << endl
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    vector<string> ss(n);
    rep(i, n) {
        cin >> ss.at(i);
        sort(all(ss.at(i)));
    }

    map<string, int> sm;
    rep(i, n) { sm[ss.at(i)]++; }

    ll count = 0;
    for(auto i = sm.begin(); i != sm.end(); ++i) {
        ll j = i->second;
        count += j * (j - 1) / 2;
    };

    p(count);
    return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,a,b) for(i=(int)a;i<(int)b;i++)
#define revloop(i,a,b) for(i=(int)a;i>=(int)b;i--)
#define stloop(it,v) for(it=v.begin();it!=v.end();++it)
#define ii pair<int,string>
#define MP make_pair
#define pb push_back
#define ll long long int
#define fill(v,d) memset(v,d,sizeof(v))
#define INF 0x3f3f3f3f
ll readli()
{
    register char c;
    for(c=getchar(); !(c>='0' && c<='9'); c=getchar());
    register long a=c-'0';
    for(c=getchar(); c>='0' && c<='9'; c=getchar())
        a=(a<<3)+(a<<1)+c-'0';
    return a;
}
template<class R,class E>
R find(R first,R last,const E& value)
{
  while(first!=last && *first!=value) first++;
  return first;
}
int main()
{  std::ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   string a;
   int i,ans=0;
   cin>>a;
   loop(i,0,a.length()-1)
   {
     if(a.at(i)!=a.at(i+1))
      ans++;
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 512
/*
C++ ???????????????????????????????????¬??????
??????AOJ-ITP1??????????????????
*/
#define _USE_MATH_DEFINES

#include <iostream> // ?¨??????\??????
#include <fstream>  // ??????????????\??????
#include <string>   // ???????????¢???
#include <vector>   // ???????????????
#include <cmath>    // ??°??????
#include <iomanip>  // stream???????????¢???
#include <algorithm>// max??¢??°??????

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;        // ????´???°????????????????????????
using std::fixed;         // ???????????????????¨???????????????????????????????
using std::setprecision;  // ?????°????°???°?????\???????????°????????????????????¨????????\???

int main() {
	int num;
	vector<int> stack;
	while (cin >> num)
	{
		if (num == 0)
		{
			// ??????????????????????????????????¶????
			cout << stack.back() << endl;
			stack.pop_back();
			continue;
		}
		// ???????????????????????°????????\??????
		stack.push_back(num);
	}
	return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}


int main() {
	ll N;
	cin >> N;

	vector<bool> B(2 * N);
	rep(i, 2 * N) {
		char c; cin >> c;
		if (c == 'B') {
			B[i] = true;
		}
		else {
			B[i] = false;
		}
	}

	ll rem = 0;
	ll ans = 1;

	rep(i, 2 * N) {
		// 前のを使用する場合
		if ((B[i] && rem % 2 == 1) ||
			(!B[i] && rem % 2 == 0)) {
			if (rem == 0) {
				cout << 0 << endl;
				return 0;
			}
			ans *= rem;
			ans %= mod;
			rem--;
		}
		// 後回しにする場合
		else {
			rem++;
		}
	}

	if (rem > 0) {
		ans = 0;
		cout << ans << endl;
		return 0;
	}

	rep(i, N) {
		ans *= (i + 1);
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main
{
    public static void main(String[] argv)
    {
        int W=0,H=0,x=0,y=0;
        try
        {
            BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
            String[] d=bf.readLine().split(" ");
            W=Integer.parseInt(d[0]);
            H=Integer.parseInt(d[1]);
            x=Integer.parseInt(d[2]);
            y=Integer.parseInt(d[3]);
        }
        catch (IOException e)
        {
            System.out.println(e);
            System.exit(0);
        }
            
            System.out.printf("%f",(double)W*H/2);
            if(2*x==W && 2*y==H)
            {
                System.out.println(" 1");
            }
            else
            {
                System.out.println(" 0");
            }
        
    }
}


Measured memory_bytes: 21204
#include<cstdio>

int N, element;

bool isPrime(int num){
	if(num <= 0) return false;
	if(num == 1) return false;
	if(num == 2) return true;
	if(num % 2 == 0) return false;
	for(int i = 2; i * i <= num; i++){
		if(num % i == 0) return false;
	}
	return true;
}

int main(void){
	scanf("%d", &N);
	int ans = 0;
	for(int i = 1; i <= N; i++){
		scanf("%d", &element);
		if(isPrime(element) == true){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2668
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val K = sc.next().toInt()
        val A = IntArray(N) { sc.next().toInt() }
        var As = IntArray(N + 1)
        var Ae = IntArray(N + 1)
        for (i in 0 until N) {
            As[max(0, i - A[i])]++
            Ae[min(N, i + A[i] + 1)]++
        }
        repeat(K - 1) {
            val As2 = IntArray(N + 1)
            val Ae2 = IntArray(N + 1)
            var c = 0
            for (i in 0 until N) {
                c = c + As[i] - Ae[i]
                val s = max(0, i - c)
                val e = min(N, i + c + 1)
                As2[s]++
                Ae2[e]++
            }
            As = As2
            Ae = Ae2
            if (As[0] == N && Ae[N] == N) {
                pw.println(Array(N) { N }.joinToString(" "))
                return
            }
            //dprint(As)
            //dprint(Ae)
        }

        val ans = IntArray(N)
        var c = 0
        for (i in 0 until N) {
            c = c + As[i] - Ae[i]
            ans[i] = c
        }
        pw.println(ans.joinToString(" "))
    }
}


Measured memory_bytes: 98008
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

constexpr int INFI = 1145141919;

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

    int K, N;
    std::cin >> K >> N;

    std::vector<int> A;
    for(int i=0; i<N; i++){
        int buf;
        std::cin >> buf;
        A.push_back(buf);
    }

    std::vector<int> distance;
    for(int i=0; i<N-1; i++){
        int buf = A.at(i+1) - A.at(i);
        distance.push_back(buf);
    }
    distance.push_back(K-(A.back()-A.front()));

    std::sort(distance.begin(), distance.end());

    std::cout << K - distance.back();

    return 0;
}


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

int main(){
	int n;
  	cin>>n;
  	vector<string> v;
  	for(int i=0;i<n;i++){
    	string s;
      	cin>>s;
      	v.push_back(s);
    }
  	sort(v.begin(), v.end());
  	
  	long long int cnt=1;
  	for(int i=1;i<n;i++){
    	if(v[i-1]!=v[i]){
        	cnt++;
        }
    }
  	cout<<cnt<<endl;
}

Measured memory_bytes: 11656
//============================================================================
// Name        : あｂｃ59ｃ.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	vector<long long> B(N);
	long long count1 = 0;
	long long count2 = 0;

	for(int i= 0; i < N; ++i){
		cin >> A[i];
	}

	if(A[0] <= 0){
		B[0] = 1;
		count1 = abs(A[0]) + 1;
	}
	else if(0 < A[0]){
		B[0] = A[0];
	}
	for(int i = 1; i < N; ++i){
		B[i] = A[i] + B[i - 1];
		if(i % 2 == 1 && 0 <= B[i]){
			count1 += abs(B[i]) + 1;
			B[i] = -1;
		}
		else if(i % 2 == 0 && B[i] <= 0){
			count1 += abs(B[i]) + 1;
			B[i] = 1;
		}
	}

	if(0 <= A[0]){
		B[0] = -1;
		count2 = abs(A[0]) + 1;
	}
	else{
		B[0] = A[0];
	}
	for(int i = 1; i < N; ++i){
		B[i] = A[i] + B[i - 1];
		if(i % 2 == 0 && 0 <= B[i]){
			count2 += abs(B[i]) + 1;
			B[i] = -1;
		}
		else if(i % 2 == 1 && B[i] <= 0){
			count2 += abs(B[i]) + 1;
			B[i] = 1;
		}
	}

	cout << min(count1, count2) << endl;

	return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;


int main() {
  long long  N, M;
  //vector<long long> a;
  const long long mod = 1000000007;
  
  cin >> N >> M;
  vector<long long> dp(N+1, 1); // dp[0]=1, dp[1]=1
  rep(i, M) {
      int tmp;
      cin >> tmp;
      //a.push_back(tmp);
      dp[tmp] = 0; // 壊れた床を0
  }

  for(int i=2; i<N+1; i++) {
      if(dp[i]>0) {
          dp[i] = (dp[i-1] + dp[i-2])%mod;
      }
  }

  cout << dp[N] << endl;
  
  return 0;
}



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

int main()
{
    int N ,K,front;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N;i++)
    {
        cin >> A.at(i);
    }

    for (int i = K; i < N; i++)
    {
        front = A.at(i - K);
        if (front < A.at(i))
        {
            cout << "Yes" << endl;
        }else
        {
            cout << "No" << endl;
        }
    }
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,c;
    cin >> a >> b >> c;
    if((a == b && b != c) || (b == c && c != a) || (a == c && c != b)){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
    return 0;
}



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

int main(){
  int n, k;
  cin >> n >> k;
  queue<int> que;
  int ans=0, nans=0;
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    que.push(x);
    if(i<k){
      ans += x+1;
      nans += x+1;
    }
    if(i>=k){
      nans += x+1;
      nans -= que.front() +1;
      ans = max(ans,nans);
      que.pop();
    }
  }
  double aans = ans;
  aans /= 2;
  printf("%.10f\n",aans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 1000005;

int prime[sze];
vi fact[sze];
map<int,int> mp;

void seive(){
    for(int i=0;i<sze;i++) prime[i]=i;
    for(int i=2;i*i<sze;i++){
        if(prime[i]==i){
            for(int j=i*i;j<sze;j+=i){
                if(prime[j]==j) prime[j]=i;
            }
        }
    }
}

void factor(){
    for(int i=2;i<=1000000;i++){
        int temp=i;
        while(temp!=1){
            fact[i].pb(prime[temp]);
            int x=prime[temp];
            temp=temp/x;
            while(temp%x==0) temp=temp/x;
        }
    }
}

void solve() {
    int n;
    cin>>n;
    int arr[n];
    int flag=1;
    int gcd=0;
    rep(i,n){
        cin>>arr[i];
        gcd=__gcd(gcd,arr[i]);
        if(arr[i]==1) continue;
        for(auto x:fact[arr[i]]) {
            //cout<<x<<" ";
            if(x==1) continue;
            if(mp[x]==0) mp[x]=1;
            else flag=0;
           
        }
       
    }
    if(flag==1){
        cout<<"pairwise coprime\n";
    }else if(gcd==1){
        cout<<"setwise coprime\n";
    }else
    {
        cout<<"not coprime\n";
    }
    
}

int main() {
    IOS;
    seive();
    factor();
    int t = 1;
    // cin >> t;
    while (t--) {
       solve();
    }

  return 0;
}


Measured memory_bytes: 70404
#include<stdio.h>

int SelectionSort(int a[],int n){
  int i, j, minj, v, cw = 0;
  for( i = 0; i < n - 1; i++){
    minj = i;
    for( j = i; j < n; j++){
      if (a[j] < a[minj])minj = j;
    }
    v = a[i]; a[i] = a[minj]; a[minj] = v;
    if ( i != minj ) cw++;
  }
  
  for( i = 0; i < n; i++){
    if (i > 0)
      printf(" ");
    printf("%d",a[i]);
  }
  
  printf("\n%d\n",cw);
  return 0;
}

int main(){
  int n, i;
  int a[100];
  
  scanf("%d", &n);
  for( i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  SelectionSort(a, n);
  
  return 0;
}

Measured memory_bytes: 1852
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(){
	int  n;// ????????????????????°
	int  i;// ??????????????????
	int  no; // ???????????????
	int  t;// ???????????????????????????
	char mark; // S,H,C,D?????????????¨????
	int mk;// 0,1,2,3??????????????????????????????
	char mks[]={"SHCD"}; // ??????????¨??????¨
	int  cards[4][13]={0}; // ???????????????

	scanf("%d%*c",&n);


	for(i=1;i<=n;i++){
		scanf("%c%d%*c",&mark,&no);
		t = no -1;
		mk= strchr(mks,mark)-mks;
		cards[mk][t] = 1;
	}
// ?¶????????????????????????¨???
	for(mk=0;mk<4;mk++){
		for(i=0;i<13;i++){
			if(cards[mk][i] == 0){
			printf("%c %d\n",mks[mk],i+1);
			}
		}
	
	}

	return 0;
}

Measured memory_bytes: 600