akhauriyash/Code-Regression huggingface dataset:
var lines = [];
var result = 0;
var readline = require("readline");

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);

    N % 2 === 0 ? console.log(N) : console.log(N * 2);
});

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <complex>
#include <algorithm>
using namespace std;

typedef pair<int,int> P;

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

int main(){
	int N;
	double R;
	cin >> N >> R;
	
	set<P> s;
	for(int i=0 ; i < N ; i++ ){
		double x, y;
		cin >> x >> y;
		int ax = floor(x / R);
		int ay = floor(y / R);
		
		bool flag = false;
		for(int j=0 ; j < 9 ; j++ ){
			int mx = ax + dx[j];
			int my = ay + dy[j];
			if( s.find(P(mx,my)) != s.end() ){
				flag = true;
			}
		}
		if( flag == false ){
			s.insert( P(ax,ay) );
		}
	}
	cout << s.size() << endl;
}

Measured memory_bytes: 5972
import heapq
import sys
input = sys.stdin.readline
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
    maxnum = heapq.heappop(a)
    heapq.heappush(a,-((-maxnum)//2))
print(-sum(a))

Measured memory_bytes: 68248
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7

ans = pow(2, n, mod) - 1

nca, ncb = 1, 1

for i in range(b):
    ncb = ncb * (n - i) % mod
    ncb *= pow(i + 1, mod - 2, mod)
    if i + 1 == a:
        nca = ncb

print((ans - (nca + ncb)) % mod)

Measured memory_bytes: 9200
#include<iostream>
using namespace std;
int main(){
  // taking n and k
  int n,k;
  cin >> n >> k;
  // taking points for r, p, s
  int r, p, st;
  cin >> r >> st >> p;
  // string by machine
  string s, t;
  cin >> s;
  t = s;
  long int res = 0;
  for (int i= 0; i < k ; i++){
  	if (s[i] == 'p') {
      t[i]='s';
      res += st;
    }
    else if (s[i] == 'r') {
      t[i]='p';
      res += p;
    }
    else {
      t[i]='r';
      res += r;
    }
  }
  // from k+1 th element onwards
  for (int i = k; i < n; i++){
  	if (s[i]==s[i-k] && s[i]!=t[i-k]) t[i] = s[i];
    else{
 
      if (s[i] == 'p') {
        t[i]='s';
        res += st;
      }
      else if (s[i] == 'r') {
        t[i]='p';
        res += p;
      }
      else {
        t[i]='r';
        res += r;
      }
    }
  }
cout << res <<'\n';
 
	return 0;
}

Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
# num={}
# for ai in a:
#     num_ai=num.get(ai, 0)
#     num[ai]=num_ai+1

# even=0
# odd=0
# for k,v in num.items():
#     if(v%2==0):
#         even+=1
#     else:
#         odd+=1


# if(even==0):
#     print(len(num))
# else:
#     print(len(num)-1)

seta=set(a)
if(len(seta)%2==0):
    print(len(seta)-1)
else:
    print(len(seta))

Measured memory_bytes: 14396
import fractions
N, M = map(int, input().split())
S = input()
T = input()
ans = (N * M) // fractions.gcd(N, M)
n = N // fractions.gcd(N, M)
m = M // fractions.gcd(N, M)
for i in range(min(N // n, M // m)):
    tmpn = S[n * i]
    tmpm = T[m * i]
    if tmpn != tmpm:
        ans = -1
        break

print(ans)

Measured memory_bytes: 5432
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int dp[120][100100];
int n,k;
int a[120];
#define MOD 1000000007
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=0;i<=k;i++)
		dp[0][i]=1;
	for(int i=1;i<=n;i++){
		dp[i][0]=dp[i-1][0]%MOD;
		for(int j=1;j<=k;j++){
			dp[i][j]=((dp[i-1][j]-(a[i]>=j?0:dp[i-1][j-a[i]-1])+MOD)%MOD+dp[i][j-1])%MOD;
		}
	}
	cout<<(dp[n][k]-(k==0?0:dp[n][k-1])+MOD)%MOD<<endl;
	return 0;
}


Measured memory_bytes: 41216
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] k = new int[n];
		int[] p = new int[n];
		
		for (int i = 0; i < n; i++){
			k[i] = sc.nextInt();
			p[i] = sc.nextInt();
		}
		
		for (int i = 0; i < n; i++){
			int res = k[i] % p[i];
			if (res == 0){
				res = p[i];
			}
			
			System.out.println(res);
		}
	}
}

Measured memory_bytes: 20372
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 1e5 + 5;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 1e9 + 7;
int n , k , a[110] , dp[110][maxn];
int pref[110][maxn];

