akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll dp[110][100010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= k; j++) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
            (dp[i + 1][min(j + a[i], k) + 1] += MOD - dp[i][j]) %= MOD;
        }
        for(ll j = 0; j <= k; j++) {
            (dp[i + 1][j + 1] += dp[i + 1][j]) %= MOD;
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, x, y;
  y = 0;
  cin >> N;
  
  for (int i = 0; i < 1; i++) {
    cin >> A;
    x = 0;
    for (int j = 0; j < 29; j++) {
      if (A % 2 != 0) break;
      else if (A % 2 == 0) {
      A /= 2;
      x++;
      }
    }
  }
  
  y = x;
  
  for (int i = 0; i < N - 1; i++) {
    cin >> A;
    x = 0;
    
    for (int j = 0; j < 29; j++) {
      if (A % 2 != 0) { 
        if (x <= y) { 
          y = x;
        }
        break;
      }
      
      else if (A % 2 == 0) {
      A /= 2;
      x++;
      }
    }
  }
  cout << y << endl;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<queue>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll INF = 1e17;






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

	int N = s.length();

	int ans[200000] = {};

	int r, l;

	for (int i = 0; i <= N-2; i++) {

		if (s[i] == 'R'&&s[i + 1] == 'L') {
			r = 0;
			for (int j = i; j >= 0 && s[j] == 'R'; j--) { r++; }

			l = 0;
			for (int j = i + 1; j < N && s[j] == 'L'; j++) { l++; }

			ans[i] = (r + 1) / 2 + l / 2;
			ans[i + 1] = r / 2 + (l + 1) / 2;

		}

	}

	for (int i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}

	

	system("PAUSE");


}


Measured memory_bytes: 1656
#include <iostream>
#include <set>
#include <cstdio>

using namespace std;

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

int n, k, card[10];
int used[10];
set<long long> s;

long long toInt() {
	long long res = 1;
	int a[4];
	REP(i, n) if (used[i] > 0) a[used[i]-1] = card[i];
	REP(i, k) {
		if (a[i] < 10) {
			res = res*10 + a[i];
		} else {
			res = res*10 + a[i]/10;
			res = res*10 + a[i]%10;
		}
	}
	return res;
}

void select(int cnt) {
	if (cnt == k) {
		s.insert(toInt());
		return;
	}
	REP(i, n) {
		if (used[i] == 0) {
			used[i] = cnt + 1;
			select(cnt + 1);
			used[i] = 0;
		}
	}
}

