akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
#define lson root<<1
#define rson root<<1|1
#define Mid (l+r>>1)
#define Int const int
struct Seg_Tree{
	int Min,lazy;
}tree[MAXN<<2];
int N,Q,cnt,ans;
int a[MAXN],sum1[MAXN],sum0[MAXN];
vector < int > S[MAXN]; 
inline int read(){
	int x=0,f=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
inline void push_down(Int root){
	tree[lson].lazy+=tree[root].lazy,
	tree[rson].lazy+=tree[root].lazy,
	tree[lson].Min+=tree[root].lazy,
	tree[rson].Min+=tree[root].lazy,
	tree[root].lazy=0;
}
inline void Insert(Int root,Int l,Int r,Int Pos,Int k){
	if(l==Pos && r==Pos){
		tree[root].Min=min(tree[root].Min,k);
		return ;
	}if(tree[root].lazy) push_down(root);
	if(Pos<=Mid) Insert(lson,l,Mid,Pos,k);
	else Insert(rson,Mid+1,r,Pos,k);
	tree[root].Min=min(tree[lson].Min,tree[rson].Min);
}
inline void Update(Int root,Int l,Int r,Int L,Int R,Int k){
	if(l>=L && r<=R){
		tree[root].lazy+=k,tree[root].Min+=k;
		return ;
	}if(tree[root].lazy) push_down(root);
	if(R<=Mid) Update(lson,l,Mid,L,R,k);
	else if(L>Mid) Update(rson,Mid+1,r,L,R,k);
	else Update(lson,l,Mid,L,R,k),Update(rson,Mid+1,r,L,R,k);
	tree[root].Min=min(tree[lson].Min,tree[rson].Min);
}
inline int Query(Int root,Int l,Int r,Int L,Int R){
	if(l>=L && r<=R) return tree[root].Min;
	if(tree[root].lazy) push_down(root);
	if(R<=Mid) return Query(lson,l,Mid,L,R);
	else if(L>Mid) return Query(rson,Mid+1,r,L,R);
	else return min(Query(lson,l,Mid,L,R),Query(rson,Mid+1,r,L,R));
}
int main(){
	N=read();for(register int i=1;i<=N;i++) 
	    a[i]=read(),sum1[i]=sum1[i-1]+(a[i]==1),sum0[i]=sum0[i-1]+(a[i]==0);
	Q=read();for(register int i=1;i<=Q;i++){
		int x=read(),y=read();
		S[x].push_back(y); 
	}for(register int i=0;i<600005;++i) tree[i].Min=1e9;
	Insert(1,0,N,0,0);
	for(register int i=1;i<=N;i++){
		for(register int j=0;j<S[i].size();j++) Insert(1,0,N,S[i][j],Query(1,0,N,0,S[i][j]));
		Update(1,0,N,0,i-1,a[i]?1:-1);
	}printf("%d",Query(1,0,N,0,N)+sum0[N]);
	return 0;
}

Measured memory_bytes: 16512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int A = input.nextInt();
      	int ans = 0;
      	for (int i = 1; i <= A; i+=2) {
          int count = 0;
          int j = 1;
          while (count < 10 && j <= i) {
          	if (i % j == 0) {
              count++;
            }
            j++;
          }
          if (count == 8) {
          	ans++;
          }
        	
        }
		System.out.print(ans);

    }
  
  	
}


Measured memory_bytes: 22612
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)