signed main() {
    
    fio;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 0; i <= k; i++){
        if(i <= a[1]) dp[1][i] = 1;
    }
    for(int i = 0; i <= k; i++){
        if(i == 0) pref[1][i] = dp[1][i];
        else pref[1][i] = (pref[1][i - 1] + dp[1][i]) % mod;
    }
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= k; j++){
            dp[i][j] += pref[i - 1][j] - (j - a[i] - 1 < 0 ? 0LL : pref[i - 1][j - a[i] - 1]);
            dp[i][j] = (dp[i][j] + mod) % mod;
            if(j == 0) pref[i][j] = dp[i][j];
            else pref[i][j] = (pref[i][j - 1] + dp[i][j]) % mod;
        }
    }
    cout << dp[n][k] << endl;
    
    return 0;
    
}


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

int main(){
    int n;
    cin >> n;
    bool buy = false;
    for(int j = 0; j <= n / 4; j++){
        for(int k = 0; k <= n / 7; k++){
            if(4 * j + 7 * k == n) buy = true;
        }
    }
    if(buy == false) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
def check(score):
  if score >= 3200:
    return -1
  for i,rating in enumerate(scores):
    if rating[0] <= score <= rating[1]:
      return i
n = int(input())
a = list(map(int,input().split()))
thopes = 0
colors = set()
scores = [(1,399),(400,799),(800,1199),(1200,1599),(1600,1999),(2000,2399),(2400,2799),(2800,3199)]
for score in a:
  ind = check(score)
  if ind==-1:
    thopes+=1
  else:
    colors.add(ind)
n = len(colors)
print(max(1,n),thopes+n)

Measured memory_bytes: 3064
n, *fp = readlines.map(&:chomp)
f = fp[0..fp.length / 2 - 1].map {|l| l.gsub(' ', '').to_i(2)}
p = fp[fp.length / 2..-1].map {|l| l.split(' ').map(&:to_i)}
patterns = 1.upto(1023).map do |t|
  ps = f.zip(p).map do |fk, pk|
    combi = (fk & t).to_s(2).split('').map(&:to_i)
    pk[combi.reduce(:+)]
  end
  ps.reduce(:+)
end
p patterns.max

Measured memory_bytes: 2684
#include <iostream>
#include <vector>

void printVector(const std::vector<int> &A) {
  auto len = A.size();
  for (auto i=0; i<len-1; ++i) {
    std::cout << A.at(i) << " ";
  }
  std::cout << A.back() << std::endl;
}

int main() {
  int n, temp;
  std::vector<int> A;
  
  std::cin >> n;
  
  for (auto i=0; i<n; ++i) {
    std::cin >> temp;
    A.push_back(temp);
  }
  
  printVector(A);
  
  for (auto i=1; i<n; ++i) {
    auto j = i-1;
    auto pivot = A.at(i);
    
    while (j >= 0 && A.at(j) > pivot) {
      A.at(j+1) = A.at(j);
      --j;
    }
    A.at(j+1) = pivot;
    
    printVector(A);
  }
}


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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  bool ans=true;
  for(int i=0;i<n;i++){
    if(s[i]!=s[n-i-1])ans=false;
  }
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[(n-1)/2-i-1])ans=false;
  }
  for(int i=(n+3)/2;i<n;i++){
    if(s[i]!=s[n-i-1])ans=false;
  }
  
  
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

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

int main(void){
    int ans = 0;
    string s;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    REP(i, s.length() / 2) {
        if (i != s.length() - 1 - i && s[i] != s[s.length() - 1 - i]) {
            ans++;
        }
    }

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

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

const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 int a[3];
 cin>>a[0]>>a[1]>>a[2];sort(a,a+3);
 if((-a[0]-a[1]+2*a[2])%2)cout<<(-a[0]-a[1]+2*a[2])/2 +2;
 else cout<<(-a[0]-a[1]+2*a[2])/2;


return 0;
}


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

using namespace std;





