akhauriyash/Code-Regression huggingface dataset:
// g++ -I ~/Documents/programming/cppLib -std=gnu++14 -o test ~/Documents/programming/cppLib/test.cpp && ./test && rm test
#include <bits/stdc++.h>
#define rep(i, n) for( lint i=0; i<(n); ++i )
#define all(v)    (v).begin(), (v).end()
using namespace std;
using lint = long long;

//  cinからvectorへ入力
template<typename T>
istream& operator >> ( istream& is, vector<T>& vec ) {
    for( T& x: vec ) {
        is >> x;
    }
    return is;
}

//  coutへvectorから出力
template<typename T>
ostream& operator << ( ostream& os, vector<T>& vec ){
    for( T& x: vec ) {
        if( x == vec[0] ) {
            cout << x;
        } else {
            cout << " " << x;
        }
    }
    return os;
}

//  それぞれのvectorから１つずつ選ぶ組み合わせを全探索
#define select( v, data ) SELECTION<typeof(data[0][0])>(data) * [&](vector<typeof(data[0][0])> v)
template<typename T> struct SELECTION {
    vector<vector <T>> &data;
    SELECTION( vector<vector <T>> &d ) :data(d) {}
    void operator* ( function<void(vector<T>&)> closure ) {
        int N = data.size();
        vector<int> K(N);
        for( int i=0; i<N; i++ ) {
            K[i] = data[i].size();
        }

        vector<int> now( N, 0 );
        vector<T> arg(N);
        while(true) {
            for( int i=0; i<N; i++ ) {
                arg[i] = data[i][now[i]];
            }

            closure(arg);

            for( int i=0; i<N; i++ ) {
                now[i] ++;
                if( now[i] < K[i] ) {
                    break;
                }
                if( i == N-1 ) {
                    return;
                }
                for( int j=0; j<=i; j++ ) {
                    now[j] = 0;
                }
            }
        }
    }
};


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

    vector<int> ABC(3);
    cin >> ABC;

    vector<int> L(N);
    cin >> L;

    vector<vector<int>> table( N, vector<int>({0,1,2,3}) );
    int minimum = INT_MAX;
    select( v, table ) {
        bool flg = true;
        int sum = 0;
        rep( i, 3 ) {
            int len = 0;
            int cnt = 0;
            rep( j, N ) {
                if( v[j] == i ) {
                    len += L[j];
                    cnt ++;
                }
            }
            if( cnt == 0 ) {
                flg = false;
            }
            sum += cnt * 10 - 10;
            sum += abs( ABC[i] - len );
        }

        if( flg ) {
            minimum = min( minimum, sum );
        }
    };

    cout << minimum << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,dp[5001][5001];