int main() {
	string s;
	cin >> s;
	int ans = 0;
	int tmp = 0;
	REP(i, s.length()) {
		if (s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C') {
			tmp++;
		}
		else {
			ans = max(ans, tmp);
			tmp = 0;
		}
	}
	ans = max(ans, tmp);
	ANS(ans)
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>

int main()
{
    std::string S;
    int W;
    std::cin >> S >> W;

    for (int i=0; i<S.length(); i+=W)
    {
        std::cout << S[i];
    }

    std:: cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[101][101][21];
int cost[21][200003];
int cost2[101][101];
int n,m,c,s,g,p[55],q[55],r[55];
void init(){
  r(i,101)r(j,101)r(k,21)dp[i][j][k]=(i==j?0:1e8);
  r(i,101)r(j,101)cost2[i][j]=(i==j?0:1e8);
  memset(cost,0,sizeof(cost));
}
void Input(){
  init();
  r(i,m){
    int x,y,d,c;
    cin>>x>>y>>d>>c;x--;y--;c--;
    dp[x][y][c]=dp[y][x][c]=min(d,dp[x][y][c]);
  }
  r(i,c)cin>>p[i];
  r(i,c){
    memset(q,-1,sizeof(q));
    int idx=0;
    r(j,p[i]-1)cin>>q[j];
    r(j,p[i])cin>>r[j];
    int sum=r[0];
    r(j,200002){
      if(q[idx]==j)sum=r[++idx];
      cost[i][j+1]=cost[i][j]+sum;
    }
  }
}
signed main(){
  while(cin>>n>>m>>c>>s>>g,n){
    Input();
    r(l,c)r(k,n)r(i,n)r(j,n)
      dp[i][j][l]=min(dp[i][j][l],dp[i][k][l]+dp[k][j][l]);
    r(k,c)r(i,n)r(j,n)if(dp[i][j][k]<1e7)
      cost2[i][j]=min(cost2[i][j],cost[k][dp[i][j][k]]);
    r(k,n)r(i,n)r(j,n)cost2[i][j]=min(cost2[i][j],cost2[i][k]+cost2[k][j]);
    cout<<(cost2[s-1][g-1]<1e7?cost2[s-1][g-1]:-1)<<endl;
  }
}


Measured memory_bytes: 20380
n = int(input())
u = set([input() for _ in range(n)])
m = int(input())
b = True
for i in range(m):
    s = input()
    if s in u:
        if b:
            print('Opened by ' + s)
        else:
            print('Closed by ' + s)
        b ^= True
    else:
        print('Unknown ' + s)


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

long long count(long long low, long long high, long long div){

    if(low % div == 0)
        return high / div - low / div + 1;

    return high / div - low / div;

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    long long a, b, c, d;

    cin >> a >> b >> c >> d;

    cout << (b - a + 1) - count(a, b, c) - count(a, b, d) + count(a, b, c / GCD(c, d) * d);

    return 0;
}


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

int main() {
  ll n,nw;
  cin >> n >> nw;
  vector<ll> w(n);
  vector<ll> v(n);
  for(ll i=0;i<n;i++) {
    cin >> w[i] >> v[i];
  }
  ll bw=w[0];
  for(ll i=0;i<n;i++) {
    w[i]-=bw;
  }
  vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>> (301,vector<ll> (n+1)));
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<=300;j++) {
      for(ll k=0;k<=i+1;k++) {
        dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
        if(j+w[i]<=300&&k+1<=n) {
          dp[i+1][j+w[i]][k+1]=max(dp[i+1][j+w[i]][k+1],dp[i][j][k]+v[i]);
        }
      }
    }
  }
  ll ans=0;
  for(ll i=0;i<=min(n,nw/bw);i++) {
    ll temp=300;
    ans=max(ans,dp[n][min(temp,nw-i*bw)][i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 25472
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e6+9;
const ld pi = acos(-1);
const ll mod = 1e8;

//bool cmp ( int a,int b ) { return a>b; }

ll po ( ll a , ll b )
{
    if ( b==0 ) { return 1; }
    ll x = po ( a , b/2 );
    x *= x%mod;
    if ( b%2 ) { x*=a%mod; }
    return x%mod;
}

ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { gcd( b , a%b ); }
}
bool cmp ( int a , int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 , 1 , -1 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 , 1 , -1 , 1 , -1 };
ll a[MX],b[MX],c[MX];
int n,m,l;


ll bs ( ll x , ll id )
{
    ll st,en,mid;
    if ( id==2 )
    {
        st=0,en=m;
    }
    else { st=0,en=l; }
    ll ans=0;
    if ( id==2 ){
    ans=m-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( b[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    else
    {
    ans=l-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( c[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    return ans;



}

int main()
{
    int k,s;
    cin>>k>>s;
    int ans=0;
    for ( int i=0 ; i<=k ; i++ )
    {
        for ( int j=0 ; j<=k ; j++ )
        {
            int x = i+j;
            if ( s-(i+j)<=k && s-(i+j)>=0 ) { ans++; }
        }
    }

    cout<<ans;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#define INF (1000000007)
#define rep(i,N) for(ll i=0;i<N;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;

int main(){
    ll N,K,t;
    ll ans=INF;
    cin>>N>>K;
    vl vec(N);
    rep(i,N){
        cin>>vec[i];
    }
    
    rep(i,N-K+1){
        t=vec[i+K-1]-vec[i]+min(abs(vec[i+K-1]),abs(vec[i]));
        ans=min(ans,t);
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    map<int,int> mp;
    for(int i=0; i<N; i++) {
        int A;
        cin >> A;
        mp[A]++;
    }

    if((N - mp.size()) % 2) {
        cout << mp.size() - 1 << endl;
    } else {
        cout << mp.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int n,k,cnt=0;
string s;
int main()
{
	cin>>n>>k>>s;
	for(int i=1;i<n;i++)
		if(s[i]==s[i-1])
			++cnt;
	int l=1,r=n-2;
	while(l<=r&&k)
	{
		while(l<n&&s[l]==s[l-1])
			++l;
		while(r>0&&s[r]==s[r+1])
			--r;
		if(l>r)
			break;
		++cnt;
		++l,--r;
		--k;
		++cnt;
	}
	if(k&&l==r+1)
		++cnt;
	cout<<cnt<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

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

ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b) {
  return a/gcd(a, b)*b;
}

signed main(void)
{
  int n;
  cin >> n;
  ll tm;
  cin >> tm;
  REP(i, n-1) {
    ll t;
    cin >> t;
    tm = lcm(tm, t);
    // cout << "tm" << tm << endl;
  }
  cout << tm << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    from collections import defaultdict

    book = defaultdict(list)
    N = int(input())
    for ind in range(1, N + 1):
        s, p = input().split()
        book[s].append((int(p), ind))

    for s in sorted(book.keys()):
        book[s].sort(key=lambda x: x[0], reverse=True)
        for _, ind in book[s]:
            print(ind)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include<atcoder/all>

using namespace std;
using namespace atcoder;

int main(){
    int Q,N;
    cin>>N>>Q;
    dsu ds(N);
    for(int i=0;i<Q;i++){
        int t,u,v;
        cin>>t>>u>>v;
        if(t==0){
            ds.merge(u,v);
        }
        else{
            cout<<ds.same(u,v)<<endl;
        }
    }
}


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

int N, M;
int m[100050];
int length[100050];
int main() {
    cin >> N >> M;
    for(int i = 1; i <= M; i++) {
        cin >> m[i];
    }
    m[M + 1] = N + 1;
    //length[1] = m[1] - 1;
    for(int i = 2; i <= M + 1; i++) {
        int delta = m[i] - m[i - 1];
        length[delta-1]++;
        //cout << delta << endl;
        //length[1] += 1;
        //length[delta+1] -= delta;
        //length[delta+2] += delta;
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = N-1; i >= 1; i--) {
        length[i] += length[i+1];
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = N-1; i >= 1; i--) {
        length[i] += length[i+1];
    }
    for(int i = 1; i <= N; i++) {
        //cout << i << " " << length[i] << endl;
    }
    for(int i = 1; i <= N; i++) {
        length[i] += m[1] - 1;
        //cout << i << " " << length[i] << endl;
    }
    int Q;
    cin >> Q;
    while(Q--) {
        int l;
        cin >> l;
        if(length[N] > l) {
            cout << -1 << endl;
            continue;
        }
        int ok = N;
        int ng = 0;
        while(ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if(length[mid] <= l) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    return 0;
}


Measured memory_bytes: 3908
N, A, B = map(int, input().split())
X = int(N)
sum = 0
ans = 0
for i in range(1, X+1):
    sum = 0
    s = str(i)
    for t in s:
        sum += int(t)
    if (sum >= A) and (sum <= B):
        ans += i
print(ans)

Measured memory_bytes: 3060
n,x=map(int,input().split())
a=list(map(int,input().split()))
b=[ai for ai in a]
res=sum(b)
for i in range(1,n):
  for j in range(n):
    b[(i+j)%n]=min(b[(i+j)%n],a[j])
  res=min(res,sum(b)+x*i)
print(res)

Measured memory_bytes: 43756
#include <stdio.h>
#include<string.h>

int main(void) {
	// your code goes here
	char s1[110];
	char s2[110];
	scanf("%s%s", s1, s2);
	int l=strlen(s1);
	int i;
	int j;
	for(i=0; i<l; ++i){
		char c=s1[l-1];
		for(j=l-1; j>0; --j){
			s1[j]=s1[j-1];
		}
		s1[0]=c;
		for(j=0; j<l; ++j){
			if(s1[j]!=s2[j]){
				break;
			}
		}
		if(j==l){
			puts("Yes");
			break;
		}
	}
	if(i==l){
		puts("No");
	}
	return 0;
}


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

int main() {
	int64_t N, b, r;
	cin >> N >> b >> r;
	int64_t ans = N/(b+r)*b;
	if (N%(b+r)==0)
	{
		cout << ans << endl;
	}
	else {
		ans += min(N % (b + r), b);
		cout << ans << endl;
	}
}


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

using namespace std;

static constexpr int modulo = 1000000007;

int main() {
  int n;
  std::cin >> n;
  std::vector<int8_t> possibles((n + 1) / 2, 0);
  int const oddOfN = n % 2;
  int a;
  int64_t ret = 1;
  while (std::cin >> a) {
    if (!ret) {
      continue;
    }
    if (a % 2 == oddOfN) {
      ret = 0;
      continue;
    }
    auto const possibleIdx = n / 2 - (a + 1) / 2;
    if (possibles[possibleIdx] >= 2) {
      ret = 0;
      continue;
    }
    possibles[possibleIdx]++;
  }
  if (oddOfN && possibles[n / 2] != 1) {
    ret = 0;
  }
  if (ret) {
    for (int i = 0; i < n / 2; i++) {
      ret *= 2;
      ret %= modulo;
    }
  }
  std::cout << ret << std::endl;
  return 0;
}

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

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

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
     int n;
     cin>>n;
     string s;
     cin>>s;
     int x=0,ma=0;
     for(int i=0;i<n;++i){
          if(s[i]=='I'){
               x++;
               if(ma<x)ma=x;
          }
          else if(s[i]=='D'){
               x--;
               if(ma<x)ma=x;
          }
     }
     cout<<ma<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	int a, b; cin >> a >> b;
	if (a > 8 || b > 8) {
		cout << ":(" << endl;
	}
	else cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    if p[i]>p[i-1] and p[i]<p[i+1]:
        ans+=1
    elif p[i]<p[i-1] and p[i]>p[i+1]:
        ans+=1
print(ans)

Measured memory_bytes: 3060
def solve():
    ans = 1
    N = int(input())
    s = input()
    ans = 0
    for i in range(1000):
    	t = str(i).zfill(3)
    	t_index = 0 
    	for s_index in range(N):
    		if s[s_index] == t[t_index]:
    			t_index += 1
    			if t_index == 3:
    				break
    	if t_index == 3:
    		ans += 1
    print(ans)
solve()

Measured memory_bytes: 41252
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, m;
vector<int> a, b;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    if(n%2&&m%2)cout<<"Odd"<<"\n";
  else cout<<"Even"<<"\n";
}


Measured memory_bytes: 256
#!/usr/bin/perl

$line = 0;
while(<>) {
    chomp;
    if($line == 0) {
        ($n) = split /\s+/, $_;
    } else {
        @s = split //, $_;
    }
    $line++;
}

while(1) {
    $mod = 0;

    $flag = 0;
    foreach $i (0 .. $#s) {
        if($d[$i]) {
            next;
        }
        if($s[$i] eq '(') {
            $flag = 1;
            $flagi = $i;
        } else {
            if($flag) {
                $d[$flagi] = 1;
                $d[$i] = 1;
                $mod = 1;
            }
            $flag = 0;
        }
    }

    if($mod == 0) {
        last;
    }
}

@out = @s;
foreach $i (0 .. $#s) {
    if($d[$i]) {
        next;
    }
    if($s[$i] eq ')') {
        unshift @out, '(';
    } else {
        push @out, ')';
    }
}

foreach (@out) {
    print;
}
print "\n";


Measured memory_bytes: 512
//Date of submission: 21-06-2020
 
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e5 + 5;
const double E= 1e-9;
 
//------------------------------------------------------------------------------
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ifstream cin("input.txt");
    ofstream cout("output.txt");*/
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];
    sort(a,a+n);
    int sum=0;
    int i=0;
    while(k--)
    sum+=a[i++];
    cout<<sum;
    return 0;
}
 
//------------------------------------------------------------------------------

Measured memory_bytes: 3624
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      String str;
      while(n > 0){
         str = sc.nextLine();
         System.out.println(str.replace("Hoshino","Hoshina"));
         n--;
      }
      
   }//main
   
   
}//class


Measured memory_bytes: 26220
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 30005
#define INF 1000000007

vector <int> divisores(int n)
{
	vector <int> ans;
	for(int i=1; i<sqrt(n)+1; i++)
	{
		if(n%i==0)
		{
			ans.push_back(i); // n/i tambien es divisor y es mayor a raiz de n 
			if(i*i != n) ans.pb(n/i);
		}
	}
	
	sort(ans.begin(),ans.end());
	//(reverse(ans.begin(),ans.end());
	return ans;
}


int main()
{ 
	FIN;
	
	#ifdef input
		freopen("T3.txt", "r", stdin);
	#endif
	
	int n;
	cin >> n;
	vector <int> v(n);
	for(int i=0; i<n; i++) cin >> v[i];
	
	vector <int> cont(1000005,0);
	
	for(int i=0; i<n; i++)
	{
		cont[v[i]]++;
	}
	
	int ans=0;
	
	//O(n^2) 4*10^10 operaciones
	//O(n*(n+1)/2) --> O(n^2)
	
	//O(n*sqrt(MAXN)) --> 2*10^5*10^3 = 2*10^8 
	
	for(int i=0; i<n; i++)
	{
		bool d = true;
		vector <int> div = divisores(v[i]);
		//for(auto u : div) cout << u << " "; cout << endl;
		for(int j=0; j<div.size(); j++)
		{
			if(div[j]==v[i]) 
			{
				if(cont[div[j]]>1)
				{
					d=false;
				}
				continue;
			}
			if(cont[div[j]]>0) d=false;
		}
		if(d==true) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7956
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static int N;

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

        N = scanner.nextInt();

        long total = 0;

        int[] map = new int[N + 5];

        int old = 0;
        int old2 = 0;

        for (int i = 0; i < N; i++) {
            int a = scanner.nextInt();
            total += Math.abs(a - old);


            if(i != 0) {

                if (Math.abs(a - old) + Math.abs(old - old2) == Math.abs(old2 - a)) {
                    map[i - 1] = 0;
                } else {
                    map[i - 1] = Math.abs(a - old) + Math.abs(old - old2) - Math.abs(old2 - a);
                }
            }

            old2 = old;
            old = a;
        }
        total += Math.abs(old);

        if (Math.abs(0 - old) + Math.abs(old - old2) == Math.abs(old2 - 0)) {
            map[N - 1] = 0;
        } else {
            map[N - 1] = Math.abs(0 - old) + Math.abs(old - old2) - Math.abs(old2 - 0);
        }

//        if(old2 * old < 0){
//            map[N - 1] = Math.abs(old) * 2;
//        }

//        System.out.println("total = " + total);
//        for (int i = 0; i < N; i++) {
//            System.out.println(map[i]);
//        }

        for (int i = 0; i < N; i++) {
            System.out.println(total - map[i]);
        }
    }




}



Measured memory_bytes: 62900
n, m = map(int, input().split())

ans = {1}
l = [1] * n

for i in range(m):
    x, y = map(int, input().split())
    l[x - 1] -= 1
    l[y - 1] += 1

    if x in ans:
        if l[x - 1] == 0: ans.remove(x); ans.add(y)
        else: ans.add(y)
print(len(ans))

Measured memory_bytes: 18144
#include<iostream>

using namespace std;

int main()
{
	int A,B;

	cin >> A >> B;

	if(A >= 13)
	{
		cout << B << endl;
	}
	else if(A >= 6){
		cout << B/2 << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<vector<int>> vec(N, vector<int>(N, 0));
    for (int i=0; i<N; i++) {
        int index, count;
        cin >> index >> count;
        for (int j=0; j<count; j++) {
            int inx;
            cin >> inx;
            vec[index-1][inx-1] = 1;
        }
    }

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            cout << vec[i][j];
            if (j < N-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3148
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n;

        while(true){
            n=scan.nextInt();
            if(n==0) break;
            int[] score=new int[n];
            double ave=0;
            for(int i=0;i<n;i++){
                score[i]=scan.nextInt();
                ave+=score[i];
            }
            ave/=(double)n;
            double dis=0;
            for(int i=0;i<n;i++) dis+=(score[i]-ave)*(score[i]-ave);
            dis/=(double)n;
            System.out.println(Math.sqrt(dis));
        }
    }
}


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

int main(void) {
    int x;
    rep(i, 0, 5) {
        cin >> x;
        if (x == 0) {
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3520
#include <iostream>
#include <algorithm>

using namespace std;

int d[100000];

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

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

	sort(d, d+n);

	int ans = d[n/2] - d[n/2-1];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   int x,k,d; cin>>x>>k>>d;
   int f=0;
   if(x<0)f=1;
   else f=0;
   x=llabs(x);
   int n=min(x/d,k);
   x-=n*d;
   k-=n;
   //cout<<x<<"\n";
   int os=d-x;
   //cout<<k<<"\n";
   if(k==0){
       cout<<x<<"\n";
       return 0;
   }
   if(k%2==0){
    if(f)cout<<x<<"\n";
    else cout<<x<<"\n";
   }
   else {
      if(f)cout<<os<<"\n";
      else cout<<os<<"\n";
   }
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read question. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

vector<ll> A, B, C;

bool isOK(vector<ll> p, ll index, ll key) {
  if(p[index] >= key) return true;
  else return false;
}

ll binary_search(vector<ll> p, ll key) {
  ll ng = -1;
  ll ok = p.size();
  while(abs(ng - ok) > 1) {
    ll mid = (ng + ok) / 2;
    if(isOK(p, mid, key)) ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  ll N; cin >> N; A.resize(N); B.resize(N); C.resize(N);
  REP(i, N) cin >> A[i];
  REP(i, N) cin >> B[i];
  REP(i, N) cin >> C[i];
  sort(all(A)); sort(all(B)); sort(all(C));
  ll ans = 0;
  REP(i, N) {
    ll a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    ll c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += a * c;
  }
  cout << ans << endl;
}

Measured memory_bytes: 2688
#include <iostream>
using namespace std;
char str[11];
int a,b;
void dps(int c,int d,int di){
  if(a==c && b==d){
    str[di]='\0';
    cout <<str<<endl;
  }
  else{
    if(a>c&&4>=c+1){
      str[di]='A';
      dps(c+1,d,di+1);
    }
    else if(b==d&&a>c){
      str[di]='A';
      dps(c+1,d,di+1);
    }
    if(b>d&&4>=d+1){
      str[di]='B';
      dps(c,d+1,di+1);
    }
    else if(a==c && b>d){
      str[di]='B';
      dps(c,d+1,di+1);
    }
    if(a==5&&b==5&&c==4&&d==4){
      str[di]='A';
      dps(c+1,d,di+1);
      str[di]='B';
      dps(c,d+1,di+1);
    }
  }
}
int main (){
  cin>>a>>b;
  dps(0,0,0);
  return 0;
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> d;
    int cnt = 0;
    //cout << a << b << k;
    for(int i = 1;i <= 100;i++){
        if(a % i == 0 && b % i == 0){
            cnt++;
            d.push_back(i);}
    }
    rep(i,d.size()){
        if(i == d.size()-k)cout << d[i];
    }
}

Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 21:00:58 2019

@author: Wataru
"""

S=input()

Stmp=S.split('/')

YY=int(Stmp[0])
MM=int(Stmp[1])
DD=int(Stmp[2])

if YY<2019:
    print('Heisei')
else:
    if MM<5:
        print('Heisei')
    else:
        print('TBD')
            

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

template <typename Monoid>
struct LazySegmentTree{
private:
    int N;
    vector<Monoid> node, lazy;

public:
    LazySegmentTree(int sz = 0){
        init(sz);
    }
    void init(int sz){
        N = 1;
        while(N < sz) N <<= 1;
        node.resize(2*N-1,0);
        lazy.resize(2*N-1,0);

    }
    void build(vector<Monoid>& v){
        int sz = int(v.size());
        init(sz);
        for(int i=0; i<sz; i++){
            node[i+N-1] = v[i];
        }
        for(int i=N-2; i>=0; i--){
            node[i] = node[i*2+1] + node[i*2+2];
        }
    }
    // node[k]
    void eval(int k){
        if(lazy[k] != 0){
            node[k] += lazy[k];
            if(k < N-1){ // 最下段でないとき
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
    // [a,b)
    void add(int a, int b, Monoid x){add(a, b, x, 0, 0, N);}
    void add(int a, int b, Monoid x, int k, int l, int r){
        eval(k);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] += x * (r-l);
            eval(k);
        }
        else{
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }
    // [a,b)
    Monoid getSum(int a, int b){return getSum(a, b, 0, 0, N);}
    Monoid getSum(int a, int b, int k, int l, int r){
        if(b <= l || r <= a) return 0;
        
        eval(k);
        if(a <= l && r <= b) return node[k];
        Monoid vl, vr;
        vl = getSum(a, b, 2*k+1, l, (l+r)/2);
        vr = getSum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    LazySegmentTree<ll> seg(n);
    for(int i=0;i<q;i++){
        int c;
        cin >> c;
        if(c == 0){
            ll s, t, x;
            cin >> s >> t >> x;
            seg.add(s-1,t,x);
        }
        else{
            int s;
            cin >> s;
            cout << seg.getSum(s-1,s) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 7080
#include<bits/stdc++.h>
using namespace std;
int main(){
	int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<arr[k-1];
	return 0;
}

Measured memory_bytes: 256
//Name: Pankaj Mandrawal (pankaj_m05)
//Problem: FROG 1
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mod 10000000009
#define sz(c) int((c).size())
#define sortall(x) sort(all(x))         
#define PI 3.1415926535897932384626     
#define all(c) (c).begin(), (c).end()
#define clr(x) memset(x, 0, sizeof(x))  
#define INF numeric_limits< int >::max() 
#define MIN numeric_limits< int >::min()
#define rall(c) (c).rbegin(), (c).rend()
#define deb(x) cerr << #x << " = " << x << endl
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define for1(i, n) for(int i = 1; i <= (int) n; ++i)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = (int)(l); i < (int)(r); ++i)
#define tr(c, it) for(typeof(c).begin() it = c.begin(); it != c.end(); it++)
#define deb2(x, y) cerr << #x << " = " << x << "," << #y << " = " << y << endl

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<ll> vill;
typedef vector<vi> vvi;
typedef pair <int,int> pi; 

ll mypow(ll x, ll y) { 
    if (y == 0) 
        return 1; 
    ll p = mypow(x, y / 2) % mod; 
    p = (p * p) % mod; 
    if (!(y & 1)) 
        return p;
    return (p * x) % mod; 
} 

void plssolve() {
	int n; cin >> n;
	vi arr(n);
	for(auto &it: arr) 
		cin >> it;
	vi dp(n, INF);
	dp[0] = 0;
	for(int it = 0; it < n; ++it) {
		if(it + 1 < n) 
			dp[it + 1] = min(dp[it + 1], dp[it] + abs(arr[it] - arr[it + 1]));
		if(it + 2 < n) 
			dp[it + 2] = min(dp[it + 2], dp[it] + abs(arr[it] - arr[it + 2]));
	}
	cout << dp[n - 1] << '\n';
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    cout << fixed;
    int t = 1;
    //cin >> t;
    while(t--) {
        plssolve();
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
    int a, b, c, x;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &x);
    int sum = 0;
    int count = 0;
    for (int i = 0; i <= a;i++){
        for (int j = 0; j <= b;j++){
            for (int k = 0; k <= c; k++){
                sum = 500 * i + 100 * j + 50 * k;
                if (sum == x){
                    count++;
                }
            }
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main(){
	int a;
	cin >> a;
	if (a < 1200){
		cout << "ABC" << endl;
	}
	else if (a < 2800){
		cout << "ARC" << endl;
	}
	else{
		cout << "AGC" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
lis=[]
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
lis.append(int(input()))
ans=0
lis_h=[]
for i in range(5):
        hito=int(str(lis[i])[-1])
        time=lis[i]
        if hito==0:
                ans+=time
        else:
                lis_h.append([hito,time])
lis_h.sort()

if len(lis_h)==0:
        print(ans)
        exit()
ans+=lis_h[0][1]

for i in range(len(lis_h)):
        if i==0:
                continue
        num = (lis_h[i][1]//10) * 10
        if lis_h[i][0] != 0:
                num+=10
        ans+=num

print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
  int n, m;
  int sum = 0;
  cin >> n >> m;
  int a[m];

  for(int i = 0; i < m; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  if( (n - sum) < 0 ) {
    cout << "-1" << endl;
  } else {
    cout << n - sum << endl;
  }
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <iostream> 
#include <math.h>

using namespace std;

int main() {
	int a, b;
	int MAX, MIN;
	int kari;
	int GCD, LCM;
	while (cin >> a >> b) {
		MAX = max(a, b);
		MIN = min(a, b);
		while(1) {
			kari = MAX % MIN;
			if(kari == 0) {
				GCD = MIN;
				break;
			}
			MAX = MIN;
			MIN = kari;
		}

		LCM = (a / GCD) * (b / GCD) * GCD;

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

Measured memory_bytes: 1144
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;
const double PI=3.14159265359;

int n,m;
vector<int> v;

long long solve(int i,  int j){
    if(i==j){
        //cout<<i<<" "<<j<<endl;
        //cout<<!(v[i]%m)<<endl;
        
        return !(v[i]%m);
    }
    long long ansl=solve(i, (i+j)/2), ansr=solve((i+j)/2+1, j);
    
    long long anstot=ansl+ansr;
    
    
    map<int, int> modL, modR;
    long long cur=0;
    for(int k=(i+j)/2; k>=i; k--){
        cur+=v[k];
        cur%=m;
        auto it=modL.find(cur);
        if(it==modL.end()){
            modL[cur]=1;
        }
        else{
            modL[cur]++;
        }
        
        
    }
    
    cur=0;
    for(int k=(i+j)/2+1; k<=j; k++){
        cur+=v[k];
        cur%=m;
        auto it=modR.find(cur);
        if(it==modR.end()){
            modR[cur]=1;
        }
        else{
            modR[cur]++;
        }
    }
    
    for(auto& p: modL){
        long long goal=m-p.first;
        goal%=m;
        
        auto it=modR.find(goal);
        if(it!=modR.end()){
            anstot+=p.second*it->second;
        }
        
    }
    
    //cout<<i<<" "<<j<<endl;
    //cout<<anstot<<endl;
    
    return anstot;
    
    
    
    
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    
    cin>>n>>m;
    
    v.resize(n);
    for(int&i:v)cin>>i;
    
    cout<<solve(0, n-1);
    
    
    
    
    
    
   
    return 0;
}


Measured memory_bytes: 4608
N = int(input())
S = [ input() for _ in range(N) ]
M = int(input())
T = [ input() for _ in range(M) ]

max_money = 0
for word in set(S):
  money = 0
  for s in S:
    if word == s:
      money += 1
  for t in T:
    if word == t:
      money -= 1
  if money > max_money:
    max_money = money

print(max(max_money, 0))

Measured memory_bytes: 3064
import sys

for l in sys.stdin:
    N = int(l)
    result = d = 0
    while d < 5:
        d += 1
        if d % 2 == 0:
            if N < (10**d):
                break
            continue
        result += (10**d) - (10**(d-1))
        if N < 10**d:
            result -= 10**d - N - 1
            break
    print(result)

Measured memory_bytes: 3060
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

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

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int a[maxn];

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return 0;
  }
  for(int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  return 1;
}

int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
}

int msolve() {
  long long left = 0;
  int cntodd = 0;
  for (int i = 0; i < n; ++i) {
    left += a[i] - 1;
    if (a[i] & 1) {
      ++cntodd;
    }
  }
  int res = (left & 1);

  if (!res && cntodd == 1 && *min_element(a, a + n) > 1) {
    int d = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] & 1) {
        --a[i];
      }
      d = gcd(d, a[i]);
    }
    assert(d % 2 == 0);

    for (int i = 0; i < n; ++i) {
      a[i] /= d;
    }

    res = !msolve();
  }
  return res;
}

void solve() {
  printf(msolve() ? "First\n" : "Second\n");
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int sum=0;
  rep(i,4){
    int tmp;
    cin>>tmp;
    sum+=tmp;
  }
  cout<<sum/60<<endl<<sum%60<<endl;
}

Measured memory_bytes: 1160
import Prelude
import Data.Maybe (fromJust)
import Data.List (sort, groupBy)

import qualified Data.Map as Map

import Data.Function (on)
import Control.Monad (replicateM, forM)

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine
    pys <- replicateM m $ (\[p, y] -> (p, y)) . fmap read . words <$> getLine
    answer $ solve n m pys

type Answer = [(Int, Int)]
answer :: Answer -> IO ()
answer pxs = do
  _ <- forM pxs $ \(p, x) -> do
    let pad n = inner n (10 ^ (5 :: Int)) (show n)
        inner n d s | n `div` d > 0 = s
                    | otherwise = inner n (d `div` 10) ('0' : s)
    putStrLn $ pad p ++ pad x
  return ()

solve :: Int -> Int -> [(Int, Int)] -> Answer
solve _ _ pys = map (\(p, y) -> (p, fromJust $ Map.lookup p oldnessMapInPref >>= Map.lookup y)) pys
  where
    oldnessMapInPref = Map.fromAscList $ map ((,) . fst . head <*> Map.fromAscList . flip zip [1..] . map snd) $ groupBy ((==) `on` fst) $ sort pys

Measured memory_bytes: 123516
#include "bits/stdc++.h"
using namespace std;

int dp[1002][1002][16];

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

int main() {
	int H, W; cin >> H >> W;
	for (int i = 0; i < 1002; ++i)for (int j = 0; j < 1002; ++j)for (int k = 0; k < 16; ++k){
		dp[i][j][k] = 1e9;
	}
	dp[1][1][0] = 0;
	vector<vector<int>>field(H + 8, vector<int>(W + 8));
	for (int i = 0; i < H; ++i) {
		string st; cin >> st;
		for (int j = 0; j < W; ++j) {
			if (st[j] != '.') {
				field[i + 1][j + 1] = st[j] - '0';
			}
		}
	}
	for (int nowy = 1; nowy < H + 1; ++nowy) {
		for (int nowx = 1; nowx < W +1; ++nowx) {
			for (int n = 0; n < 16; ++n) {
				const int eat_ld = n & 1;
				const int eat_d = (n & 2) >> 1;
				const int eat_r = (n & 4) >> 2;
				const int eat_ru = (n & 8) >> 3;
				if (1e9 <= dp[nowy][nowx][n])continue;
				vector<vector<char>>eats(4, vector<char>(4));
				eats[2][0] = eat_ld;
				eats[2][1] = eat_d;
				eats[1][2] = eat_r;
				eats[0][2] = eat_ru;
				eats[1][1] = true;
				for (int way = 0; way < 2; ++way) {
					const int  nextx = nowx + dx[way];
					const int nexty = nowy + dy[way];
					const int ax = 1 + dx[way];
					const int ay = 1 + dy[way];
					for (int w = 0; w < 4; ++w) {
						int nexteat_ld = eats[2 + dy[way]][0 + dx[way]];
						int nexteat_d = eats[2 + dy[way]][1 + dx[way]];
						int nexteat_r = eats[1 + dy[way]][2 + dx[way]];
						int nexteat_ru = eats[0 + dy[way]][2 + dx[way]];
						int eat_sum = 0;
						if (!eats[ay][ax]) {
							if (ay == 2 + dy[way] && ax == 0 + dx[way])nexteat_ld = true;
							if (ay == 2 + dy[way] && ax == 1 + dx[way])nexteat_d = true;
							if (ay == 1 + dy[way] && ax == 2 + dx[way])nexteat_r = true;
							if (ay == 0 + dy[way] && ax == 2 + dx[way])nexteat_ru = true;
							eat_sum += field[nexty][nextx];
						}
						for (int v = 0; v < 4; ++v) {
							if (v == w)continue;
							else {
								if (!eats[ay + dy[v]][ax + dx[v]]) {
									if (ay + dy[v]== 2 + dy[way] && ax + dx[v] == 0 + dx[way])nexteat_ld = true;
									if (ay + dy[v]== 2 + dy[way] && ax + dx[v] == 1 + dx[way])nexteat_d = true;
									if (ay + dy[v]== 1 + dy[way] && ax + dx[v] == 2 + dx[way])nexteat_r = true;
									if (ay + dy[v]== 0 + dy[way] && ax + dx[v] == 2 + dx[way])nexteat_ru = true;
									eat_sum += field[nexty + dy[v]][nextx + dx[v]];
								}
							}
						}
						int n = dp[nowy][nowx][eat_ld+2*eat_d+4*eat_r+8*eat_ru] + eat_sum;
						dp[nexty][nextx][nexteat_ld+2*nexteat_d+4*nexteat_r+8*nexteat_ru] = min(dp[nexty][nextx][nexteat_ld + 2 * nexteat_d + 4 * nexteat_r + 8 * nexteat_ru], n);
					}
				}
			}
		}
	}
	int ans = 1e9;
	for (int l = 0; l < 16; ++l) {
		ans = min(ans, dp[H][W][l]);	
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 69612
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , a[N];

int main(){
  scanf("%d",&n);
  map<int,int> times;
  rep(i,0,n) scanf("%d",a+i) , times[a[i]]++;
  int sum = 0;
  for(auto e : times)
    sum += e.se - 1;
  sum += sum & 1;
  printf("%d\n",n - sum);
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;

using namespace std;

int main()
{
  map<string, bool> m;
  int n;
  cin >> n;
  vector<string> w(n);
  REP(i, n)
  {
    cin >> w[i];
  }
  m[w[0]] = true;
  FOR(i, 1, n)
  {
    if (w[i - 1][w[i - 1].length() - 1] != w[i][0] || m[w[i]])
    {
      cout << "No" << endl;
      return 0;
    }
    m[w[i]] = true;
  }
  cout << "Yes" << endl;
}


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

int main() {
    int N, K; cin >> N >> K;
    string S; cin >> S;

      // 「1 の個数」「0 の個数」を交互に記録していく
    vector<int> nums;
    if (S[0] == '0') nums.push_back(0); // 先頭が 0 だったら
    for (int i = 0; i < S.size();) {
      int j = i;
      while (j < S.size() && S[j] == S[i]) ++j; // S[i] の数値がどこまで続くか
      nums.push_back(j - i);
      i = j;
    }
    if (S.back() == '0') nums.push_back(0); // 最後尾が 0 だったら
    // 累積和
    vector<int> sums(nums.size() + 1, 0);
    for (int i = 0; i < nums.size(); ++i) sums[i+1] = sums[i] + nums[i];
    // 偶数番目の添字から始まる、長さ 2K+1 (以下) の区間の総和のうち、最大値を求める
    int ans = 0;
    for (int left = 0; left < sums.size(); left += 2) {
        int right = min(left + K * 2 + 1, (int)nums.size());
        ans = max(ans, sums[right] - sums[left]);
    }
    cout << ans << endl;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a+b) %24 << endl;
}

Measured memory_bytes: 256