int main(){

    long long n, m, l;
    
    cin >> n >> m >> l;

    long long A[n][m];
    long long B[m][l];
    long long C[n][l];

    for(long long y = 0; y < n; y++){
        for(long long x = 0; x < m; x++){
            cin >> A[y][x];
        }
    }

    for(long long y = 0; y < m; y++){
        for(long long x = 0; x < l; x++){
            cin >> B[y][x];
        }
    }

    long long sum = 0;

    for(long long x = 0; x < l; x++){
        for(long long y = 0; y < n; y++){
            sum = 0;
            for(long long z = 0; z < m; z++){
                sum = sum + A[y][z] * B[z][x];
            }
            C[y][x] = sum;
        }
    }

    for(long long y = 0; y < n; y++){
        for(long long x = 0; x < l; x++){
            if(x != l - 1){
                printf("%lld ", C[y][x]);
            }
            else{
                printf("%lld\n", C[y][x]);
            }
        }
    }

    return 0;


}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

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

  int n, m;
  cin >> n >> m;

  vi es[101010];
  vi h(101010, 0);
  REP(i, n + m - 1) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    es[a].push_back(b);
    h[b]++;
  }

  int root = 0;
  REP(i, n) if (h[i] == 0)  {
    root = i;
  }

  queue<int> que;
  que.push(root);
  vi pre(n, -1);
  while (!que.empty()) {
    int u = que.front(); que.pop();
    for (int v: es[u]) {
      h[v]--;
      if (h[v] == 0) {
        pre[v] = u;
        que.push(v);
      }
    }
  }

  // cout << root << endl;

  REP(i, n) {
    cout << pre[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 7168
#include<bits/stdc++.h>
using namespace std;
int n,m;
char s[105];
int cnt[100];
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>s;
        for(int j=0;j<m;j++){
            cnt[s[j]-'a'+1]++;
        }
    }
    if(n%2==0&&m%2==0){
        for(int j=1;j<=26;j++){
            if(cnt[j]%4!=0){
                puts("No");
                return 0;
            }
        }
        puts("Yes");
        return 0;
    }else if(n%2==1&&m%2==1){
        int tmp=0,tt=0;
        for(int i=1;i<=26;i++){
            if(cnt[i]%2==1)tt++;
            tmp+=cnt[i]/4;
        }
        if(tt>1||tmp<(n-1)*(m-1)/4){
        	puts("No");
		}else{
        	puts("Yes");
		}
    }else{
        if(n%2==0){
        	swap(n,m);
		}
        int tmp=0;
        for(int i=1;i<=26;i++){
           	if(cnt[i]%2==1){
                puts("No");
                return 0;
            }else{
            	tmp+=cnt[i]/4;
			}
        }
        if(tmp<(n-1)*m/4){
        	puts("No");
		}else{
        	puts("Yes");
		}
    }
    return 0;
}

/*

in:
2 5
abxba
abyba

out:
No

in:
4 3
aaa
aaa
ccb
bbb

out:
Yes

*/

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


int main() {
    int K;
    std::cin >> K;

    int val = 7;
    int mod = val % K;
    for (int i = 0; i < K; i++) {
        if (mod == 0) {
            std::cout << i + 1 << std::endl;
            return 0;
        }
        val = (val * 10) % K;
        mod = (mod + val) % K;
    }
    std::cout << -1 << std::endl;
}


Measured memory_bytes: 3632
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e3+5;
ll n  , m   , dp[maxN][maxN];
string s[maxN];
void solve(){
	cin>> n >> m ;
	for(ll i=0;i<n ;i++)cin>>s[i];
	for(ll i=0;i<=n ;i++){
		for(ll j=0;j<=m ; j++){
			if(i==0 || j==0)dp[i][j]=0;
			else if(i==1 && j==1 ){
				if(s[i-1][j-1]=='.')dp[i][j]=1;
			}
			else{
				if(s[i-1][j-1]=='.'){
					dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
				}
			}
		}
	}
	cout<<dp[n][m]<<endl;
}
int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 16584
from collections import defaultdict
import sys
input = sys.stdin.readline

h, w, n = map(int, input().split())
d = defaultdict(int)
dx = [1, 1, 1, 0, 0, 0, -1, -1, -1]
dy = [1, 0, -1, 1, 0, -1, 1, 0, -1]
for i in range(n):
    a, b = map(int, input().split())
    for k in range(9):
        na = a+dx[k]
        nb = b+dy[k]
        if na <= 1 or nb <= 1 or na > h-1 or nb > w-1:
            continue
        d[(na, nb)] += 1

ans = [0] * 10
for key in d:
    ans[d[key]] += 1
ans[0] = (h-2) * (w-2) - sum(ans)

for ans_i in ans:
    print(ans_i)


Measured memory_bytes: 166892
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

// TCR
// Suffix array in O((n+S) log n)
// S is the size of alphabet, meaning that 0<=s[i]<S for all i
// You can change vector<int> s to string s. In that case S is 256
// This is CIRCULAR SUFFIX ARRAY. Append $ to the string to make if non circular
#include <bits/stdc++.h>
using namespace std;
vector<int> suffixArray(vector<int> s, int S = 256) {
	int n=s.size();int N=n+S;
	vector<int> sa(n), ra(n);
	for(int i=0;i<n;i++) {sa[i]=i;ra[i]=s[i];}
	for(int k=0;k<n;k?k*=2:k++) {
		vector<int> nsa(sa), nra(n), cnt(N);
		for(int i=0;i<n;i++) nsa[i]=(nsa[i]-k+n)%n;
		for(int i=0;i<n;i++) cnt[ra[i]]++;
		for(int i=1;i<N;i++) cnt[i]+=cnt[i-1];
		for(int i=n-1;i>=0;i--) sa[--cnt[ra[nsa[i]]]]=nsa[i];
		int r=0;
		for(int i=1;i<n;i++) {
			if(ra[sa[i]]!=ra[sa[i-1]]) r++;
			else if(ra[(sa[i]+k)%n]!=ra[(sa[i-1]+k)%n]) r++;
			nra[sa[i]]=r;
		}
		ra=nra;
	}
	return sa;
}

