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

int main(){
  int a = 0; 
  int b = 0;
  string s, t, u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (s == u)
    cout << a-1 <<" "<< b << endl;
  if (t == u)
    cout << a <<" "<< b-1 << endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
a=[]
for _ in range(H):
  a.append(list(input()))

for i in range(H):
  is_in_black=False
  for j in range(W):
    if a[i][j]=='#':
      is_in_black=True
      break
  if is_in_black == False:
    for j in range(W):
      a[i][j]=0
  pass

for j in range(W):
  is_in_black=False
  for i in range(H):
    if a[i][j]=='#':
      is_in_black=True
      break
  if is_in_black == False:
    for i in range(H):
      a[i][j]=0
  pass

# print ans
for i in range(H):
  ans = ''
  for j in range(W):
    if a[i][j]!=0:
      ans+=a[i][j]
  if len(ans)!=0:
    print(ans)



Measured memory_bytes: 3188
n,m = map(int, input().split())
AC = [0] * (n+1)
WA = [0] * (n+1)

for j in range(m):
    p,s = input().split()
    p = int(p)

    if s == 'AC':
        AC[p] = 1
    elif s == 'WA'and AC[p] != 1:
        WA[p] += 1

for i in range(n + 1):
    if AC[i] != 1:
        WA[i] = 0

print(sum(AC),sum(WA))


Measured memory_bytes: 4596
using System;
class Program
{
          static void Main(string[] args)
        {
            var H = int.Parse(Console.ReadLine());
            var W = int.Parse(Console.ReadLine());
            var N = int.Parse(Console.ReadLine());
            var a = (H > W) ? H : W;
            int ans = N / a + ((N % a == 0) ? 0 : 1);

            Console.WriteLine(ans.ToString());
          }
}

Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main(){
    int a,b,c=0;
    scanf("%d%d%d",&a,&b,&c);
    if(c-(a-b)<0){printf("%d",0);}
    else{printf("%d",c-(a-b));}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
  int i,b;
  int m[10];
  int f;

  for( i=0;i<3;i++)m[i]=0;

  for( i=0;i<10;i++){
    scanf("%d ",&m[i]);
  }

  do{
    f=0;
    for(i=0;i<9;i++){
      if( m[i]<m[i+1] ){
	b=m[i];
	m[i]=m[i+1];
	m[i+1]=b;
	f=1;
      }
    }
  }while(f==1);


  for(i=0;i<3;i++)
    printf("%d\n",m[i]);

  return 0;

}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

const int Max = 303;

int main() {

  for(string s_; cin >> s_ && s_ != "#END";) {
    const int N = s_.size();

    string max_string;
    int max_length = 0;

    REP(k, 1, N) {
      const int sn = k;
      const int tn = N - k;
      string s = string(s_.begin(), s_.begin() + sn);
      string t = string(s_.begin() + sn, s_.end());
      int dp[Max][Max];
      int trans[Max][Max];

      zero(dp);
      minus(trans);

      rep(i, sn) {
        rep(j, tn) {
          if(s[i] == t[j]) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            trans[i + 1][j + 1] = 2;
          }
          else if(dp[i + 1][j] > dp[i][j + 1]) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
            trans[i + 1][j + 1] = 0;
          }
          else {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            trans[i + 1][j + 1] = 1;
          }
        }
      }

      if(dp[sn][tn] > 0) {
        int i = sn, j = tn;
        string res;
        while(trans[i][j] >= 0) {
          if(trans[i][j] == 1) i--;
          else if(trans[i][j] == 0) j--;
          else {
            i--, j--;
            res.push_back(s[i]);
          }
        }

        if(max_length < res.size()) {
          reverse(res.begin(), res.end());
          max_length = res.size();
          max_string = res;
        }
      }
    }

    cout << max_string << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3892
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
struct cake{
  ll x,y,z;
};
int main(){
  ll n,m,tmp,ans=0,vsum[8]={},xv,yv,zv;
  cin >> n >> m;
  vector<cake> val;
  ll x[n],y[n],z[n];
  for(int i=0;i<n;i++){
    cin >> x[i]>>y[i]>>z[i];
    val.push_back({x[i],y[i],z[i]});
  }
  for(int i=0;i<8;i++){
    sort(val.begin(),val.end(),[i](const cake& a,const cake &b){
      ll xsign,ysign,zsign;
      ll aval,bval;
      xsign = ((i&1)==1)?1:-1;
      ysign = ((i&2)==2)?1:-1;
      zsign = ((i&4)==4)?1:-1;
      aval = a.x*xsign + a.y*ysign + a.z*zsign;
      bval = b.x*xsign + b.y*ysign + b.z*zsign;
      return aval > bval;
    });
    xv = yv = zv = 0;
    for(int j=0;j<m;j++){
      xv += val[j].x;
      yv += val[j].y;
      zv += val[j].z;
    }
    tmp = llabs(xv)+llabs(yv)+llabs(zv);
//    cout << tmp<<endl;
    ans = max(tmp,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int lNum = s.nextInt();
		int rNum = s.nextInt();
		int ldim = lNum % 2019;
		int rdim = rNum % 2019;
		s.close();
		int min = 2019;
		if (lNum / 2019 == rNum / 2019) {
			for (int i = ldim; i < rdim; i++) {
				for (int j = i + 1; j <= rdim; j++) {
					int amari = (i * j) % 2019;
					if (amari < min) {
						min = amari;
					}
					if(amari == 0) {
						min = 0;
						break;
					}
				}
			}
		}else {
			min = 0;
		}
		System.out.println(min);

	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a<=c&&c<=b?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
N = int(input())
a = [0] * N
for i in range(N):
    k = int(input())
    li = [i+1,k]
    a[i] = li
a.insert(0,[0,0])
import sys
sys.setrecursionlimit(100000000)
seen = [False] * (N+1)
def dfs(i):
    seen[i] = True
    if seen[a[i][1]] == False:
        dfs(a[i][1])
dfs(1)
def search(a):
    import collections
    from collections import deque
    que = deque()
    count = 0
    que.append(1)
    while len(que) != 0:
        i = que.popleft()
        if i != 2:
            count+=1
            que.append(a[i][1])
        if i == 2:
            return count
if seen[2]:
    k = search(a)
    print(k)
else:
    print(-1)

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

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

    vector<double> p(N);
    rep(i, 0, N){
        cin >> p[i];
    }

    vector<double> acc(N+1,0);
    rep(i, 1, N+1){
        acc[i] = acc[i-1] + (p[i-1]+1)/2;
    }

    double ans = 0;
    rep(i, 0, N-K+1){
        ans = max(ans, acc[i+K]-acc[i]);
    }

    printf("%12.12lf\n", ans);
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> mochi(N);
  for (int i = 0; i < N; i++){
    cin >> mochi.at(i);
  }
  
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      if (mochi.at(i) > mochi.at(j)){
        int x;
        x = mochi.at(i);
        mochi.at(i) = mochi.at(j);
        mochi.at(j) = x;
      }
    }
  }
  cout << endl;
  int stair = 1;
  for (int i = 0; i < N - 1; i++){
    if(mochi.at(i+ 1) < mochi.at(i)){
      stair++;
    }
  }
  cout << stair << endl ;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
ls = [[i for i in '.'+input()+'.'] for i in range(h)]
ls.insert(0, ['.' for i in range(w+2)])
ls.append(['.' for i in range(w+2)])

ans = 'Yes'
for i in range(1, h+1):
    for j in range(1, w+1):
        if ls[i][j] == '#' and '#' not in [ls[i][j-1], ls[i][j+1], ls[i-1][j], ls[i+1][j]]:
            ans = 'No'

print(ans)


Measured memory_bytes: 3064
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            var input = Console.ReadLine().Split(' ');
            long[] numbers = new long[n];
            long res = 1;
            bool haszero = false;
            double logres = 0;

            for (int i = 0; i < n; i++)
            {
                numbers[i] = long.Parse(input[i]);
                if (numbers[i] == 0)
                    haszero = true;
            }

            if (haszero)
            {
                Console.WriteLine(0);
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    res *= numbers[i];
                    logres += Math.Log10(numbers[i]);

                    if (res > 1000000000000000000 || logres > 18)
                    {
                        res = -1;
                        break;
                    }
                }
                Console.WriteLine(res);
            }

        }

    }
}



