akhauriyash/Code-Regression huggingface dataset:
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll x, y, z;
        char c;
        cin >> x >> c >> y >> c >> z;
        if(x > 2019 || y > 4) cout << "TBD" << endl;
        else cout << "Heisei" << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
    */ 
      //te
      solve();
      return 0;
    } 

Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>	tree_set;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll mod=1e9 + 7;

int main()
{
    fast();
    ll x,y;
    cin>>x>>y;

    if(x<=8 && y<=8)
        cout<<"Yay!";
    else
        cout<<":(";

}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>

using namespace std;
/*
方針

*/
int main(){
  int N;
  cin >> N;
  vector<int> t(210);
  vector<int> v(210);

  for(int i = 0; i < N; i++) cin >> t[i];
  for(int i = 0; i < N; i++) cin >> v[i];

  double ret = 0, sp = 0;
  for(int i = 0; i < N; i++){
    for(double j = 0; j < t[i]; j += 0.5){
      bool flag1 = true, flag2 = true;
      double ti = t[i] - j - 0.5;
      for(int k = i+1; k < N; k++){
        ti += t[k];
        if(sp + 0.5 - ti > v[k+1]) flag1 = false;
        if(sp - v[k+1] > ti) flag2 = false;
      }
      if(sp+0.5 <= v[i] && flag1 && (sp + 0.5 -(t[i] - j - 0.5)) <= v[i+1]){
        ret += sp * 0.5;
        ret += 0.125;
        sp += 0.5;
      } else if(sp - v[i+1] <= t[i]-j-0.5 && flag2){
        ret += sp*0.5;
      } else {
        sp -= 0.5;
        ret += sp * 0.5;
        ret += 0.125;
      }
    }
  }

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


Measured memory_bytes: 256
import math

def nCr(n,r):

    if n-r >= 0:
        return math.factorial(n) // (math.factorial(n-r) * math.factorial(r))
    else:
        return 0

def nC2(n):
    if n-2 >= 0:
        return (n*(n-1)) // 2
    else:
        return 0

def wantp(n): #Union-Find木の親の探索

    nown = n
    Q = []
    cnt = 0
    while True:

        if nown != p[nown]:
            Q.append(nown)
            nown = p[nown]

        else:
            for i in Q: #探索した途中にあるノードの親を根に変更
                p[i] = nown
                cnt += 1

            break

        cnt += 1

        if cnt > 10:
            print (n,nown,p[nown])

    return nown


N,M = map(int,input().split())

AB = []
for i in range(M):

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

    AB.append([A-1,B-1])

AB.reverse()


ans = []
ans.append(nCr(N,2))

p = [] #親
c = [] #子の数
rank = [1] * N #そのノードの子で構成された木の深さ

for i in range(N):

    p.append(i)
    c.append(1)

for i in range(M): #最後の橋から1本ずつ足していく

    #if i % 1000 == 0 or i > 25000:
        #print (i)

    #if i > 25000 : print ("A")

    a = AB[i][0]
    b = AB[i][1]

    #if i > 25000 : print ("B") 

    ap = wantp(a)
    bp = wantp(b)

    #if i > 25000 : print ("C")

    now = ans[-1]

    if ap != bp: #前回の答えから導出、Union-Find木の結合
        now = now + nC2(c[ap]) + nC2(c[bp]) - nC2(c[ap]+c[bp])

        #if i > 25000 : print ("D")

        if rank[ap] > rank[bp]:

            p[bp] = ap
            c[ap] += c[bp]

        elif rank[ap] < rank[bp]:

            p[ap] = bp
            c[bp] += c[ap]

        else:

            p[ap] = bp
            c[bp] += c[ap]

            rank[bp] += 1

        #if i > 25000 : print ("E")

    ans.append(now)
    #if i > 25000 : print ("F")
    #print (now,p)

#print ("test")
ans.reverse()

for i in range(M):
    print (ans[i+1])


Measured memory_bytes: 99416
n=input()
if n=="SUN":
  print(7)
elif n=="MON":
  print(6)
elif n=="TUE":
  print(5)
elif n=="WED":
  print(4)
elif n=="THU":
  print(3)
elif n=="FRI":
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;

bool Check_Warm_Color(string str) {
	char c = str[0];
	for (int i = 1; i < str.length(); ++i) {
		if (c != str[i]) {
			return false;
		}
	}
	return true;
}

char Check_Color(char c1, char c2) {
	if (c1 < c2) {
		swap(c1,c2);
	}
	if (c1 == 'r') {
		if (c2 == 'g') {
			return 'b'; 
		}
		else {
			return 'g';
		}
	}
	return 'r';
}

int main(void) {
	string str,ss;
	cin >> str;
	while (str != "0") {
		int len = str.length();
		map<string,bool> ob;
		ob[str] = true;

		queue<string> warm;
		queue<int> deep;
		warm.push(str);
		deep.push(0);
		bool find = false;
		int d;
		int ret = -1;
		while (!find && !warm.empty()) {
			str = warm.front();
			d = deep.front();
			warm.pop();
			deep.pop();
			if (Check_Warm_Color(str)) {
				ret = d;
				find = true;
			}
			else {
				for (int i = 0; i < str.length() - 1; ++i) {
					ss = str;
					if (str[i] != str[i+1]) {
						char temp = Check_Color(str[i],str[i+1]);
						ss[i] = temp;
						ss[i+1] = temp;
					}
					if (!ob[ss]) {
						ob[ss] = true;
						warm.push(ss);
						deep.push(d+1);
					}
				}
			}
		}
		if (ret < 0) {
			cout << "NA" << endl;
		}
		else {
			cout << ret << endl;
		}

		cin >> str;
	}
	return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

    int total=0,keep=N;

    while(N!=0){
        total += N%10;
        N=N/10;
    }

    if(keep%total==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B) {
        cout << C << endl;
    } else if (B == C) {
        cout << A << endl;
    } else {
        cout << B << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
  for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
  for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
  return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
  os<<"{ ";for(auto m:M)os<<"("<<m.first<<":"<<m.second<<")";
  return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
//For multiset use less_equal operator but it does support erase operations for multiset
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define all(v) (v).begin(),(v).end()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mp make_pair


const int mod = 1e9+7;

inline int add(int a,int b){a+=b;if(a>=mod)a-=mod; return a;} 
inline int sub(int a,int b){a-=b;if(a<0) a += mod; return a;}
inline int mul(int a, int b){ return a*1ll*b%mod;}
inline int power(int x, ll y){
  int res = 1;
  while(y){
    if(y&1) res = mul(res , x);
    x = mul(x,x);
    y >>= 1;
  }
  return res;
}

int main(){
  fio; cout<<fixed<<setprecision(25);	
  string s; cin >> s;
  int cnt = 0; 
  int mx = 0;
  for(auto c: s){
    if(c == 'R'){
      ++cnt;
    }
    else{
      mx = max(mx ,cnt);
      cnt = 0;
    }
  }
  mx = max(mx , cnt);
  cout << mx << endl;
  return 0;
}



Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int i[3][110000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b,c,d=0,e=0,f,g;
  string s;
  cin >>a>>b>>c;
  d=a+b,e=a+c,f=b+c;
  cout <<min(d,min(e,f))<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<n;i++)
#define REP1(i,n) for(long long i=1;i<=n;i++)
#define REP2D(i,j,h,w) for(long long i=0;i<h;i++) for(long long j=0;j<w;j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=h;i++) for(long long j=1;j<=w;j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) (a.begin()),(a.end())
#define RANGE(a) (a),(a+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<a<<endl;
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);
#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 10
#define MAXD 10
#define MAXSQ 130
//---------------------

int n,d;
int x[MAXN][MAXD];
int sqnum[MAXSQ];

int main(){
  	cin>>n>>d;
  	REP2D(i,j,n,d){
  		cin>>x[i][j];
  	}
  	REP(i,MAXSQ){
  		sqnum[i]=i*i;
  	}
  	ll ct=0;
  	
  	REP(i,n-1){
  	  	
  		FOR(j,i+1,n){
  		  	ll dist=0;
  		  	REP(k,d){
  		  		dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]) ;

  		  	}
  		  	if(*lower_bound(sqnum,sqnum+MAXSQ,dist)==dist) {ct++;};
  		}
  	}
  	
  	cout<<ct<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long a, long long b){
    if( (a*b) % 2 == 0){
        cout << "Even" << endl;
    } else {
        cout << "Odd" << endl;
    }
}