const int INF = (int)1e9 + 7;

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

	int n, k;
	cin >> n >> k;
	string str;
	cin >> str;

	vector<int> s(2*n+1);
	for (int i = 0; i < n; ++i) s[i] = str[i];
	for (int i = n; i < 2*n; ++i) s[i] = str[2*n-1-i];
	s[2*n] = '$';
	vector<int> sa = suffixArray(s);
	vector<int> rev(2*n+1);
	for (int i = 0; i < 2*n+1; ++i) rev[sa[i]] = i;

	char mc = 'z';
	vector<int> cou(n, 1);
	for (int i = 0; i < n; ++i) {
		mc = min(mc, str[i]);
		if (i > 0 && str[i] == str[i-1]) cou[i] += cou[i-1];
	}

	vector<pair<pair<int, int>, int>> offs;
	for (int i = 0; i < n; ++i) {
		if (str[i] == mc) {
			int len, loc;
			if (i < n-1) {
				len = cou[i];
				loc = i+1;
			} else {
				len = 2*cou[i];
				loc = i+1 + cou[i];
			}
			offs.push_back({{-len, rev[loc]}, loc});
		}
	}
	sort(offs.begin(), offs.end());

	int act = -offs[0].first.first;
	for (; act < n && k > 1; --k) act *= 2;
	act = min(act, n);

	for (int j = 0; j < act; ++j) cout << mc;
	for (int j = 0; j < (n-act); ++j) cout << (char)s[offs[0].second + j];
	cout << '\n';
}