int main() {
	while (true) {
		s.erase(s.begin(), s.end());
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		REP(i, n) scanf("%d", &card[i]);
		select(0);
		cout << s.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1324
#include<cstdio>

using namespace std;

int main(){
    long int a, b, k;
    scanf("%ld %ld %ld", &a, &b, &k);
    if(a > k){
        printf("%ld %ld\n", a - k, b);
    }else if(b > k - a){
        printf("%d %ld\n", 0, b - k + a);
    }else{
        printf("%d %d\n", 0, 0);   
    }
}

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

typedef long long ll;
const ll MOD = 7 + 1e+9;

vector<ll> PrimeFactor(const ll N) {
    ll X = N;
    vector<ll> res(1000,0);
    for(int i=2; i<= N; i++) {
	while( X%i == 0 ) {
	    res[i]++;
	    X /= i;
	}
    }
    return res;
}
vector<ll> VecSum(const vector<ll> a, const vector<ll> b) {
    assert(a.size()==b.size());
    vector<ll> res(a.size());
    for(int i=0; i<a.size(); i++) {
	res[i] = a[i] + b[i];
    }
    return res;
}

int main () {

    ll N;
    cin >> N;

    vector<ll> res(1000,0);
    for(ll i=2; i<=N; i++) {
	vector<ll> pf = PrimeFactor(i);
	res = VecSum(res,pf);
    }
    ll ans = 1;
    for(int i=0; i<1000; i++) {
	ans *= res[i]+1;
	ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	ll H, W;
	cin >> H >> W;
	if (H % 3 == 0 || W % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1LL << 60;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			ll w = W / 3 + j;
			ll area[3];
			area[0] = H * w;
			area[1] = H * ((W - w) / 2);
			area[2] = H * W - area[0] - area[1];
			sort(area, area + 3);
			ans = min(ans, area[2] - area[0]);
			area[0] = H * w;
			area[1] = (H / 2) * (W - w);
			area[2] = H * W - area[0] - area[1];
			sort(area, area + 3);
			ans = min(ans, area[2] - area[0]);
		}
		swap(H, W);
	}
	cout << ans << endl;
}


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

const ll INF = 1e18;

int n,k;
int a[15];
int r[15];

ll cost(vector<int> &c) {
  ll s = 0;
  int p = r[c[0]];
  for(int i=0; i<c.size(); i++) {
    p = max(p, r[c[i]]);
    if(p >= a[c[i]]) {
      s += p - a[c[i]] + 1;
      p++;
    }
    else {
      p = a[c[i]];
    }
  }
  return s;
}

ll dfs(vector<int> &c, int index=0) {
  if(c.size() == k) return cost(c);
  int rest = n-index;
  if(c.size()+rest < k) return INF;
  ll s = INF;
  c.push_back(index);
  s = min(s, dfs(c, index+1));
  c.pop_back();
  s = min(s, dfs(c, index+1));
  return s;
}

signed main() {
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  r[0] = 0;
  for(int i=1; i<n; i++) r[i] = max(r[i-1], a[i-1]);

  vector<int> c;
  c.reserve(n);
  cout << dfs(c) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args
   */
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int l = Integer.parseInt(sc.next());
    
    
    int sum = 0;
    int min = Math.abs(1 + l - 1);
    for (int j = 1; j <= n; j++) {
      min = Math.min(Math.abs(j + l - 1), min);
      sum += j + l - 1;
    }
    if (sum < 0)
      System.out.println(sum + min);
    else
      System.out.println(sum - min);
  }

}


Measured memory_bytes: 22608
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n, t, a, h;
	double best = inf;
	int ans = 0;
	cin >> n >> t >> a;
	for (int i = 0; i < n; ++i) {
		cin >> h;
		double ct = (double)t - h * 0.006;
		if (abs(ct - a) < best)
			best = abs(ct - a), ans = i;
	}
	cout << ans + 1;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n;
	cin >> n;
	//vector<ll> a(n);
	map<ll, ll> b;
	rep(i, n) {
		ll a;
		cin >> a;
		++b[a];
	}

	if(n % 3 != 0 || b.size() == 1) {
		YesNo(b[0] == n);
		return 0;
	}

	vector<ll> keys;
	vector<ll> values;	
	for(auto itr = b.begin(); itr != b.end(); ++itr) {
		keys.push_back(itr->first);
		values.push_back(itr->second);
	}

	if(b.size() == 2) {
		if(keys[0] > keys[1]) {
			swap(keys[0], keys[1]);
			swap(values[0], values[1]);
		}

		YesNo(keys[0] == 0 && values[0] * 2 == values[1]);
	} else if(b.size() == 3) {
		YesNo( (keys[0] ^ keys[1] ^ keys[2]) == 0 && values[0] == values[1] && values[1] == values[2] );
	} else {
		YesNo(false);
	}

	return 0;
}


Measured memory_bytes: 6692
H, N = map(int, input().split())
dp = [10**8 for i in range(H+1)]

dp[0] = 0

for i in range(N):
  a, b = map(int, input().split())
  
  for j in range(H):
    dp[min(j+a, H)] = min(dp[min(j+a, H)], dp[j] + b)


print(dp[H])

Measured memory_bytes: 44508
import java.util.Scanner;

 public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int pivot = partition(a, 0, n - 1);

        for (int i = 0; i < n; i++) {
            if (i != 0)
                System.out.print(" ");
            if (i == pivot) {
                System.out.print("[" + a[i] + "]");
            } else {
                System.out.print(a[i]);
            }
        }
        
        System.out.println();
    }

    static int partition(int[] a, int p, int r) {
        int x = a[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (a[j] <= x) {
                i++;
                swap(a, i, j);
            }
        }
        swap(a, i + 1, r);
        return i + 1;
    }

    private static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}


Measured memory_bytes: 72664
def is_all_even(ary, n):
    for i in range(n):
        if ary[i] % 2 == 1:
            return False
    return True

N = int(input())
A = list(map(int, input().split()))
count = 0

while is_all_even(A, N):
    for i in range(N):
        A[i] //= 2
    count += 1

