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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
#define pqasc priority_queue<long long, vector<long long>, greater<long long>>

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ul = unsigned long;

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

class UnionFind{
private:
  vector<int> Parent; 
 public:
  UnionFind(int N){
    Parent = vector<int>(N, -1);
  }
  
  int root(int A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  int size(int A){
    return -Parent[root(A)]; 
  }
  
  bool connect(int A, int B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(int A, int B){
    return root(A) == root(B);
  }
};

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vll a(n), b(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  
  ll cnt=0;
  rep(i,n){
    if(a[i]<b[i]) cnt+=(b[i]-a[i])/2;
    else cnt-=a[i]-b[i];
  }
  if(cnt>=0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
typedef long long ll;
static const int D[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const int DT[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
static const int MT[] = {144000, 7200, 360, 20, 1};
bool isLeap(int y){ return ( y%4 == 0 && ( y%100 || y%400 == 0 ));}

ll getDay(int y, int m, int d){
  ll sum = 0;
  for ( int i = 1; i <= y; i++ ){
    sum += 365 + (isLeap(i-1)?1:0);
  }
  sum += DT[m-1];
  if ( isLeap(y) && m >= 3 ) sum++;
  sum += d - 1;
  return sum;
}

void toMaya(vector<int> v){
  ll d = getDay(v[0], v[1], v[2]) - getDay(2012, 12, 21);
  d %= MT[0]*13;
  for ( int i = 0; i < 5; i++ ){
    if (i) cout << ".";
    cout << d/MT[i]; d %= MT[i];
  }
  cout << endl;
}

void toGregorian(vector<int> v){
  ll sum = getDay(2012,12,21);
  for ( int i = 0; i < 5; i++ ) sum += v[i]*MT[i];
  ll y = 0, m = 1, d = sum;
  
  while(1){
    int dd = (isLeap(y)?366:365);
    if ( d >= dd ) d -= dd;
    else break;
    y++;
  }

  for ( int i = 0; d >= D[i]; i++ ){
    m = i+2;
    d -= D[i];
    if ( isLeap(y) && i == 1 ) d--;
  }
  d++;
  if ( m == 3 && d == 0 ) { m = 2; d =29; }
  cout << y << "." << m << "." << d << endl;
}

main(){
  string line;
  char ch;
  int x;
  int tcase = 0;
  while(1){
    //cin >> line;
    getline(cin, line);
    if ( line == "#" ) break;
    tcase++;
    vector<int> d;
    stringstream sin(line);
    for ( ; sin >> x ; sin >> ch ) d.push_back(x);
    if ( d.size() == 3 ) toMaya(d);
    else if ( d.size() == 5 ) toGregorian(d);
  }
}

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

string S;

bool check(int a,int b){
    for(int i=a;i+1<=b;i++){
        if(S[i]=='#'&&S[i+1]=='#'){
            return false;
        }
    }
    return true;
}

int main(){
    int N;
    cin >> N;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cin >> S;
    S='#'+S+'#';
    if(!check(a,b)||!check(c,d)){
        cout << "No" << endl;
        return 0;
    }
    if(c>d){
        for(int i=b;i<=d;i++){
            if(S[i-1]=='.'&&S[i]=='.'&&S[i+1]=='.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n)
  {
    cin >> a[i];
  }

  if (a.size() == 1)
  {
    cout << 1 << endl;
    return 0;
  }

  int inc = a[0] <= a[1] ? (a[0] == a[1] ? 2 : 1) : 0;
  int ans = 1;
  FOR(i, 1, n)
  {
    if (a[i - 1] == a[i])
      continue;
    if (inc == 2)
      inc = a[i - 1] < a[i] ? 1 : 0;
    if (inc == 1 && a[i - 1] < a[i])
      continue;
    if (inc == 0 && a[i - 1] > a[i])
      continue;
    ans++;
    inc = 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;

int main(){
  int N; cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++) cin >> A[i];
  int ans = 1000000007;
  for(int i = 0; i < N; i++){
    int num = 0;
    while(true){
      if(A[i] % 2 == 0){
        num++;
        A[i] /= 2;
      }else{
        break;
      }
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
    int n;
    int ans = 0;
    cin >> n;
    map<long,int> mp;
    for (int i=0; i<n; i++) {
        long a;
        cin >> a;
        mp[a]++;
    }
    
    for (auto p : mp) {
        if (p.second %2 == 1) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
std::vector<int> v;
std::vector<int> best;
int k;
int INF = 999999999;
int solve(int x,int sum){
     // cout << sum <<" " << x <<  endl;
     if(x<0){
          return INF;
     }
     if(x<=k){
          return abs(v[0]-v[x]);
     }
     // if(x==2){
     //      return abs(v[0]-v[2]);
     // }
     // if(x==0){
     //      return min(abs(v[0]-v[1]),abs(v[0]-v[2]));
     // }
     // if(x==1){
     //      return abs(v[0]-v[1]);
     // }
     if(best[x]==-1){
          int mina = INF;
          for(int i=1;i<=k;i+=1){
               int score = abs(solve(x-i,sum))+abs(v[x]-v[x-i]);
               if(mina>score){
                    mina = score;
               }
          }
          best[x] = sum+mina;//+min(,abs(solve(x-2,sum))+abs(v[x]-v[x-2]) );
     }
     return best[x];  
}
int main() {
     int n;
     cin >> n >> k;
     vector<int> moon(n,-1);
     best = moon;
     for(int i=0;i<n;i++){
          int x;
          cin >> x;
          v.push_back(x);
     }
     cout << solve(n-1,0);
}


Measured memory_bytes: 10852
def larger(x, y):
	if x > y:
		return x
	else:
		return y

def main():
	n = int(raw_input())
	tmp = raw_input().split()
	tmpt = int(tmp[0])
	tmpa = int(tmp[1])
	for i in range(1, n):
		inpt = raw_input().split()
		inptt = int(inpt[0])
		inpta = int(inpt[1])
		trate = tmpt / inptt
		if tmpt % inptt != 0:
			trate += 1
		arate = tmpa / inpta
		if tmpa % inpta != 0:
			arate += 1
		rate = larger(trate, arate)
		tmpt = inptt * rate
		tmpa = inpta * rate

	print (tmpt + tmpa)

main()

Measured memory_bytes: 2692
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);		
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		System.out.println(arr[n - 1] - arr[0]);
	}
}


Measured memory_bytes: 23764
import sys
input=sys.stdin.readline

def main():
    s = input().strip()

    # 同じ文字が2文字連続するならそこが答えになる
    for i in range(1,len(s)):
        if s[i-1] == s[i]:
            print(i, i+1)
            return
    # 同じ文字が3文字中に2つ現れたらそこが答えになる
    for i in range(2,len(s)):
        if s[i-2] == s[i]: # 2連続は処理済みなのでこれで良い
            print(i-1, i+1)
            return
    # それ以外で条件を満たすことはない
    print(-1,-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    string s,t;cin >> s >> t,cout <<t << s << endl;return 0;

}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		int num = Integer.parseInt(str);
		
		int i;
		
		for(i = 0; i < 100; i++){
			if(num >= Math.pow(2, i)-1){
				continue;
			}else{
				break;
			}
		}
		
		System.out.println(i-1);
	}
}



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

const int64_t MOD = 1e9+7;
const int MAX = 1e6+1;
int64_t dp[MAX], dps[MAX];

int main(){
    int64_t N;
    cin >> N;
    dp[1] = dps[1] = N;
    dp[2] = N*N % MOD;
    dps[2] = (dp[1] + dp[2]) % MOD;
    for(int i=3; i<=N; i++){
        dp[i] = ((N-1)*(N-1) + dp[i-1] + dps[i-3] + N-i+2) % MOD;
        dps[i] = (dp[i] + dps[i-1]) % MOD;
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 16000
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int S = 16;
int dp[S+1][1 << S];

const int MAXW = (1 << S) + 10;
int fact[MAXW+10], finv[MAXW+10];

int mod_pow(int n, int k) {
    int res = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (res *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return res;
}

void init() {
    fact[0] = 1;
    for(int i=1; i<=MAXW; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }

    finv[MAXW] = mod_pow(fact[MAXW], MOD-2);
    for(int i=MAXW-1; i>=0; i--) {
        finv[i] = (finv[i+1] * (i+1)) % MOD;
    }
}

int perm(int n, int r) {
    if(r < 0 or n < r) return 0;
    return fact[n] * finv[n-r] % MOD;
}

signed main() {
    init();
    int N, M; cin >> N >> M;
    vector<int> A(M);
    for(int i=0; i<M; i++) {
        cin >> A[i];
    }
    reverse(A.begin(), A.end());

    // M * N * (2^N)
    const int W = 1 << N;
    dp[0][0] = 1;
    for(int i=0; i<M; i++) {
        for(int bit=0; bit<(1<<N); bit++) {
            if(dp[i][bit] == 0) continue;

            // 自分より大きいやつをすでに bit 個使ってる
            int rem = W - A[i] - bit;
            
            // 使わない場合
            (dp[i+1][bit] += dp[i][bit]) %= MOD;
            
            // 使う場合
            for(int k=0; k<N; k++) {
                if(bit >> k & 1) continue;
                int nbit = bit | (1 << k);

                // A[i] をどこにおくか
                int mul = (1 << k);

                // 入れ方 (rem P (2^k - 1))
                (mul *= perm(rem, (1 << k) - 1)) %= MOD;
                (dp[i+1][nbit] += dp[i][bit] * mul) %= MOD;
            }
        }
    }

    int ans = 0;
    for(int bit=0; bit<(1<<N); bit++) {
        int val = dp[M][bit];
        
        // まだ決まってないところは何人分あるか？
        // そこに関してはどう入れても良い
        int rem = W - 1;
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) rem -= (1 << i);
        }
        (val *= perm(rem, rem)) %= MOD;
        
        // 1 を入れる箇所は (1 << N) 箇所ある
        (val *= W) %= MOD;

        int cnt = __builtin_popcount(bit);
        if(cnt % 2 == 1) (ans += MOD - val) %= MOD;
        else (ans += val) %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	string S;
	string ans = "";
	int w;
	cin >> S;
	cin >> w;
	for (int i = 0; i < S.length(); i += w) {
		ans += S[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().ToInt();
            var S = Console.ReadLine();

            var w = new int[N];
            var e = new int[N];

            for(var i = 1; i < N; i++)
            {
                w[i] = (S[i - 1] == 'W' ? 1 : 0) + w[i - 1];
            }

            for(var i = N - 2; i >= 0; i--)
            {
                e[i] = (S[i + 1] == 'E' ? 1 : 0) + e[i + 1];
            }

            var ret = int.MaxValue;
            for(var i = 0; i < N; i++)
            {
                var cost = w[i] + e[i];
                ret = Math.Min(ret, cost);
            }
            Console.WriteLine(ret);
        }
    }
    
    static class StringExtention
    {
        static public int ToInt(this string input)
        {
            return int.Parse(input);
        }

        static public int[] ToIntArray(this string input)
        {
            return input.Split(' ').Select(int.Parse).ToArray();
        }

        static public long ToLong(this string input)
        {
            return long.Parse(input);
        }

        static public long[] ToLongArray(this string input)
        {
            return input.Split(' ').Select(long.Parse).ToArray();
        }
    }
}


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

#define MOD 1000000007

int main()
{
    long long n, k;
    scanf("%d%d", &n, &k);
    int a[n];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }

    long long ans = 0;
	for(int i = 0; i < n; i++)
    {
		for (int j = i + 1; j < n; j++)
		{
			if (a[i] > a[j])
			{
				ans += k * (k + 1) / 2;
				ans %= MOD;
			}
			else if(a[i]<a[j])
			{
				ans += k * (k - 1) / 2;
                ans %= MOD;
			}
		}
	}

	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
int main(){
    int x,y,n;
    std::cin >> n;
    
    std::cout << 24-n+24;
    std::cout << std::endl;
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readlines()
n, m, q = map(int, input().split())

d = [[0 for j in range(n + 1)] for i in range(n + 1)]
a = [[0 for j in range(n + 1)] for i in range(n + 1)]

for _ in range(m):
    l, r = map(int, input().split())
    a[l][r] += 1

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

for _ in range(q):
    l, r = map(int, input().split())
    print(d[r][r] - d[r][l - 1] - d[l - 1][r] + d[l - 1][l - 1])


Measured memory_bytes: 17116
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, A = 0, C = 1, G = 2;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int dp[4][4][4] = {};
  dp[3][3][3] = 1;
  for (int it = 0; it < n; it++) {
    int nxt[4][4][4] = {};
    for (int cur = 0; cur < 4; cur++) {
      for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
          for (int k = 0; k < 4; k++) {
            if (cur == C && i == G && j == A) continue;
            if (cur == C && i == A && j == G) continue;
            if (cur == G && i == C && j == A) continue;
            if (cur == C && i == G && k == A) continue;
            if (cur == C && j == G && k == A) continue;
            (nxt[cur][i][j] += dp[i][j][k]) %= mod;
          }
        }
      }
    }
    swap(dp, nxt);
  }
  int ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ans = (ans + dp[i][j][k]) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s = int(input())
lst = [s]

cnt = 1
while True:
    if int(lst[-1]) & 1 == 0:
        cnt += 1
        next_a = lst[-1]/2
        if next_a in lst:
            m = cnt
            break
        lst.append(next_a)
        
    else:
        cnt += 1
        next_aa = 3*lst[-1] +1
        if next_aa in lst:
            m = cnt
            break
        lst.append(next_aa)

print(m)

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

int main() {
  int D;
  cin >> D;
  
  if(D == 25) {
    cout << "Christmas" << endl;
  }
  else if(D == 24) {
    cout << "Christmas" << " " << "Eve" << endl;
  }
  else if(D == 23) {
    cout << "Christmas" << " " << "Eve" << " " << "Eve" << endl;
  }
  else if(D == 22) {
    cout << "Christmas" << " " << "Eve" << " " << "Eve" << " " << "Eve" << endl;
  }
}


Measured memory_bytes: 256
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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


char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, m; cin >> n >> m;
    dsu d(n);
    REP(i, 0, m){
        int a, b; cin >> a >> b;
        a--; b--;
        d.merge(a, b);
    }
    int k = d.groups().size();
    cout << k-1 << endl;
}

Measured memory_bytes: 8948
#include<bits/stdc++.h>
using namespace std;
#define ULL unsigned long long
const int maxn=200010;
int n,k,l;
int fa1[maxn],fa2[maxn];
map<ULL,int>mp;
int find1(int x){
	return fa1[x]==x?x:fa1[x]=find1(fa1[x]);
}
int find2(int x){
	return fa2[x]==x?x:fa2[x]=find2(fa2[x]);
}
int uni1(int x,int y){
	int a=find1(x),b=find1(y);
	if(a!=b)fa1[b]=a;
}
int uni2(int x,int y){
	int a=find2(x),b=find2(y);
	if(a!=b)fa2[b]=a;
}
int main(){
	scanf("%d%d%d",&n,&k,&l);
	int a,b;
	for(int i=0;i<=n;i++)fa1[i]=fa2[i]=i;
	for(int i=0;i<k;i++){
		scanf("%d%d",&a,&b);
		uni1(a,b);
	}
	for(int i=0;i<l;i++){
		scanf("%d%d",&a,&b);
		uni2(a,b);
	}
	for(int i=1;i<=n;i++)fa1[i]=find1(i),fa2[i]=find2(i);
	for(int i=1;i<=n;i++)
		mp[(ULL)((ULL)fa1[i]*12345678+(ULL)fa2[i])]++;
	for(int i=1;i<=n;i++)
		if(i!=n)printf("%d ",mp[(ULL)((ULL)fa1[i]*12345678+(ULL)fa2[i])]);
		else printf("%d\n",mp[(ULL)((ULL)fa1[i]*12345678+(ULL)fa2[i])]);
}



Measured memory_bytes: 13568
// ABC077B - 

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

typedef unsigned long long int ull;
typedef long long int ll;

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

	map<ull, ull> t;

	for (ull i = 1; i <= 100000; i++) {
		t[i * i] = 1;
	}

	for (ull i = N; i >= 1; i--) {
		if (t[i] == 1) {
			cout << i << endl;
			return 0;
		}
	}


	return 0;
}


Measured memory_bytes: 10496
/**
        Bismilla- hir rahma-nir rahi-m
    @uthor Md Hasibur Rahman (Evan)
                JKKNIU
*/


#include<bits/stdc++.h>
#define         ll              long long
#define         FI              freopen("input.txt","r",stdin)
#define         FO              freopen("output.txt","w",stdout)
#define         PrintCase(i)    printf("Case %d: ",i)
#define         sc(a)           scanf("%d",&a)
#define         scl(a)          scanf("%lld",&a)
#define         rep(i,n)        for(int i=0;i<n;i++)
#define         pb              push_back
#define         MAX             1000000
#define         fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define			endl			"\n"


using namespace std;

bool isPrime(ll a)
{
    for(ll i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}






bool isPowerOfTwo(ll a)
{
    if(a==1)
        return true;
    if(a&1)
        return false;
    while(a)
    {
        a/=2;
        if(a!=1 && a&1)
            return false;
        if(a==1)
            return true;
    }
    return true;
}




ll gcd(ll a, ll b)
{
    if(a<0 || b<0)
    {
        a = abs(a);
        b = abs(b);
    }
    if(a<b)
        swap(a,b);
    if(a%b==0 || b==0)
        return b;
    else
        return gcd(b,a%b);
}



ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a,b);
}



ll power(ll base, ll exponent)
{
    ll ans = 1;
    for(ll i=1;i<=exponent;i++)
        ans*=base;
    return ans;
}




bool isPowerOfX(ll x, ll value)
{
    if(value==1)
        return true;
    while(value)
    {
        value/=x;
        if(value%x && value!=1)
            return false;
    }	
    return true;
}





int main()
{
    fast;
    ll d,t,s;
    cin>>d>>t>>s;
    if((t*s)>=d)
    	cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        int su = ty - sy;
        int sr = tx - sx;

        for(int i = 0; i < su; i++){
            System.out.print("U");
        }
        for(int i = 0; i < sr; i++){
            System.out.print("R");
        }
        for(int i = 0; i < su; i++){
            System.out.print("D");
        }
        for(int i = 0; i < sr; i++){
            System.out.print("L");
        }
        System.out.print("L");
        for(int i = 0; i < su+1; i++){
            System.out.print("U");
        }
        for(int i = 0; i < sr+1; i++){
            System.out.print("R");
        }
        System.out.print("DR");
        for(int i = 0; i < su+1; i++){
            System.out.print("D");
        }
        for(int i = 0; i < sr+1; i++){
            System.out.print("L");
        }
        System.out.print("U");
    }
}

Measured memory_bytes: 25044
n = int(input())
d = {}
m = 0
for i in range(n):
    s = input()
    d[s] = d.get(s, 0) + 1
    if m <= d[s]:
        m = d[s]
c = []
for i in d:
    if d[i]==m:
        c.append(i)
c.sort()
for x in c:
    print(x)

Measured memory_bytes: 35256
#include <iostream>

using namespace std;

int main(){
	int height, width;
	while(true){
		cin >> height >> width;
		if(height == 0 && width == 0) break;

		for(int i = 0; i < height; i++){
			for(int j = 0; j < width; j++){
				if((i+j) % 2 == 0) cout << '#';
				else cout << '.';
			}
			cout << endl;
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N = Integer.parseInt(sc.next());
	static int K = Integer.parseInt(sc.next());
	public static void main(String[] args) {
		if (N >= K*2-1 ) {
			System.out.println("YES");

		} else {

			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21972
n, k, s = gets.split(' ').map(&:to_i)

if k == 0
  puts ([s == 1_000_000_000 ? 1 : s + 1] * n).join(' ')
elsif k == n
  puts ([s] * n).join(' ')
elsif s == 1
  a = (0...n).map { |i| i < k ? 1 : 2 }
  puts a.join(' ')
else
  a = (0...n).map do |i|
      if i > k
        s == 1_000_000_000 ? 999_999_998 : 1_000_000_000
      elsif i % 2 == 0
        1
      else
        s - 1
      end
    end

  puts a.join(' ')
end

Measured memory_bytes: 4732
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class BGoldenCoins {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int x;
        cin >> x;

        int res = 0;
        res += x / 500 * 1000;
        x -= x / 500 * 500;
        res += x / 5 * 5;
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    BGoldenCoins solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
A = list(map(int, input().split()))

#N,K = 5000,5000
#A = [1]*N

# K以上のものはAから省く
B = []
for a in A:
    if a<K:
        B.append(a)

B.sort(reverse=True)

isNeeded = [False]*(len(B))
# iをスタックに入れる
for i in range(len(B)-1):
    res = B[i]
    stack = [i]
    for j in range(i+1,len(B)):
        res += B[j]
        stack.append(j)
        if res >= K:
            for s in stack:
                if isNeeded[s]:
                    continue
                else:
                    isNeeded[s] = True
            stack.pop()
            res -= B[j]
            
noNeed = len(B) - sum(isNeeded)
print(noNeed)

Measured memory_bytes: 45404
import random
class Dice:
    def __init__(self, usr_input):
        self.eyes = list(map(int, usr_input.split()))
        self.pos = {label:eye for label, eye in zip(range(1, 7), self.eyes)}
        #self.com = list(command)

    def roll(self,c):
        self.eyes = [n for n in self.pos.values()]
        if c == 'E':
            self.pos[1] = self.eyes[3]
            self.pos[3] = self.eyes[0]
            self.pos[4] = self.eyes[5]
            self.pos[6] = self.eyes[2]
        elif c == 'N':
            self.pos[1] = self.eyes[1]
            self.pos[2] = self.eyes[5]
            self.pos[5] = self.eyes[0]
            self.pos[6] = self.eyes[4]
        elif c == 'S':
            self.pos[1] = self.eyes[4]
            self.pos[2] = self.eyes[0]
            self.pos[5] = self.eyes[5]
            self.pos[6] = self.eyes[1]
        elif c == 'W':
            self.pos[1] = self.eyes[2]
            self.pos[3] = self.eyes[5]
            self.pos[4] = self.eyes[0]
            self.pos[6] = self.eyes[3]

if __name__ == '__main__':
    dice1 = Dice(input())
    dice2 = Dice(input())
    def is_same(obj_1, obj_2):
        for i in range(720):
            if obj_1.pos == obj_2.pos:
                return True
            c = random.choice(['N','E','W','S'])
            obj_1.roll(c)
        return False
    if is_same(dice1, dice2):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 11692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			for(int i=0;i<n;i++) {
				BigInteger a = new BigInteger(br.readLine());
				BigInteger b = new BigInteger(br.readLine());
				String c = a.add(b).toString();
				if(a.toString().length() > 80 || b.toString().length() > 80 || c.length() > 80) {
					System.out.println("overflow");
				} else {
					System.out.println(c);
				}
			}
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 19080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
    ll N,X; cin >> N >> X;
    V<ll> L(N); for(int i = 0; i < N; ++i) cin >> L[i];
    V<ll> D(N+1,0);
    for(int i = 1; i <= N; ++i) D[i] = D[i-1] + L[i-1];
    ll ans = 0;
    for(int i = 0; i <= N; ++i) if(D[i]<=X) ans++;
    cout << ans << endl;
    
  

    return 0;
}


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

int main() {
  int n, a, cnt = 0;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> a;
    a -= (i+1-cnt);
    if (a != 0) cnt++;
  }
  if (cnt < n) cout << cnt << endl;
  else cout << -1 << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int n;
	cin>>n;
	int head=0,tail=n-1;
	int hm;
	cout<<0<<endl;
	string s;
	cin>>s;
	if(s[0]=='V')return 0;
	else if(s[0]=='M') hm=0;
	else hm=1;
	while(1){
		//cout<<"hm="<<hm<<"head="<<head<<"tail="<<tail<<endl;
		cout<<(head+tail+1)/2<<endl;
		cin>>s;
		if(s[0]=='V')return 0;
		else if(s[0]=='M') {
			if(((head+tail+1)/2-head+hm)%2==0){
				hm=0;
				head=(head+tail+1)/2;
			}else{
				tail=(head+tail+1)/2-1;
			}
		}else{
			if(((head+tail+1)/2-head+hm)%2==1){
				hm=1;
				head=(head+tail+1)/2;
			}else{
				tail=(head+tail+1)/2-1;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 852
n,Capacity=list(int(i) for i in input().split())
maxv=0
W=[]
Values=[]
for i in range(n):
    w,v=list(int(i) for i in input().split())
    if v>maxv:
        maxv=v
    W.append(w)
    Values.append(v)
dp=[[0 for j in range(Capacity+1)]for i in range(n+1)]
for i in range(n+1):
    for w in range(Capacity+1):
        if i==0 or w==0:
            dp[i][w]=0
        elif w>=W[i-1]:
            dp[i][w]=max(dp[i-1][w],Values[i-1]+dp[i-1][w-W[i-1]])
        else:
            dp[i][w]=dp[i-1][w]
print(dp[-1][-1])


Measured memory_bytes: 171656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  map<int, int> S;
  
  for (int i = 2; i <= n; i++) {
    int x = i;
    for (int j = 2; j <= n; j++) {
      while(x%j == 0){
        S[j]++;
        x /= j;
      }
    }
  }
  
  int64_t ans = 1;
  for (auto x : S) {
    ans *= x.second + 1;
    ans %= 1000000007;
  }
  

  cout << ans << endl;

  
}
             
 

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  
  ll ans = 0;


  for (int i = 1; i < 361; i++){
    if ((i*n) % 180 == 0 && (i*n/180) % 2 == 0){
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3648
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	if N%2 == 0 {
		ans := 0
		d := 10
		for N >= d {
			ans += N / d
			d *= 5
		}
		out(ans)
	} else {
		out(0)
	}
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    vector<int> a(4);
    rep(i,4) cin>>a[i];
    cout<<min(a[0],a[1])+min(a[2],a[3]);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n,W; cin >> n >> W;
    ll sum = 0;
    vl w(n); rep(i,n) cin >> w[i], sum += w[i];
    sort(rall(w));
    vvl dp(n+1,vl(W+1,0));
    dp[0][0] = 1;
    rep(i,n){
        rep(j,W+1){
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= mod;
            if(j + w[i] > W) continue;
            dp[i+1][j+w[i]] += dp[i][j];
        }
    }
    ll acc = 0;
    ll ans = (sum <= W);
    /*rep(i,n+1){
        rep(j,W+1) cout << dp[i][j] << " ";
        cout << endl;
    }*/
    for(int i=n-1; i>=0; i--){
        for(ll j=max(0LL,W-w[i]-acc+1); j<=W-acc; j++){
            ans += dp[i][j];
            ans %= mod;
        }
        ans %= mod;
        acc += w[i];
        if(acc > W) break;
    }
    cout << ans << endl;
}


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

using namespace std;

int main() {
  string str;
  int length;
 cin >> length >> str;
	if(str.size() <= length) {
		cout << str << endl;
		}
	else{
	cout << str.substr(0,length) << "..." << endl;
    
    }
   
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int h, w;
	cin >> h >> w;
	V<string> s(h);
	rep(i, h)cin >> s[i];

	V<V<bool>> vis(h, V<bool>(w, false));
	vi dy = { 0,0,1,-1 };
	vi dx = { 1,-1,0,0 };
	ll ans = 0;

	rep(i, h)rep(j, w) {

		if (vis[i][j])continue;

		ll bl = 0, wh = 0;
		queue<P> que;
		que.push(make_pair(i, j));
		vis[i][j] = true;

		while (!que.empty()) {

			int y = que.front().first;
			int x = que.front().second;que.pop();
			if (s[y][x] == '#')bl++;
			else wh++;

			rep(k, 4) {
				int ey = y + dy[k];
				int ex = x + dx[k];
				if (ey < 0 || h <= ey || ex < 0 || w <= ex)continue;
				if (s[y][x] == s[ey][ex] || vis[ey][ex])continue;
				vis[ey][ex] = true;
				que.push(P(ey, ex));
			}

		}

		ans += bl * wh;

	}

	cout << ans << endl;
	
}

Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <set>
#include <bitset>

using namespace std;
#define lowbit(i) (i & (-i))
#define eps 1e-7
#define GETMID int mid = (l + r) >> 1
#define lson u << 1
#define rson u << 1 | 1
#define Lson u << 1, l, mid
#define Rson u << 1 | 1, mid + 1, r
#define Maxn (100000 + 10)
#define MP(a, b) make_pair(a, b)
#define PB(a) push_back(a);
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, a, b, ans[140000], len;

void solve(int l, int r, int A, int B) {
	if(r - 1 == l) {
		ans[l] = A;
		ans[r] = B;
		return;
	}
	
	int x;
	for(int i = 0; i < n; ++i)
		if((A & (1 << i)) ^ (B & (1 << i))) {
			x = i;
			break;
		}
	
	int _A, _B, C;
	_A = ((A >> (x + 1)) << x) + (A & ((1 << x) - 1));
	_B = ((B >> (x + 1)) << x) + (B & ((1 << x) - 1));
	C = _A ^ 1;
	int mid = (l + r) >> 1;
	solve(l, mid, _A, C);
	solve(mid + 1, r, C, _B);
	
	for(int i = l, num = (1 << x) & A; i <= mid; ++i)
		ans[i] = ((ans[i] >> x) << (x + 1)) + num + (ans[i] & ((1 << x) - 1));
	for(int i = mid + 1, num = (1 << x) & B; i <= r; ++i)
		ans[i] = ((ans[i] >> x) << (x + 1)) + num + (ans[i] & ((1 << x) - 1));
}

bool check(int A, int B) {
	int ret1 = 0, ret2 = 0;
	while(A) {
		if(A & 1) ++ret1;
		A >>= 1;
	}
	while(B) {
		if(B & 1) ++ret2;
		B >>= 1;
	}
	return (ret1 & 1) ^ (ret2 & 1);
}

int main() {
	scanf("%d%d%d", &n, &a, &b);
	if(!check(a, b)) puts("NO");
	else {
		puts("YES");
		solve(0, len = (1 << n) - 1, a, b);
		for(int i = 0; i <= len; ++i)
			printf("%d%c", ans[i], (i == len ? '\n' : ' '));
	}
	
	return 0;
}


Measured memory_bytes: 1536
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Math;

class Program
{
    static long mod = (long)1e9 + 7;

    static void Main()
    {
        string[] input = Console.ReadLine().Split();
        int n = int.Parse(input[0]), m = int.Parse(input[1]);
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] t = Console.ReadLine().Split().Select(int.Parse).ToArray();

        long[,] dp = new long[n + 1, m + 1];
        dp[0, 0] = 1;
        for (int i = 1; i <= n; i++)
            dp[i, 0] = 1;
        for (int i = 1; i <= m; i++)
            dp[0, i] = 1;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                dp[i, j] = ((dp[i - 1, j] + dp[i, j - 1]) % mod + mod - dp[i - 1, j - 1]) % mod;
                if (s[i - 1] == t[j - 1])
                    dp[i, j] = (dp[i, j] + dp[i - 1, j - 1]) % mod;
            }
        }
        Console.WriteLine(dp[n, m]);
    }
}


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

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    if(n == 1) printf("Hello World\n");
    else{
        int x, y;
        scanf("%d%d", &x, &y);
        printf("%d\n", x + y);
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int i=1;
    while(1) {
        int x;
        cin >> x;
        if (x == 0)
            break;
        cout << "Case " << i << ": " << x << endl;
        i++;
    }
    return 0;
}

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

int main()
{
    int arr[5],ans;
    for(int i=0;i<5;i++)
    {
        cin>>arr[i];
        if(arr[i]==0)
            ans=i+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    a, b, c, d = map(int, input().split())

    print(max(a*c, a*d, b*c, b*d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10272
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

ll L;
int main(void){
    cin >> L;
    double res = pow(double(L)/3.0, 3);
    cout << setprecision(10) << res << endl;
    return 0;
}



Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

def main():
    x,k,d = map(int, input().split())
    x = abs(x)
    n = x//d
    ans = x
    if n >= k:
        print(x-k*d)
        exit()

    x -= n*d
    k -= n
    ans = x
    ans_2 = abs(ans - d)
    if k%2 ==0:
        print(ans)
    else:
        print(ans_2)

if __name__=="__main__":
    main()


Measured memory_bytes: 65088
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;
int n; 
int main(){
	cin>>n;
	int ans=n/2;
	if(n%2==0)
	ans--;
	cout<<ans;
	re 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i = 1;
	int a, b, c;
	a = 0; b = 0; c = 0;
	char str1[101], str2[101], str3[101];
	scanf("%s%s%s",str1, str2, str3);
	while (1) {
		switch (i) {
		case 1: {
			if (str1[a] == 'a') i = 1;
			else if (str1[a] == 'b') i = 2;
			else if (str1[a] == 'c') i = 3;
			a++;
			break; }
		case 2:
		{
			if (str2[b] == 'a') i = 1;
			else if (str2[b] == 'b') i = 2;
			else if (str2[b] == 'c') i = 3;
			b++;
			break;
		}
		case 3:
		{
			if (str3[c] == 'a') i = 1;
			else if (str3[c] == 'b') i = 2;
			else if (str3[c] == 'c') i = 3;
			c++;
			break;
		}
		}
		if (str1[a] == '\0'&&i==1) { printf("A\n"); break; }
		else if (str2[b] == '\0'&&i==2) {printf("B\n"); break;
	}
		else if (str3[c] == '\0'&&i==3) { printf("C\n"); break; }
 }
	return 0;
}

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

using namespace std;
typedef long long ll;

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

  int c[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int a;
      cin >> a;
      if (a < 0) continue;
      ans += c[a][1];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384