int main(){

    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    ll t=exp(x,y/2);
    return (t*t);
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}
  
int main(){
  string s,t;cin >> s >> t;
  t.pop_back();
  if(s==t)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define MOD 1000000007
#define INF 1000000007
using namespace std;
//
int main(){
  int N;
  set<int> S;
  cin>>N;
  FOR(i,0,N){
    int A;
    cin>>A;
    if(S.find(A)!=S.end()){
      S.erase(A);
    }else{
      S.insert(A);
    }
  }
  cout<<S.size()<<endl;
  return 0;
}


Measured memory_bytes: 4864
n = int(input())
H = list(map(lambda x: int(x)-1, input().split()))
for i in range(n-1):
    if H[i] > H[i+1]:
        if H[i] <= H[i+1] + 1:
            # 次に1を足して大きいならOK
            # 足した場合は記録する
            H[i+1] += 1
        else:
            print('No')
            break
else:
    print('Yes')

Measured memory_bytes: 20516
#include <iostream>
#include <algorithm>
#include <vector>

void exchange(std::vector<int>& A, int i, int j) {
    int temp = A[i];
    A[i] = A[j];
    A[j] = temp;
}

int Partition(std::vector<int>& A, int p, int r) {
    int x = A[r];
    int i = p-1;
    for (int j=p; j<r; ++j) {
        if (A[j] <= x) {
            i++;
            exchange(A, i, j);
        }
    }
    exchange(A, i+1, r);
    return i+1;
}

int main() {
    int N, temp;
    std::cin >> N;
    std::vector<int> A;
    for (int i=0; i<N; ++i) {
        std::cin >> temp;
        A.push_back(temp);
    }
    
    int q = Partition(A, 0, N-1);
    
    for (int i=0; i<N; ++i) {
        if (i!=N-1) {
            if (i!=q) {
                std::cout << A[i] << " ";
            } else {
                std::cout << "[" << A[i] << "] ";
            }
        } else {
            std::cout << A[i] << std::endl;
        }
    }
}


Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
#define P pair<int,int>
typedef long long ll;
using namespace std;

vector<string> ans;

void dfs(int num, int keta, string now){
    int nowl=now.length();
    if(ans.size()<100000){
        if(keta==0){
            rep(i,9){
                now[keta]=i+1+'0';
                if(nowl==1){
                ans.push_back(now);
                num++;
                }
            else dfs(num,keta+1,now);
            }
            now='1'+now;
            dfs(num,0,now);
        }
        else{
            for(int i=-1; i<=1; i++){
                now[keta]=now[keta-1];
                if(now[keta-1]=='9' && i==1) continue;
                if(now[keta-1]=='0' && i==-1) continue;
                now[keta]+=i;
                if(keta==nowl-1){
                ans.push_back(now);
                num++;
                }
                else dfs(num,keta+1,now);
            }
        }
    }
}

  

int main(){
    int k; cin >> k;
    dfs(0,0,"0");
    cout << ans[k-1] << endl;
return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n+1),b(n);
  for(int i=0; i<n+1; i++){
    cin >> a.at(i);
  }
  for(int i=0; i<n; i++){
    cin >> b.at(i);
  }
  
  int r;
  long long answer1 = 0, answer2 = 0;
  
  for(int i=0; i<n; i++){
    if(a.at(i) <= b.at(i)){
      answer1 += a.at(i);
      r = b.at(i) - a.at(i);
      if(r <= a.at(i+1)){
        a.at(i+1) -= r;
        answer1 += r;
      }else{
        answer1 += a.at(i+1);
        a.at(i+1) = 0;
      }
    }else{
      answer1 += b.at(i);
    }
  }
  
  for(int i=n; i>0; i--){
    if(a.at(i) <= b.at(i-1)){
      answer2 += a.at(i);
      r = b.at(i-1) - a.at(i);
      if(r <= a.at(i-1)){
        a.at(i-1) -= r;
        answer2 += r;
      }else{
        answer2 += a.at(i-1);
        a.at(i-1) = 0;
      }
    }else{
      answer2 += b.at(i-1);
    }
  }
  
  long long answer = max(answer1,answer2);
  cout << answer << endl;
  
  
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 60
#define ll long long
#define ull unsigned long long
#define RNG mt19937
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 1005;
int n;
vector<int> g[N];
int x[N];
bool val = true;

int gdp(int cur){
	bool cdp[5001] = {};
	cdp[0] = 1;
	bool ndp[5001] = {};
	int rsum = 0;
	for(int a:g[cur]){
		int oth = gdp(a);
		rsum += oth + x[a];
		fd(i,x[cur] - oth,0){
			if(cdp[i])ndp[i + oth] = 1;
		}
		fd(i,x[cur] - x[a],0){
			if(cdp[i])ndp[i + x[a]] = 1;
		}
		fd(i,x[cur],0){cdp[i] = ndp[i];ndp[i] = 0;}
	}
	int best = -1;
	fd(i,x[cur],0){
		if(cdp[i]){best = i; break;}
	}
	if(best == -1){val = false;return 0;}
	else return rsum - best;
}

int main(){
	fast_io();
	cin >> n;
	fu(i,2,n){
		int a;
		cin >> a;
		g[a].pb(i);
	}
	fu(i,1,n)cin >> x[i];
	gdp(1);
	cout << (val?"POSSIBLE":"IMPOSSIBLE") << '\n';
}


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

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
L, R = [None] * M, [None] * M
for i in range(M):
    L[i], R[i] = map(int, input().split())

ans = max(min(R) - max(L) + 1, 0)

print(ans)


Measured memory_bytes: 10868
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
#include <cmath>
#include <set>
#include <unordered_set>
#include <climits>
using namespace std;
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
#define ForInt(i, n) for (int i = 0; i < (n); ++i)
#define ForLong(i, n) for (int64 i = 0; i < (n); ++i)
#define ForIntInit(i, begin, end) for (int i = (begin); i < (end); ++i)
#define ForItr(it, itBegin, itEnd) for (auto it = (itBegin); it != (itEnd); ++it)
#define Min(a, b) ((a) < (b) ? (a) : (b))
#define Max(a, b) ((a) > (b) ? (a) : (b))



int main()
{
	int n, k;
	cin >> n >> k;
	vint v(n);
	ForInt(i, n)
	{
		cin >> v[i];
	}

	int max = INT_MIN;
	ForInt(a, n)
	{
		ForInt(b, n - a)
		{
			if (a + b > k) break;

			vint take(a + b);
			copy(v.begin(), v.begin() + a, take.begin());
			copy(v.rbegin(), v.rbegin() + b, take.begin() + a);
			int sum = 0;
			ForInt(i, take.size())
			{
				sum += take[i];
			}
			int restK = k - a - b;
			if (restK > 0)
			{
				sort(take.begin(), take.end());
				for (int i = 0; i < restK && i < take.size() && take[i] < 0; ++i)
				{
					sum -= take[i];
				}
			}
			//cout << "a = " << a << ", b = " << b << ", sum = " << sum << endl;
			max = Max(max, sum);
		}
	}

	// a + b = n
	if (k >= n)
	{
		int sum = 0;
		ForInt(i, n)
		{
			sum += v[i];
		}
		int restK = k - n;
		if (restK > 0)
		{
			sort(v.begin(), v.end());
			for (int i = 0; i < restK && i < n && v[i] < 0; ++i)
			{
				sum -= v[i];
			}
		}
		max = Max(max, sum);
	}
	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s = if x == [5, 5, 7] then "YES" else "NO"
  where x = sort $ fmap read (words s) :: [Int]

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
# -*- coding: utf-8 -*-
import itertools
import sys
import math
from functools import lru_cache

# 1整数
# n = int(input())

# 空白区切り2変数
from queue import Queue
from operator import mul
from functools import reduce

# N個整数
a, b, c = list(map(int, input().split()))

# 1整数
# n = int(input())

# 空白区切りリスト整数
# b = list(map(int, input().split()))

if a == b and b == c:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4436
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!

int main(void){
    ll N, d[100], ans=0;
    scanf("%lld", &N);
    rep(i, N) {
        scanf("%lld", d+i);
        rep(j, i) ans += d[j]*d[i];
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] ws = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = std.nextInt();
        }

        int left = 0;
        int right = 0;
        int rightIndex = n - 1;
        for (int i = 0; i < n; i++) {
            for (int j = rightIndex; j >= 0; j--) {
                if (rightIndex < i) {
                    break;
                }
                int rightValue = ws[j];
                if (right <= left) {
                    right += rightValue;
                    rightIndex--;
                } else {
                    break;
                }
            }

            if (rightIndex < i) {
                break;
            }
            int leftValue = ws[i];
            if (left <= right) {
                left += leftValue;
            }
        }

        System.out.println(Math.abs(left - right));
    }
}