print(count)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int ti = clock();
    int D; cin >> D;
    vector<ll> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26));
    rep(i, D)rep(j, 26) cin >> s[i][j];
    vector<ll> t(D);
    rep(i, D) t[i] = 26-i%26;
    ll ans = 0;
    vector<ll> last(26);
    vector<ll> t_ans(ALL(t));
    for (int d = 1; d <= D; d++) {
        for (int i = 1; i <= 26; i++) {
            if (t[d-1] == i) {
                ans += s[d-1][i-1];
                last[i-1] = d;
            }
            else {
                ans -= c[i-1]*(d-last[i-1]);
            }
        }
    }
    ll tmp;
    while ((double)(clock() - ti)/CLOCKS_PER_SEC <= 1.98) {
        t[rand()%D] = rand()%26 + 1;
        last.clear();
        last.resize(26);
        tmp = 0;
        for (int d = 1; d <= D; d++) {
            for (int i = 1; i <= 26; i++) {
                if (t[d-1] == i) {
                    tmp += s[d-1][i-1];
                    last[i-1] = d;
                }
                else {
                    tmp -= c[i-1]*(d-last[i-1]);
                }
            }
        }
        if (tmp > ans || rand() % 2000 == 0) {
            swap(ans, tmp);
            rep(i, D) t_ans[i] = t[i];
        }
    }
    rep(i, D) cout << t_ans[i] << endl;
  	//cout << ans << endl;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define PI 3.1415926535897932385 //pi
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
bool kaibun(string s, int i, int j)
{
    i--; j--;
    bool fl = true;
    while(i <= j)
    {
        if(s[i] != s[j])
        {
            fl = false;
            break;
        }
        i++; j--;
    }
    if(!fl)
    {
        //cout << s << "2 " << i << " " << j << endl;
        return false;
    }
    else
    {
        //cout << s << " " << i << " " << j << endl;
        return true;
    }
    
}

int main()
{
    string result{"No"};
    string s; cin >> s;
    //cout << s << endl;
    lol len = s.length();
    if(kaibun(s, 1, len) && kaibun(s, 1, (len-1)/2) && kaibun(s, (len+3)/2, len))
        result = "Yes";
    

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll N,M;
  cin>>N>>M;
  cout<<100*(18*M+N)*pow(2,M);
return 0;}

Measured memory_bytes: 4232
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

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

  int n,a; cin >> n >> a;
  cout << n*n-a;

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
#素因数分解　#大きい数を数回
def prime_factorize(n):
    a = [] #素数が入る
    a.append(1)
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    
    b = [[],[]]
    cnt = 1
    for i in range(len(a)+1):
        if i > 0 and i < len(a):
            if a[i] == a[i-1]:
                cnt += 1
            else:
                b[0].append(a[i-1])
                b[1].append(cnt)
                cnt = 1
        if i == len(a) and i > 0:
            b[0].append(a[i-1])
            b[1].append(cnt)
        elif i == len(a) and i == 0:
            b[0].append(a[i])
            b[1].append(cnt)
    return b #b[0]:素数, b[1]:肩の数字  #ex) 2^2*3 -> [[1,2,3][1,2,1]]


n = int(input())
a = prime_factorize(n)
ans = 0
for i in range(1, len(a[1])):
    ans += int((-1 + pow(1 + 8*a[1][i], 0.5)) / 2)
print(ans)


Measured memory_bytes: 9544
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

set<int> setOfEvens(int x) {
	set<int> ans;
	for (int i = 1; i <= x; ++i) {
		ans.insert(2*i);
	}
	return ans;
}

set<int> answer(int n) {
	if (n == 3) {
		set<int> ans = {2, 5, 63};
		return ans;
	} else if (n == 19999 || n == 19997) {
		set<int> ans = answer(n+1);
		ans.erase(6);
		return ans;
	} else if (n < 15002) {
		if (n % 3 == 2 || n % 3 == 1) {
			set<int> ans = setOfEvens(n-2);
			ans.insert(3);
			ans.insert(9);
			return ans;
		} else {
			set<int> ans = setOfEvens(n-4);
			ans.insert(3);
			ans.insert(9);
			ans.insert(15);
			ans.insert(21);
			return ans;
		}
	} else {
		set<int> ans = setOfEvens((n%2 == 0 ? 15000 : 14997));
		int stillNeeded = n - (n%2 == 0 ? 15000 : 14997);
		for (int extra = 3; stillNeeded > 0; extra += 6, --stillNeeded) {
			ans.insert(extra);
		}
		return ans;
	}
}