Measured memory_bytes: 616
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x - 1] = i + 1;
  }
  for (int x : a) cout << x << " ";
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t1 = sc.nextInt();
        int t2 = sc.nextInt();
        long a1 = sc.nextLong();
        long a2 = sc.nextLong();
        long b1 = sc.nextLong();
        long b2 = sc.nextLong();

        if (a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2) {
            System.out.println("infinity");
            System.exit(0);
        }

        long dif1 = a1 * t1 - b1 * t1;
        long dif2 = a2 * t2 - b2 * t2;

        long ans;
        // aの方が最初に早い || bの方が最初に早い
        if ((dif1 > 0 && dif1 + dif2 < 0) || (dif1 < 0 && dif1 + dif2 > 0)) {
            if (-dif1 % (dif1 + dif2) == 0) {
                ans = -dif1 / (dif1 + dif2) * 2;
            } else {
                ans = -dif1 / (dif1 + dif2) * 2 + 1;
            }
        } else {
            ans = 0;
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 22996
#include <iostream>
using namespace std;
int main()
{
	int n, k, ans = 1;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		if(ans > k)
		{
			ans = ans + k;
		}
		else
		{
			ans = ans  + ans;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int tree_depth[100002] = {};
int parent[100002] = {};
int v[100002] = {};

int find(int x){
  if (parent[x]==0) {
    return(x);
  } else {
    int ans = find(parent[x]);
    parent[x] = ans;
    return(ans);
  }
}

void merge(int x, int y){
  int root_x = find(x);
  int root_y = find(y);
  if (root_x == root_y) {
    return;
  }
  if (tree_depth[root_x] < tree_depth[root_y]) {
    parent[root_x] = root_y;
    tree_depth[root_x] = tree_depth[root_y];
  } else {
    parent[root_y] = root_x;
    if (tree_depth[root_x] == tree_depth[root_y]) {
      tree_depth[root_x]++;
    }
    tree_depth[root_y] = tree_depth[root_x];
  }
  return;
}


int main(){
  int n, m;
  cin >> n >> m;
  for (int i=1;i<=n;i++) {
    int p;
    cin >> p;
    v[i] = p;
    tree_depth[i] = 1;
  }
  for (int i=0;i<m;i++) {
    int src, dst;
    cin >> src >> dst;
    merge(src, dst);
  }
  int ans = 0;
  for (int i=1;i<=n;i++) {
    int a = find(i);
    int b = find(v[i]);
    if (a == b) {
      ans++;
    }
  }
  cout << ans << endl;
  return(0);
}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**6)

n,q=map(int,input().split())
pair=[i for i in range(n)]

def root(x):
    if pair[x]==x:
        return x
    else:
        pair[x]=root(pair[x])
        return pair[x]

for i in range(q):
    com,x,y=map(int,input().split())
    if com==0:
        x1=root(x-1)
        y1=root(y-1)
        if x1!=y1:
            pair[x1]=y1
    elif com==1:
        if root(x-1)==root(y-1):
            print(1)
        else:
            print(0)



Measured memory_bytes: 13092
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#define ll long long
using namespace std;

int main() {
	string a, b;
	cin >> a >> b;
	if (a == "H") cout << b << endl;
	else if (b == "H") cout << "D" << endl;
	else cout << "H" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 1005
#define ll long long
#define ld double
#define mod 998244353
using namespace std;
int a[maxn], n, k;
ll sum[maxn * maxn];
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int cnt = 0;
	for(int i = 1; i <= n; i++)
	{
		ll sm = 0;
		for(int j = i; j <= n; j++)
		{
			sm += a[j];
			sum[cnt++] = sm;
		}
	}
	ll ans = 0;
	for(int i = 60; i >= 0; i--)
	{
		ll ns = 1ll << i;
		ans ^= ns;
		int tot = 0;
		for(int j = 0; j < cnt; j++)
			if((sum[j] & ans) == ans) tot++;
		if(tot < k) ans ^= ns;
	//	cout<<i<<" "<<tot<<endl;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4352
import sys
N,K,Q=map(int,input().split())
#そもそも問題数が持ち点より少ないときは誰も敗退しない
if Q < K:
    for i in range(N):
        print('Yes')
    sys.exit()
correct_answer_users =[]
for j in range(1,Q+1):
    correct_answer_users.append(int(input()))
user_base_points =[K-Q]*N 
for user in correct_answer_users:
    user_base_points[user-1] += 1
for point in user_base_points:
    if point>0:
        print('Yes')
    else :
        print('No')

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(v) cout<<v<<"\n"

int main() {
  int N, Y;
  scanf("%d%d", &N, &Y);

  rep(i, N + 1) rep(j, N-i + 1) {
    int k = N - i - j;
    if (Y == 10000 * i + 5000 * j + 1000 * k) {
      printf("%d %d %d\n", i, j, k);
      return 0;
    }
  }
  printf("-1 -1 -1\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve(vector<int> a, vector<int> & b) {
  if(a.size() == 0) return;
  for(int i = a.size() - 1; i >= 0; i--){
 	if(a[i] == i){
      b.push_back(i);
      vector<int> na;
      for(int j = 0; j < i; j++) na.push_back(a[j]);
      for(int j = i + 1; j < a.size(); j++) na.push_back(a[j]);
      solve(na, b);
      return;
    }
  }
  b.clear();
}
int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(int & v : a) cin >> v;
  for(int & v : a) v--;
  vector<int> an;
  solve(a, an);
  if(an.size() == n) {
    for(int i = 0; i < n; i++) cout << an[n-i-1]+1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {

    ll x, y;
    cin >> x >> y;

    if (x == 1 && y == 2) {
        cout << 3 << endl;
        ret();
    }
    if (x % y == 0) {
        cout << -1 << endl;
    } else {
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
const int MAXN = 2e5 + 10;


int n, l;
int a[MAXN];
int d[MAXN];
typedef long long LL;

LL solve() {
  static LL sum[MAXN], sum1[MAXN], sum2[MAXN];
  for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + d[i];
  for (int i = 1; i <= n; i++) {
    sum1[i] = sum1[i - 1] + 2ll * i * d[i];
    sum2[i] = sum2[i - 1] + 2ll * (n - i) * d[i];
  }
  
  LL ans = 0;
  for (int i = 1; i < n; i++) {
    LL tot = i * sum[n - i];
    if (i & 1) {
      int p = n - (i >> 1);
      tot += (sum1[n] - sum1[p - 1]) - (sum[n] - sum[p - 1]) * 2 * p;
      tot += (sum2[p - 1] - sum2[n - i]) - (sum[p - 1] - sum[n - i]) * (2 * (n - p) + 1);
    } else {
      int p = n - (i >> 1) + 1;
      tot += (sum1[n] - sum1[p - 1]) - (sum[n] - sum[p - 1]) * (2 * p - 1);
      tot += (sum2[p - 1] - sum2[n - i]) -
        (sum[p - 1] - sum[n - i]) * (2 * (n - p + 1));    
    }
    //fprintf(stderr, "%lld\n", tot);
    ans = std::max(ans, tot);
  }
  return ans;
}
int main() {
  scanf("%d%d", &l, &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= n; i++) {
    d[i] = a[i] - a[i - 1];
  }
  n++;
  d[n] = l - a[n - 1];
  long long ans = solve();
  std::reverse(d + 1, d + n + 1);
  ans = std::max(ans, solve());
  printf("%lld\n", ans);
  
  
}


Measured memory_bytes: 6400
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <unordered_map>

using namespace std;

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

const ll mod = 1000000007;

unordered_map<ll, int> primeFactorize(ll a) {
  ll i = 2;
  unordered_map<ll, int> factor;
  while (i * i <= a) {
    if (a % i == 0) {
      factor[i]++;
      a /= i;
    }
    else i++;
  }
  factor[a]++;
  return factor;
}

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

  int n;
  cin >> n;

  unordered_map<ll, int> totalFactor;
  for (int i = 2; i <= n; i++) {
    auto factor = primeFactorize(i);
    for (auto &x: factor) totalFactor[x.first] += x.second;
  }

  ll ans = 1;
  for (auto &x: totalFactor) ans = (ans * (x.second + 1)) % mod;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
abc = input().split()
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])
d = int(abc[3])
e = int(abc[4])
f = int(abc[5])

x = []
y = []
pair = []
con = []


for i in range(int((f/100)+1)):
    for j in range(int((f/100)+1)):
        canx = ((a*i)+(b*j))*100
        if canx<=f:
            x.append(canx)

if x == []:
    print('x is empty')
            
for i in range(f):
    for j in range(f):
        cany = (c*i)+(d*j)
        if cany<=f:
            y.append(cany)
            
if y == []:
    print('y is empty')
            
for i in x:
    for j in y:
        if i+j<=f:
            if i!=0:
                if 100*j/i<=e:
                    pair.append([i, j])

if pair == []:
    print('pair is empty')

for i in pair:
    if sum(i)!=0:
        con.append(i[1]/sum(i))
    
if con == []:
    print('con is empty')
    
ans = pair[con.index(max(con))]
print(sum(ans), ans[1])

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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main(void){

    int n, a, b;
    cin >> n >> a >> b;

    if((b - a) % 2){
        cout << "Borys" << "\n";
    } else{
        cout << "Alice" << "\n";
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include<algorithm>
using namespace std;
int main(){
    int R[200000],n;
    
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>R[i];
    int maxv = -2000000000;
    int minv = R[0];
        
    for(int i=1;i<n;i++){                                  
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }   
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3868
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
  

int main() {
	int n;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	vector <pair<int,int>> vect;
	for(int i=0;i<n;i++)
	{
		vect.push_back(make_pair(a[i],b[i]));
	}
	sort(vect.begin(), vect.end(), sortbysec); 
	long long sum=0;
	int i=0;
	int flag=1;
  for(int i=0;i<n;i++)
            {
            	sum+= vect[i].first;
               if(vect[i].second < sum)
               {flag=0 ;
               break; 
               	
               }
  }
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
	

Measured memory_bytes: 3956
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int f[101][5][2];
int p[101][11];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 5; j++){
      for(int k = 0; k < 2; k++){
        cin >> f[i][j][k];
      }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < 11; j++){
      cin >> p[i][j];
    }
  }
  ll res = -linf;
  for(int i = 1; i < 1024; i++){
    ll tmp = 0;
    for(int j = 0; j < n; j++){
      int c = 0;
      for(int k = 0; k < 10; k++){
        if((i >> k) % 2 == 1 && f[j][k / 2][k % 2] == 1)c++;
      }
      tmp += p[j][c];
    }
    res = max(res, tmp);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#include<regex>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

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

	vector<double> V(N);
	rep(i, N) cin >> V[i];

	sort(ALL(V));

	while (V.size() > 1) {
		double tmp = (V[0] + V[1]) / 2;
		rep(i, 2) V.erase(V.begin());
		V.insert(V.begin(), tmp);
	}

	cout << V[0] << endl;
	return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
#define MAX 510000
#define MOD 1000000007
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 modinv(ll a, ll m){
  ll b=m,u=1,v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if(u<0) u+=m;
  return u;
}
long long pow(long long a, long long n, long long m) {
    if (n == 0) return 1 % m;
    long long t = pow(a, n / 2, m);
    t = (t * t)%m;
    if (n & 1) t = (t * a)%m;
    return t;
}

#define MN 1100
  ll dp[MN][MN]={};
signed main(){
  init_io();
  COMinit();
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  dp[0][0] = 1;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=b-a+1;j++){
      ll v = a+j;
      dp[i][j+1] += dp[i][j];
      dp[i][j+1] %= MOD;
      for(int k=c;k<=d;k++){
        ll idx = i + v*k;
        if(idx > n) break;
        ll cm = COM(n-i,v*k);
        ll dv = fac[v*k] * pow(finv[v],k,MOD)%MOD;
        ll ml = ((cm * dv)%MOD * finv[k])% MOD;
        dp[idx][j+1] += (dp[i][j] * ml % MOD)%MOD;
      }
    }
  }
  cout << dp[n][b-a+1]<<endl;
}


Measured memory_bytes: 21632
# coding: utf-8
# Your code here!

# ITP1_6_C

N=int(input())
buildings= list()
floor= list()
result=""
for j in range(4):
    floor= list()
    for i in range(3):
        floor.insert(i,list("0"*10))
    buildings.insert(j,floor)


for _ in range(N):
    b,f,r,v=map(int,input().split())
    buildings[b-1][f-1][r-1]=int(buildings[b-1][f-1][r-1])+v

for i,building in enumerate(buildings):
    # print(building)
    for floor in building:
        result=" "+" ".join(map(str,floor))
        print(result)
    if(i==len(buildings)-1):
        break
    print("####################")
    
    
    
    


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int r,i,d,x;
	cin >> r >> d >> x;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
		x = r*x - d;
		cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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++)
int INF=1e9+7;

int main() {
  int N,K;
  cin >> N >> K;
  vi A(N);
  rep(i,N) cin >> A[i];
  
  int l=0,r=INF;
  while(r-l>1) {
    int m=(r+l)/2;
    int count=0;
    rep(i,N) {
      count+=A[i]/m;
      if(A[i]%m) count++;
    }
    if(count-N<=K) r=m;
    else l=m;
  }
  
  cout << r << endl;
}

Measured memory_bytes: 3988
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7


def comb_mod(n, k, mod):
    numerator = 1
    denominator = 1
    for i in range(k):
        numerator = (numerator * (n - i)) % mod
        denominator = (denominator * (i + 1)) % mod

    return (numerator * pow(denominator, mod - 2, mod)) % mod


n_c_a = comb_mod(n, a, mod)
n_c_b = comb_mod(n, b, mod)

result = (pow(2, n, mod) - 1 - n_c_a - n_c_b) % mod
print(result)


Measured memory_bytes: 39152
#include <stdio.h>

int main(){
    int N, K, i, num=1;

    scanf("%d %d", &N, &K);

    for(i=0; i<N; i++){
        if(num < K)
            num *= 2;
        else
            num += K;
    }

    printf("%d\n", num);

    return 0;
}

Measured memory_bytes: 128
H, W = (int(i) for i in input().split())
S = []
for i in range(H):
	row = input()
	S.append([(0 if row[j]=="." else 1) for j in range(W)])

D = [[10000 for j in range(W)] for i in range(H)]
R = [[False for j in range(W)] for i in range(H)]

N_black = 0
for i in range(H):
	for j in range(W):
		if S[i][j] == 1:
			D[i][j] = -1
			R[i][j] = True
			N_black += 1

def update(i0, j0, i1, j1):
	global D
	center = D[i0][j0]
	adj = D[i1][j1]
	r = R[i1][j1]
	if adj != -1 and r == False and center + 1 < adj:
		D[i1][j1] = center + 1


def check_around(i ,j):
	# UP
	if i != 0:
		update(i, j, i-1, j)
	# LEFT
	if j != 0:
		update(i, j, i, j-1)
	# DOWN
	if i != H-1:
		update(i, j, i+1, j)
	# RIGHT
	if j != W-1:
		update(i, j, i, j+1)

def minimum_point():
	global H, W
	m = 10001
	ni = 0
	nj = 0
	for i in range(H):
		for j in range(W):
			d = D[i][j]
			if d != -1 and R[i][j] == False and d < m:
				m = d
				ni = i
				nj = j
	return (ni, nj)


D[0][0] = 1
R[0][0] = True

pi = 0
pj = 0

for idx in range(W*H):
	check_around(pi, pj)
	pi, pj = minimum_point()
	R[pi][pj] = True

if D[H-1][W-1] == 10000:
	print(-1)
else:
	print(W*H-D[H-1][W-1]-N_black)

Measured memory_bytes: 3192
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mod  = 1e9+7;
ll power(ll x,ll y)
{
	ll ans=1;
	while(y)
	{
		if(y&1) ans = (ans*x)%mod;
		y>>=1;
		x=(x*x)%mod;
	}
	return ans;
}
		
int solve()
{
	ll n;cin>>n;
	vi c(n);
	rep(i,0,n) cin>>c[i];
	sort(c.begin(), c.end(),greater<ll> ());
	ll ans=0;
	rep(i,0,n) ans = (ans + (((i+2)*c[i])%mod))%mod;
	cout<<(ans*power(4,n-1))%mod;
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

using namespace std;

int main(){
   long long int N;
   cin >> N;
   vector<long long int> A(N);
   for(long long int i=0;i<N;i++)cin >> A[i];
   long long int ans=0;
   long long int sum=0;
   for(long long int i=0;i<N;i++){
      if(A[i]){
         sum += A[i];
      }
      else{
         ans += sum/2;
         sum = 0;
      }
   }
   ans += sum/2;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int l = s.length();
		for(int i=l-2;i>1;i-=2) {
			String a = s.substring(0, i/2);
			String b = s.substring(i/2, i);
			if(a.equals(b)) {
				System.out.println(i);
				return;
			}
		}
	}

}

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

using namespace std;

int main(){
  vector<double> heightarray;
  double height;
  while(cin>>height){
    heightarray.push_back(height);
  }
  sort(heightarray.begin(),heightarray.end());
  cout<<-heightarray[0]+heightarray[heightarray.size()-1]<<endl;
}

Measured memory_bytes: 1304
#include <iostream>

using namespace std;

int main(){
	int n , t, n1, t1;
	cin >> n >> t;
	
	int cost = 10000;
	
	for(int  i = 0 ; i < n; i++){
		cin >> n1 >> t1;
		if(cost > n1 && t >= t1){
			cost = n1;
		}
	}
	if(cost == 10000){
		cout << "TLE";
	}	
	else{
		cout << cost;
	}
		
	
	
	
	
	
	
	
}

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

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

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

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

char a, b;


int main(){
	
	cin>>a>>b;
	
	
	if( a == 'H' ) cout<<b<<endl;
	else{
		if( b == 'H' ) puts("D");
		else{		puts("H");}
	}
	
	return 0;

}

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

def get_input() -> str:
    """
    標準入力を取得する.

    Returns:\n
        str: 標準入力
    """
    S = input()

    return S


def main(S: str) -> None:
    """
    メイン処理.

    Args:\n
        S (str): 文字列(|S| = 4, 各文字は"+"または"-")
    """
    # 求解処理
    ans = S.count("+") - S.count("-")

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    S = get_input()

    # メイン処理
    main(S)


Measured memory_bytes: 8948
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	map<string,int> M;
	string S,MS("");
	while(cin>>S){
		M[S]++;
		if(S.size()>MS.size()){
			MS = S;
		}
	}
	
	int num=0;
	for(auto& x:M){
		if(x.second>num){
			S = x.first;
			num = x.second;
		}
	}
	out(S,MS);
	return 0;
}


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

using namespace std;

long long cnt[100010]={0};

int main()
{
    long long n,k,a,b,i;
    scanf("%lld%lld",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld%lld",&a,&b);
        cnt[a]+=b;
    }
    i=0;
    while(k>0){
        i++;
        k-=cnt[i];
    }
    printf("%lld",i);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    long long w, h;
    cin >> w >> h;
    vector<long long> p(w), q(h);
    long long sum = 0;
    for (auto& i : p) cin >> i;
    for (auto& i : q) {
        cin >> i;
        sum += i;
    }
    sort(begin(q), end(q));
    vector<long long> accum = {0};
    partial_sum(begin(q), end(q), back_inserter(accum));
    for (auto& i : p) {
        auto connect = upper_bound(begin(q), end(q), i);
        auto news = distance(begin(q), connect);
        cerr << "news = " << news << endl;
        auto over = accum[news];
        sum += over + (h + 1ll - news) * i;
    }
    cout << sum << endl;
}


Measured memory_bytes: 2936
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)

int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

string IntToString(int number){
  stringstream ss;
  ss << number;
  return ss.str();
}

int main(void){
  int N;
  string s;
  while(cin>>N,N){
    cin>>s;
    rep(i,N){
      string t;
      rep(j,s.size()){
	string p = s.substr(j,1);
	int cnt = 1;
	loop(k,j+1,k<s.size()){
	  j = k ;
	  if(s.substr(k,1)==p)cnt++;
	  else {j--;break;}
	}
	t+=IntToString(cnt)+p;
      }
      s = t;
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 1356
#include <math.h>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> V[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    
    int ans = 0;
    int sum = 0;
    int money = 0;
    for (int bit = 0; bit < (1<<N); bit++) {
        sum = 0;
        money = 0;
        for (int i = 0; i < N; i++) {
            if (bit & (1<<i)) {
                sum += V[i];
                money += C[i];
            }
        }
        ans = max(ans, sum - money);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N){
      cin>>a[i];
      a[i]--;
    }
	int ans = 0;
	rep(i,N){
		if(a[a[i]]==i)ans++;
	}
	ans/=2;
	cout<<ans<<endl;
}


Measured memory_bytes: 640
X = list(map(int,input().split()))
A = X[0]
B = X[1]
C = X[2]
K = int(input())
cnt = 0
if A >= B:
  for i in range(7):
   B = B*2
   cnt = cnt + 1
   if A < B:
    break
if B >= C:
  for j in range(7):
   C = C*2
   cnt = cnt + 1
   if B < C:
    break
if cnt <= K:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int flg = 0;
    int table[n]; rep(i, n) table[i] = 0;
    int a[n]; rep(i, n) {
        cin >> a[i];
        if (a[i] % 2 == 0) flg = 1;
        while (a[i]) {
            if (a[i] % 2 == 0) {
                a[i] /= 2;
                table[i]++;
            } else {
                break;
            }
        }
    }
    if (flg == 0) {
        cout << 0 << endl;
        return 0;
    }
    int sum = 0;
    rep(i, n) sum += table[i];
    cout << sum << endl;
    
}


Measured memory_bytes: 384
#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+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

int main(){
  string s;
  cin >> s;
  bool suc = 0;
  if(s[0] == s[1] && s[1] == s[2]) suc = 1;
  if(s[1] == s[2] && s[2] == s[3]) suc = 1;
  if(suc) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256