Measured memory_bytes: 23508
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-01 22:53:07
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

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

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int x, y;
    cin >> x >> y;

    vector<int> a, b;
    a = {1, 3, 5, 7, 8, 10, 12};
    b = {4, 6, 9, 11};

    int X, Y;
    for (int i = 0; i < a.size(); i++) {
        if (x == a[i]) X = 0;
        if (y == a[i]) Y = 0;
    }
    for (int i = 0; i < b.size(); i++) {
        if (x == b[i]) X = 1;
        if (y == b[i]) Y = 1;
    }
    if (x == 2) X = 2;
    if (y == 2) Y = 2;

    if (X == Y) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

vi calc(int x) {
  vi ret;
  while (x > 0) {
    ret.push_back(x % 10);
    x /= 10;
  }
  return ret;
}

int main() {
  int n;
  scan(n);
  vi a = calc(n);
  vi b = a;
  reverse(all(b));
  if (a == b) {
    print("Yes");
  } else {
    print("No");
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  //input
  string x,y;
  cin>>x>>y;
  
  //prepare
  x=" "+x;
  y=" "+y;
  int xlen,ylen;
  xlen=x.size();
  ylen=y.size();
  int mlen=max(xlen,ylen);
  int dp[1002][1002];//dp[i][j]:=xのi文字目までとyのj文字目までを使って一致させるのに必要な最低作業回数
  rep(i,mlen)dp[i][0]=dp[0][i]=i;//i文字まで一致であれば最大でもi回の操作でいける

  
  rep(i,xlen){
    rep(j,ylen){
      if(x[i+1]==y[j+1])dp[i+1][j+1]=min(dp[i][j],min(dp[i+1][j]+1,dp[i][j+1]+1));
      else dp[i+1][j+1]=min(dp[i][j]+1,min(dp[i+1][j]+1,dp[i][j+1]+1));
      //xのi文字目とｙのｊ文字目までを使って一致させるまでの作業＝
      //xのi-1(i)文字目までとyのj(j-1)文字目までの文字列にする作業に対し、x(y)の最後に位置文字挿入する
      //or　i文字目とj文字目を一致させるように置換する
      
      //cout<<dp[i][j];//dptable用
    }//cout<<endl;//dptable用    
  }
  //output
  cout<<dp[xlen-1][ylen-1]<<endl;   
    
  return 0;
}


Measured memory_bytes: 7128
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	n := readInt()
	points := make([]Point, n)
	for i := range points {
		a := readInt()
		b := readInt()
		c := readInt()
		points[i] = Point{
			t: a,
			x: b,
			y: c,
		}
	}
	
	fmt.Println(solve(points))
}