int main() {
	int n; scanf("%d", &n);
	//printf("%d\n", n); // REMOVE THIS LINE
	set<int> ans = answer(n);
	for (int i : ans) {
		printf("%s%d", (i == *ans.begin() ? "" : " "), i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1280
while True:
  n, x = map(int, input().split())
  if n == x == 0: break
  a = 0
  for i in range(1, n+1):
    for j in range(i+1, n+1):
      for k in range(j+1, n+1):
        if i+j+k == x:
          a += 1
  print(a)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7, A = 2e3 + 2;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
  cin >> n;
  map<int, int> mop;
  for (int i = 0, x; i < n; i++)
  {
    cin >> x;
    if (mop[x] > 0)
      return cout << "NO", 0;
    mop[x]++;
  }
  cout << "YES";
    return 0;
}

Measured memory_bytes: 9600
using System;
class Program
{
    static void Main()
    {
        int k = int.Parse(Console.ReadLine());
        string[] In = Console.ReadLine().Split(' ');
        int a = int.Parse(In[0]);
        int b = int.Parse(In[1]);
        bool flag = false;
        for(int i=1; i<=1000;i++)
        {
            if (b<k*i) break;
            if (a <= k * i & k * i <= b) { flag = true; break; }
        }
        if (flag) Console.WriteLine("OK");
        else Console.WriteLine("NG");
    }
}

Measured memory_bytes: 27440
using System;
using System.Collections.Generic;

partial class ShellSort {

    static long insertionSort(int[] A, int n, int g) {
        long cnt = 0;
        for (int i = g; i < n; i++) {
            int v = A[i];
            int j = i-g;
            while (j >= 0 && A[j] > v) {
                A[j+g] = A[j];
                j -= g;
                cnt++;
            }
            A[j+g] = v;
        }
        return cnt;
    }

    static long shellSort(int[] A, int n) {
        long cnt = 0;
        int m = 0;
        List<int> G = new List<int>();
        for (int h = 1; ;) {
            if (h > n)
                break;
            G.Add(h);
            h = 3*h + 1;
        }
        m = G.Count;
        for (int i = m-1; i >= 0; i--) {
            cnt += insertionSort(A, n, G[i]);
        }
        return cnt;
    }

    static void Main()
    {
        List<int> G = new List<int>();
        int m = 0;
        long cnt = 0;
        int[] A = new int[1000000];
        int n = int.Parse(Console.ReadLine());

        for (int h = 1; ;) {
            if (h > n)
                break;
            G.Add(h);
            h = 3*h + 1;
        }

        m = G.Count;

        for (int i = 0; i < n; i++)
            A[i] = int.Parse(Console.ReadLine());

        cnt += shellSort(A, n);

        Console.WriteLine(m);

        for (int i = m-1; i >= 0; i--) {
            Console.Write(G[i]);
            Console.Write(i == 0 ? "\n" : " ");
        }

        Console.WriteLine(cnt);

        for(int i = 0; i < n; i++)
            Console.WriteLine(A[i]);
    }
}

Measured memory_bytes: 16468
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST

scan [] = True
scan (x:xs)
  | elem x "ACGT" = scan xs
  | otherwise = False

step acc xs
  | length acc < length xs = xs
  | otherwise = acc

main = do
  s <- getLine
  let l = length s
  let xs = [length s' | i<-[0..l], j<-[0..l], let s' = take j $ drop i s, scan s']
  print $ maximum xs 


Measured memory_bytes: 508
#include<cstdio>
using namespace std;
int N;
int A[10];
int main(){
scanf("%d", &N);
int all = 1, bad = 1;
for(int i = 0; i < N; ++i){
scanf("%d", A + i);
all *= 3;
if(A[i] % 2 == 0) bad *= 2;
}
printf("%d\n", all - bad);
return 0;
}

Measured memory_bytes: 1672
import java.util.Scanner;

class Main{

	static int N;
	static long M;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力

		int N = sc.nextInt();
		int M = sc.nextInt();
		int Q = sc.nextInt();
		int[] L  = new int[M];
		int[] R  = new int[M];

		int[][] memo = new int[N+1][N+1];

		for(int i= 0;i < M;i++){
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			memo[L[i]][R[i]]++; 
		}

		int[][] dp = new int[N+1][N+1];

		for(int i = 1;i <= N;i++){
			for(int j = 1;j <= N;j++){
				dp[i][j] = dp[i][j-1] + memo[i][j];
			}
		}


		for(int i= 1;i <= Q;i++){
			int	p = sc.nextInt();
			int	q = sc.nextInt();
			int sum = 0;
			for(int j = p;j <= q;j++){
				sum += (dp[j][q] - dp[j][p-1]);
			}

			System.out.println(sum);
		}



	}


}





Measured memory_bytes: 156852
#import <Foundation/Foundation.h>
#import <stdarg.h>

@interface StdIO : NSObject
+(NSMutableString*)stringFromStdIn;
+(void)printf:(NSString*)format, ...;
@end
@implementation StdIO
+(NSMutableString*)stringFromStdIn
{
    NSFileHandle *handle = [NSFileHandle fileHandleWithStandardInput];
    NSMutableString *result = [NSMutableString string];
    NSData *data = [handle availableData];
    while ([data length] > 0) {
        [result appendString:[[[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding] autorelease]];
        data = [handle availableData];
    }
    return result;
}
+(void)printf:(NSString*)format, ...
{
    va_list arguments;
    va_start(arguments, format);
    NSString *string = [[[NSString alloc] initWithFormat: format arguments: arguments] autorelease];
    NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
    [fileHandle writeData:[string dataUsingEncoding: NSUTF8StringEncoding]];
    va_end(arguments);
}
@end

  
int main() {
    @autoreleasepool {
        NSString *input = [StdIO stringFromStdIn];
        NSArray *numbers = [(NSArray*)[[input componentsSeparatedByString: @"\n"] objectAtIndex:1] componentsSeparatedByString:@" "];
        NSInteger min = NSIntegerMax;
        for (NSNumber *number in numbers) {
            NSInteger i = [number integerValue];
            NSInteger count = 0;
            while (i%2 == 0) {
                i >>= 1;
                count++;
            }
            min = MIN(min, count);
        }
        [StdIO printf: @"%ld", min];
    }
    return 0;
}


Measured memory_bytes: 9628
import itertools
n = int(input())
s = ['' for _ in range(n)]
for i in range(n):
    s[i] = input()[0]
cnt = [s.count('M'), s.count('A'), s.count('R'), s.count('C'), s.count('H')]
ans = 0
for x in itertools.combinations(cnt, 3):
    ans += x[0] * x[1] * x[2]
print(ans)


Measured memory_bytes: 3948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		sc.nextInt();
		sc.nextInt();
		sc.nextInt();
		int e = sc.nextInt();
		int k = sc.nextInt();
		String s = (e -a <= k) ? "Yay!" : ":(" ;
		System.out.println(s);
	}

}


Measured memory_bytes: 22740
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

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

int cnt(int a) {
    int m2 = 0;
    while (a%2 == 0) {
        a /= 2;
        m2++;
    }
    return m2;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    int m = gi();
    int n2;
    int l;
    for (int i = 0; i < n; i++) {
        int a = gi()/2;
        int m2 = cnt(a);;
        if (i) {
            if (n2 != m2) {
                printf("0\n");
                return 0;
            }
            ll lc = ll(a / gcd(a, l)) * ll(l);
            if (lc > ll(m)) {
                printf("0\n");
                return 0;
            }
            l = lc;
        } else {
            n2 = m2;
            l = a;
        }
    }

    int h = m/l;
    if (h%2 == 0)
        h--;
    printf("%d\n", (h+1)/2);

    return 0;
}


Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

string bfs(int k) {
  int cnt = -1;
  queue<string> Q;
  Q.push("");
  while (Q.size()) {
    string s = Q.front(); Q.pop();
    cnt++;
    if (cnt == k) {
      return s;
    }
    loop(i,0,10) {
      if (s == "" and i == 0) continue;
      if (s == "") Q.push(s + (char)(i + '0'));
      else {
        int d = (int)(s[s.size()-1] - '0');
        if (abs(d-i) <= 1) Q.push(s + (char)(i + '0'));
      }
    }
  }
  
  return "-1";
}
int main() {
  int k; cin >> k;
  cout << bfs(k) << endl;
  return 0;
}


Measured memory_bytes: 9440
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, long long K, std::vector<long long> A, std::vector<long long> F){
  long long l, r;
  sort(A.begin(), A.end());
  sort(F.begin(), F.end());
  l = -1;
  r = 0;
  for (int i = 0; i < N; i++) {
    r = max(A[i]*F[N-1-i], r);
  }
  bool isOK;
  long long j;
  while(r-l > 1) {
    long long mid = l + (r - l) / 2;

    j = 0;
    for (int i = 0; i < N; i++) {
      if (A[i]*F[N-1-i]-mid > 0) {
        j += max(0LL, (A[i]*F[N-1-i]-mid-1)/F[N-1-i] + 1);
      }
    }
    if (j <= K) r = mid;
    else l = mid;
  }
  std::cout << r << std::endl;

}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  std::vector<long long> F(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&F[i]);
  }
  solve(N, K, std::move(A), std::move(F));
  return 0;
}


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

