akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* 
   kD_Tree
   build:O(n log^2(n))
   search:O(n^(1-1/K)+A)
   K:次元数 A:領域に含まれる点の数
*/


class KDT{
public:
  typedef long long ll; /*型に注意!!!!*/
  struct node{
    vector<ll> point;
    int l,r;
    node(){}
    node(vector<ll> point):point(point){l=r=-1;}
  };
  int K;// K:次元数
  vector<vector<ll> > P;// それぞれの要素はK+1個(各次元の値と固有ID)
  vector<node> G;
  int ok = 0;

  KDT(int K=2):K(K),ok(0){};
  
  void add_point(vector<ll> a/*座標*/){ 
    static int id = 0;
    if((int)a.size() < K+1) a.push_back(id++);
    assert((int)a.size() == K+1);
    P.push_back(a);
  }
  
  int build(int depth=0,int l=0,int r=-2){
    if(r == -2) r = (int)P.size()-1,ok = 1;
    if(l>r) return -1;
    int D=depth%K; // D:ソートする基準の次元
    sort(P.begin()+l,P.begin()+r+1,[&](const vector<ll> &A,const vector<ll> &B){return A[D]<B[D];});

    int m=(l+r)/2,res=G.size();
    G.push_back(node(P[m]));
    int vl=build(depth+1,l,m-1);
    int vr=build(depth+1,m+1,r);
    G[res].l=vl; G[res].r=vr;
    return res;
  }

  vector<vector<ll> > points;//searchの座標集合と固有ID
  void search(int x,int depth,const vector<ll> &ld,const vector<ll> &ru){
    if(P.empty()) return;
    bool f=true;
    for(int i=0;i<K;i++)
      if(G[x].point[i]<ld[i]||ru[i]<G[x].point[i]) f=false;
    
    if(f) points.push_back(G[x].point);
    
    int D = depth%K;// D:ソートする基準の次元
    if(G[x].point[D]<=ru[D]&&G[x].r!=-1) search(G[x].r,depth+1,ld,ru);
    if(ld[D]<=G[x].point[D]&&G[x].l!=-1) search(G[x].l,depth+1,ld,ru);
  }

  
  //[0,K)の要素が座標,K番目の要素が固有IDになっている。
  vector<vector<ll> > search(vector<ll> ld/*左下*/,vector<ll> ru/*右上*/){
    assert(ok);
    points.clear();
    search(0,0,ld,ru);
    return points;
  }
};

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

  KDT kdt;
  for(int i=0;i<n;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    kdt.add_point({x,y});
  }

  kdt.build();
  int q;
  cin>>q;
  while(q--){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    auto point = kdt.search({a,c},{b,d});
    vector<int> ans;
    for(auto &p:point) ans.push_back(p.back());
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++) printf("%d\n",ans[i]);
    printf("\n");
  }
  
}



Measured memory_bytes: 60016
#include <stdio.h>
#include <math.h>
#define MAX 1000
 