type Point struct {
	t int
	x int
	y int
}

func solve(points []Point) string {
	for _, point := range points {
		if !(point.x+point.y <= point.t && (point.x+point.y+point.t)%2 == 0) {
			return "No"
		}
	}
	
	return "Yes"
}

func checkErr(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func toInt(s string) int {
	i, e := strconv.Atoi(s)
	checkErr(e)
	return i
}

func nextLine(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	var num int
	_, e := fmt.Scan(&num)
	checkErr(e)
	return num
}

func readStr() string {
	var str string
	_, e := fmt.Scan(&str)
	checkErr(e)
	return str
}

func readLine() string {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines)
	return nextLine(scanner)
}


Measured memory_bytes: 5888
#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 main()
{
	string s;
	cin>>s;
	rep(i,SZ(s))
	{
		if(s[i]=='7')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
    return 0;
}

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

int main(){
    int N, K, S;
    cin >> N >> K >> S;
    vector<int> A(N);
    for(int i=0; i<K; i++) A[i] = S;
    const int M = 1e9;
    for(int i=K; i<N; i++){
        int v = (S == M ? M-1 : S+1);
        A[i] = v;
    }
    for(int i=0; i<N; i++) cout << A[i] << " \n"[i==N-1];
    return 0;
}


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

int N,A,B,C,l,ans;
vector<int> v(8);
int solve(int x,int a,int b,int c){
	if (x == N){
		if (min(min(a,b),c) > 0){//どれも一回は足されないとダメ
			return abs(A-a) + abs(B-b) + abs(C-c) - 30;//1度目の+10のぶんは引いておく
		}
		else{
			return INF;
		}
	}
	int r1 = solve(x + 1,a,b,c);//何処にも使わないとき
	int r2 = solve(x + 1,a + v[x],b,c) + 10;//Aの材料
	int r3 = solve(x + 1,a,b + v[x],c) + 10;//Bの材料
	int r4 = solve(x + 1,a,b,c + v[x]) + 10;//Cの材料
	return min(min(min(r1,r2),r3),r4);
}

int main(){
	cin >> N >> A >> B >> C;
	for (int i = 0;i < N;i++){
		cin >> l;
		v[i] = l;
	}
	cout << solve(0,0,0,0) << endl;
}



Measured memory_bytes: 256
using System;

public class p1042{
	p1042 ()
	{
		string str;
		string[] st;
		
		while ((str=Console.ReadLine())!=null && str != "END OF INPUT") {
			st = str.Split (' ');
			foreach (string s in st)
				Console.Write ("{0}", s.Length);
			Console.WriteLine ("");
		}
	}
	public static int Main (string[] args)
	{
		new p1042 ();
		return 0;
	}
}

Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
vector<long long> mymax(vector<long long> a,vector<long long> b, vector<long long> c){
    if(a<b) a=b;
    if(a<c) a=c;
    return c;
}
int main(){
    long long x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    priority_queue<pair<long long,int>> p;
    for(int i =0; i<a; i++){
        long long t;
        cin>>t;
        p.push(make_pair(t,0) );
    }
    for(int i =0; i<b; i++){
        long long t;
        cin>>t;
        p.push(make_pair(t,1));
    }
    for(int i =0; i<c; i++){
        long long t;
        cin>>t;
        p.push(make_pair(t,2));
    }
    vector<long long> v(3,0);
    vector<int> ma(3,0);
    ma.at(0)=x;
    ma.at(1)=y;
    ma.at(2)=(x+y);
    long long ans = 0;
    int wa=0;
    while(wa<x+y){
        pair<long long,int> tmp=p.top();
        if(v.at(tmp.second)>=ma.at(tmp.second)){
            p.pop();
        }
        else{
            ans += tmp.first;
            v.at(tmp.second)++;
            wa++;
            p.pop();
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10348
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
ll N,M;


int main(){
  int N;cin >> N;
  int f=0,k=0;
  rep(i,N){
    int a;cin >> a;
    if(a%4==0) f++;
    if(a%2==1) k++;//奇数
  }
  if(N%2){
    cout << (k-1 <= f?"Yes":"No") << "\n";
  }else{
    cout << (k <= f ?"Yes":"No") << "\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
signed main(){
    int n;
    cin>>n;
    cout<<fixed<<setprecision(15);
    cout<<(double)((n-1)/2+1)/(double)n<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <stdio.h>
void swap(int *a, int *b) {
    int temp = *a;
    *a = *b;
    *b = temp;
}

int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}




Measured memory_bytes: 2000
#include <cstdio>
#include <cmath>

#define FOR( i, l, r) for(int i = (l)    ; i <  (r); i++)
#define FOR1(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define REV( i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define REV1(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define INC( i, n) FOR( i, 0, n)
#define INC1(i, n) FOR1(i, 1, n)
#define DEC( i, n) REV( i, 0, n)
#define DEC1(i, n) REV1(i, 1, n)

typedef long long   signed int LL;
typedef long long unsigned int LU;

template<typename T> void swap(T &x, T &y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> void m_sort_(T a[], T b[], int l, int r, bool as) {
	if(r - l < 2) { return; }
	
	int m = (l + r) / 2;
	m_sort_(a, b, l, m, as);
	m_sort_(a, b, m, r, as);
	
	int ll = l, rr = m, bb = 0;
	while(bb < r - l) {
		bool l_flag;
		if(rr == r || ll == m) { l_flag = (rr == r); }
		else { l_flag = ( as ? (a[ll] <= a[rr]) : (a[rr] <= a[ll]) ); }
		
		b[bb++] = (l_flag ? a[ll++] : a[rr++]);
	}
	
	for(int i = l; i < r; i++) { a[i] = b[i - l]; }
}
template<typename T> void m_sort(T a[], int l, int r, bool as = true) {
	T *b = new T[r - l];
	m_sort_(a, b, l, r, as);
	delete[] b;
}

struct P {
	int a, b;
	bool operator<=(const P &obj) {
		return (*this).a <= obj.a;
	}
};

int n;
P a[200000];
LL ans;

#define SEG (1 << 18)

int sl[SEG], sr[SEG];
void init() {
	INC(i, SEG) { sl[i] = -1; sr[i] = -1; }
}

bool l_end(int j) {
	return ((j & (j - 1)) == 0);
}

void add(P arg) {
	int v = arg.a;
	int m = arg.b;
	
	int j;
	
	// L
	j = SEG + m; j /= 2;
	int ll = -1;
	while(j != 0) {
		if(sl[j] == -1) { j /= 2; }
		else if(sl[j] < m) {
			ll = (m < sr[j] ? sl[j] : sr[j]);
			break;
		} else {
			if( ! l_end(j) ) { j--; } else { break; }
		}
	}
	
	// R
	j = SEG + m; j /= 2;
	int rr = n;
	while(j != 0) {
		if(sr[j] == -1) { j /= 2; }
		else if(m < sr[j]) {
			rr = (sl[j] < m ? sr[j] : sl[j]);
			break;
		} else {
			if( ! l_end(j + 1) ) { j++; } else { break; }
		}
	}
	
	// UPDATE
	j = SEG + m; j /= 2;
	while(j != 0) {
		if(sl[j] == -1) { sl[j] = m; sr[j] = m; j /= 2; }
		else if(sl[j] < m && m < sr[j]) { break; }
		else {
			setmin(sl[j], m);
			setmax(sr[j], m);
			j /= 2;
		}
	}
	
	ans += static_cast<LL>(m - ll) * (rr - m) * v;
}

int main() {
	scanf("%d", &n);
	INC(i, n) { scanf("%d", &a[i].a); a[i].b = i; }
	
	init();
	
	m_sort(a, 0, n);
	INC(i, n) { add(a[i]); }
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 5376
N = input()
N_list = [int(i) for i in N]
top_num = N_list[0]
length = len(N_list)
flag = True
for i in range(length-1):
  if top_num == 9:
    flag = True
    break
  if N_list[i]>N_list[i+1]:
    flag = True
    break
  elif N_list[i]==N_list[i+1]:
    flag = True
  else:
    flag = False
    break

if flag:
  print(str(top_num)*length)
else:
  print(str(top_num+1)*length)

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

int n;
int D[110];
string S;

int main(){
	cin >> n;
	cin >> S;
	int left = 0,right = 0,x = 0;
	for(int i=0;i<S.size();i++){
		if(S[i] == '(') left++;
		else right++;
		D[i] = left-right;
		if(x > D[i]) x = D[i];
	}
	int T = S.size();
	for(int i=0;i<-x;i++){
		S = '(' + S;
	}
	for(int i=0;i<D[T-1]-x;i++){
		S += ')';
	}
	cout << S << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	string b = "";
	rep(i, w + 2) b += '#';
	cout << b << endl;
	rep(i, h){
		cout << '#' << s[i] << '#' << endl;
	}
	cout << b << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int par[200005];
int s[200005];
int Rank[200005];
set<int>ss;
void init(int n) {
  for(int i = 0; i <= n; i++) {
    par[i] = i;
    s[i] = 0;
    Rank[i] = 0;
  }
  return;
}

int f(int x) {
  return (x == par[x]) ? x : (par[x] = f(par[x]));
}
void u(int x, int y) {
  int a = f(x);
  int b = f(y);
  if(a == b) return;
  s[a] += s[b];
  s[b] = s[a];
  if(Rank[a] > Rank[b]) {
    par[b] = a;
  }
  else {
    par[a] = b;
    if(Rank[a] == Rank[b]) Rank[a]++;
  }
}
    
  
int main() {
  int n;
  cin >> n;
  init(n);
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(ss.find(a) == ss.end()) {
      s[a]++;
      ss.insert(a);
    }
    if(s[a-1] > 0) {
      u(a,a-1);
    }
  }
      

  int ans = 0;
  for(int i = 0; i <= n; i++) {
    ans = max(ans,s[i]);
   // cout <<i<<"   "<<s[i] << endl;
    }

  cout << n - ans << endl;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

using Edge = pair<int, int>; // next, weight
using Graph = vector<vector<Edge>>;
vector<int> res;

int N;
Graph G;

void dfs(int now, int parent, int color) {
    res[now] = color;
    for(auto edge : G[now]) {
        if (edge.first == parent) continue;
        if (edge.second & 1) // edge.second % 2 == 1
            dfs(edge.first, now, 1-color);
        else
            dfs(edge.first, now, color);
    }
}

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

    cin >> N;
    G.assign(N, vector<Edge>());

    rep(i, 0, N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }

    res.assign(N, 0);
    dfs(0, -1, 1);
    
    for(auto v : res) cout << v << endl;
}

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

void solve(long long K, long long A, long long B)
{
    bool ok = false;
    for (int i = A; i <= B; i++)
    {
        if (i % K == 0)
        {
            ok = true;
            break;
        }
    }

    cout << (ok ? "OK" : "NG") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(K, A, B);
    return 0;
}


Measured memory_bytes: 3764
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int h=sc.nextInt(),w=sc.nextInt();
    char[][] ch=new char[h][w];
    int[] dx={1,0,-1,0,1,-1,1,-1};
    int[] dy={0,1,0,-1,1,-1,-1,1};
    for(int i=0;i<h;i++){
      ch[i]=sc.next().toCharArray();
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(ch[i][j]=='#'){
          System.out.print(ch[i][j]);
        }else{
          int num=0;
          for(int d=0;d<8;d++){
            int ni=i+dx[d];
            int nj=j+dy[d];
            if(ni<0||ni>=h){
              continue;
            }else if(nj<0||nj>=w){
              continue;
            }else{
              if(ch[ni][nj]=='#'){
                num++;
              }
            }
          }
          System.out.print(num);
        }
      }
      System.out.print("\n");
    }
  }
}


Measured memory_bytes: 22868