akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  int T[N], tot = 0; 
  rep(i,N) cin >> T[i], tot+=T[i];
  int M; cin >> M;
  int P[M], X[M]; rep(i,M) cin >> P[i] >> X[i];

  rep(i,M){
    cout << tot-T[P[i]-1]+X[i] << endl;
  }
  

  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
 int main (){
     int x,y,i = 0;
     while(i++<10000){
         cin >> x >> y;
         if (x == 0 && y == 0){
             return 0;
         }else{
             if (x <= y){
                 cout << x <<" " << y << endl;
             }else{
                 cout << y <<" " << x << endl;
             }
         }
     }
 }


Measured memory_bytes: 2992
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n;
set<ll> st;

void f(ll x){
	if(x<=1) return;
	ll N=n;
	while(N%x==0) N/=x;
	if(N%x==1) st.insert(x);
}

int main(){
	cin>>n;
	for(ll i=1;i*i<=n;i++) if(n%i==0){
		f(i);
		if(i*i!=n) f(n/i);
	}
	for(ll i=1;i*i<=n-1;i++) if((n-1)%i==0){
		f(i);
		if(i*i!=n-1) f((n-1)/i);
	}
	cout<<st.size()<<endl;
}

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

const ll INF = 1e17;

int main() {
    ll n, x, ans = 5, bn = INF;
    cin >> n;

    for (int i = 0; i < 5; i++) {
        cin >> x;
        bn = min(bn, x);
    }

    if (bn < n) {
        ans = ans + ((n - 1) / bn);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        N_fact = factorization(N)
        ans = 0
        for i in range(len(N_fact)):
            Ni =  N_fact[i][1]
            ans = ans + int((-1 + math.sqrt(1 + 8 * Ni)) / 2)
        print(ans)
resolve()

Measured memory_bytes: 9524
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S;
  cin >> S;
  int ans = 0;
  int cnt = 0; // 0+方向, 1-方向
  for (int i = 0; i < S.length(); i++) {
    if (S[i]=='0' && cnt < 0) {
      cnt++; // delete
      ans++;
    } else if (S[i]=='1' && cnt > 0) {
      cnt--; // delete
      ans++;
    } else {
      if (S[i]=='0') cnt++;
      if (S[i]=='1') cnt--;
    }
  }
  cout << ans*2 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010], z[200010];
int main(){
  int n;
  while(cin>>n){
    for(int i=0; i<n; ++i){
      cin>>a[i];
      if(i==0){
        if(a[i]==0)
          z[i]=n-1-i;
        else
          z[i]=-1;
      }
      else{
        if(a[i]==0)
          z[i]=n-1-i;
        else
          z[i]=z[i-1];
      }
    }
    reverse(a, a+n);
    reverse(z, z+n);
    ll ans=0, tmp=n;
    a[n]=(1e9) + 100;
    for(int i=0; i<n; ++i){
      if(i+a[i] >= n){
        ans=-1;
        break;
      }
      else{
        if(i-tmp != a[tmp] - a[i]){
          if(a[tmp]- (i-tmp) > a[i] && tmp!=n){
            ans=-1;
            break;
          }
          tmp=i;
          ans+=a[i];
        }
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}




Measured memory_bytes: 1792
import java.util.Scanner;

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

		String firstChar = String.valueOf(s.charAt(0));
		String lengthChar = String.valueOf(s.length() - 2);
		String lastChar = String.valueOf(s.charAt(s.length() - 1));

		// 出力
		System.out.println(firstChar + lengthChar + lastChar);

		sc.close();
	}
}


Measured memory_bytes: 22612
n,k=map(int,input().split())
l=[]
for i  in range(n):
    l.append(i+1)
for i in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for z in a:
        if z in l:
            l.remove(z)
print(len(l))

Measured memory_bytes: 9128
import numpy as np
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    sumcum_odd = 0
    sumcum_even = 0
    ans_odd = 0
    ans_even = 0
    for i in range(n):
        if i%2 ==0:#odd
            if sumcum_odd + a[i] >0:
                sumcum_odd += a[i]
            elif sumcum_odd <=0:
                ans_odd += 1-1*(sumcum_odd+a[i])
                sumcum_odd = 1
            if sumcum_even + a[i] <0:
                sumcum_even += a[i]
            elif sumcum_even >= 0:
                ans_even += sumcum_even + a[i] +1
                sumcum_even = -1
        else:
            if sumcum_odd + a[i] <0:
                sumcum_odd += a[i]
            elif sumcum_odd >=0:
                ans_odd += sumcum_odd + a[i] +1
                sumcum_odd = -1
            if sumcum_even + a[i] >0:
                sumcum_even += a[i]
            elif sumcum_even <= 0:
                ans_even += 1-1*(sumcum_even+a[i])
                sumcum_even = 1
    print(min(ans_odd,ans_even))



if __name__ == '__main__':
    main()

Measured memory_bytes: 23272
#include <stdio.h>
int main(void)
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a==5){
    if((b==7 && c==5)||(b==5 && c==7))
      printf("YES\n");
    else
      printf("NO\n");
}else if(a==7){
    if((b==5 && c==5))
      printf("YES\n");
    else
      printf("NO\n");}
  return 0;

}