string s;
int main(){
    cin>>n>>s;
    for(int i=n-1;i>=0;i--){
        for(int j=n-1;j>=0;j--){
            if(s[i]!=s[j])dp[i][j]=0;
            else dp[i][j]=dp[i+1][j+1]+1;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++){
        if(i>=j)continue;
        ans=max(ans,min(dp[i][j],j-i));
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
#define ll long long

int main(void){
    ll ans = 0;
    vector<ll> food(5);
    for(int i=0;i<5;i++){
        cin >> food[i];
        ans += ((food[i]+9)/10)*10;
    }



    ll tmp = 9;
    for(int i=0;i<5;i++){
        if((food[i]-1)%10 < tmp){
            tmp = (food[i]-1)%10;
        }
    }

    cout << ans - (10 - tmp - 1) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib> // abs() for integer
#include <cmath>   // abs() for float, and fabs()
#include <climits>
using namespace std;
int main()
{
    int N;
    double T,A;

    cin >> N >> T >> A;

    int  H[N];
    double val;
    double ANS = 100000;
    int  ANS_NO;
    for(int i = 0; i < N; i++){
        cin >> H[i];
        val = T - (H[i] * 0.006);
        if (abs(val - A) < ANS)
        {
            ANS = abs(val - A);
            ANS_NO = i + 1;
        }
    }
    cout << ANS_NO << endl;
    return 0;
}


Measured memory_bytes: 256
#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(void){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(),h.end());
    ll c = 0;
    int x = n - k;
    rep(i,x) c += h[i];
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 1024
S=input()
ans=True
for i in range(len(S)):
  if i%2==0:
    if S[i] not in ('R', 'U', 'D'):
      ans=False
      break
  else:
    if S[i] not in ('L', 'U', 'D'):
      ans=False
      break
print(("No","Yes")[ans])

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

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

int n;
ll a[200000];
ll b[200001];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i + 1] = b[i] + a[i];
        b[i + 1] %= MOD;
    }
    ll ans = 0;
    for (int i = n - 1; i >= 1; --i) {
        ans += (a[i] * b[i]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6720
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){

    int N,M,X,A[110]={},l=0,r=0;

    cin >> N >> M >> X;

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

    for(int i=X;i!=0;i--){
        for(int j=0;j<=M;j++){
            if(i==A[j]){
                l+=1;
            }
        }
    }

    for(int i=X;i<=N+1;i++){
        for(int j=0;j<=M;j++){
            if(i==A[j]){
                r+=1;
            }
        }
    }

    cout << min(l,r) << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
for c in range(n):
    x,y=map(int,input().split())
    a.append(x+y)
    b.append(x-y)
s1=max(a)-min(a)
s2=max(b)-min(b)
print(max(s1,s2))

Measured memory_bytes: 24824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  sort(all(A), greater<ll>());
  ll ans = 0;
  ans += A[0];
  rep(i, (n-2)/2) {
    ans += 2*A[i+1];
  }
  if(n%2) ans += A[n/2];
  cout << ans << "\n";
  return 0;
}


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

//整数转换成二进制串
char* itobs(int n,char *ps){
    int i;
    int size = 8 * sizeof(int);
    for(i=size-1;i>=0;i--,n >>=1)
        ps[i]=(1&n) + '0'; //如果前面是1，‘0’+1变‘1’，前面是0，‘0’+0变‘0’
    return ps;
}

void andOp(char *a, char *b, char *res){
    for(int i =0;i<32;++i){
        if(a[i]=='1' && b[i]=='1') res[i] = '1';
        else res[i] = '0';
    }
}

void orOp(char *a, char *b, char *res){
    for(int i =0;i<32;++i){
        if(a[i]=='0' && b[i]=='0') res[i] = '0';
        else res[i] = '1';
    }
}

void xorOp(char *a, char *b, char *res){
    for(int i =0;i<32;++i){
        if(a[i]==b[i]) res[i] = '0';
        else res[i] = '1';
    }
}


void show_bstr(char *str){
    for(int i =0;i<32;++i){
        putchar(str[i]);
    }
}

int main(void){
    char bin_a[8*sizeof(int)];
    char bin_b[8*sizeof(int)];
    char bin_op[8*sizeof(int)];
    int a, b;
    scanf("%d %d",&a,&b);
    itobs(a,bin_a);
    itobs(b,bin_b);
    andOp(bin_a,bin_b,bin_op);
    show_bstr(bin_op);
    printf("\n");

    orOp(bin_a,bin_b,bin_op);
    show_bstr(bin_op);
    printf("\n");

    xorOp(bin_a,bin_b,bin_op);
    show_bstr(bin_op);
    printf("\n");
    return 0;
}




Measured memory_bytes: 3156
#include <stdio.h>

int med3(int x, int y, int z){
	if(x<y){
		if(y<z){
			return y;
		}
		else if(z<x){
			return x;
		}
		else{
			return z;
		}
	}
	else{
		if(x<z){
			return x;
		}
		else if(z<y){
			return y;
		}
		else{
			return z;
		}
	}
}

void sort(int a[], int left, int right){
	if(left<right){
		int i=left, j=right;
		int pivot=med3(a[i], a[i+(j-i)/2], a[j]);
		int temp;
		while(1){
			while(a[i]<pivot){
				i++;
			}
			while(pivot<a[j]){
				j--;
			}
			if(i>=j){
				break;
			}
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
			
			i++;
			j--;
		}
		sort(a, left, i-1);
		sort(a, j+1, right);
	}

}

int main(void){
	int a[210000], n, k, j, i;
	
	scanf("%d", &n);
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	sort(a, 0, n-1);
	
	for(i=0; i<n-1; i++){
		if(a[i]==a[i+1]){
			printf("NO\n");
			return 0;
		}
	}
		
		printf("YES\n");
		return 0;
		
	
}

Measured memory_bytes: 896
h = int(input())
w = int(input())
n = int(input())

#field = [[0] * h] * w

h_len = h
w_len = w
num = 0
count_num = 0

while (num <= n):
    if (h == w):
        if (h_len > 0):
            num += h
            h_len -= 1
            count_num += 1
        else:
            num += w
            w_len -= 1
            count_num += 1
    elif (h > w):
        if (h_len > 0):
            num += h
            h_len -= 1
            count_num += 1
        else:
            num += w
            w_len -= 1
            count_num += 1
    elif (w > h):
        if (w_len > 0):
            num += w
            w_len -= 1
            count_num += 1
        else:
            num += h
            h_len -= 1
            count_num += 1
    
    if (num >= n):
        break

print(count_num)

Measured memory_bytes: 3064
function s1(c)
  if c == "A" then
    return s2
  elseif c == "K" then
    return s3
  else
    return nil
  end
end
function s2(c)
  if c == "K" then
    return s3
  else
    return nil
  end
end
function s3(c)
  if c == "I" then
    return s4
  else
    return nil
  end
end
function s4(c)
  if c == "H" then
    return s5
  else
    return nil
  end
end
function s5(c)
  if c == "A" then
    return s6
  elseif c == "B" then
    return s7
  else
    return nil
  end
end
function s6(c)
  if c == "B" then
    return s7
  else
    return nil
  end
end
function s7(c)
  if c == "A" then
    return s8
  elseif c == "R" then
    return s9
  else
    return nil
  end
end
function s8(c)
  if c == "R" then
    return s9
  else
    return nil
  end
end
function s9(c)
  if c == "A" then
    return s10
  elseif c == "\n" then
    print("YES")
    os.exit(0)
  else
    return nil
  end
end
function s10(c)
  if c == "\n" then
    print("YES")
    os.exit(0)
  else
    return nil
  end
end

local s = s1
while true do
  local c = io.read(1)
  s = s(c)
  if not s then
    print("NO")
    break
  end
end

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

int main() {

  int A;
  cin >> A;
  
  int sum = 0;
  
  for (int i = 0; i < A; i++) {
    
    int B, C;
    cin >> B >> C;
    
    sum += C - B + 1;
  }

  cout << sum << endl;
}


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

int N;
int s[111];
bool dp[111][11111];

int main() {
   cin >> N;
   for (int i = 0; i < N; i++) {
      cin >> s[i];
   }

   dp[0][0] = true;
   int ans = 0;
   for (int i = 0; i < N; i++) {
      for (int j = 0; j <= 11111; j++) {
         dp[i+1][j] |= dp[i][j];
         if (j >= s[i]) {
            if (dp[i][j-s[i]]) {
               dp[i+1][j] = true;
               if (j % 10 != 0) ans = max(ans, j);
            }
         }
      }
   }

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        int K = scan.nextInt();
        long[] A = new long[N];
        long[] B = new long[M];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        for (int i = 0; i < M; i++) {
            B[i] = scan.nextInt();
        }
        long[] sumA = new long[N+1];
        long[] sumB = new long[M+1];
        for (int i = 0; i < N; i++) {
            sumA[i+1] = sumA[i] + A[i];
        }
        for (int i = 0; i < M; i++) {
            sumB[i+1] = sumB[i] + B[i];
        }
        TreeMap<Long, Integer> sb = new TreeMap<>();
        for (int i = 0; i <= M; i++) {
            sb.put(sumB[i], i);
        }
        long ans = 0;
        for (int i = 0; i <= N; i++) {
            long sum = sumA[i];
            long remain = K - sum;
            if (remain < 0) {
                continue;
            }
            long key = sb.floorKey(remain);
            long t = i + sb.get(key);
            ans = Math.max(ans, t);
        }
        System.out.println(ans);
    }
}


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

#define M1 1000000007
#define M2 1000000009
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define f0(i, n) for (int i = 0; i < (int)(n); ++i)
#define f1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fc0(i,l,r) for(int i = (int)(l); i<(int)(r); ++i)
#define fc1(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define fr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
 
void init()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      freopen("error.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}

signed main()
{
    init();

    ll n,k;
    cin>>n>>k;
    ll a[n];

    f0(i,n){cin>>a[i];}

    f0(i,n-k)
    {
      if(a[i]<a[i+k])
        cout<<"Yes"<<endl;
      else
        cout<<"No"<<endl;
    }

    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}

Measured memory_bytes: 5368
n,l =map(int ,input().split())
apple =[]
eat =0
ans =0

for i in range(1 ,n+1):
    apple.append(l+i-1)
apple_pai = sum(apple)

if l >0:
    eat =l
elif l+n-1 <0:
    eat =l+n-1
ans =apple_pai - eat
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
int main()
{
    int n, d;
    cin >> n >> d;
    if (n >= 10) cout << d << endl;
    else {
        cout << d + 100 * (10 - n) << endl;
    }
}

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

using namespace std;

using ll = long long;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

vector<string> parse(string s) {
  // cout << s << endl;
  vector<string> res;
  int sz = s.size();
  if('0' <= s[1] && s[1] <= '9') {
    res.push_back(s.substr(1, sz - 2));
  } else {
    int prev = 1;
    int depth = 0;
    for(int i=1;i<sz-1;++i) {
      // cout << i << endl;
      if(s[i] == '[') depth++;
      else if(depth == 1 && s[i] == ']') {
        res.push_back(s.substr(prev, i - prev + 1));
        prev = i+1;
        depth = 0;
      } else if(s[i] == ']') {
        depth--;
      }
    }
  }
  // printv(res);
  return res;
}

int solve(string s) {
  vector<string> v = parse(s);
  if('0' <= v[0][0] && v[0][0] <= '9') {
    return atoi(v[0].c_str())/2+1;
  } else {
    int sz = v.size();
    vector<int> need(sz);
    for(int i=0;i<sz;++i) {
      need[i] = solve(v[i]);
    }
    sort(need.begin(), need.end());
    int res = 0;
    for(int i=0;i<sz/2+1;++i) {
      res += need[i];
    }
    return res;
  }
}

int main() {
    cin.tie(0);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    for(int i=0;i<n;++i) {
      string s; cin >> s;
      cout << solve(s) << endl;
    }
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<pair<int, int> >;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int h, w; cin >> h >> w;
	vs t(h);

	vvi ans(h, vector<int>(w));

	rep(i, h) {
		string s; cin >> s;
		t[i] = s;
	}

	rep(pos_y, h) {
		rep(pos_x, w) {
			if (t[pos_y][pos_x] == '.') {
				int cnt = 0;

				rep(k, 8) {
					int y = pos_y + dy[k];
					int x = pos_x + dx[k];

					if (0 <= y && y < h && 0 <= x && x < w) {
						if (t[y][x] == '#') cnt++;
					}
				}
				ans[pos_y][pos_x] = cnt;
			}
			else ans[pos_y][pos_x] = -1;
		}
	}

	rep(pos_y, h) {
		rep(pos_x, w) {
			if (ans[pos_y][pos_x] == -1) cout << '#';
			else cout << ans[pos_y][pos_x];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>

using namespace std;
const int mod = 1e9+7;
int add(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sub(int x,int y) { x-=y; return x<0?x+mod:x; }
int mul(int x,int y) { return 1ll*x*y%mod; }
int en[205],la[205],nt[205],owo=1,orz[205];
void adg(int x,int y) {
	en[++owo]=y; nt[owo]=la[x]; la[x]=owo;
}
int gcd(int a,int b) {
	return !b?a:gcd(b,a%b);
}
int n,m,k;

int fac[205],inv[205],ifac[205],mi[205];
int lss[205],lat;
int GC(int x,int y) {
	if(x<y) return 0;
	return mul(fac[x],mul(ifac[y],ifac[x-y]));
}
bool yo[205];
int ans;
int dfn[205],low[205],dfx,tp,sta[205];
void tarjan(int x) {
	low[x] = dfn[x] = ++dfx;
	for(int it=la[x];it;it=nt[it]) {
		if(orz[it]) continue;
		int y = en[it];
		orz[it] = orz[it^1] = 1;
		sta[++tp] = it;
		if(!dfn[y]) {
			tarjan(y);
			low[x] = min(low[x],low[y]);
			if(low[y]>=dfn[x]) {
				int y; bool oo = 1;
				int cnt = 0;
				for(;sta[tp+1]!=it;tp--) {
					cnt++;
					if(yo[en[sta[tp]]]) oo = 0; 
					else yo[en[sta[tp]]] = 1,lss[++lat] = en[sta[tp]];
				}
				if(oo) {
					int oo = 0;
					for(int i=1;i<=cnt;i++) oo = add(oo,mi[gcd(i,cnt)]);
					oo = mul(oo,inv[cnt]);
					ans = mul(ans,oo);
				} else ans = mul(ans,GC(cnt+k-1,k-1));
				while(lat)  yo[lss[lat--]] = 0;
			}
		} else low[x] = min(low[x],dfn[y]);
	}
}
int main() {
	scanf("%d%d%d",&n,&m,&k);
	mi[0] = 1; mi[1] = k;
	fac[0] = inv[0] = inv[1] = fac[1] = ifac[0] = ifac[1] = 1;
	for(int i=2;i<=m+k;i++) fac[i] = mul(fac[i-1],i),inv[i]=mul((mod-mod/i),inv[mod%i]),ifac[i]=mul(ifac[i-1],inv[i]),mi[i] = mul(mi[i-1],k);
	for(int i=1;i<=m;i++) {
		int x,y; scanf("%d%d",&x,&y);
		adg(x,y); adg(y,x);
	}
	ans = 1;
	for(int i=1;i<=n;i++) {
		if(!dfn[i]) tarjan(i);
	}
	cout<<ans;
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    double students[1000] = {0}, sum, m, div;

    while(true){
        scanf("%d", &n);
        if(n == 0) break;
        div = sum = 0;
        for(int i = 0; i < n; i++){
            scanf("%lf", &students[i]);
            sum += students[i];
        }
        m = sum / n;
        for(int i = 0; i < n;i++){
            div += (students[i] - m) * (students[i] - m);
            students[i] = 0;
        }
        printf("%.8lf\n", sqrt(div / n));
    }
    return 0;
}



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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int     main() {
	long X, Y;
	cin >>X >>Y;
	if (0==X%Y) {
		cout <<-1 <<endl;
		return 0;
	}
	long i=2;
	for(;;) {
		long S=i*X;
		if (S>1000000000000000000) {
			cout <<-1 <<endl;
			return 0;
		}
		if (0!=S%Y) {
			cout <<S <<endl;
			return 0;
		}
		i++;
	}
	return 0;
}



Measured memory_bytes: 256
from math import factorial
mod = 10**9 + 7
N, M = [int(i) for i in input().split()]

if N == M:
    print((factorial(N) * factorial(M) * 2) % mod)
elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % mod)
else:
    print(0)

Measured memory_bytes: 5184
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

N,_=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
size = A.size
B=Array.new(size)
evd = size % 2 == 0 ? -1 : 1
odd = size % 2 == 0 ? 1 : -1
if(size % 2 == 0)
	for i in 0..(size-1) do
		if((i+1)%2 == 0)
			B[size/2 + (i+1)/2*-1] = A[i]
		else
			B[size/2 + (i+1)/2] = A[i]
		end
	end
else
	for i in 0..(size-1) do
		if((i+1)%2 == 0)
			B[size/2 + (i+1)/2] = A[i]
		else
			B[size/2 + (i+1)/2*-1] = A[i]
		end
	end
end
puts B.join(" ")


Measured memory_bytes: 29692
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int k;
    int x;
    
    cin >> k >> x;
    
    if(k*500>=x){
        
        cout << "Yes" << endl;
        return 0;
        
    }
    
    cout << "No" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#x**5-y**5 - int(input()) = 0


X = int(input()) #X <= 10**9

#x**5-y**5 <= 10**9



count = 0
for l in range(-1000,1000):
  for i in range(-1000,1000):
    if(l**5 -i**5 == X):
      print(l,i)
      count += 1
      break
  if(count == 1):
    break
   
	



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

int main(){
  int a;
  string s;
  std::cin >> a;
  std::cin >> s;
  if(a >= 3200){
    std::cout << s << '\n';
  }
  else{
    std::cout << "red" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<ciso646>
#include<cstring>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;

//解説ac
int main()
{
	int k,x; cin >> k>>x;
	if (500 * k >= x)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3616
import numpy as np
n,m = list(map(int,input().rstrip().split()))
graph = [[] for _ in range(n)]
route_list = []
for _ in range(m):
    a,b = list(map(int,input().rstrip().split()))
    a -=1
    b -=1
    route_list.append([a,b])
    graph[a].append(b)
    graph[b].append(a)

def dfs(mask, p,graph):
    mask[p] = 1
    if mask.all():
        return True
    nexts = graph[p]
    for n in nexts:
        if mask[n] == 1:
            continue
        else:
            if dfs(mask,n,graph):
                return True
    return False

counter = 0
for r in route_list:
    graph[r[0]].remove(r[1])
    graph[r[1]].remove(r[0])
    mask = np.zeros(len(graph),int)
    if dfs(mask,0,graph) == False:
        counter += 1
    graph[r[0]].append(r[1])
    graph[r[1]].append(r[0])
print(counter)


Measured memory_bytes: 12520
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

S = input()

if S == "ABC":
    print("ARC")
else:
    print("ABC")

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N, C;
ll x[100005];
ll v[100005];

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

	cin >> N >> C;

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

	ll sum_l[100005], sum_r[100005];

	ll max_l[100005], max_r[100005];
	ll ans = 0;

	sum_r[0] = v[0];
	max_r[0] = v[0]-x[0];
	for (int i = 1;i < N;i++){
		sum_r[i] = sum_r[i-1]+v[i];
		max_r[i] = max(max_r[i-1], sum_r[i]-x[i]);
	}

	ans = max(ans, max_r[N-1]);

	sum_l[N-1] = v[N-1];
	max_l[N-1] = v[N-1]-(C - x[N-1]);
	for (int i = N-2;i >= 0;i--){
		sum_l[i] = sum_l[i+1]+v[i];
		max_l[i] = max(max_l[i+1], sum_l[i]-(C-x[i]));
		ans = max(ans, sum_l[i] - (C-x[i]));
	}

	ans = max(ans, max_l[0]);

	for (int i = 0;i < N-1;i++){
		ll cal = sum_r[i] - x[i]*2 + max_l[i+1];
		ans = max(ans,cal);
	}

	for (int i = N-1;i > 0;i--){
		ll cal = sum_l[i] - (C-x[i])*2 + max_r[i-1];
		ans = max(ans, cal);
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 4992
N = int(input())
c = list(input())
counter = 0
left = 0
right = N-1

while left < right:
    if c[left] == 'W':
        flag = True
        while flag:
            if left >= right:
                flag = False
            if c[right] == 'R':
                c[right] = 'W'
                c[left] = 'R'
                counter += 1
                right -= 1
                flag = False
            else:
                right -= 1
    left += 1

print(counter)

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

ll n, m;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cin>>n>>m;
  if (n>m) swap(n,m);

  if (n==1) {
    if (m==1) out(1);
    if (m==2) out(0);
    out(m-2);
  }

  ll ans = (n-2)*(m-2);
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res;
	string S; cin >> S;
	long mylength = S.length();
	long cuts = 0; //取り除かれたSの個数(=Tの個数)

	long nows = 0; //左から捜査してSの数を数える。
	
	for (int i = 0; i < mylength; i++){
		if (S[i] == 'S') nows++;
		else if (nows > 0){ nows--; cuts++ ;}

	}

	res = mylength - 2 * cuts;

	cout << res << endl;

}

Measured memory_bytes: 640
N = int(input())
A = [int(l) for l in input().split()]

count = 0
k = 0
while True:
    for i in range(N):
        if A[i]/2** k % 2 !=0:
            break
    else:
        count += 1    
        k += 1
        continue
    break

print(count)

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

ll dp[101][40000][2];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;cin>>N>>K;
  //cerr<<"!!!"<<endl;
  for(ll j=1;j*j<=N;j++){
    dp[1][j][0]=j;
    dp[1][j][1]=N/j;
  }
  for(ll i=2;i<=K;i++){
    ll j=1;
    for(;j*j<=N;j++){
      dp[i][j][0] = dp[i][j-1][0];
      dp[i][j][0] = (dp[i][j][0]+dp[i-1][j][1])%MOD;
    }
    j--;
    //debug(j);
    dp[i][j][1] = dp[i][j][0];
    dp[i][j][1]=(dp[i][j][1]+dp[i-1][j][0]*(N/j-j)%MOD)%MOD;
    for(j--;j>=1;j--){
      dp[i][j][1] = dp[i-1][j][0]*(N/j-N/(j+1))%MOD;
      dp[i][j][1] = (dp[i][j][1]+dp[i][j+1][1])% MOD;

    }
  }
  cout<<dp[K][1][1]<<endl;
  return 0;
}


Measured memory_bytes: 62080
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,a,b)       for(i=a;i<=b;i++)
#define FOR(i,a,b)      for(i=a;i>=b;i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define sz(v)           (int)v.size()
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p) {int ans=1;x%=mod;while(p>0){if(p&1)ans=(ans*x)%mod;p=p>>1;x=(x*x)%mod;}return ans;}
int inv(int x){return po(x,mod-2)%mod;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f,q;




ld eps=1e-18;



void sol()
{   
    cin>>n>>k;
    in1(a,n);
    ld c=0,x;
    fo1(i,k)c+=log(a[i]);

    FO(i,k+1,n)
    {
        x=c;
        c+=log(a[i])-log(a[i-k]);
        if(c-x>eps)cout<<"Yes\n";
        else cout<<"No\n";
    }

    
    
    
    //cout<<  <<endl;
}





int32_t main()
{   
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //pre();
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 4804
#include <iostream>
#include <map>
#include <cstdio>
#include <set>
#include <algorithm>
#include <functional>

using namespace std;

int h[100];

int main() {
	for (int i = 0; i < 4; i++) {
		int a;
		cin >> a;
		h[a] = 1;
	}
	if (h[1] && h[7] && h[9] && h[4]) {
		puts("YES");
	} else {
		puts("NO");
	}
	return 0;
}

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

int main() {
  int N;
  
  cin >> N;
  int A = N / 1000;
  int B = (N - A * 1000) /100;
  int C = ((N - A * 1000)-B *100)/10;
  int D = ((N - A * 1000)-B *100)%10;
 
  if ( A==B && B==C ) {
    cout << "Yes" << endl;
  }
  else if (B==C && C==D){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
 
 
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,n,l[100],maxi,max=0,sum=0;
  scanf("%d",&n );
  for(i=0;i<n;i++){
  scanf("%d",&l[i]);
  if(l[i]>max){
    max=l[i];
    maxi=i;
  }
  }
  for(i=0;i<n;i++){
    if(i==maxi)
      continue;
  sum+=l[i];
}
  if(max<sum)
  printf("Yes\n");
  else printf("No\n");
}


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

int main()
{
    int N, af = 0, bf = 0, cf = 0,count=0;
    cin >> N;
    vector<char> S(N);
    for(int i=0;i<N;i++){
        cin >> S.at(i);
        if(S.at(i)=='A'){
            af = 1;
            bf = 0;
            cf = 0;
        }
        else if (af == 1 && S.at(i) == 'B'&&bf!=1){
            af = 1;
            bf = 1;
            cf = 0;
        }
        else if (af == 1 && bf==1&&S.at(i)=='C'&&cf!=1){
            count++;
            af = 0;
            bf = 0;
            cf = 0;
            //cout << i-2 << endl;
        }
        else{
            af = 0;
            bf = 0;
            cf = 0;
        }

    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i <= y; i ++)
#define repi(x, y)  for (ll i = x; i >= y; i --)
priority_queue< ll > cancel;
string a,b;
ll dp[3005][3005];
string s="";
ll lcs(ll aind,ll bind)
{
    if(dp[aind][bind]!=-1)
    {
        return dp[aind][bind];
    }
    else
    {
        if(a[aind-1]==b[bind-1])
        {
            dp[aind][bind]=lcs(aind-1,bind-1)+1;
        }
        else
        {
            dp[aind][bind]=max(lcs(aind-1,bind),lcs(aind,bind-1));
        }
        return dp[aind][bind]; 
    }
    
}
int main()
{
    ll test=1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        cin>>a>>b;
        for(ll i=0;i<=a.length();i++)
        {
            for(ll j=0;j<=b.length();j++)
            {
                dp[i][j]=-1;
            }
        }
        for(ll i=0;i<=a.length();i++)
        {
            dp[i][0]=0;
        }

        for(ll i=0;i<=b.length();i++)
        {
            dp[0][i]=0;
        }

        lcs(a.length(),b.length());
        ll i=a.length();
        ll j=b.length();
        while(i>0 && j>0)
        {
            if(a[i-1]==b[j-1])
            {
                s=a[i-1]+s;
                i--;
                j--;
            }
            else
            {
                if(dp[i-1][j]>=dp[i][j-1])
                {
                    i--;
                }
                else
                {
                    j--;
                }
                
            }
            
        }
        cout<<s<<endl;
    }
}

Measured memory_bytes: 74276
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int x, n, p[100],pp, ansi, ansa, ans;
	cin >> x >> n;
	ansi = x;
	ansa = x;
	rep(i, n)cin >> p[i];
	sort(p, p + n);
	rep(i, n) {
		pp = p[i];
		if (ansa == pp)ansa = ansa + 1;
	}
	rep(i, n) {
		pp = p[n-i-1];
		if (ansi == pp)ansi = ansi - 1;
	}
	if (x - ansi < ansa - x)ans = ansi;
	else if (x - ansi > ansa - x)ans = ansa;
	else if (x - ansi == ansa - x)ans = ansi;
	cout << ans << endl;
	
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define PB push_back
#define test int t;cin>>t; while(t--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
int main()
{
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
cout<<n+n*n+n*n*n<<endl;

}


Measured memory_bytes: 3632
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

s = input()

ans = 0
for i in s:
    if i == "1":
        ans += 1
print(ans)


Measured memory_bytes: 8980
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;
use num::*;


fn main() {
    input! {
    a:String,
    b:String,
  }
    let a=a.chars().map(|a|a.to_digit(10).unwrap()).collect_vec();
    let b=b.chars().map(|a|a.to_digit(10).unwrap()).collect_vec();
    if a.len()==b.len() {
        for i in 0..a.len() {
            if a[i]>b[i] {println!("GREATER");exit(0)}
            if a[i]<b[i] {println!("LESS");exit(0)}
        }
        println!("EQUAL")
    }
    else if a.len()>b.len(){
        println!("GREATER")
    }
    else {
        println!("LESS")
    }
}

Measured memory_bytes: 2184
w,h,n = map(int,input().split())
xl=0
xh=w
yl=0
yh=h
for _ in range(n):
    x,y,a = map(int,input().split())
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xh=min(xh,x)
    elif a==3:
        yl=max(yl,y)
    else:
        yh=min(yh,y)

if xl>=xh or yl>=yh:
    print(0)
else:
    print((xh-xl)*(yh-yl))


Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

    int n,r;
    cin >> n >> r;

    if(n >= 10)cout << r << endl;
    else{
        cout << r+100*(10-n) << endl;;
    }

    
    



	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://abc156.contest.atcoder.jp/tasks/abc156_b

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;
using namespace std;
int MAX=100001;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }
 
    ll size(int x){
        return Size[root(x)];
    }
};

int main() {
    int N, M, K;
    int A[MAX], B[MAX], C[MAX], D[MAX], ans[MAX];
    cin >> N >> M >> K;

    UnionFind tree(N);
    
    REP(int,i,0,M){
        cin >> A[i] >> B[i];
        tree.merge(A[i],B[i]);
    }
    REP(int,i,0,K) cin >> C[i] >> D[i];
    
    REP(int,i,1,N+1) ans[i]=tree.size(tree.root(i))-1;
    REP(int,i,0,M){
        if(tree.issame(A[i],B[i])){
            ans[A[i]]--; ans[B[i]]--;
        }
    }
    REP(int,i,0,K){
        if(tree.issame(C[i],D[i])){
            ans[C[i]]--; ans[D[i]]--;
        }
    }

    REP(int,i,1,N+1) cout << ans[i] << " ";
    return 0;
}

Measured memory_bytes: 4352
/*      ex5_3
        Tarara  */
#include <stdio.h>

#define MAX_LENGTH 100 + 5

int height, width;
char field[MAX_LENGTH][MAX_LENGTH];

int exsitsBlackCellinRow(int row);
int exsitsBlackCellinCol(int col);

int main(void)
{
    scanf("%d %d", &height, &width);
    for (int i = 0; i < height; i++)
    {
        scanf("%s", field[i]);
    }

    int is_whites_rows[MAX_LENGTH];
    int is_whites_cols[MAX_LENGTH];
    for (int i = 0; i < height; i++)
        is_whites_rows[i] = !exsitsBlackCellinRow(i);
    for (int i = 0; i < width; i++)
        is_whites_cols[i] = !exsitsBlackCellinCol(i);

    for (int i = 0; i < height; i++)
    {
        if (is_whites_rows[i])
            continue;

        for (int j = 0; j < width; j++)
        {
            if (is_whites_cols[j])
                continue;

            printf("%c", field[i][j]);
        }
        printf("\n");
    }
    return 0;
}
int exsitsBlackCellinCol(int col)
{
    for (int i = 0; i < height; i++)
    {
        if (field[i][col] == '#')
            return 1;
    }
    return 0;
}

int exsitsBlackCellinRow(int row)
{
    for (int i = 0; i < width; i++)
    {
        if (field[row][i] == '#')
            return 1;
    }
    return 0;
}


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

int main(){
        int n, m;
        cin >> n >> m;
        vector<int> a(m);
        for(int i = 0; i < m; i++) cin >> a[i];
        sort(a.begin(), a.end(), greater<int>());
        vector<int> count(n + 1);
        count[0] = 0;
        for(int i = 1; i <= n; i++){
                int tmp = 99999;
                for(int j = 0; j < m; j++){
                        if(i - a[j] >= 0){
                                tmp = min(tmp, count[i - a[j]]);
                                //count[i] = count[i - a[j]] + 1;//7 + 8のような可能性を考える
                        }
                }
                count[i] = tmp + 1;
                //cout << i << " " << count[i] << endl;
        }
        cout << count[n] << endl;
        return 0;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
#define ll long long
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int D,T,S;
    cin>>D>>T>>S;
    if(S*T>=D){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
//based on SPOJ STRSEQ
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const ll MOD = 1000000007;

char s[200005];
int len;
int x[200005][26];
int y[200005];
int dp[200005];

int main() {
	int i, j, k;
	scanf("%s", s);
	len = strlen(s);
	for (i = len; i > 0; i--)
		s[i] = s[i - 1];
	for (j = 0; j < 26; j++)
		x[len + 1][j] = len + 1;
	for (i = len; i >= 1; i--)
	{
		for (j = 0; j < 26; j++)
			x[i][j] = x[i + 1][j];
		x[i][s[i] - 'a'] = i;
	}
	for (i = j = 0; j < 26; j++)
		x[i][j] = x[i + 1][j];
	for (i = len; i >= 0; i--)
	{
		dp[i] = MOD, y[i] = -1;
		for (j = 0; j<26; j++)
		{
			int id = x[i + 1][j];
			if (id <= len)
			{
				if (dp[id] < dp[i])
					dp[i] = dp[id], y[i] = j;
			}
			else {
				dp[i] = -1;
				y[i] = j;
				break;
			}
		}
		dp[i]++;
	}
	if (x[0][0] > len)
		printf("a\n");
	else {
		int mi = MOD, res = -1;
		for (j = 0; j < 26; j++)
		{
			int id = x[1][j];
			if (id <= len)
			{
				if (dp[id] < mi)
					mi = dp[id], res = j;
			}
			else {
				mi = -1, res = j;
				break;
			}
		}
		int now = 0;
		while (now <= len) {
			printf("%c", res+'a');
			now = x[now + 1][res];
			res = y[now];
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 22272
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

const int inf = 1<<25;

ll dp[3005][3005];
ll arr[3005], n;

ll solve(int i, int j)
{
    if(i >= n || j < 0 || i > j)
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];

    ll ret = max(arr[i] - solve(i + 1, j), arr[j] - solve(i, j - 1));

    return dp[i][j] = ret;

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

    memset(dp, -1, sizeof(dp));
    cin>>n;

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

    ll res = solve(0, n - 1);

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 74428
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const double pi = acos(-1.0);

int main() {
	string s; cin >> s;
	puts(s[0] == '9' || s[1] == '9' ? "Yes" : "No");
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll n; cin >> n; string s,t ; cin >> s >> t; bool flag = true;
  ll ans = n;
  
  for(ll i=0; i < n; i++){
    flag = true;
    
    for(ll j=0; j < n-i; j++){
      if(s[i+j] != t[j]){
        flag = false;
        break;
      }
    }
    
    if(flag){
      ans = i;
      break;
    }
  }
  
  cout << n + ans << endl;
}
        

Measured memory_bytes: 256