akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  atCoder
//
//  Created by 佐々木勇星 on 2019/07/23.
//  Copyright © 2019 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <regex>


int main(void) {
    
    using namespace std;
    
    int N;
    int count = 0,countmax = 0;
    //int flag=0;
    cin >> N;
    
    vector<int> height(N);
    
    for(int i=0; i<N; i++){
        cin >> height[i];
    }
    
   // reverse(height.begin(), height.end());
    
//    for(int i=0; i<N; i++){
//        if(height[flag+i] >= height[flag+i+1]){
//            cout << height[flag+i]  << " " << height[flag+i+1] << endl;
//            count++;
//        }else{
//            flag=i+1;
//            countmax=count;
//            count=0;
//        }
//    }
    
    for(int i=1; i<N; i++){
        if(height[i-1] >= height[i]) count++;
            else count=0;
        countmax = max(countmax, count);
    }
    
    cout << countmax << endl;
    
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

        while(true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W ==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 63280
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define NREP(i, n) for(int i = 1; i <= (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int nums(int n){
	return to_string(n).length();
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cout << fixed << setprecision(7);
////////////////////////////////////////////
	int n;
	cin >> n;
	int ans=0;
	while(n>0){
		if(nums(n)%2==1){
			ans++;
		}
		n--;
	}
	cout << ans << endl;
///////////////////////////////////////////
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int read()
{
	int k=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) k=k*10+c-'0';return k*f;
}
int n;
int main()
{
	n=read();
	int now=0;
	for(int i=1;i<=n+1;i++)
	{
		now=(1ll*now*10+7)%n;
		if(!now) {printf("%d\n",i);return 0;}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

ll lcm(ll x, ll y) {
    return x/__gcd(x, y)*y;
}

ll weight(ll x, ll y, ll z) {
    if (x == y && y == z) return 1;
    if (x != y && y != z && x != z) return 6;
    else return 3;
}

int main() {
    ll K; cin >> K;
    ll ans = 0;
    for (int i = 1; i <= K; ++i) {
        for (int j = i; j <= K; ++j) {
            for (int k = j; k <= K; ++k) {
                ll tmp_ans = gcd(gcd(i, j), k);
                ans += weight(i, j, k) * tmp_ans;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
    ll a,b,n;
    cin>>a>>b>>n;
    ll ans = 0;
    ll tmp = 10000000;
    ll cnt = 0;
    if(n<=tmp){
        for(ll i=1;i<=n;i++){
            ll axb = (a*i)/b;
            ll xb = i/b;
            xb = xb*a;
            /*if(ans<axb-xb){
                cout<<i<<" "<<axb<<" "<<xb<<endl;
            }*/
            ans = max(ans, axb - xb);
        }
    }else{
        for(ll i=n-tmp;i<=n;i++){
            ll axb = (a*i)/b;
            ll xb = i/b;
            xb = xb*a;
            /*if(ans<axb-xb){
                cout<<i<<" "<<axb<<" "<<xb<<endl;
            }*/
            ans = max(ans, axb - xb);
        }
        for(ll i=1;i<=tmp;i++){
            ll axb = (a*i)/b;
            ll xb = i/b;
            xb = xb*a;
            /*if(ans<axb-xb){
                cout<<i<<" "<<axb<<" "<<xb<<endl;
            }*/
            ans = max(ans, axb - xb);
        }
        for(ll i=10000001;i<=n-10000000;i=i+100000){
            //cnt++;
            ll axb = (a*i)/b;
            ll xb = i/b;
            xb = xb*a;
            /*if(ans<axb-xb){
                cout<<i<<" "<<axb<<" "<<xb<<endl;
            }*/
            ans = max(ans, axb - xb);
            /*if(cnt>=10000000){
                i+=10000000000;
                cnt = 0;
            }*/
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
from bisect import bisect_left
from itertools import accumulate

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

Acum = [0] + list(accumulate(A))

left = 0
right = max(A) * 2 + 1

while left + 1 < right:
  mid = (left + right) // 2
  tmp = 0
  for i in range(N):
    bi = bisect_left(A, mid - A[i])
    tmp += N - bi
  if tmp <= M:
    right = mid
  else:
    left = mid

cnt = 0
answer = 0
for i in range(N):
  bi = bisect_left(A, right - A[i])
  cnt += N - bi
  answer += Acum[N] - Acum[bi] + A[i] * (N - bi)

print(answer + (M - cnt) * left)

Measured memory_bytes: 59392
N, K = map(int, input().split())

if K > (N - 2) * (N - 1) // 2:
    print(-1)
    exit()

add = (N - 2) * (N - 1) // 2 - K

print(N - 1 + add)
for i in range(2, N + 1):
    print(1, i)

for i in range(2, N):
    for j in range(i + 1, N + 1):
        if add:
            print(i, j)
            add -= 1

Measured memory_bytes: 9240
import sys

iter_num = 5 * (10**5) + 10
sys.setrecursionlimit(iter_num)

s = input()
n = len(s) + 1

a = [0 for _ in range(n)]
next_num=0

def solve(num):
	global next_num
	if num == 0:
		if s[0] == '<':
			a[num] = 0
			next_num = 1
			return 0
		else:
			next_num = 1
			a[num] = solve(num+1) + 1
	if num == n-1:
		if s[n-2] == '>':
			next_num = -1
			a[num] = 0
			return 0
		else:
			a[num] = solve(num-1) + 1
			next_num = -1
			return a[num]

	if s[num-1] == '>' and s[num] == '<':
		next_num = num+1
		a[num] = 0
		return 0
	elif s[num-1] == '>' and s[num] == '>':
		a[num] = solve(num+1) + 1
		return a[num]
	elif s[num-1] == '<' and s[num] == '>':
		next_num = num+1
		a[num] = max(solve(num-1),solve(num+1)) + 1
		return a[num]
	else:
		#a[num] = solve(num-1) + 1
		a[num] = a[num-1] + 1
		next_num = num+1
		return a[num]

while next_num != -1:
	solve(next_num)

#print(a)
print(sum(a))


Measured memory_bytes: 453904
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];
 
 
int main () {
    int N;
    cin >> N;

    long long ans=0;
    rep(i,N+1){
        if( i%3 !=0 && i%5 !=0 ){
            ans += i;
        }
    }
    cout  << ans << endl;


}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    string x;
    cin >> x;
    stack<char> s;
    for(int i = 0; i < x.length(); i++){

        if(s.empty()) s.push(x[i]);
        else{
            if(x[i] == 'S') s.push(x[i]);
            else if(x[i] == 'T'){
                if(s.top() == 'S') s.pop();
                else s.push(x[i]);
            }
        }
    }
    cout << s.size() << endl;
    return 0;
}

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

int main() {
  int N, A, M;
  cin >> N >> A;
  
  
  if(N<A){
      cout << "Yes" << endl;
  }
  else if(N % 500 == 0 ){
      cout << "Yes" << endl;
  }
  else if(N % 500 != 0){
      M = N % 500;
      if(M <= A) cout << "Yes" << endl;
      else cout << "No" << endl;
  } 
  else{
     cout << "No" << endl;
  }
     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  cin >> N;
  vector<HOGE> A;
  rep(i, 0, N){
    ll A_tmp;
    cin >> A_tmp;
    HOGE HOGE_tmp(i, A_tmp);
    A.push_back(HOGE_tmp);
  }

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

  ll count=0;

  for(int i=0; i<N; i+=2){
    if(A[i].index%2 != 0){
      count++;
    }
  }

  cout << count << "\n";

  return 0;
}

Measured memory_bytes: 2420
import numpy as np
import copy
import sys

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

def temp(t, x):
	return t-x*0.006

near=np.inf; arg_near=-1
for i in range(N):
	if (near > abs(A-temp(T, H[i]))):
		near = abs(A-temp(T, H[i]))
		arg_max = i+1
print(arg_max)

Measured memory_bytes: 12508
k=0
s=0
combi = 0

def nyu():
    num1,num2 = input().split()
    k = int(num1)
    s = int(num2)
    return k,s

def calc(l_k,l_s):
    l_combi = 0
    for x in range(l_k):
#        check_tmp =0
#        check_tmp =check1(x,l_s,l_k)
#        if check_tmp == 1:
#            break
#        elif check_tmp  == 2:
#            continue
        for y in range(l_k):
#            check_tmp =check2(x,y,l_s,l_k)
#            if check_tmp == 1:
#                break
#            elif check_tmp  == 2:
#                continue2
#            sum = x+y+l_k 
            sum = l_s- x-y 
            if 0<=sum and sum <= k:
#                print("x=",x,"y="   ,y) 
                l_combi +=1
    return l_combi

def check1(x,s,k):
    if s<x:
        return 1
    if x+(k-1)*2 < s:
        return 2
    return 0

def check2(x,y,s,k):
    sum = x+y
    if s<sum:
        return 1
    if x+y+k-1 < s:
       return 2
    return 0

def check3(x,y,z,s):
    sum = x+y+z
    if s<sum:
        return 1
    return 0    

def check_ini(k,s):
    if k*3 < s:
        return True
    return False


k,s=nyu()
if check_ini == True:
    print("0")
else :
    print(calc(k+1,s))









Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int result = 0;
    int W, H, N;
    cin >> W >> H >> N;
    vector<int> xList;
    vector<int> yList;
    vector<int> aList;
    for(int i=0; i<N; i++) {
        int x;
        int y;
        int a;
        cin >> x >> y >> a;
        xList.push_back(x);
        yList.push_back(y);
        aList.push_back(a);
    }
    int a1MaxX = -1;
    int a2MinX = 101;
    int a3MaxY = -1;
    int a4MinY = 101;
    for(int i=0; i<N; i++) {
        int x = xList[i];
        int y = yList[i];
        int a = aList[i];
        if (a == 1) {
            if (x > a1MaxX) {
                a1MaxX = x;
            }
        } else if (a == 2) {
            if (x < a2MinX) {
                a2MinX = x;
            }
        } else if (a == 3) {
            if (y > a3MaxY) {
                a3MaxY = y;
            }
        } else {
            if (y < a4MinY) {
                a4MinY = y;
            }
        }
    }
    int whiteW = W;
    int whiteH = H;
    if (a1MaxX != -1) {
        whiteW -= a1MaxX;
    }
    if (a2MinX != 101) {
        whiteW -= (W - a2MinX);
    }
    if (a3MaxY != -1) {
        whiteH -= a3MaxY;
    }
    if (a4MinY != 101) {
        whiteH -= (H - a4MinY);
    }
    if (whiteW < 0) {
        whiteW = 0;
    }
    if (whiteH < 0) {
        whiteH = 0;
    }
    result = whiteW * whiteH;
    if (result < 0) {
        result = 0;
    }
    cout << result;

    return 0;
}


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

int binarySearch(vector<int> A, int key){
	int left = 0, right = A.size();
	while(left < right){
		int mid = (left + right) / 2;
		if(A[mid] < key)
			left = mid + 1;
		else
			right = mid;
	}

	return left;
}

int LIS(vector<int> a){
	vector<int> lis;

	lis.push_back(a[0]);
	for(int i=1;i<a.size();i++)
		if(a[i] > lis[lis.size()-1])
			lis.push_back(a[i]);
		else if(a[i] < lis[lis.size()-1])
			lis[binarySearch(lis, a[i])] = a[i];
		
		

		return lis.size();
}

int main(){

	int n, num;
	vector<int> a, lis;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>num;
		a.push_back(num);
	}

	cout<<LIS(a)<<endl;
	return 0;
}

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

using namespace std;
int main(){
  int n;
  int i=1;
  
  while(true){
  	cin>>n;
    
  		if(n!=0){
  		cout<<"Case "<<i<<": "<<n<<endl;  
    		i++;
  		
        }
    	else
          if(n==0) break;
        
  }
  
	return 0;
}


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

int main() {
	string s,p;
	cin >> s;
	int n, h;
	while (s != "-") {
		cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> h;
			p = s.substr(0, h);
			s.erase(0, h);
			s += p;
		}
		cout << s << endl;
		cin >> s;
	}

	return 0;
}


Measured memory_bytes: 3176
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define gcd __gcd
// ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
// {
//   ll ans=0;
//   if(i>=n)
//     return 0;

//   if(dp[i][k]!=-1)
//     return dp[i][k];


//   if(k!=0)
//   ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
//   else
//   ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

//   return dp[i][k]=ans;

// }

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};


int temp[1000002]={0};

void sieve()
{
  temp[1]=1;
  for(int i=2;i<1000002;i++)
  {
    if(temp[i]==0)
    { temp[i]=i;
      for(int j=i*2;j<1000002;j+=i)
      { 
        if(temp[j]==0)
        temp[j]=i;
      }
    }
  }

}

int dfs(int i,vector<vector<int> > &g,vector<int>& p,vector<int>& c)
{
  int sub=1;
  for(auto x:g[i])
  {
    if(p[i]!=x)
    {
      p[x]=i;
      sub+=dfs(x,g,p,c);
    }
  }

  return c[i]=sub;
}


int main() { 

int n;
cin>>n;
int a[n],fa[n+1]={0};
int b[n],fb[n+1]={0};

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

for(int i=0;i<n;i++)
{
  cin>>b[i];
  fb[b[i]]++;
}
int flag=0;

for(int i=1;i<=n;i++)
{
  if(fa[i]+fb[i]>n)
  {
    flag=1;
    break;
  }
}
if(flag)
{
  cout<<"No"<<"\n";
  return 0;
}

 cout<<"Yes"<<"\n";

reverse(b,b+n);

int i=0;
int j=0;

while(i<n)
{
  if(a[i]!=b[i])
    { i++;
      continue;}

  swap(b[i],b[j]);
  j++;

}

i=n-1;
j=n-1;

while(i>=0)
{
  if(a[i]!=b[i])
    { i--;
      continue;}

  swap(b[i],b[j]);
  j--;


}

 for(int i=0;i<n;i++)
  cout<<b[i]<<" ";
cout<<"\n";

return 0;
}
/*
1
4
1 2
2 3
3 4
*/


Measured memory_bytes: 6736
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.nextLine();

        long sum = 0;
        for (int i = 0; i < N.length(); i++) {
//            System.out.println((int) N.charAt(i) - 48);
            sum += (int) N.charAt(i) - 48;
        }

//        if (sum == 0){
//            System.out.println("No");
//        } else
        if (sum % 9 == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 41200
#include "iostream"
using namespace std;

int main(int argc, char const *argv[])
{
	int m, f, r=0;
	int  Score;
	char Grade;
	while(true)
	{
		cin >> m >> f >> r;
		if(m==-1 && f==-1 && r==-1)
		{
			break;
		}
		Score = m + f;

		if(m==-1 || f==-1 || Score<30)
		{
			Grade = 'F';
		}
		else if(Score>=80)
		{
			Grade = 'A';
		}
		else if (80>Score && Score>=65)
		{
			Grade = 'B';
		}
		else if (65>Score && Score>=50)
		{
			Grade = 'C';
		}
		else if (50>Score && Score>=30)
		{
			if(r>=50)
			{
				Grade = 'C';
			}
			else
			{
				Grade = 'D';
			}
		}

		cout << Grade<< endl;
	}
	return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

vec a;

int fu(int m) {
    int n = a.size();
    int res = 0;
    rep(i, n) {
        int t = m % a[i];
        res += t;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];

    int res = accumulate(all(a), 0);
    res -= n;

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[200003], b[200003];
    vector<int> v[200010];
    queue <int> q;
    q.push(1);
    int way[200003];
    set<int> s;
    s.insert(1);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
        v[a[i]].push_back(b[i]);
        v[b[i]].push_back(a[i]);
    }  
    while (!q.empty()) {
        for (int i = 0; i < (int)v[q.front()].size(); i++) {
            if (s.count(v[q.front()][i]) == 0) {
                s.insert(v[q.front()][i]);
                way[v[q.front()][i] - 2] = q.front();
                q.push(v[q.front()][i]);
            }
        }
      q.pop();
    }
  if ((int)s.size()!=n)
        cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for (int i = 0; i < n - 1; i++)
            cout << way[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 18840
/*Allah Vorosha*/
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define uniq(v)         v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 1000000007
#define yes cout << "YES\n"
#define no cout << "NO\n";
#define take for(auto &it : a) cin >> it;
#define out cout << a << "\n";
#define l_b lower_bound
#define u_b upper_bound
#define Max 100005
template<typename T> T mymax(T x, T y) {
    return (x > y ? x : y);
}

using namespace std;

const int N = 2e5 + 5;

void solve() {
    long long x, l;
    cin >> x >> l;
    ll m = x / 2019;
    ll k = (m + 1) * 2019;
    //cout << k;
    if(x % 2019 == 0 || k <= l) {
        //yes;
        cout << 0 << '\n'; return;
    }
    ll ans = 1e8;
    for(ll i = x; i < l; i++) {
        for(ll j = i + 1; j <= l; j++) {
            ll prod = ((i % 2019) * (j % 2019)) % 2019;
            ans = min(ans, prod);
        }
    }
    cout << ans;
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 3612
package main

import (
	"fmt"
	"io"
	"os"
	"sort"
)

func fscanNums(r io.Reader, len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Fscan(r, &num)
		nums = append(nums, num)
	}
	return
}

func intSearch(a []int, b int) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

type msDiff struct {
	Number int
	Diff   int
}

type msDiffs []msDiff

func (f msDiffs) Len() int {
	return len(f)
}

func (f msDiffs) Less(i, j int) bool {
	return f[i].Diff > f[j].Diff
}

func (f msDiffs) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func max(a,b int) int {
	if a > b {
		return a
	}
	return b
}

func answer(r io.Reader, w io.Writer) {

	msSizes := []int{0, 2, 5, 5, 4, 5, 6, 3, 7, 6}

	var numMS int
	var numDigits int
	fmt.Fscan(r, &numMS)
	fmt.Fscan(r, &numDigits)
	nums := fscanNums(r, numDigits)
	sort.Sort(sort.Reverse(sort.IntSlice(nums)))

	dp := make([]int, numMS + 1)
	dp[0] = 0
	for i := 1; i <= numMS; i++{
		maxDigit := -1
		for j := 0; j < numDigits; j++{
			index := i - msSizes[nums[j]]
			if index >= 0 && dp[index] >= 0 {
				maxDigit = max(maxDigit, dp[index]+1)
			}
		}
		dp[i] = maxDigit
	}

	remain := numMS
	for remain > 0 {
		maxDigit := -1
		for j := 0; j < numDigits; j++ {
			index := remain - msSizes[nums[j]]

			if index >= 0 && dp[index] == dp[remain] - 1 {
				maxDigit = max(maxDigit, nums[j])
			}
		}
		remain = remain - msSizes[maxDigit]
		fmt.Fprintf(w,"%v", maxDigit)
	}
}


func main() {
	answer(os.Stdin, os.Stdout)
}


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

int main() {
    int A[3];
    scanf("%d%d%d", &A[0], &A[1], &A[2]);
    for (int i = 0; i < 2; i++) {
        for (int j = i + 1; j <= 2; j++) {
            if (A[i] > A[j]) {
                int t = A[i];
                A[i] = A[j];
                A[j] = t;
            }
        }
    }
    printf("%d %d %d\n", A[0], A[1], A[2]);
    return 0;
}

Measured memory_bytes: 3204
n = int(input())
ls = list(map(int,input().split()))
p = 0
k = float("inf")
q = 0
for i in range(n):
  p += abs(ls[i])
  if k > abs(ls[i]):
    k = abs(ls[i]) 
di = [e for e in ls if e <= 0]
if len(di) % 2== 0:
  print(p)
else:
  print(p-2*k)

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

int main()
{
    ll n, m;
    cin >> n;
    vecll a(n), b, result;
    for (auto &x : a)
        cin >> x;

    cin >> m;
    b.resize(m);
    for (auto &y : b)
        cin >> y;

    set_intersection(all(a), all(b), inserter(result, end(result)));

    for (auto &z : result)
        cout << z << endl;
}


Measured memory_bytes: 6472
from collections import defaultdict as dd
n, q = map(int, input().split())
Connections = dd(list)
for i in range(n-1):
    a, b = map(int, input().split())
    Connections[a].append(b)
    Connections[b].append(a)

#Tree[node] -> children(list)
Tree = dd(list)
visited = set()
stack = [1]
while stack != []:
    temp = []
    for taregt_node in stack:
        for next_node in Connections[taregt_node]:
            if next_node not in visited:
                Tree[taregt_node].append(next_node)
                visited.add(taregt_node)
                temp.append(next_node)
    stack = temp
#print(Tree)

#Point[node] -> point
Point = dd(int)
for i in range(q):
    p, x = map(int, input().split())
    Point[p] += x
#print(Point)

Counter = dd(int)
#visited = set()
stack = [1]
Counter[1] = Point[1]
while stack != []:
    temp = []
    for target_node in stack:
        for next_node in Tree[target_node]:
            Counter[next_node] = Counter[target_node] + Point[next_node]
            temp.append(next_node)
    stack = temp
#print(Counter)

for i in range(1, n):
    print(Counter[i], end=" ")
print(Counter[n])

Measured memory_bytes: 208064
#include <iostream>
#include<cstdio>
using namespace std;
int main() {
	int s;
	typedef unsigned long long lu;
	lu a[86] = { 0 };
	a[0] = 2;
	a[1] = 1;

	cin >> s;
	if (s == 86)
		cout << 939587134549734843 << endl;
	else {
		for (int i = 2; i <= s; i++) {
			a[i] = a[i - 2] + a[i - 1];
		}
		cout << a[s] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations as comb
from math import sqrt
n, d = map(int, input().split())
dn = []
for i in range(n):
    dn.append(list(map(int, input().split())))

comb_list = list(comb([i for i in range(n)], 2))
ans = 0
for comb in comb_list:
    y_point = dn[comb[0]]
    z_point = dn[comb[1]]
    sum = 0

    for i in range(len(y_point)):
        sum += (y_point[i] - z_point[i])**2

    if sqrt(sum).is_integer():
        ans += 1

print(ans)


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
using namespace std;

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; cin >> n;
	vector<int> h(n);
	vector<int> data(n,INT_MAX);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
		if (i > 1) {
			chmin(data.at(i), data.at(i - 2) + abs(h.at(i) - h.at(i - 2)));
			chmin(data.at(i), data.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
		}
		else if (i > 0) {
			chmin(data.at(i), data.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
		}
		else {
			data.at(i) = 0;
		}
	}
	cout << data.at(n - 1) << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int k = (int) Math.log10(n)+1;
		long ans = 0;

		for(int j=0; j<Math.pow(2, k-1); j++) {
			long tmpN = n;
			int tasInt = j|(int)(Math.pow(2, k-1));
			String tasStr = Integer.toBinaryString(tasInt);
			long tmp = tmpN%10;
			tmpN /= 10;
			int ct = 10;
			for(int i =1; i<k; i++) {
				if(tasStr.charAt(i) == '0') {
					tmp += (tmpN%10)*ct;
					tmpN /= 10;
					ct *= 10;
				}else {
					ans += tmp;
					tmp = tmpN%10;
					tmpN /= 10;
					ct = 10;
				}
			}
			ans += tmp;
		}
		System.out.println(ans);

	}
}


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

using namespace std;

int main()
{
  char str[222];
  scanf("%s", str);
  int n = strlen(str);
  for (int i = n-2; i ;i -= 2){
    if (strncmp(str, str+i/2, i/2) == 0){
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	const int naxies=100001;
    int n,x[naxies],y[naxies],t[naxies];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
    }
    for(int i=1;i<=n;i++){
        if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0){
        	cout<<"No";
            return 0;   
        }    	
	}
    cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
using namespace std;
int N,cnt,p[50],s[50];
int main() {
    scanf("%d",&N); for (int i = 0;i < N;i++) scanf("%d",&p[i]),s[i] = p[i]; sort(s,s+N);
    for (int i = 0;i < N;i++) if (p[i] != s[i]) cnt++;
    if (cnt <= 2) printf("YES\n"); else printf("NO\n");
}


Measured memory_bytes: 128
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n,m] <- getl $ wrds toInt
  unless (n == 0 && m == 0) $ do
    if n == 0 || m == 0 then
      solve [] <$> (getl $ wrds toInt) >>= print
    else
      solve <$> (getl $ wrds toInt) <*> (getl $ wrds toInt) >>= print
    main

solve :: [Int] -> [Int] -> Int
solve ls rs = maximum $ zipWith (-) ts (0:ts)
  where
    ts = sort $ ls ++ rs

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 11332
#include <iostream>
#define size 3
using namespace std;
int bingo(int table[size][size], int number[], int n)
{
    for (int x = 0; x < n; x++)
    {
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                if (table[i][j] == number[x])
                {
                    table[i][j] = 0;
                }
            }
        }
    }
    for (int i = 0; i < size; i++)
    {
        if (table[i][0] == 0 && table[i][1] == 0 && table[i][2] == 0)
        {
            return 1;
        }
    }
    for (int j = 0; j < size; j++)
    {
        if (table[0][j] == 0 && table[1][j] == 0 && table[2][j] == 0)
        {
            return 1;
        }
    }
    if (table[0][0] == 0 && table[1][1] == 0 && table[2][2] == 0)
    {
        return 1;
    }
    if (table[0][2] == 0 && table[1][1] == 0 && table[2][0] == 0)
    {
        return 1;
    }
    return 0;
}
int main()
{
    int table[size][size];
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++)
        {
            cin >> table[i][j];
        }
    }
    int n;
    cin >> n;
    int number[n];
    for (int x = 0; x < n; x++)
    {
        cin >> number[x];
    }
    if (bingo(table, number, n) == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){
  return (b!=0 ? gcd(b,a%b):a);
}

int main(){
  ll n,m;
  cin >> n >> m;
  string s,t;
  cin >> s;
  cin >> t;
  ll l = n/gcd(n,m)*m;
  map<ll,char> mp;
  for(int i=0;i<n;i++){
    mp[l/n*i] = s[i];
  }
  for(int i=0;i<m;i++){
    if(mp.count(l/m*i)>0 && mp[l/m*i]!=t[i]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << l << endl;
  return 0;
}


Measured memory_bytes: 6144
def binary(N, LIST, num):  # 二分探索 # N:探索要素数
    l, r = -1, N
    while r - l > 1:
        if LIST[(l + r) // 2] > num:  # 条件式を代入
            r = (l + r) // 2
        else:
            l = (l + r) // 2
    return r + 1


n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [i for i, j in xh]
h = [(j + a - 1) // a for i, j in xh]

bomb, bsum, ans = [0] * (n + 1), [0] * (n + 1), 0
for i in range(n):
    j = binary(n, x, x[i] + 2 * d) - 1
    bnum = max(h[i] - (bsum[i - 1] + bomb[i]), 0)
    bomb[i] += bnum
    bomb[j] -= bnum
    bsum[i] += bsum[i - 1] + bomb[i]
    ans += bnum
print(ans)


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

#define ll long long

int main(){
    int n;
    char c[200000];
    scanf("%d%s", &n, c);

    int rs = 0, ws = 0;
    for(int i=0;i<n;i++){
        if(c[i]=='R') rs += 1;
        else ws += 1;
    }

    int diff = 0;
    for(int i=0;i<rs;i++){
        if(c[i]!='R') diff += 1;
    }
    for(int i=rs;i<n;i++){
        if(c[i]!='W') diff += 1;
    }
    printf("%d\n", diff/2);
    return 0;
}

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

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j;i>=k;i--)
#define FORR(i,j,k,l) for(int i=j;i<=k;i+=l)
#define inf         freopen("in.txt", "r", stdin)
#define outf        freopen("out.txt", "w", stdout)
#define pf          printf
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c)    scanf("%d %d %d", &a, &b, &c)
#define clean(mat,n)   FOR(i,0,n) mat[i].clear()
#define minn          (long long)-1000000000000000000
#define maxx          (long long) 1000000000000000000
#define mod          1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define LL           long long
#define NL '\n'
#define cnd tree[idx]
#define lnd (idx<<1)
#define rnd ((idx<<1)+1)
#define PB push_back
#define F first
#define S second
#define MAX 1000010
#define MP make_pair
#define valid(nx,ny)  ((nx >= 0) && (nx < row) && (ny >= 0) && (ny < col))
typedef pair<int,int> pr;


LL ar[MAX], br[MAX];
int main()
{
    ios::sync_with_stdio(false);
    ///inf;
    ///outf;

    int n;
    LL a, b, c, x, y, z;

    cin >> n;

    FOR(i,0,n-1) cin >> ar[i];
    FOR(i,0,n-1) cin >> br[i];

    a = 0;
    FOR(i,0,n-1)
    {
        a += ar[i];
        ar[i] = a;
    }

    a = 0;
    REV(i,n-1,0)
    {
        a += br[i];
        br[i] = a;
    }

    c=0;
    FOR(i,0,n-1)
    {
        c = max(c,ar[i]+br[i]);
    }

    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 2304
#include <cstdio>
#include <algorithm>

int main()
{
	int n;
	long long k;
	scanf("%d%lld", &n, &k);
	int a[200000];
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", a + i);
	}
	int b[200000];
	std::fill(b, b + n, -1);
	int i = 0;
	int cnt = 0;
	while (b[i] == -1)
	{
		b[i] = cnt;
		i = a[i] - 1;
		cnt += 1;
	}
	int cycle = cnt - b[i];
	int cs = i;

	int j = 0;
	while (k > 0 && j != i)
	{
		k -= 1;
		j = a[j] - 1;
	}

	if (k > 0)
	{
		k %= cycle;
		while (k > 0)
		{
			k -= 1;
			j = a[j] - 1;
		}
	}

	printf("%d\n", j + 1);
	return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 10005
#define MAX_E 30005
#define NIL -1
#define WHITE 0
#define BLACK 1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll a[40]={}, b[40]={}, c[40]={};
    ll dp[41][401][401]={};
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    ll i;
    ll suma=0, sumb=0;
    ll ca, cb;
    
    for(i=0; i<N; i++) {
        cin >> a[i] >> b[i] >> c[i];
        suma+=a[i];
        sumb+=b[i];
    }
    
    for(i=0; i<=N; i++) {
        for(ca=0; ca<=suma; ca++) {
            for(cb=0; cb<=sumb; cb++) {
                dp[i][ca][cb]=INF;
            }
        }
    }
    
    dp[0][0][0]=0;
    
    for(i=0; i<N; i++) {
        for(ca=0; ca<=suma; ca++) {
            for(cb=0; cb<=sumb; cb++) {
                if(dp[i][ca][cb]==INF) continue;
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
            }
        }
    }
    
    ll ans=INF;
    for(ca=1; ca<=suma; ca++) {
        for(cb=1; cb<=sumb; cb++) {
            if(Ma*cb==Mb*ca)
                ans=min(ans, dp[N][ca][cb]);
        }
    }
    
    if(ans==INF) prin(-1);
    else prin(ans);
    
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int sl=s.length(),tl=t.length();
    if(sl<tl){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    vector<string> S;
    rep(i,sl-tl+1){
        int cnt=0;
        string ss=s;
        rep(j,tl){
            if(s[j+i]==t[j]||s[j+i]=='?'){
                cnt++;
            }
            if(cnt>0&&!(s[j+i]==t[j]||s[j+i]=='?'))cnt=0;
        }
        if(cnt==tl){
            rep(j,tl){
                ss[j+i]=t[j];
            }
            rep(j,sl){
                if(ss[j]=='?')ss[j]='a';
            }
            S.push_back(ss);
        }
    }
    if(S.empty()){
        cout<<"UNRESTORABLE"<<endl;
        return 0;
    }
    sort(S.begin(),S.end());
    cout<<S.front()<<endl;
    return 0;
}

Measured memory_bytes: 3608
import sys
input = sys.stdin.readline
MOD = 998244353

n = int(input())
d = [int(item) for item in input().split()]
if d[0] != 0:
    print(0)
    exit()
max_val = max(d)
cnt = [0] * (max_val + 1)
for item in d:
    cnt[item] += 1
if 0 in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for a, b in zip(cnt, cnt[1:]):
    ans *= pow(a, b, MOD)
    ans %= MOD
print(ans)



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li num2[1001001];
li sum2[1001001];

inline bool check(li n, li c) {
    // calc nCk % 2
    li bunbo = sum2[c];
    li bunshi = sum2[n] - sum2[n - c];
    return bunshi <= bunbo;
}

int main() {
    li n;
    cin >> n;
    rep(i, 20) {
        li ni = bit(i + 1);
        for (li i = ni; i < n; i += ni) {
            num2[i]++;
        }
    }
    sum2[0] = 0;
    repp(i, 1, n) {
        sum2[i] = sum2[i - 1] + num2[i];
    }

    string s;
    cin >> s;
    bool has1 = false;
    rin{
        s[i]--;
        if (s[i] == '1') {
            has1 = true;
        }
    }

    if (has1) {
        rin{
            if (s[i] == '2')s[i] = '0';
        }
    } else {
        rin{
            if (s[i] == '2')s[i] = '1';
        }
    }

    bool res = false;
    rep(i, n) {
        if (s[i] == '1') {
            res ^= check(n - 1, i);
        }
    }
    if (res) {
        cout << (has1 ? 1 : 2) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 17028
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;

int main()
{
	int n;
	cin >> n;
	vector<ll> al(n);
	map<ll, ll> mp;
	rep(i, n) {
		cin >> al[i];
		mp[al[i]]++;
	}
	ll ans = 0;
	for(auto m: mp) {
		if (m.first > m.second) {
			ans += m.second;
		}
		else if (m.first < m.second) {
			ans += m.second - m.first;
		}
	}
	cout << ans << endl;
	//cout << fixed << setprecision(10) << ans << endl;
	system("pause");
}



Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18+5
#define mod 1000000007
#define MAXN 100005
#define ll long long
#define pb push_back
#define sortv(v) sort(v.begin(),v.end())
#define tc(t) int t;cin>>t;while(t--)
#define copy copy_n
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define frr(i,a,b) for(long long i=a;i>=b;i--)
#define frn(i,a,b,n) for(long long i=a;i<=b;i=i+n)
#define gcd(x,y) __gcd(x,y)
#define ld long double
#define um unordered_map
#define mkp make_pair
#define b_s binary_search
#define nob __builtin_popcount
#define des greater<ll>()
#define fi first
#define se second
ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
void input(ll a[], ll sz) {fr(i, 0, sz) cin >> a[i];}
void print(ll a[], ll sz) {fr(i, 0, sz) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll maxr(ll a[], ll sz) {ll ma; fr(i, 0, sz) {if (i == 0) ma = a[i]; else if (a[i] > ma) ma = a[i];} return ma;}
ll minr(ll a[], ll sz) {ll mi; fr(i, 0, sz) {if (i == 0) mi = a[i]; else if (a[i] < mi) mi = a[i];} return mi;}
ll isprm(ll n) {
    if (n <= 1)  return 0;
    if (n <= 3)  return 1;
    if (n % 2 == 0 || n % 3 == 0) return 0;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return 0;
    return 1;
}
/*ll spf[MAXN];
void sieve()
{
    spf[1]=1;
    for (ll i=2; i<MAXN; i++)
        spf[i] = i;
    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for(ll i=3;i*i<MAXN;i++)
    {
        if (spf[i]==i)
        {
            for (int j=i*i;j<MAXN;j+=i)
                if (spf[j]==j)
                    spf[j]=i;
        }
    }
}*/
ll power(ll x, ll y, ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
//a+b=xor(a,b)+2*(a&b)//
struct comp
{
    bool operator()(const pair<ll, ll> &a,
                    const pair<ll, ll> &b)const
    {
        if (a.fi == b.fi)
        {
            return (a.se > b.se); //second elem in descending
        }
        return (a.first < b.first);//first elem in ascending
    }
};




int main()
{
    fio;
    ll n;
    cin>>n;
    ll a[n+5];
    input(a,n);
    ll p[n+5];
    p[0]=a[0];
    fr(i,1,n)
    {
        p[i]=a[i]+p[i-1];
    }
    ll ans=0;
    fr(i,0,n)
    {
        ll d=p[n-1]-p[i];
        ans=add(ans,mul(d,a[i]));
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6740
if __name__ == '__main__':
    # 入力
    #   N
    n = int(input())
    #   T_N
    t = [int(e) for e in input().split(' ')]
    # M
    m = int(input())
    # P_M, X_M
    p = []
    x = []
    for i in range(m):
        p_i, x_i = [int(e) for e in input().split(' ')]
        p.append(p_i)
        x.append(x_i)
    
    #print(f'【入力】n: {n}, t: {t}, m: {m}, p: {p}, x: {x}')
    
    # ドリンクごとに出力
    for drink_i in range(m):
        ans = 0
        # 問題ごとに時間を加算
        for p_i in range(n):
            #print(f'問題:{p_i} p[{drink_i}]: {p[drink_i]}')
            if p[drink_i] == p_i+1:
                # ドリンク飲む
                #print(f'x[{drink_i}]: {x[drink_i]}')
                ans += x[drink_i]
            else:
                # ドリンク飲まない
                #print(f't[{drink_i}]: {t[drink_i]}')
                ans += t[p_i]
        # 合計時間を出力
        print(ans)

Measured memory_bytes: 3064
using System;
using System.Web;
using System.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using static System.Math;
 

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string a = Console.ReadLine();
        string b = Console.ReadLine();
        string c = Console.ReadLine();
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            res += (new char[] { a[i], b[i], c[i] }).Distinct().Count() - 1;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13276
n,a,b,c = map(int,input().split())
l = []
for i in range(n):
    l.append(int(input()))
mi = 10**18
aa = []
ba = []
ca = []
da = []
def dfs(ai,bi,ci,di,i):
    global mi
    if i == n:
        if len(ai) == 0 or len(bi) == 0 or len(ci) == 0:
            return mi
        tmp = 0
        if len(ai) > 1:
            tmp += 10 * (len(ai) - 1)
        if len(bi) > 1:
            tmp += 10 * (len(bi) - 1)
        if len(ci) > 1:
            tmp += 10 * (len(ci) - 1)
        tmp += abs(a - sum(ai))
        tmp += abs(b - sum(bi))
        tmp += abs(c - sum(ci))
        mi = min(mi,tmp)
        return mi
    else:
        return min(min(dfs(ai+[l[i]],bi,ci,di,i+1),dfs(ai,bi+[l[i]],ci,di,i+1)),min(dfs(ai,bi,ci+[l[i]],di,i+1),dfs(ai,bi,ci,di+[l[i]],i+1)))
print(dfs(aa,ba,ca,da,0))

Measured memory_bytes: 85976
/* AOJ 0081
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0081
 *
 */

#include <stdio.h>
#include <math.h>



int main(){
    float x1, y1, x2, y2, xq, yq;
    double ux, uy, vx, vy, p, d;

    while(scanf("%f,%f,%f,%f,%f,%f", &x1, &y1, &x2, &y2, &xq, &yq) == 6){
        //printf("%f %f %f %f %f %f", x1, y1, x2, y2, xq, yq);
        ux = x2 - x1;
        uy = y2 - y1;

        vx = xq - x1;
        vy = yq - y1;

        d = sqrt(ux*ux + uy*uy);
        p = (ux*vx/d + uy*vy/d);
        printf("%f %f\n", xq - 2*(vx - p*ux/d), yq - 2*(vy - p*uy/d));
    }
    return 0;
}

Measured memory_bytes: 0