int main(){
    int n;
    int i, j=0, sum;
    int score[MAX];
    double ave, tmp;
    double dev[MAX];
 
    while(1){
        scanf("%d", &n);
        if(n==0)break;
        sum=0;
        for(i=0;i<n;i++){
            scanf("%d", &score[i]);
            sum+=score[i];
        }
        ave=(double)sum/(double)n;
        tmp=0.0;
        for(i=0;i<n;i++){
            tmp+=pow(score[i]-ave, 2);
        }
        dev[j++]=sqrt(tmp/(double)n);
    }
    for(i=0;i<j;i++){
        printf("%f\n", dev[i]);
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  string t;
  
  cin >> s;
  cin >> t;

  int r = 0;

  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) {
      r++;
    }
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int n,a,b,c,temp,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d %d %d",&a,&b,&c);
  if(a<b){
    temp=a;
    a=b;
    b=temp;
  }
  if(a<c){
    temp=a;
    a=c;
    c=temp;
  }
  if(a*a==b*b+c*c){
    puts("YES");
  }
  else{
    puts("NO");
  }
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int l;
double d;
int main()
{
	cin>>l;
	double a=(double)(l*1.000000000000)/(double)(3.000000000000);
	d=a*a*a;
	printf("%.12f",d);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2009;
const int inf=1e9;

int n;

int f[maxn][maxn];
int mxr[maxn];

struct state{
	int x,y,a;
	state(int _x=0,int _y=0,int _a=0){
		x=_x;y=_y;a=_a;
	}
};
vector<state>update;
void trans1(int x,int y,int z){
	update.push_back(state(y,z,f[x][x]+1));
}
void trans2(int x,int y,int z){
	for(int i=1;i<=n;++i){
		update.push_back(state(i,z,f[i][x]+1));
	}
}
void trans3(int x){
	for(int i=1;i<=n;++i){
		update.push_back(state(i,x,mxr[i]));
	}
}
void trans4(int x,int y){
	int mx=-inf;
	for(int i=1;i<=n;++i)mx=max(mx,mxr[i]);
	update.push_back(state(x,y,mx));
}

int cnt,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		mxr[i]=-inf;
		for(int j=1;j<=n;++j){
			f[i][j]=-inf;
		}
	}
	int x,y,z;scanf("%d%d",&x,&y);
	f[x][y]=f[y][x]=0;mxr[x]=mxr[y]=0;
	
	for(int i=3;i+2<=3*n;i+=3){
		scanf("%d%d%d",&x,&y,&z);
		if(x==y&&x==z){
			++cnt;continue;
		}
		
		trans1(x,y,z);
		trans1(y,x,z);
		trans1(z,x,y);
		if(x==y)trans2(x,y,z);
		if(x==z)trans2(x,z,y);
		if(y==z)trans2(y,z,x);
		
		trans3(x);
		trans3(y);
		trans3(z);
		
		trans4(x,y);
		trans4(x,z);
		trans4(y,z);
		
		for(int j=0;j<update.size();++j){
			int x=update[j].x,y=update[j].y,a=update[j].a;
			f[x][y]=max(f[x][y],a);
			f[y][x]=max(f[y][x],a);
			mxr[x]=max(mxr[x],a);
			mxr[y]=max(mxr[y],a);
		}
		update.clear();
	}
	
	scanf("%d",&x);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i==x&&j==x)ans=max(ans,cnt+f[i][j]+1);
			else ans=max(ans,cnt+f[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 19668
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

ll A[5*1010];
ll B[5*1010][210];
int N,M;
ll mB[210];
int main(){
  cin>>N>>M;
  repeat(i,N-1){
    scanf("%lld",&A[i+1]);
    A[i+1]+=A[i];
  }
  repeat(i,N){
    repeat(j,M){
      scanf("%lld",&B[i][j]);
    }
  }
  ll ans = 0;
  repeat(l,N){
    repeat(j,M)mB[j]=0;
    ll sum=0;
    for(ll r=l;r<N;r++){
      repeat(j,M){
        if(mB[j]<B[r][j]){
          sum += -mB[j]+B[r][j];
          mB[j]=B[r][j];
        }
      }
      ans = max(ans,sum-(A[r]-A[l]));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8448
n, K = map(int,input().split())

MOD = 10**9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
    fac[k] = (fac[k-1]*k)%MOD
    inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
    finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
    return (fac[n]*finv[r]*finv[n-r])%MOD

ans = 0
for i in range(min(n,K+1)):
    ans += nCr(n,i)*nCr(n-1,n-i-1)
    ans %= MOD

print(ans)


Measured memory_bytes: 26840
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int A, B, C; cin >> A >> B >> C;
    
    int ans = 0;
    if (A-B >= C) {
        ans = 0;
    } else {
        ans = C - (A - B);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import fractions


def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b <= c + 1:
        return True
    gcd_bd = fractions.gcd(b, d)
    cc = c - a % gcd_bd
    b //= gcd_bd
    cc //= gcd_bd
    if b <= cc + 1:
        return True
    return False


t = int(input())
buf = []
for _ in range(t):
    a, b, c, d = map(int, input().split())
    buf.append('Yes' if solve(a, b, c, d) else 'No')
print('\n'.join(map(str, buf)))


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


def main():
    from statistics import median

    n = int(input())
    a = list(map(int, input().split()))

    for i in range(n):
        a[i] -= (i + 1)

    b = int(median(a))
    ans = 0

    for j in range(n):
        ans += abs(a[j] - b)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

#define rep(i,n) for(int64_t i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int64_t i = (int)begin_i; i <= (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];

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

vector<pair<long long, int>> factorize(long long n){
        vector<pair<long long , int >>res;
    for(long long i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while(n%i==0){
            n /=i;
            res.back().second++;
        }
    }
    if(n!=1){
        res.emplace_back(n,1);
    }
    return res;
}

int main(){
    int64_t a,b;
    cin>>a>>b;
    int64_t x=gcd(a,b);
    auto f = factorize(x);
    cout<<f.size()+1<<endl;
    return 0; 
}




Measured memory_bytes: 256
#include<iostream>
#include<stack>
using namespace std;
static const int N=100;
static const int WHITE = 0;
static const int GRAY =1;
static const int BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

int next(int u){
  for(int v=nt[u];v<n;v++){
    nt[u]=v+1;
    if(M[u][v])return v;
  }
  return -1;
}

void dfs_visit(int r){
  for(int i=0;i<n;i++)nt[i]=0;

  stack<int>S;
  S.push(r);
  color[r]=GRAY;
  d[r]=++tt;

  while(!S.empty()){
    int u=S.top();
    int v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
        color[v]=GRAY;
        d[v]=++tt;
        S.push(v);
      }
    }else{
      S.pop();
      color[u]=BLACK;
      f[u]=++tt;
    }
  }
}

void dfs(){
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    //nt[i]=0;
  }
  tt=0;
  for(int u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
  }
}
int main(){
  int u,k,v;

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

  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 3120
//
//  main.cpp
//  AOJ0189
//
//  Created by aki33524 on 2014/08/25.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;

const int INF = 1e8;

void solve(int c, int G[10][10]){
    for(int k=0; k<c; k++)
        for(int i=0; i<c; i++)
            for(int j=0; j<c; j++)
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
    
    int tmin = INF;
    int res;
    for(int i=0; i<c; i++){
        int s = 0;
        for(int j=0; j<c; j++)
            s += G[i][j];
        if(s < tmin){
            tmin = s;
            res = i;
        }
    }
    cout << res << " " << tmin << endl;
}

int main(int argc, const char * argv[])
{
    int n;
    while(cin >> n, n){
        int G[10][10];
        for(int i=0; i<10; i++)
            for(int j=0; j<10; j++)
                G[i][j] = i!=j ? INF : 0;
        
        int s, t, d;
        int c = 0;
        for(int i=0; i<n; i++){
            cin >> s >> t >> d;
            G[s][t] = d;
            G[t][s] = d;
            c = max(c, max(s, t));
        }
        solve(++c, G);
    }
    
    return 0;
}

Measured memory_bytes: 1164
// ARC081-D
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
   void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int N;
char S[2][60];
const ll INF = 1e9+7;

int main() {
   cin >> N;
   rep (i, 2) {
      string s;
      cin >> s;
      rep (j, N) {
         S[i][j] = s[j];
      }
   }
   string s;
   rep (i, N) {
      if (S[0][i] == S[1][i]) {
         s.push_back('x');
      } else {
         s.push_back('y');
         i++;
      }
   }
   reverse(all(s));

   ll ans = 0;
   if (s[0] == 'x') {
      ans += 3;
   } else {
      ans += 6;
   }
   repp (i, 1, s.size()) {
      if (s[i-1] == 'x') {
         ans = ans * 2 % INF;
      } else {
         if (s[i] == 'y') {
            ans = ans * 3 % INF;
         }
      }
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

//dp[i][j][k] ：i番目のカードの選択を決めた時点でjポイントで，k枚のカードを所持．
ll dp[50][2501][51] = {};

int main(){
    INT(N);INT(A);
    ll x[50];
    REP1(i,N) scanf("%lld",&x[i]);
    
    dp[0][0][0] = 1;
    dp[0][x[0]][1] = 1;
    
    REP2(r,1,N-1){
        REP1(c,2501){
            REP1(d,N+1){
                if (dp[r-1][c][d] != 0) {
                    dp[r][c][d] = max(dp[r-1][c][d],dp[r][c][d]);
                    if(c + x[r] <= 2500 && d + 1 <= N){
                        dp[r][c + x[r]][d+1] = dp[r-1][c + x[r]][d+1] + dp[r-1][c][d];
                    }
                }
            }
        }
    }
    ll sum = 0;
    REP2(i,1,2500){
        REP2(j,1,N){
            if (i == j*A) {
                sum += dp[N-1][i][j];
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 13312
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {n: usize};
    let mut buf: Vec<usize> = vec![0, 0, 0];
    let mut result: Vec<usize> = vec![0; n];

    dfs(0, n, &mut buf, &mut result);

    for i in result.iter() {
        println!("{}", i)
    }
}

fn dfs(index: usize, n: usize, buf: &mut Vec<usize>, result: &mut Vec<usize>) {
    let mut count = 0;
    if index == 3 {
        let mut sum = buf[0] * buf[0]
            + buf[1] * buf[1]
            + buf[2] * buf[2]
            + buf[0] * buf[1]
            + buf[1] * buf[2]
            + buf[2] * buf[0];

        if sum <= n {
            for i in 1..n + 1 {
                if sum == i {
                    result[i - 1] += 1;
                    // println!("{:?}", buf);
                    // println!("{}", sum);
                    break;
                }
            }
        }
    } else {
        let upperLimit = (n as f64).sqrt() as usize + 1;
        for i in 1..upperLimit {
            buf[index] = i;
            dfs(index + 1, n, buf, result);
        }
    }
}


Measured memory_bytes: 2248
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, mut M) = read!(usize, usize);

    let mut total = 0;

    let k = min(N, M / 2);
    total += k;
    M -= k * 2;

    total += M / 4;

    println!("{}", total);
}


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


int main(void){
    //////////////////////////
    int A, B, C, D;
    string S;
    cin >> S;
    A = S[0] - '0';
    B = S[1] - '0';
    C = S[2] - '0';
    D = S[3] - '0';

    if (A + B + C + D == 7){
        cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
    }else if (A + B + C - D == 7){
        cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
    }else if (A + B - C + D == 7){
        cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    }else if (A - B + C + D == 7){
        cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    }else if (A + B - C - D == 7){
        cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    }else if (A - B + C - D == 7){
        cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
    }else if (A - B - C + D == 7){
        cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    }else if (A - B - C - D == 7){
        cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
    }

    //////////////////////////


    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto s = readln.chomp;
    auto t = readln.chomp;

    foreach (i; 0..N+1) {
        if (s[i..$] == t[0..N-i]) {
            writeln(N + i);
            return;
        }
    }
}

Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int r; cin >> r;
    if(r<2800){
        if(r<1200){
            cout << "ABC";
        }else{
            cout << "ARC";
        }
    }else{
        cout << "AGC";
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if (v <= w || abs(a - b) > (v - w) * (ll)t )cout << "NO\n";
  else cout << "YES\n";

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 3048
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
tree=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=mp()
    tree[a].append((b,c))
    tree[b].append((a,c))
q,k=mp()
dist=[-1]*(n+1)
dist[k]=0
deq=deque()
deq.append(k)

while len(deq):
    p=deq.popleft()
    for x,y in tree[p]:
        if dist[x]==-1:
            dist[x]=dist[p]+y
            deq.append(x)
for i in range(q):
    xi,yi=mp()
    print(dist[xi]+dist[yi])

Measured memory_bytes: 43800
<?php 
  list($n, $m, $c) = explode(" ", trim(fgets(STDIN)));
  $bArray = explode(" ", trim(fgets(STDIN)));
  $count = 0;
  for($i = 0; $i < $n; $i++){
    $aArray = explode(" ", trim(fgets(STDIN)));
    $t = $c;
    for($j = 0; $j < $m; $j++){
      $t += $aArray[$j] * $bArray[$j];
    }
    if($t > 0)$count++;
  }
  echo $count;



Measured memory_bytes: 4604
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll i,j,n,k,p,maxi,dp[2][100005],arr[105];

int main()
{
	cin>>n>>k;
	for(i=0;i<n;i++)
		cin>>arr[i];
	memset(dp,-1,sizeof(dp));
	sort(arr,arr+n);
	for(i=0;i<arr[0];i++)
	{
		dp[0][i]=1;
		dp[1][i]=0;
	}
	for(i=0;i<n;i++)
	{
		dp[0][arr[i]]=0;
		dp[1][arr[i]]=1;
	}
	for(i=arr[0]+1;i<=k;i++)
	{
		if(dp[0][i]!=-1)
			continue;
		for(j=0;j<2;j++)
		{
			if(j==0)
				dp[j][i]=1;
			else
				dp[j][i]=0;
			for(ll p=0;p<n;p++)
			{
				if(i-arr[p]>0)
				{
					if(dp[(j+1)%2][i-arr[p]]==j)
						dp[j][i]=j;
				}
			}
		}
	}
	if(dp[0][k]==1)
		cout<<"Second";
	else
		cout<<"First";
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
using namespace std;


const int INF = 1e8;

int n, k, dis[2010][2010];
vector < int > g[2010];

bool used[2010][2010], check;

vector < pair <int, int> > pos_ans;

map < pair <int, int>, bool> mp;

void dfs(int orig, int v, int ct = 0) {

    used[orig][v] = 1;

    if(ct > k) {check = 1; return;}

    if(orig != v) {

        dis[orig][v] = ct;

        if(ct == k && !mp[mper(min(orig, v), max(orig, v))]) {pos_ans.pb(mper(orig, v)); mp[mper(min(orig, v), max(orig, v))] = 1;}


    }




    for(auto to : g[v]) {

        if(!used[orig][to]) {

            dfs(orig, to, ct + 1);

        }

    }

}

int main(){

mal


cin >> n >> k;



for(int i = 1, l, r; i < n; ++i) {

    cin >> l >> r;

    g[l].pb(r);
    g[r].pb(l);

}

for(int i = 1; i <= n; ++i) {
    dfs(i, i);
}


if(!check) {cout << 0;return 0;}


int ans = (int)1e8;

for(auto to : pos_ans) {

    int a = to.fe;
    int b = to.se;
    int ct = 0;



    for(int i = 1; i <= n; ++i) {

        if(i == a || b == i) {continue;}

        if(dis[a][i] == 0) {ct++;}
        else if(dis[b][i] == 0) {ct++;}

    }

    ans = min(ans, ct);

}

cout << ans;

return 0;
}

/*

2000 2


*/


Measured memory_bytes: 160484
#include <stdio.h>
  int main(void){
    int a,b,c;
    int n;
    scanf("%d%d%d",&a,&b,&c);
    n=100*a+10*b+c;
    if(n%4==0){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }

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

// Data Type
#define ull     unsigned long long int
#define ll      long long int

// Loops
#define loop(i,s,e)     for(ll i=(s);i<(e);i++)
#define rloop(i,s,e)    for(ll i=(s);i>=(e);i--)

// Stl
#define pb      push_back
#define eb      emplace_back
#define pf      push_front
#define popb    pop_back
#define popf    pop_front
#define mp      make_pair
#define ff      first
#define ss      second

// Maths
#define PI          (2*acos(0.0))
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (((a)*(b))/(__gcd((a),(b))))
#define log(x,b)    (log(x)/log(b))
#define INF         LLONG_MAX

// Big data
const int Mod = 1e9+7;
#define mul(a,b)         ((a%Mod)*(b%Mod))%Mod
#define sum(a,b)         ((a%Mod)+(b%Mod))%Mod

// Bit-Manipulation
#define setbit(n,pos)       n |= (1LL<<pos)
#define resetbit(n,pos)     n &= (~(1LL<<pos))
#define toogle(n,pos)       n ^= (1LL<<pos)
#define atpos(n,pos)        ((n&(1LL<<pos))!=0)

// Extra
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; nl;
#define nl              cout<<'\n'
#define endl            '\n'

void solve()
{
	ll a,b;
	cin>>a>>b;
	cout<<(6-a-b);
}

int main()
{
	try
	{
		ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t = 1; 
		while(t--)
			solve();
	}
    catch(...)
    {
    	// nothing.
    }
	return 0;
}
/*
greater<int>()
fill_n(array,size,value);
fill(start,end,value);
getline(cin,string);
cin.getline(char array,size);
LLONG_MAX
DBL_MAX
*/

Measured memory_bytes: 256
function main(input) {
  input=input.trim()
  if(input.indexOf("a")>=0&&input.indexOf("b")>=0&&input.indexOf("c")>=0){
    console.log("Yes");
  }else{
    console.log("No");
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 7372
def prime(x):
  max_x = (x ** (1 / 2)) // 1
  ans = 1
  for i in range(2, int(max_x) + 1):
    if x % i == 0:
      ans = 0
  return ans

if __name__ == "__main__":
  n = int(input())
  ans = 0
  while ans == 0:
    ans = prime(n)
    if ans == 0:
      n += 1
  print(n)

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n,k; cin >> n >> k;
    string s; cin >> s;
    int cnt = 0;
    rep(i,n) {
        if (s[i] == 'L') {
            if (i > 0 && s[i-1] == 'L') cnt++;
        } else {
            if (i < n-1 && s[i+1] == 'R') cnt++;
        }
    }
    int cnt2 = n-1-cnt;
    int ans = cnt + min(2*k,cnt2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  string sd, t, ans;
  cin >> sd >> t;
  int n = sd.length();
  int m = t.length();
  int Qmin = m + 1;
  int start = -1;
  for(int i = 0; i < n - m + 1; i++) {
    if(sd[i] == t[0] || sd[i] == '?'){
      int q = 0;
      bool ok = true;
      for(int j = 0; j < m; j++) {
        if(sd[i + j] == t[j]){
          continue;
        }else if(sd[i + j] == '?'){
          q++;
        } else {
          ok = false;
          break;
        }
      }
      if(ok){
        start = i;
        if(q == 0){
          break;
        }
      }
    }
  }
  for(int i = 0; i < n; i++){
    if(i >= start && i < start + m){
      ans += t[i - start];
    }else if(sd[i] == '?'){
      ans += 'a';
    }else{
      ans += sd[i];
    }
  }
  if(start == -1) {
    cout << "UNRESTORABLE\n";
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    rep(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}
//===========================================

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

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll n, k;
  cin >> n >> k;

  ll ans = 1;

  REP(i, n) { ans = (2 * ans < ans + k ? 2 * ans : ans + k); }

  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,d;cin>>n>>d;
  lint res=0;
  lint dd=d*d;
  rep(i,n){
    lint x,y;cin>>x>>y;
    if(x*x+y*y<=dd)++res;
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3632
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 3005;
const int Mod = 998244353;

int n, s;
int arr[N];
int dp[N][N];

int solve(int i, int rem) {
  if(rem == 0) return n - i + 1;
  if(i >= n) return 0;
  int& r = dp[i][rem];
  if(r != -1) return r;
  r = solve(i + 1, rem);
  if(arr[i] <= rem)
    r = (r + solve(i + 1, rem - arr[i])) % Mod;
  return r;
}

int solve() {
  int ans = 0;
  memset(dp, -1, sizeof dp);
  for(int i = 0 ; i < n ; i++) {
    if(arr[i] <= s) {
      int cur = solve(i + 1, s - arr[i]);
      ans = (ans + 1LL * (i + 1) * cur % Mod) % Mod;
    }
  }
  return ans;
}

int main()
{
  cin >> n >> s;
  for(int i = 0 ; i < n ; i++)
    cin >> arr[i];
  cout << solve() << endl;
  return 0;
}


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

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

    vector<ll> p_factor;
    ll n_kari = n;
    //試し割り法でnを素因数分解．
    for(ll i=2; i < (ll)sqrt(n_kari)+1; ++i){
        //nがi(の累乗)で割り切れるかを調べる
        ll t=0;
        while(n_kari%i==0){
            if(t==0){
                p_factor.push_back(i);
            }
            n_kari /= i;//約数iでnを割って更新．
            ++t;
        }
    }
    //nの平方根より大きい素因数が存在する場合はnを約数に加える．
    if(n_kari>1) p_factor.push_back(n_kari);
    // rep(i,(int)p_factor.size()) cout<<p_factor.at(i)<<endl;

    ll cnt=0;
    for(ll p:p_factor){
        ll e=1;
        ll pe = (ll)pow(p,e);
        while(n%pe==0){
            ++cnt;
            n /= pe;
            ++e;
            pe = (ll)pow(p,e);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 4056
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  int a[2][100];
  REP(i,2){
    REP(j,n){
      scanf("%d", &a[i][j]);
    }
  }

  int dp[3][101] = {};
  dp[0][0] = a[0][0];
  REP(i,n - 1){
    dp[0][i + 1] = dp[0][i] + a[0][i + 1];
  }
  dp[1][0] = dp[0][0] + a[1][0];
  REP(i,n - 1){
    dp[1][i + 1] = max(dp[0][i + 1], dp[1][i]) + a[1][i + 1];
  }

  printf("%d\n", dp[1][n - 1]);
  return 0;
}



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

const int N = 2005;

int n, sum;
bitset<2000005> bs;

int main() {
	cin >> n;
	bs[0] = 1;
	for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		bs |= bs << x, sum += x;
	} 
	for (int i = (sum + 1) / 2; i <= sum; ++i) {
		if (bs[sum - i]) {
			cout << i; return 0;
		}
	}
}

Measured memory_bytes: 1024
// Created by SAMAN on ۷/۳۱/۲۰۲۰ م..

#include <iostream>
#include <algorithm>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <fstream>
#include <cstdlib>
#include <iterator>
#include <cmath>
#include <ctime>
#include <iomanip>

#define lint long long int
#define kill(x) return cout<<x<<'\n', 0;
#define debug(x) cout << #x << " : " << x << '\n'
#define pb push_back
#define ppb pop_back

using namespace std;
const int oo = 1000*1000*1000;
int n,k;
const int maxn = 4e5;
int a[maxn];
int dp[maxn];
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 
    cin >> n >> k;
    for(int i = 1;i<=n;i++)
        cin >> a[i];
    dp[1] = 0;
    for(int i = 2;i<=n;i++){
        dp[i] = oo;
        for(int j = i-1;j >= max (1,i-k); j--)
             dp[i] = min(dp[i],abs(a[i] - a[j])+ dp[j]);
    }
    cout<<dp[n];    
}

Measured memory_bytes: 3892
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int H, W, N;
    cin >> H >> W >> N;
    VEC(Pii) cells(N);
    set<Pii> cellset;
    FOR(i, 0, N) {
        cin >> cells[i].first >> cells[i].second;
        cellset.emplace(cells[i].first, cells[i].second);
    }

    vector<set<Pii> > countset(10);
    set<Pii> computed;
    FOR(i, 0, N) {
        int cy = cells[i].first, cx = cells[i].second;
        FOR(y, cy - 2, cy + 1)
            FOR(x, cx - 2, cx + 1) {
                if (y <= 0 || x <= 0 || y + 2 > H || x + 2 > W ||
                        computed.count(PAIR(y, x)))
                    continue;
                computed.insert(PAIR(y, x));

                int count = 0;
                FOR(yy, y, y + 3) {
                    FOR(xx, x, x + 3)
                        count += cellset.count(PAIR(yy, xx));
                }

                if (count > 0) {
                    countset[count].insert(PAIR(y, x));
                }
            }
    }

    int nonzero = 0;
    FOR(i, 1, 10)
        nonzero += countset[i].size();

    lint zero = (H - 2) * 1LL * (W - 2) - nonzero;
    cout << zero << endl;
    FOR(i, 1, 10)
        cout << countset[i].size() << endl;
    return 0;
};


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

int n;
vector <pii> v1, v2;
bool cmp1(pii p1, pii p2)
{
	if (p1.first != p2.first) return p1.first > p2.first;
	else return p2.first > p2.first;
}
bool cmp2(pii p1, pii p2)
{
	return p1.second - p1.first > p2.second - p2.first;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int sum = 0;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string str; cin >> str;
		int rs = 0;
		int mn = 0;

		for (char c : str)
		{
			if (c == '(') rs++;
			else rs--;

			mn = min(mn, rs);
		}

		sum += rs;
		if (rs >= 0) v1.push_back({ mn, rs });
		else v2.push_back({ mn, rs });
	}

	if (sum)
	{
		cout << "No";
		return 0;
	}

	sort(v1.begin(), v1.end(), cmp1);
	sort(v2.begin(), v2.end(), cmp2);

	bool ans = true;

	int cur = 0;
	for (pii it : v1)
	{
		int mn = it.first;
		int rs = it.second;

		if (cur + mn < 0)
		{
			ans = false;
			break;
		}

		cur += rs;
	}

	for (pii it : v2)
	{
		int mn = it.first;
		int rs = it.second;

		if (cur + mn < 0)
		{
			ans = false;
			break;
		}

		cur += rs;
	}

	if (ans) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 11236
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
 
#include <bits/stdc++.h>
#include <vector> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(int i=a;i<b;i++)
const int hell=1000000007;
 
 int h[100010][2]={0};
 int dp[101][100010];
 int n,w;



int solve(){    

  cin>>n>>w;
  rep(i,0,n)rep(j,0,2)cin>>h[i+1][j];
    
    rep(i,1,n+1)
    {
       rep(j,0,w+1)
       {
        if(j>=h[i][0])
          dp[i][j]=max(dp[i-1][j-h[i][0]]+h[i][1],dp[i-1][j]);
        else dp[i][j]=dp[i-1][j];
       }
    }
  
  cout<<dp[n][w];


return 0;
}

 
signed main()
{    
   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    

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

 int t=1;                                                                                                                  
// cin>>t;
    while(t--)
     {
      solve();
     }
    return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC";
    else
        cout << "ABC";
}


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

#define INF 0x3f3f3f3f3f3f3f3fll
#define faster ios_base::sync_with_stdio(0);
#define faster_tie cin.tie(0);
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define NL cout<<'\n'

ll x;
int n, k;
vector<ll>height;
ll sol[110000];

ll solve(int pos)
{
    if(pos==1)
    {
        return 0;
    }
    if(sol[pos]!=-1)return sol[pos];
    ll a=INF;

    for(int i=pos-1;i>pos-1-k;i--)
    {
        if(i==0)break;
        a=min(a,solve(i)+abs(height[i]-height[pos]));
    }
    sol[pos]=a;
    return a;

}


int main()
{
	
	memset(sol,-1,sizeof sol);
	
    cin>>n>>k;
    
    height.push_back(-1);
    
    for(int i=0;i<n;i++)
    {
        cin>>x;
        height.push_back(x);
    }

    ll ans=solve(n);
    cout<<ans<<"\n";



    return 0;
}


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

const int MAX_N = 1e+6;
const int INF = 1e+8;

int f(int n){
	return n * (n+1) * (n+2) / 6;
}

int dp[2][MAX_N+1] = {0};

int main(){
	for(int i=0 ; i < MAX_N ; i++ ){
		dp[0][i] = dp[1][i] = INF;
	}
	for(int i=1 ; f(i) < MAX_N ; i++ ){
		dp[0][f(i)] = 1;
		if( f(i) % 2 )
			dp[1][f(i)] = 1;
	}
	for(int i=1 ; i < MAX_N ; i++ ){
		if( dp[0][i] != INF ){
			for(int j=1 ; i + f(j) < MAX_N ; j++ ){
				dp[0][i+f(j)] = min( dp[0][i+f(j)] , dp[0][i]+1 );
			}
		}
		if( dp[1][i] != INF ){
			for(int j=1 ; i + f(j) < MAX_N ; j++ ){
				if( f(j) % 2 )
					dp[1][i+f(j)] = min( dp[1][i+f(j)] , dp[1][i]+1 );
			}
		}
	}
	
	int n;
	while( cin >> n , n ){
		cout << dp[0][n] << " " << dp[1][n] << endl;
	}
}

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

int main() {
  int n, m;

  cin >> n;
  vector<string> blue(n);
  for (int i = 0; i < n; i++) {
    cin >> blue.at(i);
  }

  cin >> m;
  vector<string> red(m);
  for (int i = 0; i < m; i++) {
    cin >> red.at(i);
  }
  
  int max = -100;
  for (int i = 0; i < n; i++) {
    int count = 0;
    int plus = 0;
    for (int j = 0; j < n; j++) {
      if (blue.at(i) == blue.at(j)) {
        plus++;
      }
    }
    count += plus;

    int minus = 0;
    for (int j = 0; j < m; j++) {
      if (blue.at(i) == red.at(j)) {
        minus++;
      }
    }
    count -= minus;

    max = (count > max)? count : max;
  }
  max = (0 > max)? 0 : max;
  cout << max << endl;
}

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

int main()
{
    string s1,s2;
    int i,num=0;
    cin >>s1;
    cin >>s2;
    for (i=0;i<s1.size();i++)
    {
        if (s1[i]!=s2[i])
            num ++;
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 3928
def main(nums)
  array = Array.new(nums.size)
  nums.size.times do |i|
    array[nums[i] - 1] = i
  end
  max = 1
  array.each_cons(2).inject(1) do |count, (x, y)|
    next 1 if x >= y

    count += 1
    max = count if count > max
    count
  end
  nums.size - max
end

nums = []
gets.to_i.times do
  nums << gets.to_i
end

puts main(nums)

Measured memory_bytes: 5428
#include<bits/stdc++.h>
#define ll long long
#define all(v) v.begin(),v.end()
#define rall(v) v.begin(),v.end()
#define sz(x) (int)sz.size()
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define what(x) cout<<#x<<" is "<<x<<endl;
using namespace std;

#ifdef LOCAL//ONLINE_JUDGE
#include "D:\c_c++\template.h"
#else
#define debug(...) 42
#endif

ll powmod(ll a,ll b,ll mod) {
    ll res=1;a%=mod;
    for(;b;b>>=1){
        if(b&1)res=res*a%mod;
			a=a*a%mod;
    }
    return res;
}

void solve(){
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		s+="es";
	}else{
		s+="s";
	}
	cout<<s<<'\n';
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
//    #ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif
    int tc=1;
    // cin>>tc;
    while(tc--)solve();
}
		

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)

    {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;
//入力
int N;
long long h[100010];

//メモ用のDPテーブル
long long dp[100010];

long long rec(int i)
{
    //DPの値が更新されていたら、そのままリターンする
    if (dp[i] < INF)
        return dp[i];

    //足場0のコストは0
    if (i == 0)
        return 0;

    //i-1, i-2を、それぞれ試す
    long long res = INF;
    chmin(res, rec(i-1)+abs(h[i]-h[i-1])); //足場i-1からきた場合
    if(i > 1)
    chmin(res,rec(i-2)+abs(h[i]-h[i-2]));//足場i-2からきた場合

    //結果をメモしながら、残す
    return dp[i] = res;
}
int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
        cin >> h[i];

    //初期化する(最小化問題であるから、INFに最小化する)
    for (int i = 0; i < 100010; ++i)
        dp[i] = INF;

    //答え
    cout << rec(N - 1) << endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    string A, B, C;
    cin >> N;
    cin >> A >> B >> C;
    int ans = 0;
    REP(i, N)
    {
        if (A[i] == B[i])
        {
            if (A[i] != C[i])
                ans++;
        }
        else if (B[i] == C[i])
        {
            if (B[i] != A[i])
                ans++;
        }
        else if (C[i] == A[i])
        {
            if (A[i] != B[i])
                ans++;
        }
        else
        {
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256