Measured memory_bytes: 40832
from itertools import chain
K, N = map(int, input().split())
S = 0
M = 0

A = map(int, input().split())

prev = next(A)
for a in chain(A, [prev+K]):
  d = a - prev
  S += d
  M = max(M, d)
  prev = a

print(S-M)

Measured memory_bytes: 18672
#include <stdio.h>
int main()
{
	int n, m;
	while(scanf("%d %d", &n, &m))
	{
		int ans = 0;
		if(n == 0 && m == 0)
		{
			break;
		}
		for(int i = 1; i < n - 1; i++)
		{
			for(int j = i + 1; j < n; j++)
			{
				for(int k = j + 1; k < n + 1; k++)
				{
					if(m == i + j + k)
					{
						ans++;
					}
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2724
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    k = int(input())
    even = k // 2
    odd = k - even
    print(even*odd)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi					3.14159265359
ll INF=1e18+10;
ll MOD=998244353;

char win(char c)
{
    if(c=='r')return 'p';
    else if(c=='p')return 's';
    return 'r';
}

int main()
{
    int n,k;cin>>n>>k;
    map<char,ll> m;
    ll r,s,p;
    cin>>r>>s>>p;
    m['r']=r,m['s']=s,m['p']=p;
    ll sum=0;
    string t;
    cin>>t;
    char a[n];
    rep(i,0,k)
        a[i]=win(t[i]);
    rep(i,k,n)
    {
        if(win(t[i])==a[i-k])
            a[i]='l';
        else
            a[i]=win(t[i]);
    }
    //rep(i,0,n)cout<<a[i];
    //cout<<endl;
    rep(i,0,n)
    if(a[i]!='l')sum+=m[a[i]];
    cout<<sum;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

class Main {

    public static void main(String[] args) {

	int[] count = new int[101];
	Scanner stdin = new Scanner( System.in );
	while ( stdin.hasNextInt() ) {
	    count[stdin.nextInt()]++;
	}

	final int max = max( count );
	for ( int i = 0; i < count.length; i++ ) {
	    if ( count[i] == max ) {
		System.out.println( i );
	    }
	}
	
    }

    static int max( int[] array ) {
	int max = 0;
	for ( int i : array ) {
	    if ( max < i ) {
		max = i;
	    }
	}
	return max;
    }
    
}

Measured memory_bytes: 18152
#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9+7;
const int MOD2 = 1e9 + 9;
const int INF = 5e18;
 
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
int exp(int a, int b){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = result*a;
 
        b >>= 1;
        a = a*a;
    }
    return result;
}

void solve(){
    int n; cin>>n;
    set<string>s;
    while(n--){
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;

}
signed main(){
    fastio; 
    // int x=0;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 19124
#include <cmath>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

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

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

	int sum = accumulate(a.begin(), a.end(), 0);

	int ans = 0;
	bitset<1024*2048> b(1);
	for(int i=0; i<n; ++i)
	{
		b |= (b << a[i]);
	}

	for(int i=0; i<=sum/2; ++i)
		if(b[i])
			ans = (sum - i);
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  int P; cin >> P;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  vector<int> o(N+1, 0), e(N+1, 0);
  e[0] = 1;
  rep(i, N) {
    if(A[i]%2 == 0) {
      o[i+1] = o[i] + o[i];
      e[i+1] = e[i] + e[i];
    } else {
      o[i+1] = o[i] + e[i];
      e[i+1] = o[i] + e[i];
    }
  }
  
  if(P == 0) cout << e[N] << endl;
  else cout << o[N] << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    int X,Y;cin>>X>>Y;
    int ans=0;
    if(X==1&&Y==1) ans+=400000;
    if(X==1) ans+=300000;
    if(X==2) ans+=200000;
    if(X==3) ans+=100000;
    
    if(Y==1) ans+=300000;
    if(Y==2) ans+=200000;
    if(Y==3) ans+=100000;
    
    cout<<ans<<endl;
}



Measured memory_bytes: 764
#ライブラリのインクルード
import math
#点間距離計算変数
S = 0
#整数カウンタの設定
C = 0
#事前情報を取得
n = input().split()
#D次元空間上にN個の点が存在
N = int(n[0])
D = int(n[1])
#座標データ格納
X = []
for k in range(N):
  X.append(input().split())
#点間距離計算
for N1 in range(N):
  for N2 in range(N):
    if N1 < N2:
      for i in range(D):
        S = S + (int(X[N1][i]) - int(X[N2][i])) ** 2
      S = math.sqrt(S)
      #整数判定(decimal：小数部分,integer:整数部分)
      decimal, integer = math.modf(S)
      if decimal == 0:
        C = C + 1
      S = 0
print(C)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

int main()
{
  int n;
  cin>>n;
  if (n == 1) cout<<"Hello World"<<endl;
  else {
    int a, b;
    cin>>a>>b;
    cout<<a+b<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
from collections import deque
import copy

def bfs(grid, start):
    H, W = len(grid), len(grid[0])
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0
    while queue:
        x, y = queue.popleft()
 
        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
    return max(map(max, distance))

h, w = map(int, input().split())
maze = [input() for _ in range(h)]


res = -1
for i in range(h):
    for j in range(w):
        if(maze[i][j] == '#'): continue
        tmpmaze = copy.deepcopy(maze)
        steps = bfs(tmpmaze, [i, j])
        if(steps > res):
            res = steps
print(res)

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 55, M = 1010;

int n;
LL f[N], p[N], x;

void solve()
{
	scanf("%d%lld", &n, &x);
	f[0] = p[0] = 1LL;
	for (int i = 1; i <= n; i ++ ) 
	{
		f[i] = 2 * f[i - 1] + 3LL;
		p[i] = 2 * p[i - 1] + 1LL;
	}	
	
	LL res = 0;
	for (int i = n; i >= 0; i -- )
	{
		if (x == 0) break;
		if (x == f[i])
		{
			res += p[i];
			break;
		}

		if (x <= 1LL + f[i - 1]) x -- ;
		else
		{
			res += 1LL;
			if (i) res += p[i - 1];
			x -= f[i - 1] + 2LL;
		}
	}
	printf("%lld\n", res);
}

int main()
{
	int T = 1;
	// scanf("%d", &T);
	// cin >> T;
	while (T -- ) solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void func(ll N,vector<ll> &p){
  
  ll i = 2;
  while(1){
    ll c = 0;

    while(1){
      if(N%i == 0){
        N = N/i;
        c++;
        if(N == 1){

          p[i] += c;
          break;
        }
       }
      else if(N%i != 0){
        if(c>=1){

          p[i] += c;
          break;
         }
         else if(c == 0){
           break;
         }
       }
      }
      i++;
      if(N ==1) break;
     }
  return ;
}

int main() {
  ll N;
  cin >> N;
 vector<ll> p(1100);

  for(int i = 2;i<=N;i++){
    func(i,p);
  }
  ll ans = 1;
  ll d = 1000000000 + 7;
  for(int i = 2;i<=N;i++){
    if(p[i] != 0){
     ans = ans*(p[i]+1)%d;
    }
  }
  cout << ans <<endl;
}


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

#define ll             long long
#define LL             long long
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define TN             typename
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define endl           '\n'

template <TN T> T gcd(T a, T b) {
    return !b ? a : gcd(b, a % b);
}

template <TN T> T lcm(T a, T b) {
    return a * (b / gcd(a, b));
}

template <TN T> T sqr(T a) {
    return a * a;
}

template <TN T> T cube(T a) {
    return a * a * a;
}

template <TN T> inline void smin(T &a, T b) {
    a = a < b ? a : b;
}

template <TN T> inline void smax(T &a, T b) {
    a = a > b ? a : b;
}

int in() {
    int n;
    scanf("%d", &n);
    return n;
}

ll Lin() {
    ll n;
    scanf("%lld", &n);
    return n;
}

double Din() {
    double n;
    scanf("%lf", &n);
    return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e6 + 5;

struct CHT_INC_MAX {
    vl m, b;

    bool bad(int f1, int f2, int f3) {
        return 1.0 * (b[f2] - b[f1]) * (m[f1] - m[f3]) > 1.0 * (b[f3] - b[f1]) * (m[f1] - m[f2]);
    }

    void add(ll M, ll B) {
        m.pb(M), b.pb(B);
        int sz = (int)m.size();
        while(sz >= 3 && bad(sz - 3, sz - 2, sz - 1)) {
            m.erase(m.end() - 2);
            b.erase(b.end() - 2);
            sz--;
        }
    }

    ll f(int idx, ll X) {
        return m[idx] * X + b[idx];
    }

    ll query(ll X) {
        int low = 0, high = (int) m.size() - 1;
        while (high - low >= 5) {
            int mid1 = (low + low + high) / 3;
            int mid2 = (low + high + high) / 3;
            if (f(mid1, X) <= f(mid2, X)) {
                low = mid1 + 1;
            } else {
                high = mid2 - 1;
            }
        }
        ll res = f(low, X);
        for (int i = low + 1; i <= high; i++) {
            res = max(res, f(i, X));
        }
        return res;
    }
};

int a[N], l[N], r[N];

int solve() {
    int n = in();
    for(int i = 1; i <= n; i++) {
        a[i] = in();
    }
    for(int i = 1; i <= n; i++) {
        if(i == 1) l[i] = a[i];
        else l[i] = max(l[i - 1], a[i]);
    }
    for(int i = n; i >= 1; i--) {
        if(i == n) r[i] = a[i];
        else r[i] = max(r[i + 1], a[i]);
    }
    for(int i = 1; i <= n; i++) {
        if(i == n) printf("%d\n", l[i - 1]);
        else if(i == 1) printf("%d\n", r[i + 1]);
        else  printf("%d\n", max(r[i + 1], l[i - 1]));
    }
    return 0;
}

int main() {
    int test = 1, tc = 0;
    //scanf("%d", &test);
    while (test--) {
        //printf("Case %d: ", ++tc);
        solve();
    }
    return 0;
}









Measured memory_bytes: 10624
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

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

using namespace std;
const int INF = 0x7fffffff;

int gcd(int x,int y){
  int mi,ma;
  ma = max(x,y);
  mi = min(x,y);
  if(ma % mi == 0){
    return mi;
  }
  else{
    return gcd(mi,ma % mi);
  }
}

struct Edge{
  int t;
  int w;
  Edge(int to,int weight){
    t = to;
    w = weight;
  }
  bool operator<(const Edge& another) const{
    return w < another.w ;
  }
};

struct Path{
  int from;
  int to;
  int weight;

  bool operator<(const Path& another) const{
    return weight < another.weight;
  }

};

struct UnionFind{
  vector<int> par;

  UnionFind(int n){
    par.resize(n);
    int ii;
    for(ii=0;ii<n;ii++){
      par[ii] = ii;
    }
    
  }

  int root(int x){
    if(par[x] == x) return x;
    return root(par[x]);
    //return par[x] = root(par[x]);
  }

  void unite(int x,int y){
    int root_x = root(x);
    int root_y = root(y);
    if(root_x == root_y) return;
    par[root_x] = root_y;
  }

  bool same(int x,int y){
    int root_x = root(x);
    int root_y = root(y);
    return root_x == root_y ;
  }
};

using Graph = vector<vector<Edge>>;

int main(){
  long ii,jj,kk;
  vector<int> a;
  int v,e;

  // 入力
  cin >> v >> e;

  Graph g;
  g.resize(v);

  int s,t,w;
  vector<Path> pathes;
  Path p;

  for(ii=0;ii<e;ii++){
    //s 開始位置
    //t TO位置
    //w 重み
    cin >> s >> t >> w;
    p.from = s;
    p.to   = t;
    p.weight = w;
    //g[s].push_back(Edge(t,w));

    pathes.push_back(p);
  }
  
  //sort(g.begin(),g.end());

  sort(pathes.begin(),pathes.end());
  
  set<int> tree[v];

  long long int sum = 0;

  int from,to,weight;
  set<int> tmp;
  UnionFind uf(v);
  //cout << "root(2)" << uf.root(2) << endl;

  //cout << "same" << uf.same(1,2) << endl;
  // Edege分回す
  for(ii=0;ii<e;ii++){

    from   = pathes[ii].from;
    to     = pathes[ii].to;
    weight = pathes[ii].weight;

    if(!uf.same(from,to)){
      sum += weight;
    }

    uf.unite(from,to);
//
//    tmp = tree[from];
//
//    //tmp.insert(to);
//    //cout << "from:" << pathes[ii].from << "to:" << pathes[ii].to << "weight:" << pathes[ii].weight << endl;
//
//    //tree上に両方の端点が無い場合sumを加算
//    if(tree[from].find(to) == tree[from].end() &&
//       tree[to].find(from) == tree[to].end()){
//      sum += weight;
//      //cout << "**from:" << pathes[ii].from << "to:" << pathes[ii].to << "weight:" << pathes[ii].weight << endl;
//    }
//
//    //treeにToをとfromを追加
//    tree[from].insert(to);
//    tree[to].insert(from);
//
//    for(auto ed : tree[from]){
//      tree[to].insert(ed);
//    }
//
//    for(auto ed : tree[to]){
//      tree[from].insert(ed);
//    }

  }

  cout << sum << endl;
  
  return 0;

}



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

int main() {
  int N,a;
  cin >> N >> a;
  vector<string> b(N);
  for(int i = 0; i < N; i++) {
    cin >> b.at(i);
  }
  for(int i = 0; i < a + 2; i++) {
    cout << "#" ;
  }
  cout << endl;
  for(int i = 0; i < N; i++) {
    cout << "#" + b.at(i) + "#" << endl;
  }
  for(int i = 0; i < a + 2; i++) {
    cout << "#" ;
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

class UnionFind():
    def __init__(self, n):
        self.n = n #要素数
        self.parents = [-1] * n #親格納配列(親のときは下流の要素数のマイナスを返す)

    def find(self,x):
        if self.parents[x] < 0: #親のとき
            return x
        else:
            self.parents[x] = self.find(self.parents[x]) #再帰で親に繋ぎ変える
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y: #親が同じときスキップ
            return

        if self.parents[x] > self.parents[y]: #要素数が多いほうをxにする
            x, y = y, x

        self.parents[x] += self.parents[y] #xの要素数はyの要素数ぶん増える
        self.parents[y] = x #yをxの子にする

    def size(self, x): #xの属するグループの要素数
        return -self.parents[self.find(x)]

    def same(self, x, y): #同じグループか判定
        return self.find(x) == self.find(y)

    def members(self, x): #xの属するグループの要素一覧
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self): #根の一覧
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self): #グループ個数
        return len(self.roots())

    def all_group_members(self): #根とその要素の辞書配列
        return {r: self.members(r) for r in self.roots()}

    def __str__(self): #print用
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
U=UnionFind(n)
A=[n*(n-1)//2]
V=[]
for i in range(m):
    a,b=map(int,input().split())
    V.append([a-1,b-1])
V=list(reversed(V))

for i in range(m):
    if i==m-1:
        continue
    a=V[i][0]
    b=V[i][1]
    if not U.same(a,b):
        s=U.size(a)
        t=U.size(b)
        u=s+t
        U.union(a,b)
        d=u*(u-1)//2-s*(s-1)//2-t*(t-1)//2
        A.append(A[-1]-d)
    else:
        A.append(A[-1])
A=reversed(A)
for a in A:
    print(a)

Measured memory_bytes: 110044
#include<bits/stdc++.h>
using namespace std;
struct Card{
    char c;
    int num;
};

void printstruct(Card a[], int n){
    for(int i=0; i<n; i++){
        cout << a[i].c << a[i].num;
        if(i!=n-1){
            cout << " ";
        }
    }
    cout << endl;
}

void bubbleSort(Card a[], int n){
    int flag = 1, count = 0;
    while(flag){
        flag = 0;
        for(int j=n-1; j>=1; j--){
            if(a[j].num<a[j-1].num){
                Card tmp = a[j];
                a[j] = a[j-1];
                a[j-1] = tmp;
                flag = 1;
                count++;
            }
        }
    }
    printstruct(a, n);
    cout << "Stable" << endl;    
}

void selectionSort(Card a[], int n){
    int count = 0;
    for(int i=0; i<n; i++){
        int minj = i;
        for(int j=i; j<n; j++){
            if(a[j].num<a[minj].num){
                minj = j;
            }
        }
        if(i!=minj){
            Card tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
            count++;
        }
    }
    printstruct(a, n);
    //cout << count << endl;
}

int main(){
    int n;
    cin >> n;
    Card a1[n], a2[n];
    for(int i=0; i<n; i++){
        cin >> a1[i].c;
        a2[i].c = a1[i].c;
        cin >> a1[i].num;
        a2[i].num = a1[i].num;
    }

    bubbleSort(a1, n);
    selectionSort(a2, n);
    int flag = 0;
    for(int i=0; i<n; i++){
        if(a1[i].c != a2[i].c){
            flag = 1;
        }
    }
    if(flag == 0){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
}


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

int main() {
    string s;
    cin >> s;
    size_t len = s.length(), i=0;
    while (len-i >= 5) {
        if (len-i >= 7 && s.substr(i,7) == "dreamer" && (len-i < 10 || s.substr(i+7,3) != "ase")) {
            i += 7;
        } else if (len-i >= 6 && s.substr(i,6) == "eraser" && (len-i < 9 || s.substr(i+6,3) != "ase")) {
            i += 6;
        } else if (s.substr(i,5) == "dream" || s.substr(i,5) == "erase") {
            i += 5;
        } else {
            break;
        }
    }
    if (len == i) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) a.begin(),a.end()

int main(){
	int X,A;cin>>X>>A;
	if(X<A){
		cout<<0<<endl;
	}else{
		cout<<10<<endl;
	}
}


Measured memory_bytes: 256
def bubbleSort(A, N):
    swap = 0
    flag = True
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                swap += 1
                flag = True
    return swap
N = int(input())
A = list(map(int,input().split()))
swap=bubbleSort(A,N)
print(" ".join(map(str,A)))
print (swap)

Measured memory_bytes: 7636
import numpy as np
import sys

n = int(input())
h = np.array(list(map(int,input().split())))
temp = h[0]

for index,value in enumerate(h):
  if temp>value:
    h[index] += 1
    if h[index-1]>h[index]:
      print("No")
      sys.exit()
  temp = h[index]

print("Yes")

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int X, Y, Z; cin >> X >> Y >> Z;
    ll sum = 0, cnt = 0;
    if(2 * Z + Y <= X) {
        cnt++;
        sum += 2 * Z + Y;
        while(sum + Y + Z <= X) {
            sum += Z + Y;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
typedef long double ll;

const ll MAX = 4000;
vector<ll> ar(3000);
vector<vector<ll>> dp(MAX, vector<ll>(MAX, -1));

ll func(ll n, ll k)
{
    if (n == 0 && k == 0)
    {
        return 1;
    }
    if (k > n)
    {
        return 0;
    }
    if (k < 0 || n < 0)
    {
        return 0;
    }
    if (dp[n][k] != -1)
    {
        return dp[n][k];
    }
    else
    {
        return dp[n][k] = func(n - 1, k) * (1 - ar[n]) + func(n - 1, k - 1) * ar[n];
    }
}

int main()
{
    int n;
    cin >> n;
    for (int x = 1; x <= n; x++)
    {
        cin >> ar[x];
    }
    ll a = 0;
    ll max = 0;
    while (max <= n)
    {
        if (max > n / 2)
            a += func(n, max);
        max++;
    }
    cout << std::setprecision(10) << a << endl;
}

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

int h[100002];

int dp[100002];

int solve(int i, int n, int k) {
    if(i == n )
        return dp[i] = 0;
    if(dp[i]!=-1)
        return dp[i];
    int ans  = 1e9;
    
    for(int j = 1; j<=k; j++) {
        if(i+j <=n)
            ans = min(ans, abs( h[i] - h[i+j])  + solve(i+j, n, k) );
        else
            break;
    }
      return dp[i] = ans;
}
int main() {
	int n, k;
	cin>>n>>k;
	int i;
	for(i=1;i<=n;i++)   cin>>h[i], dp[i] = -1;
	int ans = solve(1, n, k);
	cout<<ans<<"\n";
	return 0;
}

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

int main(){
	int num_battle;
	int a, b;
	int point_a = 0;
	int point_b = 0;
	string cards;

	cin >> num_battle;
	
	for(; num_battle != 0;){
		while(num_battle > 0){
			cin >> a >> b;
			if(a == b){
				point_a += a;
				point_b += b;
			}else if(a > b){
				point_a += a + b;
			}else{
				point_b += a + b;
			}
			num_battle--;
		}
		cout << point_a << " " << point_b << endl;
		// initialize
		point_a = 0;
		point_b = 0;
		cin >> num_battle;
	}

	return 0;
}

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

const ll MOD = 1e9 + 7;
map<pll, ll> dp;

ll f(ll s, ll x) {
  if (dp.count(pll(s, x))) return dp[pll(s, x)];
  if (s == 0 && x == 0) return 1;

  ll res = f(s/2, x/2) % MOD;
  if (s >= 1 && x >= 1) {
    res = (res + f((s-1)/2, (x-1)/2)) % MOD;
  }
  if (s >= 2) {
    res = (res + f((s-2)/2, x/2)) % MOD;
  }
  return dp[pll(s, x)] = res;
}

main() {
  ll N;
  cin >> N;
  cout << f(N, N) << endl;
}

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

const ll MAX_N = 100000;


// ll monster(ll h, ll sum){
// 	if(h==1)sum++;
// 	else if(h>1) return monster(floor(h/2),sum);  
// //  return sum;
// }

int main() {
ll h;
ll t;
ll sum = 1;
scanf("%lld",&h);
while(h>1){
	h/=2;
	sum*=2;
	sum++;
}
// sum = monster(h,0);
printf("%lld",sum);

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1005;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s;cin>>s;
    ll k;cin>>k;
    ll n=s.size();
    set<string> a;
    if(n<=50){
        for(ll i=0;i<n;i++){
            string cur="";
            for(ll j=i;j<n;j++)cur+=s[j],a.insert(cur);
        }
    }
    else{
        for(ll i=0;i<n;i++){
            string cur="";
            for(ll j=i,len=1;len<=k&&j<n;j++,len++)cur+=s[j],a.insert(cur);
        }
    }

    for(;k>0;k--)s=(*a.begin()),a.erase(a.begin());
    cout<<s;
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import sys

def main():
	num = int(raw_input())
	list = map(int, raw_input().split())
	sort(num, list)

def sort(num, list):
	output(list)
	for i in range(1, num):
		key = list[i]
		j = i - 1
		while j >= 0 and list[j] > key:
			list[j+1] = list[j]
			j -= 1
		list[j+1] = key
		output(list)
def output(list):
	print " ".join(map(str, list))
			


if __name__ == "__main__":
	main()
		

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

long long GCD(long long a, long long b){
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

long long LCM(long long a, long long b){
     return (a * b) / GCD(a, b); 
}

int main(){
    long long a, b;
    cin >> a >> b;
    long long ans = LCM(a, b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fo(i,n) for(ll i=0;i<n;i++)
#define fok(i,k,n) for(ll i=k;i<n;i++)
#define ci(x) cin>>x
#define ci2(x,y) cin>>x>>y
#define co(x) cout<<x<<"\n"
#define co2(x,y) cout<<x<<" "<<y<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define PI 3.1415926535897932384626
#define deb1(x) cout<<#x<<" "<<x<<endl
#define deb2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n"
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;	
constexpr ll INF = static_cast<ll>(1e18);


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll ans=0;
	ll n, a ,b;
	ci2(n,a); ci(b);
	ll x = (n)/(a+b);
	ans += x*a;
	ll y = n%(a+b);
	if(y>a){
		ans += a;
	}
	else{
		ans += y;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;


int main(){
    int N,m;cin >> N >> m;
    vector<P> v;
    for (int i = 0; i < m; i++) {
        int c,d;
        cin >> c >> d;
        v.pb({c,d});
    }
    v.pb({N+1,N+1});
    sort(ALL(v));
    int ans=0;
    int d=0,mx=v[0].fs,mi=v[0].sc;
    for (int i = 0; i < m+1; i++) {
        P p=v[i];
        if(p.fs>mx){
            ans+=mx-d+2*(mx-mi);
            mi=INF;
            d=mx;
        }
        mx=max(mx,p.sc);
        mi=min(mi,p.fs);
    }
    ans+=N+1-d;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define pi pair<int,int>
#define PQ priority_queue<double, vector<double>, greater<double> >q
#define _sort(v) sort(v.begin(),v.end())
#define MP map<ll int, int>mp
#define MEM(x) memset(x,0,sizeof(x))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vec() vector<ll int>v1,v2
#define VEC(n) ll int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
//Upper_bound   auto x=upper_bound(v[a].begin(),v[a].end(),les);les=*x; if(x==v[a].end())break;
//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
int n;
cin>>n;
cout<<1-n<<endl;
}





Measured memory_bytes: 3596
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int term(char* &s);
int number(char* &s);
int factor(char* &s);
int expr(char* &s);


//数
int number(char* &s){
  int res = 0;

  while('0' <= *s && *s <= '9')
    res = res*10 + (*s++ - '0');

  return res;
}


//乗算除算
int term(char* &s){
  int res = factor(s);

  while(1){
    if(*s == '*') res *= factor(++s);
    else if(*s == '/') res /= factor(++s);
    else break;
  }

  return res;
}

//式
int expr(char* &s){
  int res = term(s);

  while(1){
    if(*s == '+') res += term(++s);
    else if(*s == '-') res -= term(++s);
    else break;
  }

  return res;
}

//括弧か数
int factor(char * &s){
  if(*s != '(') return number(s);
  int res = 0;  
  res = expr(++s); s++;
  return res;
}




int main(){
  int n;

  scanf("%d", &n);

  while(n--){
    char s[SIZE];
    cin >> s;
    for(int i=0;i<n;i++) if(s[i] == '=') s[i] = '\0';
    char *p = s;
    cout << expr(p) << endl;
  }
  
  return 0;
}



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

int main() {
	int n, a;
	scanf("%d", &n);
	int k = 1;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a % 2 == 0) {
			if (a % 5 != 0 && a % 3 != 0) {
				k = 0;
				break;
			}
		}
	}
	if (k) printf("APPROVED\n");
	else printf("DENIED\n");
	return 0;
} 

Measured memory_bytes: 256
fn main() {
    let (k, a, b) = input();
    println!("{}", solve(k, a, b));
}

fn input() -> (u32, u32, u32) {
    let mut buf1 = String::new();
    let mut buf2 = String::new();
    std::io::stdin().read_line(&mut buf1).unwrap();
    std::io::stdin().read_line(&mut buf2).unwrap();
    buf1.pop();
    buf2.pop();
    let k: u32 = buf1.parse().unwrap();
    let mut iter = buf2.split_whitespace();
    let a: u32 = iter.next().unwrap().parse().unwrap();
    let b: u32 = iter.next().unwrap().parse().unwrap();
    (k, a, b)
}

fn solve(k: u32, a: u32, b: u32) -> String {
    if k == 1 { return String::from("OK"); }
    if a % k == 0 || b % k == 0 { return String::from("OK"); }
    if ((a/k)+1) * k <= b {
        return String::from("OK")
    }
    String::from("NG")
}

Measured memory_bytes: 2104
#line 1 "main_d.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

#line 2 "/home/imperi/cp-library/lib/UnionFind/UnionFind.hpp"

#include <cstddef>
#line 6 "/home/imperi/cp-library/lib/UnionFind/UnionFind.hpp"

class UnionFind {
 public:
  using size_t = std::size_t;

 private:
  std::vector<size_t> par, sz;
  size_t group;

 public:
  UnionFind(size_t n = 0) : par(n, 0), sz(n, 1), group(n) {
    std::iota(par.begin(), par.end(), 0);
  }

  size_t root(size_t n) {
    if (par[n] == n) return n;
    return par[n] = root(par[n]);
  }

  bool unite(size_t a, size_t b) {
    a = root(a);
    b = root(b);
    if (a == b) return false;
    group--;
    if (sz[a] < sz[b]) std::swap(a, b);
    sz[a] += sz[b];
    par[b] = a;
    return true;
  }

  size_t size() { return par.size(); }
  size_t groups() { return group; }
  size_t group_size(size_t n) { return sz[root(n)]; }

  bool same(size_t a, size_t b) { return root(a) == root(b); }
};
#line 85 "main_d.cpp"

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

  i64 n,m;
  std::cin>>n>>m;

  UnionFind uni(n);

  rep(i,0,m){
    i64 a,b;
    std::cin>>a>>b;
    a--;b--;

    uni.unite(a,b);
  }

  i64 ans=0;

  rep(i,0,n)chmax(ans,uni.group_size(i));

  std::cout<<ans<<"\n";
  
  return 0;
}


Measured memory_bytes: 6348
#include <iostream>
#include <algorithm>
using namespace std;
long long n,no,ans,notw,anstw;

int main(){
	cin>>n;
	int a;
	for(int i=0;i<n;i++){
		cin>>a;
		if(no>0){
			no+=a;
			if(no>=0){
				ans+=no+1;
				no=-1;
			}
		}else{
			no+=a;
			if(no<=0){
				ans+=no*-1+1;
				no=1;
			}
		}
		if(notw>=0){
			notw+=a;
			if(notw>=0){
				anstw+=notw+1;
				notw=-1;
			}
		}else{
			notw+=a;
			if(notw<=0){
				anstw+=notw*-1+1;
				notw=1;
			}
		}
	}
	cout<<min(ans,anstw)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S[] = new String[N];
		for (int i = 0; i < N; i++) {
			S[i] = sc.next();
		}
		if (Arrays.asList(S).contains("Y")) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
	}
}

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

int main(){
  
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  
  for(int i = 0; i < A + 1; i++){
    for(int j = 0; j < B + 1; j++){
      for(int k = 0; k < C + 1; k++){
  if(500 * i + 100 * j + 50 * k == X){
    count++;
  }
      }
    }
  }
  
  cout << count << endl;
}


  

Measured memory_bytes: 256
import fractions
n=int(input())
lst=list(map(int,input().split()))
xlst=list(reversed(lst))
#1~5と6のgcdは1~6のgcd
#i番目の左側と右側のgcdを求める
#left[i-1]はlstのi番目までのgcd
#xright[i]はlstのnからi-
#lstのi+1番目は右から見たらn-i+1番目



left=[lst[0]]
xright=[lst[n-1]]
for i in range(1,len(lst)):
    left.append(fractions.gcd(left[i-1],lst[i]))

for i in reversed(range(0,len(lst)-1)):
    xright.append(fractions.gcd(xright[n-i-2],lst[i]))


#i-1番目までの左からのgcdはleft[i-2]
#i＋1番目以上のgcdは right[i+2]
result=1
for i in range(1,n-1):
    a=fractions.gcd(left[i-1],xright[n-i-2])
    if a>result:
        result=a
print(max(result,xright[n-2],left[n-2]))


Measured memory_bytes: 16152