int main() {
    string s;
    string ans;
    int x;

    cin >> x;
    cin >> s;
    int y;
    y = s.size();

    int i;
    if (x > y) {
        x = y;
    }
    for (i = 0; i < x; i++) {
        ans.push_back(s.at(i));
    }
    if (y <= x) {
        cout << ans << endl;
    }
    else {
        cout << ans << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll n,res=0;

int main(){
	cin>>n;
	ll t=1;
	while(n){
		res+=t;
		n/=2;
		t*=2;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
# 1行目と2行目を引いて全ての列で同じか確かめる
# それをあと３回繰り返す

def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    cs = [list(map(int, input().split())) for _ in range(3)]
    for i in range(2):
        tmp_diff = [0] * 3
        for j in range(3):
            tmp_diff[j] = cs[i][j] - cs[i + 1][j]
        if len(set(tmp_diff)) == 1:
            pass
        else:
            print("No")
            exit()
    
    for i in range(2):
        tmp_diff = [0] * 3
        for j in range(3):
            tmp_diff[j] = cs[j][i] - cs[j][i + 1]
        if len(set(tmp_diff)) == 1:
            pass
        else:
            print("No")
            exit()
    print("Yes")



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            #define N           5000005
            using namespace std;
            ll n,k,sum,q,res,m,val;
            ll x,y;
            
            void solve()    
            {   

                    cin>>n;
                    vector<ll> v(n);
                    ll ans=0;
                    for(int i=0;i<n;i++) {cin>>v[i];ans^=v[i];}
                    for(int i=0;i<n;i++)
                    {   x=ans^v[i];
                        cout<<x<<" ";
                    }

            }
            int main()
            {   
                ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;
                //cin>>t;
                
                for(int i=1;i<=t;i++)
                    solve();
            
            }            

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int ans = 0;
  if (K <= A) {
    cout << K << endl;
  }
  else if (A < K && K <= A + B) {
    cout << A << endl;
  }
  else if (A + B < K && K <= A + B + C) {
    cout << A - (K - (A + B)) << endl;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int mod = 1000000007;

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    if(a - k >= 0){
        cout << a - k << " " << b << endl;
        return 0;
    }
    b -= (k - a);
    if(b <= 0){
        cout << "0" << " " << "0" << endl;
    }else{
        cout << "0" << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N,K,S=map(int,input().split())
ans=[]

if S<10**9:
    ans=[S for i in range(K)]
    ans+=[S+1 for i in range(N-K)]
else:
    ans=[S for i in range(K)]
    ans+=[1 for i in range(N-K)]

print(*ans)

Measured memory_bytes: 13748
def main():
    n = int(input())

    ans = [1]
    for i in range(2, n + 1):
        j = 2
        while i ** j <= n:
            ans.append(i ** j)
            j += 1

    print(max(ans))


def main2():
    n = int(input())
    ans = 1
    for i in range(2, n + 1):
        j = 2
        while pow(i, j) <= n:
            ans = max([ans, pow(i, j)])
            j += 1

    print(ans)


if __name__ == '__main__':
    main2()


Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split();
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);

        if (a <= 8 && b <= 8) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
    }
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    a.resize(n);
    for (int i = 0; i < n; i++)
    {
        rep(j,m){
        int temp;
        cin >> temp;
        temp--;
        a[i].push_back(temp);
        }
    }
    vector<bool> used(m,true);
    int ans=INF;
    rep(i,m){
        map<int,int> summ;
        rep(j,n){
            rep(k,m){
                if(used[a[j][k]]){
                    summ[a[j][k]]++;
                    break;
                }
            }
        }
        int maxi;
        int maxs=0;
        rep(j,m){
            if(summ[j]>maxs){
                maxi=j;
                maxs=summ[j];
            }
        }
        used[maxi]=false;
        chmin(ans,maxs);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+10;
int n,m,inde[N],ans[N],x,y; 
vector<int>E[N];
queue<int> q;
int main()
{
	cin>>n>>m;
	for(int i=0;i<n+m-1;i++)
	{
		cin>>x>>y;
		x--,y--;
		E[x].push_back(y);
		inde[y]++; 
	} 
	queue<int>q;
	for(int i=0;i<n;i++) if(!inde[i]) ans[i+1]=0,q.push(i);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=0;i<E[u].size();i++)
		{
			int uu=E[u][i];
			inde[uu]--;
			if(!inde[uu]) ans[uu+1]=u+1,q.push(uu);
		}
	}
	for (int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 7040
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
const int N=105;
char s[N][N];
int sumr[N][N];
int sumc[N][N];
int n,m,ex,ey;
short dp[N][N][N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            sumr[i][j]=sumr[i][j-1]+(s[i][j]=='o');
            sumc[i][j]=sumc[i-1][j]+(s[i][j]=='o');
            if(s[i][j]=='E')
                ex=i,ey=j;
        }
    int L=ey-1,R=m-ey,U=ex-1,D=n-ex;
    int ans=0;
	memset(dp,-1,sizeof(dp));
	dp[0][0][0][0]=0;
	for(int l=0;l<=L;l++)
		for(int r=0;r<=R;r++)
			for(int u=0;u<=U;u++)
				for(int d=0;d<=D;d++)
				{
					int tmp=dp[l][r][u][d];
					if(tmp==-1) continue;
					ans=max(tmp,ans);
					int up=max(ex-u,d+1),dn=min(ex+d,n-u),le=max(ey-l,r+1),ri=min(ey+r,m-l);
					if(up>dn||le>ri) continue;
					if(u<U-d) dp[l][r][u+1][d]=max((int)dp[l][r][u+1][d],tmp+sumr[ex-u-1][ri]-sumr[ex-u-1][le-1]);
					if(d<D-u) dp[l][r][u][d+1]=max((int)dp[l][r][u][d+1],tmp+sumr[ex+d+1][ri]-sumr[ex+d+1][le-1]);
					if(r<R-l) dp[l][r+1][u][d]=max((int)dp[l][r+1][u][d],tmp+sumc[dn][ey+r+1]-sumc[up-1][ey+r+1]);
					if(l<L-r) dp[l+1][r][u][d]=max((int)dp[l+1][r][u][d],tmp+sumc[dn][ey-l-1]-sumc[up-1][ey-l-1]);
				}
	printf("%d\n",ans);
}


Measured memory_bytes: 237696
#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)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];

ull LCM(ull a, ull b)
{

    return a * (b / __gcd(a, b));
}

int main()
{
    int N;
    cin >> N;
    vector<ull> T(N);
    ull lcm = 1;
    rep(i, N)
    {
        cin >> T[i];
        lcm = LCM(lcm, T[i]);
    }
    cout << lcm;
    return 0;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
h,w=map(int,input().split())
s=[input() for i in range(h)]
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
uf = WeightedUnionFind(h*w)
for i in range(h):
    for j in range(w):
        if (i+1)+1<=h and s[i][j]!=s[i+1][j]:
            uf.union(i*w+j+1,(i+1)*w+j+1,0)
        if (j+1)+1<=w and s[i][j]!=s[i][j+1]:
            uf.union(i*w+j+1,i*w+j+2,0)
        if (i+1)-1>=1 and s[i][j]!=s[i-1][j]:
            uf.union(i*w+j+1,(i-1)*w+j+1,0)
        if (j+1)-1>=1 and s[i][j]!=s[i][j-1]:
            uf.union(i*w+j+1,i*w+j,0)
li=[[0,0] for i in range(h*w+1)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            li[uf.find(i*w+j+1)][0]+=1
        else:
            li[uf.find(i*w+j+1)][1]+=1
# print(li)
ans=0
for i in range(h):
    for j in range(w):
        ans+=li[i*w+j+1][0]*li[i*w+j+1][1]
print(ans)

Measured memory_bytes: 106756
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);
vector<ll>memo(100010,-1);
ll fib(int n){
  if(memo[n]!=-1)return memo[n];
  memo[n]=fib(n-1)+fib(n-2);
  memo[n]%=MOD;
  return memo[n];
}
  
int main(){
  int n,m;
  cin >> n >> m;
  memo[0]=0;
  memo[1]=1;
  ll ans=1;
  vector<int>a(m);
  rep(i,m){
    cin >> a[i];
    if(i){
      if(a[i]==a[i-1]+1){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  int now=0;
  rep(i,m){
    if(now==a[i]){
      now+=1;
    }
    else{
      ans*=fib(a[i]-now);
      ans%=MOD;
      now=a[i]+1;
    }
  }
  ans*=fib(n+1-now);
  ans%=MOD;
  cout << ans <<endl;
  
}


Measured memory_bytes: 5760
#include <stdio.h>
int main(){
	char a[4];
	
	a[0]=getchar();
	a[1]=getchar();
	a[2]=getchar();
	a[3]=getchar();
	if(a[0]=='Y' && a[1]=='A' && a[2]=='K' && a[3]=='I'){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    static final int MODULUS = 1_000_000_007;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        System.out.println(solve(N, K));

        sc.close();
    }

    static int solve(int N, int K) {
        int[] cuts = buildCuts(N);

        List<Range> ranges = Collections.singletonList(new Range(1, N, 1, 0));
        for (int i = 0; i < K - 1; ++i) {
            int prefixSum = 0;
            List<Range> nextRanges = new ArrayList<>();
            for (int j = 0; j < cuts.length; ++j) {
                int begin = (j == 0) ? 1 : (cuts[j - 1] + 1);
                int end = cuts[j];
                int value = computePrefixSum(ranges, N / begin);
                Range nextRange = new Range(begin, end, value, prefixSum);

                nextRanges.add(nextRange);
                prefixSum = addMod(prefixSum, computeRangeValueSum(nextRange));
            }

            ranges = nextRanges;
        }

        return ranges.stream().mapToInt(Main::computeRangeValueSum).reduce(Main::addMod).getAsInt();
    }

    static int computePrefixSum(List<Range> ranges, int x) {
        int index = -1;
        int lower = 0;
        int upper = ranges.size() - 1;
        while (true) {
            int middle = (lower + upper) / 2;
            Range range = ranges.get(middle);

            if (range.begin > x) {
                upper = middle - 1;
            } else if (range.end < x) {
                lower = middle + 1;
            } else {
                index = middle;

                break;
            }
        }

        Range range = ranges.get(index);

        return addMod(range.prefixSum, multiplyMod(x - range.begin + 1, range.value));
    }

    static int[] buildCuts(int N) {
        List<Integer> divisors = new ArrayList<>();
        for (int i = 1; i * i <= N; ++i) {
            divisors.add(i);
            divisors.add(N / i);
        }

        return divisors.stream().distinct().sorted().mapToInt(x -> x).toArray();
    }

    static int computeRangeValueSum(Range range) {
        return multiplyMod(range.end - range.begin + 1, range.value);
    }

    static int addMod(int x, int y) {
        return (x + y) % MODULUS;
    }

    static int multiplyMod(int x, int y) {
        return (int) ((long) x * y % MODULUS);
    }
}

class Range {
    int begin;
    int end;
    int value;
    int prefixSum;

    Range(int begin, int end, int value, int prefixSum) {
        this.begin = begin;
        this.end = end;
        this.value = value;
        this.prefixSum = prefixSum;
    }
}

Measured memory_bytes: 83152
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    N = I()
    G = [[] for _ in range(N)]
    edges = []
    edge2color = {}
    for _ in range(N-1):
        a, b = LI_()
        G[a].append(b)
        G[b].append(a)
        edges.append((a, b))
    K = -1
    for adj_v in G:
        K = max(K, len(adj_v))
    visited = [0] * N
    def colorGraph(v, parColor=-1):
        children = G[v]
        colorNum = 1
        visited[v] = 1
        for child_v in children:
            if visited[child_v]:
                continue
            if colorNum == parColor:
                colorNum += 1
            edge2color[(v, child_v)] = colorNum
            edge2color[(child_v, v)] = colorNum
            colorGraph(child_v, colorNum)
            colorNum += 1
    # import pdb
    # pdb.set_trace()
    colorGraph(0)
    print(K)
    for edge in edges:
        key = (edge[0], edge[1])
        print(edge2color[key])

main()



Measured memory_bytes: 141464
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a;
    cin>>n;
    ll b[100005];
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++){
        cin>>a;
        b[a]++;
        b[a+1]++;
        b[a+2]++;
    }
    ll ans=0;
    for(int i=0;i<100005;i++){
        ans=max(ans,b[i]);
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 1024