akhauriyash/Code-Regression huggingface dataset:
def traveling():
    n = int(input())
    t, x, y = [0], [0], [0]

    for i in range(n):
        cin = list(map(int, input().split()))
        t.append(cin[0])
        x.append(cin[1])
        y.append(cin[2])

    can = True

    for i in range(n):
        dt = t[i+1] -t[i]
        distance = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i])

        if dt < distance or distance % 2 != dt % 2:
            can = False

    return "Yes" if can else "No"


if __name__ == '__main__':
    print(traveling())

Measured memory_bytes: 11788
#include <stdio.h>
int main()
{
    int a,b,c,d,f,bg;
    scanf("%d%d",&a,&b);
    c=a+b;
    d=a-b;
    f=a*b;
    if(c>=d && c>=f){
        bg=c;
    }
    else if(d>=c && d>=f){
        bg=d;
    }
    else{
        bg=f;
    }
    printf("%d\n",bg);

    return 0;

}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        int n = sc.nextInt();
        int h[] = new int[n];
        for(int i = 0; i < n; i++) h[i] = sc.nextInt();
        
        int dp[] = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(h[1]-h[0]);
        for(int i = 2; i < n; i++)
        {
        	dp[i] = Math.min(dp[i-1]+Math.abs(h[i]-h[i-1]),dp[i-2]+Math.abs(h[i]-h[i-2]));
        }
        out.println(dp[n-1]);
        out.close();
	}

}


Measured memory_bytes: 30440
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        cin>>n>>a;
        for(i=0;i<n;i++)
        {
            cin>>c>>d;
            if((c*c+d*d)<=a*a)cnt++;


        }
        cout<<cnt<<endl;

    }
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
using namespace std;
using ll =long long;

int main() {
	int N;
	string c;
	cin >> N;
	map<string,int> S;
	vector<pair<int,string>>X;
	int max = 0;
	for (int i = 0; i < N; i++) {
		cin >> c;
		S[c]++;
		if (max < S[c]) {

			max = S[c];

	}
	}
	for (auto i = S.begin(); i != S.end(); i++) {
		X.push_back(make_pair(i->second, i->first));
	}
	sort(X.begin(), X.end());

	for (auto i = 0; i < X.size(); i++) {

		if (X[i].first == max) {
			cout << X[i].second << endl;
		}
	}
}


Measured memory_bytes: 29680
s = list(input())[::-1]+["L"]
n = len(s)

ans = 0
count = 0
now = 0
while now < n-1:
    if s[now] == "C" and s[now+1] == "B":
        count += 1
        now += 2
    elif s[now] == "A":
        if count > 0:
            ans += count
        else:
            count = 0
        now += 1
    else:
        count = 0
        now += 1
print(ans)

Measured memory_bytes: 11868
#include<stdio.h>
int main()
{
int x,y,z,d,temp,m;
scanf("%d %d %d %d",&x,&y,&z,&d);
if(x<z) m=z-x;
else m=x-z;
if(m<=d){ printf("Yes\n"); return 0; }
if(x>y){ temp=x; x=y; y=temp; }
	if(y>z){ temp=y; y=z; z=temp; }
	if(x>y){ temp=x; x=y; y=temp; }
  if(z-y<=d && y-x<=d) printf("Yes\n");
	else printf("No\n");
	}

Measured memory_bytes: 1664
def main():
    ans = 0
    a,b,n = map(int, input().split())
    if b > n:
        ans = (a*n)//b - a*(n//b)
    else:
        ans = (a*(b-1))//b - a*((b-1)//b)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9116
#include <stdio.h>
int main(void){
  int n = 0;
  scanf("%d",&n);
  int x = n / 100;
  if(x != 7){
    int y = (n - x*100) / 10;
    if (y != 7){
      int z = (n - x*100 - y*10);
      if(z != 7){
        printf("No");
        return 0;
      } else {
        printf("Yes");
        return 0;
      }
    } else {
      printf("Yes");
      return 0;
    }
  } else {
    printf("Yes");
    return 0;
  }
}

Measured memory_bytes: 1728
n,k = map(int,input().split())
a = [0] + list(map(int,input().split()))

step = 0
init_loop = 0
interval = 0
state = 1
visited = [-1]*(n+1)
visited[1] = 0
for i in range(1,3*n):
    state = a[state]
    if i == k:
        print(state)
        exit()
    if visited[state] >= 0:
        init_loop = visited[state]
        interval = i - init_loop
        break
    visited[state] = i

mod = (k - init_loop) % interval
for idx,v in enumerate(visited):
    if v == mod +init_loop:
        print(idx)
        exit()

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