Measured memory_bytes: 1624
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve(){

}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t = 1;
    cin >> t;
    while(t--){
       solve();
    }*/
    ll n;cin>>n;
    vll a(n);
    vll s(n,0);
    forn(i,n){
        cin >> a[i];
    }
    s[0] = a[0];
    fore(i,1,n-1){
        s[i] = s[i-1]+a[i];
    }
    ll ans=ll(2e9);
    fore(i,1,n-1){
        ans = min(ans,abs(s[i] - (s[n-1]-s[i])));
    }
    cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  string s, t;
  cin >> s >> t;
  int n = s.size();

  vector<vector<int>> a(26, vector<int>(0));
  set<vector<int>> h;

  for (int i = 0; i < n; i++){
    a[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; i++){
    h.insert(a[i]);
  }


  vector<vector<int>> b(26, vector<int>(0));
  set<vector<int>> g;
  
  for (int i = 0; i < n; i++){
    b[t[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < 26; i++){
    g.insert(b[i]);
  }
  if (h == g){
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
    
  

  return 0;
}



Measured memory_bytes: 4488
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MAX 100000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  string s[110000];
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  sort(s,s+N);
  ll hantei=1,ans=0;
  for(int i=1;i<N;i++){
    if(s[i]==s[i-1]){
      ans+=hantei;
      hantei++;
    }else hantei=1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2816
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nrl=arr.shift().split(" ").map(Number);
var n=nrl[0];
var L=nrl[2];
var t=[];
var max=[0,0];
var time=0;
for(var i=0;i<n;i++)t[i]=[0,0,i];
arr.push([1,L,0].join(" "));
arr.forEach(function(v){
   v=v.split(" ").map(Number);
   var d=v[0]-1;
   var T=v[1];
   var x=v[2];
   t[max[0]][1]+=T-time;
   time=T;
   t[d][0]+=x;
   if(x>0){
      if(t[d][0]>max[1])max=[d,t[d][0]];
      else if(t[d][0]==max[1] && d<=max[0])max=[d,t[d][0]];
   }
   else if(x<0 && max[0]==d){
      var MAX=0;
      var m=0;
      t.forEach(function(V,index){
         if(MAX<V[0])m=index;
      });
      max=[m,t[m][0]];
   }
});
t.sort(function(a,b){
   if(a[1]==b[1])return a[2]-b[2];
   else return b[1]-a[1];
});
console.log(t[0][2]+1);

Measured memory_bytes: 126960
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
LL a,b;
string c,d;
int main()
{
	scanf("%lld%lld",&a,&b);
	for(int i=1;i<=a;i++)
		d+=(char)(b+'0');
	for(int i=1;i<=b;i++)
		c+=(char)(a+'0');
	if(a<b)
		cout<<c<<endl;
	else
		cout<<d<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"


func main(){
  var a string
  fmt.Scan(&a)
  str:=output_konaboard(a)
  for i:=0; i<len(str); i++{
    fmt.Printf(str[i])
  }
  fmt.Printf("\n");
}

func output_konaboard(str string) []string{
  out := make([]string, 10)
  var pointer = 0
  for i:=0; i<len(str); i++{
    tmp := str[i:i+1]
    if tmp=="0" {
      out[pointer] = "0"
      pointer++
    }else if tmp=="1" {
      out[pointer] ="1"
      pointer++
    }else if tmp=="B" {
      if pointer > 0 {
        pointer--
      }
    }
  }
  return out[0:pointer]
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int W, H;
string mat[10][20];
int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<string> strs;
int oi, oj;

void dfs(int i, int j, int k, string str){
	int ni = (i+dx[k]+H)%H; int nj = (j+dy[k]+W)%W;
	if(ni == oi && nj == oj) { strs.push_back(str); return; }
	str.append(mat[ni][nj]);	
	dfs(ni, nj, k, str);
	return;
}

int main(){
	while(cin >> H >> W and W + H){
		strs.clear();
		REP(i, H) {
			string str;
			cin >> str;
			REP(j, W) mat[i][j] = string(&str[j], 1);
		}
		REP(i, H) REP(j, W) REP(k, 8){
			oi = i; oj = j;
			dfs(i, j, k, mat[i][j]);
		}
		sort(ALL(strs));
		int rcnt = 0;
		string res;
		REP(i, strs.size()-1){
			int cnt = 0;
			REP(j, min(strs[i].size(), strs[i+1].size())){
				if(strs[i][j] != strs[i+1][j]) break;
				cnt++;
			}
			if(cnt > rcnt) { rcnt = cnt; res = strs[i].substr(0, rcnt); }
		}
		if(rcnt < 2) cout << "0" << endl;
		else cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll n, x;
vector<ll> a = {1}, b = {1};

ll solve(ll N, ll X){
    if(N == 0) return (X <= 0 ? 0 : 1);
    else if(X <= 1 + a[N-1]) return solve(N-1, X-1);
    else return 1 + b[N-1] + solve(N-1, X-2-a[N-1]);
}

int main() {
    cin >> n >> x;
    rep(i, n){
        a.push_back(a[i] * 2 + 3);
        b.push_back(b[i] * 2 + 1);
    }
    cout << solve(n, x) << endl;
}

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

int n;
int ar1[20] = {};
int ar2[20] = {};


int func(int x){
	int val;
	int cnt = 0;;
	for(int i = 0; i < n; i++){
		if(ar1[i] == x){
			cnt++;
		}
	}
	val = cnt;
	return val;
}


int main(){
	while(cin >> n, n){
		for(int i = 0; i < n; i++){
			cin >> ar1[i]; 
		}
		int all_cnt = 0;
		while(1){
			for(int i = 0; i < n; i++){
				ar2[i] = func(ar1[i]);		
			}

			bool flag = true;
			for(int i = 0; i < n; i++){
				if(ar1[i] != ar2[i]){
					flag = false;
				}
			}
			if(flag == true) {
				cout << all_cnt << endl;
				for(int i = 0; i < n; i++){
					cout << ar2[i];
					if(i != n-1){
						cout << " ";
					}
				}
				cout << endl;
				break;
			}else{
				all_cnt++;
				for(int i = 0; i < n; i++){
					ar1[i] = ar2[i];
				}
				continue;
			}
		}
	}
}

Measured memory_bytes: 1160
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
rc = [[0] * W for _ in range(H)]
for i in range(H):
    j = 0
    for k in range(W):
        if S[i][k] == '#':
            j = k + 1
        else:
            rc[i][j] += 1
    j = 0
    while j < W:
        rc0 = rc[i][j]
        if rc0 < 2:
            j += 1
            continue
        for k in range(j, j + rc0):
            rc[i][k] = rc0
        j += rc0
cc = [[0] * W for _ in range(H)]
for j in range(W):
    i = 0
    for k in range(H):
        if S[k][j] == '#':
            i = k + 1
        else:
            cc[i][j] += 1
    i = 0
    while i < H:
        cc0 = cc[i][j]
        if cc0 < 2:
            i += 1
            continue
        for k in range(i, i + cc0):
            cc[k][j] = cc0
        i += cc0
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, rc[i][j] + cc[i][j] - 1)
print(ans)

Measured memory_bytes: 125912
#include <iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n, m,number;

	int A[100][100];
	int b[100];

	int answer[100] = {};

	cin >> n >> m;


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> number;
			A[i][j] = number;
		}
	}

	for (int i = 0; i < m; i++) {
		cin >> number;
		b[i] = number;
	}


	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			answer[i] += A[i][j] * b[j];
			
		}
	}
	
	for (int i = 0; i < n; i++) {
		cout << answer[i] << endl;
	}

	return 0;
}




Measured memory_bytes: 3136
N = int(input())

ans = [0 for _ in range(10010)]
for x in range(1, 101):
    for y in range(x, 101):
        for z in range(y, 101):
            v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if v < 10001:
                if x == y == z:
                    ans[v] += 1
                elif x == y or x == z or z == y:
                    ans[v] += 3
                else:
                    ans[v] += 6
for i in range(1,N+1):
    print(ans[i])


Measured memory_bytes: 9252
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
const int N=8000005,dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int qx[N],qy[N],qd[N],b,e;
int main()
{
	ios::sync_with_stdio(false);
	int n,m,k,bx,by,ex,ey;
	cin>>n>>m>>k>>bx>>by>>ex>>ey;
	vector<vector<char>>s(n,vector<char>(m,'.'));
	vector<vector<int>>d[4];
	vector<int>zh(m,1e9);
	for(int i=0;i<4;i++)
		for(int j=0;j<n;j++)
			d[i].push_back(zh);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>s[i][j];
	bx--,by--,ex--,ey--;
	for(int i=0;i<4;i++)
	{
		d[i][bx][by]=0;
		qx[e]=bx,qy[e]=by,qd[e]=i,e++;
	}
	while(b<e)
	{
		int x=qx[b],y=qy[b],dd=qd[b];b++;
		for(int i=0;i<4;i++)
			d[i][x][y]=d[dd][x][y];
		if(x==ex&&y==ey)
			break;
		for(int i=0;i<4;i++)
		{
			int zh=0,kx=x,ky=y;
			while(1)
			{
				kx+=dx[i],ky+=dy[i],zh++;
				if(kx<0||kx>=n||ky<0||ky>=m||s[kx][ky]=='@')
					break;
				if(d[i][kx][ky]>d[0][x][y]+1)
				{
					d[i][kx][ky]=d[0][x][y]+1;
					qx[e]=kx,qy[e]=ky,qd[e]=i,e++;
				}
				else if(d[i][kx][ky]<=d[0][x][y])
					break;
				if(zh==k)
					break;
			}
		}
	}
	printf("%d\n",d[0][ex][ey]==1e9?-1:d[0][ex][ey]);
	return 0;
}


Measured memory_bytes: 32512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  for(int i=b;i<=c;i++)
  {
    if(i%a==0)
    {
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;

int main(){
   int a,b,c;
   cin >> a>>b>>c;
   int k;
   cin >> k;
   vector<int> A,B,C;
   A.push_back(a);
   B.push_back(b);
   C.push_back(c);
   rep(i,k+1){
      A.push_back(A[i]*2);
   }
   rep(i,k+1){
      B.push_back(B[i]*2);
   }
   rep(i,k+1){
      C.push_back(C[i]*2);
   }
   rep(i,k+1){
      rep(j,k+1){
         rep(l,k+1){
            if(i+j+l<=k&&A[i]<B[j]&&B[j]<C[l]){
               cout << "Yes" <<endl;
               return 0;
            }
         }
      }
   }
   cout << "No" <<endl;
}

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

typedef pair<int,int> P;

int main(){
    int n,k;
    cin >> n >> k;
    int ans = 1;
    int k2 = k;
    while(1){
        if (n < k){
            cout << ans << "\n";
            return 0;
        }
        ans++;
        k *= k2;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n,m,t,i;
  cin >> n >> m;
  for(i=0;i<m;i++){
    cin >> t;
    n-=t;
    if(n<0){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << n << endl;
  return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N, M, X, Y;
  scanf("%lld %lld %lld %lld", &N, &M, &X, &Y);

  vector<ll> x_list;
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    x_list.emplace_back(v);
  }

  vector<ll> y_list;
  for (ll i = 0; i < M; i++) {
    ll v;
    scanf("%lld", &v);
    y_list.emplace_back(v);
  }

  sort(x_list.begin(), x_list.end());
  sort(y_list.begin(), y_list.end());

  // cout << "x_list[N - 1]:" << (x_list[N - 1]) << endl;
  // cout << (y_list[0]) << endl;

  if (X < y_list[0] && x_list[N - 1] < Y && x_list[N - 1] < y_list[0]) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
}


Measured memory_bytes: 3700
N,Q = map(int,input().split())
G = [[] for n in range(N)]
ans = N*[0]

for n in range(N-1):
  a,b = map(int,input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)

for q in range(Q):
  p,x = map(int,input().split())
  ans[p-1]+=x

f = N*[1]
t = [0]
while t:
  v = t.pop()
  f[v] = 0
  for k in G[v]:
    if f[k]:
      ans[k]+=ans[v]
      t.append(k)

print(*ans)

Measured memory_bytes: 56252
W, H, N = map(int, input().split())
ans = W * H
t, b, l, r = H, 0, 0, W
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        l = max(l, x)
    elif a == 2:
        r = min(r, x)
    elif a == 3:
        b = max(b, y)
    else:
        t = min(t, y)
print(max(0, (t - b)) * max(0, (r - l)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long n,a,ans;
    cin >> n;
    vector<long long> v;
    for(long long i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            v.push_back(i);
            if(i * i != n) v.push_back(n / i);
        }
    }
    sort(v.begin(), v.end());
    while(v[v.size()/2]!=0){
        v[v.size()/2] /= 10;
        ans++;
    }
    cout << ans;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
		int X = sc.nextInt();
		
		if(A<X){
			System.out.println("0");
		}else{
			System.out.println("10");
		}

	    
   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 22996
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    ll a[N][N];
    REP(i, N) REP(j, N) cin >> a[i][j];

    ll r[N][N];
    REP(i, N) REP(j, N) r[i][j] = a[i][j];

    bool no = false;
    REP(k, N) {
        REP(i, N) {
            REP(j, N) {
                if (a[i][j] == 0 || a[i][k] == 0 || a[k][j] == 0) continue;
                if (a[i][j] > a[i][k] + a[k][j]) {
                    no = true;
                    break;
                } else if(a[i][j] == a[i][k] + a[k][j]) {
                    r[i][j] = 0;
                }
            }
            if (no) break;
        }
        if(no) break;
    }


    if (no) {
        cout << -1 << endl;
        return 0;
    } else {
        ll ans = 0;
        REP(i, N) REP(j, N) {
            ans += r[i][j];
        }

        cout << ans / 2 << endl;
    }
    
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <time.h>
#include <vector>
#include <stdio.h>
#include <queue>
#include <map>
#include <math.h>
#define ll long long
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll k = n / (a + b);
	ll y = n % (a + b);
	if(y == 0)
	{
		cout<<k*a<<endl;
	}
	else 
	{
		if(y>a)
			cout<<k*a + a<<endl;
		else cout<<k*a + y<<endl;
	}
	return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const array<pair<int,int>,4> fd{make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int h,w;bool c[410][410];bool v[410][410];stack<array<int,3>> s;ll ans;

void bfs(){
  ll bb = 0, ww = 0;
  while(!s.empty()){
    auto p = s.top();s.pop();
    if(p[0] < 0 || p[1] < 0 || p[0] >=w || p[1] >= h || c[p[0]][p[1]] != p[2] || v[p[0]][p[1]]){
      //cout << p[0] << " " << p[1] << " " << p[2] << endl;
      continue;
    }
    v[p[0]][p[1]] = true;
    if(c[p[0]][p[1]]){
      bb++;
    }else{
      ww++;
    }
    rep(i,4){
      s.push({p[0]+fd[i].first, p[1]+fd[i].second, !(p[2])});
    }
  }
  //cout << "------------------" << endl;
  ans += bb * ww;
}

int main(){
  cin>>h>>w;
  rep(i,h){
    string ss;cin>>ss;
    rep(j,w){
      c[j][i] = (ss[j] == '#');
    }
  }
  rep(i,w)rep(j,h)v[i][j] = false;
  
  rep(i,w)rep(j,h){
    if(!v[i][j]){
      s.push({i,j,c[i][j]});
      bfs();
    }
  }
  cout << ans << endl;
}

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

int n;
int a[250005];
int id[505][505];
int dis[505][505],res[505][505];
bool lgl[505][505];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dis[i][j]=min(min(i-1,n-i),min(j-1,n-j));
		}
	}
	for(int i=1;i<=n*n;i++){
		int s;
		scanf("%d",&s);
		int x=(s-1)/n+1,y=(s-1)%n+1;
		res[x][y]=dis[x][y];
		lgl[x][y]=1;
		queue<pair<int,int>> q;
		q.emplace(x,y);
		while(q.size()){
			pair<int,int> T=q.front();
			q.pop();
			int x=T.first,y=T.second;
			int to=dis[x][y]+(!lgl[x][y]);
			for(int i=0;i<4;i++){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<1||nx>n||ny<1||ny>n){
					continue;
				}
				if(dis[nx][ny]>to){
					dis[nx][ny]=to;
					q.emplace(nx,ny);
				}
			}
		}
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			sum+=res[i][j];
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 6012
#include<bits/stdc++.h>
using namespace std;
int main(){
string S,T;
  cin>>S>>T;
  if(S.at(0)==T.at(0)&&S.at(1)==T.at(1)&&S.at(2)==T.at(2)){
  cout<<3<<endl;
  }
else if(S.at(0)==T.at(0)&&S.at(1)==T.at(1)&&S.at(2)!=T.at(2)){
cout<<2<<endl;
}
  else if(S.at(0)==T.at(0)&&S.at(1)!=T.at(1)&&S.at(2)==T.at(2)){
  cout<<2<<endl;
  }
 else if(S.at(0)!=T.at(0)&&S.at(1)==T.at(1)&&S.at(2)==T.at(2)){
  cout<<2<<endl;
  }
else if(S.at(0)==T.at(0)&&S.at(1)!=T.at(1)&&S.at(2)!=T.at(2)){
     cout<<1<<endl;
}
  else if(S.at(0)!=T.at(0)&&S.at(1)==T.at(1)&&S.at(2)!=T.at(2)){
  cout<<1<<endl;
  }
 else if(S.at(0)!=T.at(0)&&S.at(1)!=T.at(1)&&S.at(2)==T.at(2)){
  cout<<1<<endl;
  }
  else{
  cout<<0<<endl;
  }
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n, m, c;
    cin >> n >> m >> c;
    V<int> b(m);
    rep(i,m) cin >> b[i];

    int cnt = 0;
    rep(i,n) {
        ll sum = 0;
        rep(j,m) {
            int a;
            cin >> a;
            sum += a * b[j];
        }
        sum += c;
        cnt += sum > 0;
    }
    cout << cnt << endl;
}   

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

const double PI = acos(-1.0);
 
double solve(int A, int B, int H, int M)
{
    double ah = PI/2 - ((H/12.0)*2*PI + (M/60.0)*PI/6);
    double am = PI/2 - (M/60.0)*2*PI;

    double hx = A*cos(ah);
    double hy = A*sin(ah);
    double mx = B*cos(am);
    double my = B*sin(am);

    double dist = hypot(hx - mx, hy - my);

    return dist;
}

int main()
{
    ios::sync_with_stdio(false);

    int A, B, H, M;
    cin >> A >> B >> H >> M;

    auto ans = solve(A, B, H, M);

    cout << setprecision(15) << fixed << ans << '\n';

    return 0;
}


Measured memory_bytes: 4184
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner sc, PrintWriter pw) {
            int x = sc.nextInt(), y = sc.nextInt();
            pw.println(lcm(x, y));
        }

        private long lcm(int x, int y) {
            return 1l * x * y / gcd(x, y);
        }

        private long gcd(int x, int y) {
            return y == 0 ? x : gcd(y, x % y);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21332
# -*- coding: utf-8 -*-

a, b, k = map(int, input().split())
counter = 0
num_list = []
for i in range(max(a, b)):
  if a % (i + 1) == 0 and b % (i + 1) == 0:
    num_list.append(i + 1)
print(num_list[::-1][k - 1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, N) for (int i=0; i<(int)N; i++)
#define rep1(i, N) for (int i=1; i<(int)N; i++)

using namespace std;

int h, a;

int main() {
  cin >> h >> a;
  cout << ceil(1.0*h / a);

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b,x,y,z;
int main()
{
    //freopen("a.txt","r",stdin);
    scanf("%d%d",&a,&b);
    b/=1000;
    for(x=0;x<=a;x++)
        for(y=0;x+y<=a;y++)
            if(9*x+4*y==b-a)
            {
                z=a-x-y;
                printf("%d %d %d",x,y,z);
                //while(1);
                return 0;
            }
    printf("-1 -1 -1");
    //while(1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
  string S;
  cin >>S;
  ll n=S.size();
  ll sum=0;
  rep(i,n) {
    sum +=S.at(i)-'0';
    sum=sum%9;
  }
  
  if(sum==0) {
cout<<"Yes"<<endl;
  }
else {
cout<<"No"<<endl;
}

}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n;cin >> n;
    vb c((int)1e6+1, 1);
    vi a(n);
    cin >> a;
    sort(all(a));

    for(int i=0;i<n;++i){
        if(!c[a[i]]) continue;
        if(i!=0 && a[i-1] == a[i]) continue;

        for(int j=2*a[i];j<=(int)1e6;j += a[i]){
            c[j] = false;
        }
    }

    rep(i,n-1){
        if(a[i] == a[i+1]) c[a[i]] = false;
    }

    int ans = 0;
    rep(i,n) if(c[a[i]]) ++ans;
    cout << ans << "\n";
}

Measured memory_bytes: 4312
n,q=map(int,input().split())
s=input()
a=[0]*(n+1)
for i in range(0,n):
    if s[i-1:i+1]=="AC":
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(q):
    l,r=[int(i) for i in input().split()]
    print(a[r-1]-a[l-1])


Measured memory_bytes: 6140
#include <stdio.h>

int main(){
   int i,n,m,l,r,ll,rr;
    
   scanf("%d %d",&n,&m);
   scanf("%d %d",&l,&r);
   for (i=1;i<m;i++) {
      scanf("%d %d",&ll,&rr);
      if (l<ll) l=ll;
      if (r>rr) r=rr;
   }
   n=r-l+1;
   if (n<0) n=0;
   printf("%d\n",n);
   return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
import numpy as np

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

N, K = MAP()
A = LIST()

def check(omit):
    # 部分和DP
    dp = np.zeros(K, dtype=np.bool)
    prev = np.zeros(K, dtype=np.bool)
    dp[0] = prev[0] = 1
    for i in range(N):
        # まとめて遷移
        if i != omit and A[i] < K:
            prev[A[i]:] |= dp[:K-A[i]]
        dp = prev.copy()
    # 今回の値A[omit]を足してKに到達できるような部分和があれば、これは必要
    for j in range(max(0, K-A[omit]), K):
        if dp[j]:
            return True
    # なければ不要
    return False

A.sort()
print(bisearch_min(-1, N, check))


Measured memory_bytes: 13156
#include <bits/stdc++.h>
#define MAX_V 100000
#define MAX_N 1000
using namespace std;

struct edge{int to, cap,cost,rev;};
int V;
vector<edge> G[MAX_V];
vector<int> dist[MAX_V];
const vector<int> INF(1<<8,1000);
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back((edge){to,cap,cost,G[to].size()});
  G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}

int min_cost_flow(int s,int t,int f){
  while(f>0){
    for(int i=0;i<V;i++) dist[i]=INF;
    dist[s]=vector<int>(1<<8,0);

    bool update = true;
    while(update){
      update = false;
      for(int v=0; v<V ;v++){
	if(dist[v]==INF) continue;
	for(int i=0; i<G[v].size(); i++){
	  edge &e = G[v][i];
	  vector<int> ncost=dist[v];
	  if(e.cost!=0)ncost[abs(e.cost)]+=e.cost/abs(e.cost);
	  
	  if(e.cap > 0 && dist[e.to] > ncost){
	    dist[e.to] = ncost;
	    prevv[e.to] = v;
	    preve[e.to] = i;
	    update = true;
	  }
	}
      }
    }
    if(dist[t]==INF) return -1;    

    int d = f;
    for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
    f -= d;
    for(int v=t; v!=s; v=prevv[v]){
      edge &e = G[prevv[v]][preve[v]];
      e.cap -= d;
      G[v][e.rev].cap += d;
    }
  }
  return 1;
}


int can[MAX_N][MAX_N];
int Biparite_Matching(int N,int K){
  int s = N+K, t = s+1;
  for(int i=0; i<N; i++) add_edge(s,i,1,0);
  for(int i=0; i<K; i++) add_edge(N+i,t,1,0);

  for(int i=0;i<N;i++)
    for(int j=0;j<K;j++)add_edge(i, N+j,1,can[i][j]);
  V=N+K+2;
  return min_cost_flow(s,t,N);
}



int main(){
  int n;
  cin>>n;
  string mp[51];
  for(int i=0;i<n;i++)cin>>mp[i];
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)can[i][j] = -mp[i][j];

  Biparite_Matching(n,n);
  string ans;
  for(int i=0;i<n;i++)
    for(int j=0;j<G[i].size();j++)
      if(G[i][j].cap==0) ans+=mp[i][G[i][j].to-n];
  sort(ans.begin(),ans.end());

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

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

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
#define reprd(i,a,b) for (int i=(a);i>=(b);--i)
#define repr(i,n) reprd(i,n,0)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int Max = 110;
ll X, K, D;

ll solve() {
    ll num = abs(X) / abs(D);
    if (abs(X-num*D) > abs(X-(num+1)*D)) {
        num +=1 ;
    }

    if (num >= K) {
        return abs(X - K * D);
    }

    if ((K - num) %2 == 0) {
        return abs(X - num * D);
    }

    return min(abs(X-(num+1) * D), abs(X-(num-1)*D));
}

int main(int argc, const char * argv[]) {
    cin >> X >> K >> D;
    X = abs(X);
    output(solve());

    return 0;
}

Measured memory_bytes: 3104
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut first = 0;
    for i in 0..a.len() {
        let ai = a[i];
        if i % 2 == 0 {
            first += ai;
        } else {
            first -= ai;
        }
    }

    first /= 2;
    let mut ans = vec![0; n];
    ans[0] = first;
    let mut prev = first;
    for i in 1..a.len() {
        ans[i] = a[i - 1] - prev;
        prev = a[i - 1] - prev;
    }

    for i in 0..n {
        print!("{} ", ans[i] * 2);
    }
}


Measured memory_bytes: 4508
#include <stdio.h>

int main(void)
{
	char s1[3],s2[3];
	scanf("%s%s",s1,s2);
	if(s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0])
		{printf("YES");}
	else
		{printf("NO");}
	return 0;
}


Measured memory_bytes: 128
def main():
    W, a, b = map(int, input().split())
    if a <= b:
        if a + W >= b:
            print(0)
        else:
            print(b - a - W)
    else:
        if b + W >= a:
            print(0)
        else:
            print(a - b - W)


if __name__ == '__main__':
    main()


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

bool check(string s)
{
    LL L = s.size();

    string x, y;
    for(LL i = 0; i < L / 2; i++)
        x.Pb(s[i]);
    for(LL i = L / 2; i < L; i++)
        y.Pb(s[i]);

    if(x == y)
        return true;
    return false;
}

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    string s;
    cin >> s;

    LL L = s.size();
    for(LL i = L - 1; i; i--){
        if(check(s.substr(0, i)))
            return cout << i << '\n', 0;
    }

    return 0;
}



Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

template <int mod>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y)
      : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const {
    return ModInt(*this) += p;
  }
  ModInt operator-(const ModInt &p) const {
    return ModInt(*this) -= p;
  }
  ModInt operator*(const ModInt &p) const {
    return ModInt(*this) *= p;
  }
  ModInt operator/(const ModInt &p) const {
    return ModInt(*this) /= p;
  }
  bool operator==(const ModInt &p) const {
    return x == p.x;
  }
  bool operator!=(const ModInt &p) const {
    return x != p.x;
  }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt ans(1), mul(x);
    while(n) {
      if(n & 1) ans *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ans;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

LL N,K;

ModInt<mod> ans = 0;

void solve(){
	vector<ModInt<mod>> gcd_i(K+1);
	for(int i=K;i>=1;i--){
		gcd_i[i] = ModInt<mod>(K/i);//1~Kのうちiで割り切れるものはK/i個
		gcd_i[i] = gcd_i[i].pow(N);
		for(int j=2*i;j<=K;j+=i) gcd_i[i] -= gcd_i[j];
		ans += ModInt<mod>(i)*gcd_i[i];
	}
}

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

    solve();

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

Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

int main()
{
	for(int v,d;cin>>v>>d;){
		deque<int> a(v+2);
		a[0]=a[1]=1;
		for(int i=0;i<v;i++){
			a[i+2]=a[i+1]+a[i];
			a[i+2]%=1001;
		}
		a.pop_front();
		a.pop_front();
		sort(a.begin(),a.end());
		
		int res=0;
		for(int i=0;i<v;i++)
			if(i==0 || a[i]-a[i-1]>=d)
				res++;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1212
#from math import gcd
from fractions import gcd
from functools import reduce

def lcm(a,b):
    return a * b // gcd(a,b)
def ls_lcm(A):
    return reduce(lcm ,A)
def ls_gcd(A):
    return reduce (gcd, A)

def count_two(n): # 2で割れる回数を取得
    cnt = 0
    while(n & 1 == 0):
        cnt += 1
        n = n >> 1
    return cnt

N, M = map(int, input().split())
A = list(map(int, input().split()))

if len(set([count_two(a) for a in A])) != 1:
    print (0)
    exit()
A = [a//2 for a in A]
half = ls_lcm(A)
print ((M + half) // (2*half))

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    int n;
    cin >> n;
    str ans = "APPROVED";
    REP(i, n) {
        int a;
        cin >> a;
        if(a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) ans = "DENIED";
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A=list(map(int, input().split()))
L=[0 for _ in range(40)]
ans=[]
ans.append(sum(a^K for a in A))
for a in A:
    i=0
    while a:
        if a&1==1:
            L[i]+=1
        a=a>>1
        i+=1

opt_str=''
for l in L[::-1]:
    if l > N-l:
        opt_str+='0'
    else:
        opt_str+='1'
opt=int(opt_str,2)

for i in range(40):
    Kr=(K&((((1<< 40-i)-1)<<(i+1))))|(opt&(1 << i)-1)
    if Kr<=K:
        ans.append(sum(a ^ Kr for a in A))

print(max(ans))

Measured memory_bytes: 15144
import math
import copy
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
P.append(N+1)
Q.append(N+1)
Mp = copy.copy(P)
Mq = copy.copy(Q)
Lp = 0
Lq = 0
for i in range(N):
  if P[i] == min(Mp) and i != N-1:
    Mp.remove(P[i])
  elif i == N-1:
    Lp += 1
  else:
    Lp += math.factorial(len(Mp)-2)*(sum(x<P[i] for x in Mp))
    Mp.remove(P[i]) 
for i in range(N):
  if Q[i] == min(Mq) and i != N-1:
    Mq.remove(Q[i])
  elif i == N-1:
    Lq += 1
  else:
    Lq += math.factorial(len(Mq)-2)*(sum(x<Q[i] for x in Mq))
    Mq.remove(Q[i])
print(abs(Lp-Lq))

Measured memory_bytes: 3444