int main(){
	int year, month, day;
	char a, b;
	cin >> year >> a >> month >> b >> day;

	if(year == 2019){
		if(month > 4){
			cout << "TBD" << endl;
			return 0;
		}
		else{
			cout << "Heisei" << endl;
			return 0;
		}
	}
	else if(year > 2019){
		cout << "TBD" << endl;
		return 0;
	}
	
	else cout << "Heisei" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
int N, H[101010], dp[101010];
float inf = std::numeric_limits<float>::infinity();
//typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N) cin >> H[i];
    rep(i, 0, N) dp[i] = 1000000000;
    
    dp[0] = 0;
 
    rep(i, 0, N) {
        //dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
        //dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
        chmin(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
        //cout << dp[i+1] << " ";
    }
 
    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    chal;
    long n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9)
        cout<<"hon";
    else if(n==0 || n==1 || n==6 || n==8)
        cout<<"pon";
    else
        cout<<"bon";
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int binarySearch(int *A, int key, int n){
    int left = 0, right = n;
    while(left < right){
        int mid = (left + right) / 2;
        if(key == A[mid]) return mid;
        if(key > A[mid]) left = mid + 1;
        else if(key < A[mid]) right = mid;
    }
    return -1;
}

int main(){
    int n, q, i, count = 0;
    cin >> n;
    int S[n];
    for(i = 0; i < n; i++) cin >> S[i];
    cin >> q;
    int T[q];
    for(i = 0; i < q; i++) cin >> T[i];
    for(i = 0; i < q; i++){
        if(binarySearch(S, T[i], n) != -1) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  vector<int> arr;
  for(int i=0;i<S.size()-1;++i) {
    if(S[i]!=S[i+1]) {
      arr.push_back(i+1);
    }
  }
  int index;
  map<int, int> amap;
  for(int i=0;i<S.size();++i) {
    index = upper_bound(arr.begin(), arr.end(), i) - arr.begin();
    if(index%2==0) { // Lにとうちゃく
      if((arr[index]-i)%2==0) {
        amap[arr[index]]++;
      }
      else {
        amap[arr[index]-1]++;
      }
    }
    else {
      index--;
      if((i-arr[index])%2==0) {
        amap[arr[index]]++;
      }
      else {
        amap[arr[index]-1]++;
      }
    }
  }
  for(int i=0;i<S.size();++i) cout<<amap[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 8408
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i ++)
using ll = long long;
const ll INF = 1ll<<55;
int N, W;
int Ws[100];
int Vs[100];
ll dp[101][100001];

int main() {
    cin >> N >> W;
    rep(i, N) cin >> Ws[i] >> Vs[i];
    rep(w, W + 1) dp[0][w] = 0;
    rep(i, N) {
        rep(w, W + 1) {
            dp[i+1][w] = max(w >= Ws[i] ? dp[i][w - Ws[i]] + Vs[i] : 0, dp[i][w]);
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

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

using namespace std;

const int INF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int x = 1, ans = 0;
    for (int i = 0; i < n; i++){
        int v;
        cin >> v;
        if (v == x)
            x++;
        else
            ans++;
    }
    if (x == 1){
        cout << -1;
    }
    else
        cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int n, m;
int day[200], a[200], b[200], c[200];
int dp[200][200];//dp[i][j] i - 1テヲツ猟・テァツ崢ョテ」ツ?ォテヲツ慊綱 - 1テ」ツつ津ァツ敖?」ツ?淌ヲツ卍づ」ツ?ョテ」ツδ凖」ツつケテ」ツδ暗」ツ?ョテ・ツ?、

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> day[i];
	for (int i = 0; i < m; i++)cin >> a[i] >> b[i] >> c[i];
	for (int i = 1; i < n; i++) {
		int tmp = 0;
		for (int j = 0; j < m; j++) {
			int ans = 0;
			if (a[j] <= day[i] && day[i] <= b[j]) {
				for (int k = 0; k < m; k++) {
					if (a[k] <= day[i - 1] && day[i - 1] <= b[k]) {
						ans = max(ans, dp[i - 1][k] + abs(c[j] - c[k]));
					}
				}
			}
			dp[i][j] = ans;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++)ans = max(ans, dp[n - 1][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3264
#!/usr/bin/env python3
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))

    B = []
    for i in range(N):
        B.append(A[i] - (i + 1))

    B.sort()
    b = B[int(N / 2)]

    err = 0
    for i in range(N):
        err += abs(A[i] - (b + i + 1))

    print(err)


if __name__ == '__main__':
    main()



Measured memory_bytes: 26832
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int frq[123];
int main(){
	Lancer();
	ll n, t, res = -1;
	string str;
	cin >> n>>str;
	//aabbca
	for (int i = 0; i < n; i++){
		t = 0;
		for (int j = 0; j <= i; j++){
			bool ch = true;
			for (int k = j-1; k >=0; k--){
				if (str[j] == str[k]){
					ch = false;
					break;
				}
			}
			if (ch){
				for (int k = i + 1; k < n; k++){
					if (str[j] == str[k]){
						t++;
						break;
					}
				}
			}
		}
		res = max(t, res);
	}
	cout << res;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3668
#include<iostream>

int main()
{
	int a, b, l, s;//a, b:???????????????, l:????????¢?????¨????????????, s:????????¢?????¢???
	std::cin>>a>>b;//??\???

	//l??¨s????????????????¨????
	l = 2 * (a + b);
	s = a * b;

	std::cout<<s<<" "<<l<<std::endl;//??????
	return 0;
}

Measured memory_bytes: 1164
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
    def find(self,x):
        root = x
        while self.parents[root] != root:
            root = self.parents[root]
        while self.parents[x] != root:
            parent = self.parents[x]
            self.parents[x] = root
            x = parent
        return root
    def unite(self,x,y):
        xroot,yroot = self.find(x),self.find(y)
        if xroot == yroot:
            return
        xrank,yrank = self.rank[xroot],self.rank[yroot]
        if xrank < yrank:
            self.parents[xroot] = yroot
        elif xrank == yrank:
            self.parents[yroot] = xroot
            self.rank[yroot] += 1
        else:
            self.parents[yroot] = xroot

N,Q = map(int,input().split())
uf = UnionFind(N)

for _ in range(Q):
    com,x,y = map(int,input().split())
    if com == 0:
        uf.unite(x,y)
    else:
        print(1 if uf.find(x)==uf.find(y) else 0)


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

int main(){
    int coin[]={500,100,50,10,5,1};
    int n;
    int i;
    int result;
    cin >> n;
    while(n){
        n = 1000 - n;
        i = 0;
        result = 0;
        while(n){
            if(n - coin[i] >= 0){
                n -= coin[i];
                result++;
            }else{
                i++;
                if(i > 6){
                    break;
                }
            }
        }
        cout << result << endl;
        cin >> n;
    }
}

Measured memory_bytes: 0
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;

int main() {
    abdelrahman010
    string s , t;
    cin >> s >> t;
    cout << t + s;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<time.h>
#include<vector>
#include<iomanip>
#define ll long long
using namespace std;
#define MAXN 100005
int fa[MAXN],rankk[MAXN];

int find(int x)
{
    if(x==fa[x])
        return x;
    else
        return x = find(fa[x]);
}
void init(int n)
{
    for(int i=0; i<=n; ++i)
    {
        fa[i] = i;
        rankk[i] = 1;
    }
}
void merge(int i,int j)
{
    int x = find(i),y = find(j);
    if(rankk[x]<=rankk[y])
        fa[x] = y;
    else
        fa[y] = x;
    if(rankk[x]==rankk[y] && x!=y)
        rankk[y]++;
}
int n,m;
int main()
{
    cin>>n>>m;
    init(n);
    for(int i=0; i<m; ++i){
        int u,v;
        cin>>u>>v;
        merge(u,v);
    }
    int sum = 0;
    for(int i=1; i<=n; ++i){
        if(fa[i]==i)
            sum++;
    }
    cout<<sum-1<<endl;
    return 0;
}



Measured memory_bytes: 3940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cmath>

using namespace std;

#define rep(i, n) for(long int i = 0; i < n; i++)

int main(){
    long int n, k;
    cin >> n >> k;
    long int ans = 0;
    long int num1 = 0;
    long int num2 = 0;
    if (k % 2 == 0){
        for (long int i = 1; i <= n; i++){
            if (i % k == k / 2){
                num1++;
            }
            if (i % k == 0){
                num2++;
            }
        }
    }else{
        for (long int i = 1; i <= n; i++){
            if (i % k == 0){
                num2++;
            }
        }
    }
    cout << num1*num1*num1 + num2*num2*num2 << endl;
}


Measured memory_bytes: 256
from collections import deque
from itertools import product

h, w = map(int, input().split())
c = tuple(map(lambda x: int(x)-1, input().split()))
d = tuple(map(lambda x: int(x)-1, input().split()))
s = list(input() for _ in range(h))

move_a_area = [(0, -1), (-1, 0), (1, 0), (0, 1)]
move_b_area = [(i, j) for i, j in product(range(-2, 3), repeat=2) if (i, j) not in [(0, 0)] + move_a_area]

cost = [[float('inf')] * w for _ in range(h)]
cost[c[0]][c[1]] = 0
que = deque([(c[0], c[1], 0)])

while que:
    y, x, m = que.popleft()
    # Move A
    for dx, dy in move_a_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m:
            continue
        cost[hh][ww] = m
        que.appendleft((hh, ww, m))
    # Move B
    for dx, dy in move_b_area:
        hh, ww = y + dy, x + dx
        if hh < 0 or h <= hh or ww < 0 or w <= ww or s[hh][ww] == '#' or cost[hh][ww] <= m + 1:
            continue
        cost[hh][ww] = m + 1
        que.append((hh, ww, m + 1))

print(cost[d[0]][d[1]] if cost[d[0]][d[1]] < float('inf') else -1)


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

typedef long long ll;
typedef pair<int,int> P;

const ll INF=1e18;
const int MOD=1e9+7;

int main(){
    ll N,K; cin >> N >> K;
    ll p[N];
    for(int i=0;i<N;i++){
        cin >> p[i]; p[i]--;
    }
    ll c[N];
    for(int i=0;i<N;i++){
        cin >> c[i];
    }
    ll ans=-INF;
    for(int i=0;i<N;i++){
        int ind=i;
        vector<ll> vs;
        ll cur=0;
        while(true){
            ind=p[ind];
            cur+=c[ind];
            vs.push_back(cur);
            if(ind==i) break;
        }
        int sz=vs.size();
        for(int j=0;j<sz;j++){
            if(j+1>K) break;
            int cnt=(K-j-1)/sz;
            if(cur<0){
                ans=max(ans,vs[j]);
            }else{
                ans=max(ans,vs[j]+cnt*cur);
            }
        }
    }
    cout << ans << endl;
}

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

#define PD(_A) printf("%d ", (_A));
#define PDN(_A) printf("%d\n", (_A));
#define PS(_A) printf("%s ", (_A));
#define PSN(_A) printf("%s\n", (_A));
#define PN() printf("\n");

int main(void) {
    int n, d;
    int t;
    int ans;
    int i, j, k, l;
    int values[10][10];
    int iv, jv, v;
    int tmp;
    double f;
    int count = 0;

    scanf("%d %d\n", &n, &d);

    for(i=0;i<n;i++) {
        for(j=0;j<d;j++) {
            scanf("%d", &values[i][j]);
        }
    }

    for(i=0;i<n;i++) {
        for(j=i+1;j<n;j++) {

            iv=0;
            jv=0;
            v=0;
            for(k=0;k<d;k++) {
                tmp = values[i][k] - values[j][k];
                v += tmp * tmp;
            }
            f = sqrt(v);
            if ( f-floor(f) == 0) {
                count++;
            }

        }
    }

    printf("%d\n", count);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i,n;
	char c1[101], c2[101];

	scanf("%d",&n);
	scanf("%s %s",c1,c2);
	for(i=0; i<n; i++) {
		printf("%c",c1[i]);
		printf("%c",c2[i]);
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define pqb         priority_queue<int>
#define pqs         priority_queue<int,vi,greater<int> >
#define MOD         1000000007
#define PI          3.1415926535897932384626
#define ps(x,y)     fixed<<setprecision(y)<<x
#define sortall(x)  sort(all(x))
#define w(x)        int x; cin>>x; while(x--)
#define fo(i,n)     for(ll i=0;i<n;i++)
#define fastio      ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {
  fastio;
  int n,x,t;
  cin >> n >> x >> t;
  
  cout << (int)(ceil((1.0*n)/x) * t) << "\n";
  return 0;
}



Measured memory_bytes: 3640
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>

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

int main() {
    ll l, r, ans = 2019;
    cin >> l >> r;
    if (r - l > 2019) {
        cout << 0 << endl;
        return 0;
    }
    l = l % 2019;
    r = r % 2019;
    if (r < l )ans = 0;
    else {
        for (int i = l; i < r; i++) {
            for (int j = i + 1; j <= r; j++) {
                ll tmp = i * j;
                tmp = tmp % 2019;
                ans = min(tmp, ans);
            }
       }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3168
n = int(input())
s = input()

l, r = [], []

for i in range(n):
    if s[i] == '(':
        l.append(i)
    else: r.append(i)

for rv in r[:]:
    if not l: break
    if rv > l[0]:
        r.remove(rv)
        del l[0]

print("(" * len(r) + s + ")" * len(l))


Measured memory_bytes: 2940
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int[] x = new int[m];
      int[] y = new int[m-1];
      int res = 0;
      for(int i = 0;i < m;i++)x[i]=sc.nextInt();
      Arrays.sort(x);
      for(int i = 0;i < m-1;i++){
      	y[i]=x[i+1]-x[i];
        res += y[i];
      }
      if(m==1){
        System.out.println(0);
        return;
      }
      Arrays.sort(y);
      for(int i = 1;i < n&&m-1-i>=0;i++)res -= y[m-1-i];
      System.out.println(res);
    }
}

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cma = 0;
    for(int i = 1;i < n;i++){
        string memo = s.substr(i);
        int cme = 0;
        for(char a = 'a';a <= 'z';a++){
            bool c1 = false, c2 = false;
            for(int j = 0;j < i;j++){
                if(s.at(j) == a)c1 = true;
            }
            for(int j = 0;j < memo.size();j++){
                if(memo.at(j) == a)c2 = true;
            }
            if(c1 && c2)cme++;
        }
        if(cma < cme)cma = cme;
    }
    cout << cma << endl;
}

Measured memory_bytes: 3592
<?php
$n=trim(fgets(STDIN));
$array =explode(" ", trim(fgets(STDIN)));
sort($array);
$ans = 0;
$flg =false;
foreach ($array as $num) {
	$ans += $num;
	if($flg){
		$ans /= 2;
	}else{
		$flg=true;
	}
}
echo $ans . "\n";
?>


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll n, k;
	cin >> n >> k;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	ll l = 1, r = 1e9;
	while (l < r)
	{
		ll m = l + (r - l) / 2;
		ll req = 0;
		for (int i = 0; i < n; ++i)
		{
			if (a[i] % m == 0)
			{
				req += a[i] / m - 1;
			}
			else req += a[i] / m;
		}
		if (req <= k)
		{
			r = m;
		}
		else l = m + 1;
	}
	cout << r << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin >> T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5164
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int a[200100];
int main()
{
	lint out=0;int n;
	cin>>n;rep(i,n) cin>>a[i];
	if(a[0]>0){
		cout<<-1<<endl;return 0;
	}
	rep(i,n-1){
		if(a[i]<a[i+1]-1){
			cout<<-1<<endl;return 0;
		}
	}
	rep(i,n-1){
		if(a[i]+1==a[i+1]) out++;else out+=a[i+1];
	}
	cout<<out<<endl;
}


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


class SegmentTree {
private:
    int n;
    vector<int> dat, v;
    const int INF = (1ll << 31) - 1;
public:
    SegmentTree(int N, string S) {
        n = 1;
        while (n < N) n *= 2;
        dat.resize(2 * n - 1, 0);
        v.resize(N);
        for (int i = 0; i < N; i++) v[i] = S[i] - 'a';
        for (int i = 0; i < N; i++) dat[i + n - 1] = 1<<v[i];
        for (int i = n - 2; i >= 0; i--) {
            dat[i] = dat[2 * i + 1] | dat[2 * i + 2];
        }
    }
 
    void update(int k, int a) {
        dat[k + n - 1] -= (1<<v[k]);
        v[k] = a;
        dat[k + n - 1] += (1<<a);
        k += (n - 1);
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = dat[2 * k + 1] | dat[2 * k + 2];
        }
    }
 
    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return 0;
        if (a <= l && r <= b) return dat[k];
        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl | vr;
    }
};
 
int main() {
    int N, Q;
    string S;
    cin >> N;
    cin >> S;
    cin >> Q;
   
    SegmentTree st(N, S);
    for (int i = 0; i < Q; i++) {
       int q1; cin >> q1;
        if (q1 == 1) {
            int q2; char q3; cin >> q2 >> q3;
            st.update(q2 - 1, q3 - 'a');
        } else {
          int q2, q3; cin >> q2 >> q3;  
          int res = 0;
            for(int i=0;i<26;i++){
              if(st.query(q2 - 1, q3) & (1 << i)) res++;
        }
          cout << res << endl;
        }
    }
    
}

Measured memory_bytes: 7428
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Enu = System.Linq.Enumerable;

class Program
{
    void Solve()
    {
        int N = reader.Int();
        var table = reader.IntGrid(N);
        long[] maxDist = { -1, -1 };
        double[] minTime = { double.MaxValue, double.MaxValue };

        for (int team = 0; team < 2; team++)
            for (int i = 0; i + 1 < N; i++)
                if (table[i][1] != table[i + 1][1] && table[i][2] == table[i + 1][2] && table[i][2] == team)
                {
                    long dist = Dist2(table[i][3], table[i][4], table[i + 1][3], table[i + 1][4]);
                    double time = table[i + 1][0] - table[i][0];
                    if (dist == 0) continue;
                    if (dist > maxDist[team] || dist == maxDist[team] && time < minTime[team])
                    {
                        maxDist[team] = dist;
                        minTime[team] = time;
                    }
                }
        for (int team = 0; team < 2; team++)
        {
            double d = (maxDist[team] > 0) ? Math.Sqrt(maxDist[team]) : -1;
            double t = d > 0 ? minTime[team] / 60 : -1;
            Console.WriteLine(d  + " " + t);
        }
        Console.ReadLine();
    }

    static long Dist2(long x1, long y1, long x2, long y2)
    {
        return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    }




    Reader reader = new Reader(Console.In);
    static void Main() { new Program().Solve(); }
}

class Reader
{
    private readonly TextReader reader;
    private readonly char[] separator = { ' ' };
    private readonly StringSplitOptions removeOp = StringSplitOptions.RemoveEmptyEntries;
    private string[] A = new string[0];
    private int i;

    public Reader(TextReader r) { reader = r; }
    public Reader(string file) { reader = new StreamReader(file); }
    public bool HasNext() { return Enqueue(); }
    public string String() { return Dequeue(); }
    public int Int() { return int.Parse(Dequeue()); }
    public long Long() { return long.Parse(Dequeue()); }
    public double Double() { return double.Parse(Dequeue()); }
    public int[] IntLine() { var s = Line(); return s == "" ? new int[0] : Array.ConvertAll(Split(s), int.Parse); }
    public int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public int[][] IntGrid(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public string Line() { return reader.ReadLine().Trim(); }
    private string[] Split(string s) { return s.Split(separator, removeOp); }
    private bool Enqueue()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return Enqueue();
        A = Split(line);
        i = 0;
        return true;
    }
    private string Dequeue() { Enqueue(); return A[i++]; }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

  vector<vector<P>> edge(N);
  vi col(N,-1);

  REP(i,N-1){
    int u,v,w;
    cin >> u >> v >> w;
    u--; v--;
    edge[u].emplace_back(v,w);
    edge[v].emplace_back(u,w);
  }

  queue<P> q;
  col[0]=0;
  q.emplace(0,0);

  while(!q.empty()){
    int x = q.front().first;
    int c = q.front().second;
    q.pop();

    for(auto e: edge[x]){
      int y = e.first;
      int w = e.second;
      if(col[y]!=-1)continue;

      if(w%2==0){
        col[y] = c;
      }else{
        col[y] = c ^ 1;
      }
      q.emplace(y, col[y]);
    }
  }

  REP(i,N){
    cout << col[i] << endl;
  }
}



Measured memory_bytes: 9412
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 3e5+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);


    int n; cin >> n;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.begin(), a.end(), greater<pair<int, int>>());
    ll ans = 0;
    const ll INF = 1e18;
    vector<vector<ll>> f(n+2, vector<ll>(n+2, -INF));
    f[0][0] = 0;

    for(int i = 1; i <= n; i++) {
        int ind = a[i-1].second+1;
        ll val = a[i-1].first;
        for(int j = 0; j <= i; j++) {
            // r, l
            f[i][j] = f[i-1][j]+abs(n-(i-j)+1-ind) * val;
            if(j > 0) {
                f[i][j] = max(f[i][j], f[i-1][j-1]+abs(ind-j)*val);
            }
        }
    }
    for(int i = 0; i <= n; i++) {
        ans = max(ans, f[n][i]);
    }
    cout << ans << endl;



    return 0;
    
}


Measured memory_bytes: 34588
N = int(input())
dic = dict()

for _ in range(N):
    s = input()
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
maxlist = []
# sort_dic = sorted(dic.items(), key=lambda x: x[1], reverse=True)
maxv = max(dic.values())
for di, dv in dic.items():
    if dv == maxv:
        maxlist.append(di)

maxlist.sort()
print("\n".join(maxlist))


Measured memory_bytes: 95412
#include <iostream>
using namespace std;
int main(void){
   int n,k;
   string s;
   cin>>n>>k;
   cin>>s;
   for(int i=0;i<n;i++){
       if(i==k-1){
           if(s[k-1]=='A'){
              s[k-1]='a'; 
           }
           else if(s[k-1]=='B'){
               s[k-1]='b';
           }
           else {
               s[k-1]='c';
           }
       }
   }
   cout<<s<<endl;
}


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

int main()
{
  char s[3];
  int sum1 = 0, sum2 = 0;
  for(int i = 0; i < 3; i++)
  {
	cin>>s[i];
    if(s[i] == 'A')
      sum1++;
    else if(s[i] == 'B')
      sum2++;
  }
  if(sum1 == 3 || sum2 == 3)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  return 0;
}           
 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 50000000000000000;
typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010
int N;
double C[VMAX][VMAX];
double d[VMAX];
bool F[VMAX];
int X[VMAX], Y[VMAX], R[VMAX];
ll ans;
 
void Dijkstra(int s) {
	std::fill(F, F + N + 2, false);
	//std::fill(d, d + N + 2, INF);
	d[s] = 0;
	while (true) {
		int v = -1;
		REP(i, N+2) {
			if (!F[i] && (v == -1 || d[i]<d[v]))v = i;
		}
		if (v == -1)break;
		F[v] = true;
		REP(i, N+2) {
			d[i] = std::min(d[i], d[v] + C[v][i]);
		}
	}
}
 
int main() {
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy >> N;
	X[N] = sx, Y[N] = sy, X[N + 1] = gx, Y[N + 1] = gy;
	R[N] = R[N + 1] = 0;
	REP(i, 1002)REP(j, 1002)C[i][j] = INF;
	REP(i, N) {
		cin >> X[i] >> Y[i] >> R[i];
	}
    REP(i,2)REP(j,N){
      double temp =
			sqrt(ll(X[N+i] - X[j])*ll(X[N+i] - X[j]) + ll(Y[N+i] - Y[j])*ll(Y[N+i] - Y[j]));
      if(temp<=R[j]){
        X[N+i]=X[j];
        Y[N+i]=Y[j];
        R[N+i]=R[j];
        break;
      }
    }
	REP(i, N + 2){REP(j, N + 2) {
		if (i == j) { continue; }
		double temp =
			sqrt(ll(X[i] - X[j])*ll(X[i] - X[j]) + ll(Y[i] - Y[j])*ll(Y[i] - Y[j]));
        if(temp<=R[i]+R[j]){C[i][j]=0;}
	    else C[i][j] = temp- R[i] - R[j];
		/*DEB(X[i])DEB(X[j])DEB(Y[i])DEB(Y[j])*/DEB(C[i][j])
	}END}
    std::fill(d, d + N + 2, INF);
	Dijkstra(N);
    Dijkstra(N);
	printf("%.10lf\n", d[N + 1]);
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
//setprecision(10);
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

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

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
        return b != 0 ? gcd(b, a % b) : a;
    }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong a,b; cin>>a>>b;
    llong ans=-1;
    if(a%b==0)  ans=-1;
    else ans=a;
    cout<<ans<<endl;


    return  0;
}


Measured memory_bytes: 256
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
MOD = 10**9 + 7

dp = [[0]*(c+1) for i in range(n+1)]
dp[0][0] = 1

ruiseki = [[0] * (410) for _ in range(c+1)]
for i in range(c + 1):
    for j in range(409):
        ruiseki[i][j + 1] = ruiseki[i][j] + pow(j, i, MOD)
        ruiseki[i][j + 1] %= MOD
  
for i in range(n):
    for all_num in range(c + 1):
        for j in range(all_num + 1):
            # i番目の子供に、j個の飴を配る
            dp[i+1][all_num] += (ruiseki[j][b[i]+1] - ruiseki[j][a[i]]) * dp[i][all_num - j]
            dp[i+1][all_num] %= MOD
print(dp[-1][-1])

Measured memory_bytes: 46088
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start()                            \
    chrono::system_clock::time_point start, end; \
    start = chrono::system_clock::now();
#define timer_wrap()                                                       \
    end = chrono::system_clock::now();                                     \
    double time = static_cast<double>(                                     \
        chrono::duration_cast<chrono::microseconds>(end - start).count() / \
        1000.0);                                                           \
    printf("%lf[ms]\n", time);                                             \
    start = end;
#define optimize_cin() \
    cin.tie(0);        \
    ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000    // 10^9
#define INFINF LLONG_MAX  // 2^63-1
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;
}
// ########## template end ##########

#ifdef DEBUG_ON
void test_all();
#endif

void resolve() {
    ll A;
    long double B;
    cin >> A >> B;
    ll ans = (A * B);
    cout << fixed << setprecision(0) << ans << endl;
}

int main() {
#ifdef DEBUG_ON
    test_all();
#else
    resolve();
#endif
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int a;
    string s;
    cin >> a >> s;
    if(a < 3200) {
        printf("red\n");
    }
    else {
        printf("%s\n", s.c_str());
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a[5],i,i2,L,S,N,w,whi,NN;
	for(i=4;i>0;i--)scanf("%1d",&a[i]);
	while(!(a[4]==0&&a[3]==0&&a[2]==0&&a[1]==0)){
		whi=0;
		while(!((a[4]==6&&a[3]==1&&a[2]==7&&a[1]==4)||(a[4]==a[3]&&a[3]==a[2]&&a[2]==a[1]))){
			for(i=1;i<=4;i++){
				for(i2=1;i2<=4;i2++){
					if(a[i]<a[i2]){
						w=a[i];
						a[i]=a[i2];
						a[i2]=w;
					}
				}
			}
			L=a[4]*1000+a[3]*100+a[2]*10+a[1];
			for(i=1;i<=4;i++){
				for(i2=1;i2<=4;i2++){
					if(a[i]>a[i2]){
						w=a[i];
						a[i]=a[i2];
						a[i2]=w;
					}
				}
			}
			S=a[4]*1000+a[3]*100+a[2]*10+a[1];
			N=L-S;
			NN=N/1000;
			a[4]=NN;
			N-=NN*1000;
			NN=N/100;
			a[3]=NN;
			N-=NN*100;
			NN=N/10;
			a[2]=NN;
			N-=NN*10;
			a[1]=N;
			whi++;
		}
		if((a[4]==a[3]&&a[3]==a[2]&&a[2]==a[1]))printf("NA\n");
		else printf("%d\n",whi);
		for(i=4;i>0;i--)scanf("%1d",&a[i]);
	}
}

Measured memory_bytes: 608
import math
import fractions
import copy
import numpy as np

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
n = ip()
a = []
ma = 1
mnum = -1
for i in range(n):
  a.append(ip())
  if mnum < a[i]:
    ma = 1
    mnum = a[i]
  elif mnum == a[i]:
    ma+=1
for i in range(n):
  if a[i] != mnum or ma>1:
    print(mnum)
  elif a[i] == mnum:
    b = copy.copy(a)
    b.pop(i)
    print(max(b))

Measured memory_bytes: 24500
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>

int main(){
/*	freopen("in.txt.txt","r",stdin);
	freopen("out.txt.txt","w",stdout);*/
    int a[3][3],n,x,i,j,k;
    for(i=0;i<3;i++){
        for(j=0;j<3;j++) scanf("%d",&a[i][j]);
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&x);
        int f=0;
        for(j=0;j<3;j++){
            for(k=0;k<3;k++){
                if(a[j][k]==x){
                    a[j][k]=-1;
                    f=1;
                    break;
                }
            }
            if(f) break;
        }
    }
    for(i=0;i<3;i++){
        if(a[i][0]==-1 && a[i][1]==-1 && a[i][2]==-1){
            printf("Yes");
            return 0;
        }
        if(a[0][i]==-1 && a[1][i]==-1 && a[2][i]==-1){
            printf("Yes");
            return 0;
        }
    }
    if(a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1){
        printf("Yes");
        return 0;
    }
    if(a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1){
        printf("Yes");
        return 0;
    }
    printf("No");
	return 0;
}

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

typedef long long ll;
typedef const void cv;
int downint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}


int main(void){
  int n,k,i,h[200000];
  ll result=0;
  scanf("%d",&n);
  scanf("%d",&k);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  if(n<=k){
    printf("0");
    return 0;
  }
  qsort(h,n,sizeof(int),downint);
  for(i=k;i<n;i++){
    result+=(ll)h[i];
  }
  printf("%lld",result);
  
  return 0;
  
  
  
  
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
#define Sart(a) sort(a, sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int H, W;
	int h, w;

	cin >> H >> W;
	cin >> h >> w;

	Out((H - h) * (W - w));
	
	return 0;
}


Measured memory_bytes: 256
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  1005

ll h,w;
bool a[N][N];
ll dp[N][N];

ll solve(ll i, ll j){
	if(i==0 and j==0)return dp[i][j]=1;
	if(i<0 or j<0)return 0;
	if(dp[i][j]!=-1)return dp[i][j];
	ll ans=0;
	if(!a[i][j])ans=(solve(i-1,j)+solve(i,j-1))%hell;
	return dp[i][j]=ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	rep(i,0,N)rep(j,0,N)dp[i][j]=-1;
	while(TESTS--)
	{
			cin>>h>>w;
			rep(i,0,h){
				string s;
				cin>>s;
				rep(j,0,w){
					if(s[j]=='#')a[i][j]=1;
				}
			}	
			cout<<solve(h-1,w-1)<<endl;
			

	}
	return 0;
}

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

Measured memory_bytes: 2968
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n;cin >> n;
  string s,t; cin >> s >> t;
  int k = n;
  REP(i,n){
    if(s[i] != t[0])continue;
    bool ok = true;
    for(int j = i; j < n; j++){
      if(s[j] != t[j - i]){
	ok = false;
	break;
      }
    }
    if(ok){
      k = i;
      break;
   }
  }
  cout << k + n << endl;
}


Measured memory_bytes: 256