akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll e=b-a+1;
    ll f=c*d/__gcd(c,d);
    ll cdiv=e/c;
    ll ddiv=e/d;
    ll fdiv=e/f;
    if(c-a%c+1<=e%c)cdiv++;
    if(d-a%d+1<=e%d)ddiv++;
    if(f-a%f+1<=e%f)fdiv++;
    cout<<e-cdiv-ddiv+fdiv<<endl;

}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, M, C int
	fmt.Scan(&N, &M, &C)
	B := make([]int, M)
	for i := 0; i < M; i++ {
		fmt.Scan(&B[i])
	}
	A := make([][]int, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int, M)
		for j := 0; j < M; j++ {
			fmt.Scan(&A[i][j])
		}
	}

	res := 0
	for i := 0; i < N; i++ {
		cur := C
		for j := 0; j < M; j++ {
			cur += A[i][j] * B[j]
		}
		if cur > 0 {
			res++
		}
	}
	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 512
#include <stdio.h>

struct Tree
{
    int o;
    int left;
    int right;
};

struct Tree T[10000000];

void preorder(int u)
{
    if (u == -1) {
        return;
    }
    else {
        printf(" %d",u);
        preorder(T[u].left);
        preorder(T[u].right);
    }
}

void inorder(int u)
{
    if (u == -1) {
        return;
    }
    else {
        inorder(T[u].left);
        printf(" %d",u);
        inorder(T[u].right);
    }
}

void postorder(int u)
{
    if (u == -1) {
        return;
    }
    else {
        postorder(T[u].left);
        postorder(T[u].right);
        printf(" %d",u);
    }
}

int main() {
    int n;
    int i;
    int o,l,r;
    int start = 0;

    scanf("%d", &n);
    for (i = 0; i < n; ++i){
        T[i].o = -1;
    }
    for (i = 0; i < n; ++i) {
        scanf("%d %d %d", &o, &l, &r);
        T[o].left = l;
        T[o].right = r;
        if (l != -1) T[l].o = o;
        if (r != -1) T[r].o = o;
    }

    for (i = 0;i < n; i++) {
        if (T[i].o == -1){
            start = i;
        }
    }
    printf("Preorder\n");
    preorder(start);
    putchar('\n');
    printf("Inorder\n");
    inorder(start);
    putchar('\n');
    printf("Postorder\n");
    postorder(start);
    putchar('\n');
    return 0;
}


Measured memory_bytes: 1924
import java.util.Scanner;
     
    public class Main{
    	public static void main(String[] args){
    		Scanner scan = new Scanner(System.in);
    		String s = scan.next();
     
    		int length = s.length();
    		int i;
    		for(i = 0; i < length; i++) {
    			System.out.print("x");
    		}
    	}
    }

Measured memory_bytes: 21844
from collections import Counter

n = int(input())
a = Counter([int(i) for i in input().split()])

res = 2 ** (n // 2)
res %= 10**9 + 7

if n % 2 == 1:
    if 0 not in a:
        res = 0
    elif a[0] != 1:
        res = 0
    for i in range(2, n, 2):
        if a[i] != 2:
            res = 0
else:
    for i in range(1, n, 2):
        if a[i] != 2:
            res = 0

print(res)


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

vector<long> lucas(87), memo(87);

long solve(int num){
	if( num == 0 ) return 2L;
	else if( num == 1 ) return 1L;
	else if( memo[num] == 1)return lucas[num];
	else {
		++memo[num];
		lucas[num] = solve(num-1) + solve(num-2);
		return lucas[num];
	}
}

int main() {
	int N; cin >> N;
	cout << solve(N) << endl;
}

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

int main(){

  //initialization
  int a, b;
  int mean;
  int surplus;

  //input
  cin >> a >> b;
  
  //solver
  mean = (a + b) * 5;
  surplus = mean % 10;
  if(surplus >= 5) mean += 10;
  
  mean = (mean -surplus) / 10;
  cout << mean << "\n";
}


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


int main() {
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int x = (a-1) % 10;
  x = min(x,(b-1) % 10);
  x = min(x,(c-1) % 10);
  x = min(x,(d-1) % 10);
  x = min(x,(e-1) % 10);
  int ans = 0;
  ans += ((a+9) / 10) * 10;
  ans += ((b+9) / 10) * 10;
  ans += ((c+9) / 10) * 10;
  ans += ((d+9) / 10) * 10;
  ans += ((e+9) / 10) * 10;
  cout << ans-9+x;
    
  return 0;
}





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

int main() {
	int n,q;
	cin >> n >> q;
	vector<vector<int> >  v(n);

	for (int i = 0; i < q; i++) {
		int c; cin >> c;
		if (c == 0) {
			int x,t;
			cin >> t >> x;
			v[t].push_back(x);
		}
		else if (c == 1) {
			int t;
			cin >> t;
			for (int i = 0; i < v[t].size(); i++) {
				if(i!=0) cout <<" ";
				cout << v[t][i];
			}
			cout << endl;
		}
		else {
			int t; cin >> t;
			v[t].clear();
		}
	}
}
	



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

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

  if (N % 500 == 0) {
    cout << "Yes" << endl;
  }
  else if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632
import heapq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]

heapq.heapify(a)

for _ in range(m):
    temp = heapq.heappop(a)
    temp = -(-temp//2)
    heapq.heappush(a, temp)

print(-sum(a))

Measured memory_bytes: 14180
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
multiset<ll> sl,sr;
ll ans,tl,tr,i,j,k,n,a[200001],b[200001];
ll av(ll x){
	return (x>=0)?x:-x;
}
int main(){
	scanf("%lld",&n);
	for (i=1;i<=n;i++) scanf("%lld%lld",&a[i],&b[i]);
	sl.clear();sr.clear();sl.insert(a[1]);sr.insert(a[1]);
	for (i=2,ans=tl=tr=0;i<=n;i++){
		tl+=b[i]-a[i];tr+=b[i-1]-a[i-1];j=*(sl.rbegin());k=*(sr.begin());
		if (j-tl>a[i]){
			ans+=av(j-tl-a[i]);
			sl.erase(sl.find(j));sl.insert(a[i]+tl);sl.insert(a[i]+tl);sr.insert(j-tl-tr);
		}else if (a[i]>k+tr){
			ans+=av(k+tr-a[i]);
			sr.erase(sr.find(k));sr.insert(a[i]-tr);sr.insert(a[i]-tr);sl.insert(k+tr+tl);
		}else{
			sl.insert(a[i]+tl);sr.insert(a[i]-tr);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if(N < 1200) {
    cout << "ABC" << endl;
  }
    else if (N < 2800) {
      cout << "ARC" << endl;
    }
      else {
        cout << "AGC" << endl;
      }
}

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

int main(){
    long long int n,buf;
    vector<long long int> a;

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>buf;
        a.push_back(buf);
    }

    long long int n_q;
    vector<long long int> q;

    cin>>n_q;
    for(int i=0;i<n_q;i++){
        cin>>buf;
        q.push_back(buf);
    }

    for(int i=0;i<n_q;i++){
        decltype(a)::iterator it=lower_bound(a.begin(),a.end(),q[i]);
    
        if(it!=a.end()){
            size_t pos = distance(a.begin(),it);
            cout<<pos<<endl;
        }
        if(it==a.end() && *it!=a[i]){
            cout<<n<<endl;
        }else if(it==a.end() && *it==a[i]){
            size_t pos = distance(a.begin(),it);
            cout<<pos<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 5680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {

    long long int n;
    cin >> n;

    long long int cnt = 0;
    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        if ( in != i + 1 ) cnt++;
    }

    if ( cnt <= 2 ) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
l, r = map(int, input().split())
m = 2019
if r - l >= 673:
    print(0)
else:
    ans = 2018
    l = l%m
    r = r%m
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, (i*j)%m)
    print(ans)

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll n;
  cin >> n;
  ll a,b,c;
  bool fin = false;
  for(a=1;a<=3500;a++)
  {
    for(b=1;b<=3500;b++)
    {
      ll l = a*b*4;
      ll r1 = n*b;
      ll r2 = n*a;
      ll r3 = n*a*b;
      ll ks = l-r1-r2;
      if(ks == 0) continue;
      if(ks < 0)
      {
        ks *= -1;
        r3 *= -1;
      }
      if(r3 <= 0) continue;
      c = r3/ks;
      if(c > 3500) continue;
      if(c*ks == r3)
      {
        printf("%lld %lld %lld", a,b,c);
        fin = true;
      }
      if(fin) break;
    }
    if(fin) break;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> v;
    int a;
    int tmp = INT_MAX;
    for (int i = 0; i < n; i++){
        std::cin >> a;
        if (a == tmp) continue;
        tmp = a;
        v.push_back(a);
    }
    for (int i = 0; i < v.size(); i++){
        std::cout << v[i];
        if (i < v.size() - 1) std::cout << " ";
    }
    std::cout << std::endl;
}


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

main(){

  ll n,m;
  cin>>n>>m;
  vector<pair<ll,ll>> s;
  rep(i,n){
    ll a;cin>>a;
    s.emplace_back(a,1);
  }
  rep(i,m){
    ll b,c;
    cin>>b>>c;
    s.emplace_back(c,b);
  }

  sort(s.begin(),s.end(),greater<>());
  ll sum=0,card=0,idx=0;
  while(card<n){
    if(card+s[idx].second<=n){
      card+=s[idx].second;
      sum+=s[idx].first*s[idx].second;
    }
    else{
      while(card<n){
        card++;
        sum+=s[idx].first;
      }
    }
    idx++;
  }
  cout<<(sum)<<endl;

}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define pi M_PI

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h + w == 0) return 0;
    else{
      REP(i, h){
        REP(j, w) cout << "#";
        cout << endl;
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 3136
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  ll N;
  while (cin >> N) {
    if (N == 0) {
      cout << "0" << endl;
      continue;
    }
    string res = "";
    while (N != 0) {
      int r = (N % 2 + 2) % 2;
      res += char('0' + r);
      N -= r;
      N /= -2;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }


// const double PI = acos(-1);


int main() {
  int n,k; cin >> n >> k;
  int x = n+1;
  if (x/2 >= k) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;
int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool ok = false;
  for (int i = 0; i < 5000; i++) {
    if (ok) break;
    if (a <= k * i && k * i <= b) ok = true;
  }
  if (ok)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}

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

#define llint long long int

using namespace std;

llint pow5(llint A){
    llint ret = 1;

    for(int i = 0; i < 5; i ++){
        ret *= A;
    }
    return ret;
}
int main(){
    llint X;

    cin >> X;

    for(llint A = -1000; A <= 1000; A ++){
        for(llint B = -1000; B <= 1000; B ++){
            if(pow5(A) - pow5(B) == X){
                cout << A << " " << B << endl;

                return 0;
            }
        }
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<n;i++)
typedef long long ll;
using namespace std;

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

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

ll f(ll x,int c,int d){
	ll res = x;
	res = res - x/c; 
	res = res - x/d;
	res = res + x/lcm(c,d);
	return res;
}


int main(){
	ll a,b;
	int c,d;
	cin >> a >> b >> c >> d;
	ll ans = f(b,c,d) - f(a-1,c,d);
	cout << ans;
	return 0;
}

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

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題163

            string[] line = Console.ReadLine().Split(' ');

            int n = int.Parse(line[0]);
            int m = int.Parse(line[1]);

            string[] line2 = Console.ReadLine().Split(' ');

            int[] a = new int[m];

            int benkyoday = 0;
            for (int i = 0; i < m; i++)
            {
                a[i] = int.Parse(line2[i]);

                benkyoday += a[i];
            }

            if (benkyoday <= n)
            {
                Console.WriteLine(n - benkyoday);
                    
            }
            else
            {
                Console.WriteLine(-1);
            }

            

        }


    }
}


Measured memory_bytes: 28344
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 998244353
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
 
int power(int x,int y,int mod) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}

void solve()
{	
	int n,w;
	cin>>n>>w;
	vector<vector<int>> dp(n+5,vector<int> (w+5));
	vector<ii> inp(n);
	for (int i=0;i<n;i++)
		cin>>inp[i].fi>>inp[i].se;
	for (int i=0;i<n;i++){
		for (int j=w;j>-1;j--){
			if (j-inp[i].fi>=0){
				if (i) dp[i][j] = max(dp[i-1][j],dp[i-1][j-inp[i].fi] + inp[i].se);
				else dp[i][j] = max(dp[i][j],inp[i].se);
			} else dp[i][j] = i ? dp[i-1][j] : 0;
		}
	}
	cout<<dp[n-1][w]<<endl;


}
 
 
signed main(){
	// int t;
	// cin>>t;
	// while (t--)	
	solve();	
 
}
	

Measured memory_bytes: 83328
s=input()
count={}
for i in s:
    count.setdefault(i,0)
    count[i]+=1
l=[count.values()]
if len(count.keys())==2:
    k,l=count.values()
    if k==l==2:
        print('Yes')
    else:
        print('No')        
else:
    print('No')


Measured memory_bytes: 2940
from itertools import product

N, K = map(int, input().split())
kk = K * 2


class CumSum2d(object):
    def __init__(self, H, W):
        self.H, self.W = H, W
        self.tiles = [[0] * W for _ in range(H)]

    def add(self, x, y, c=1):
        self.tiles[y][x] += c

    def build(self):
        for y in range(self.H):
            for x in range(1, self.W):
                self.tiles[y][x] += self.tiles[y][x - 1]
        for y in range(1, self.H):
            for x in range(self.W):
                self.tiles[y][x] += self.tiles[y - 1][x]

    def get(self, sx, sy, tx, ty):
        assert sx <= tx and sy <= ty
        cnt = self.tiles[ty][tx]
        if sx > 0:
            cnt -= self.tiles[ty][sx - 1]
        if sy > 0:
            cnt -= self.tiles[sy - 1][tx]
        if sx > 0 and sy > 0:
            cnt += self.tiles[sy - 1][sx - 1]
        return cnt


cs = CumSum2d(kk, kk)
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'B':
        y += K
    cs.add(x % kk, y % kk)
cs.build()

ans = 0
for x, y in product(range(K), repeat=2):
    cnt = cs.get(x, y, x + K - 1, y + K - 1)
    cnt += cs.get(x + K, y + K, kk - 1, kk - 1)
    if x > 0:
        cnt += cs.get(0, y + K, x - 1, kk - 1)
    if y > 0:
        cnt += cs.get(x + K, 0, kk - 1, y - 1)
    if x > 0 and y > 0:
        cnt += cs.get(0, 0, x - 1, y - 1)
    ans = max(ans, cnt, N - cnt)
print(ans)

Measured memory_bytes: 83292
class UnionFind:
    def __init__(self, n):
        self.ps = [-1] * (n + 1)

    def find(self, x):
        if self.ps[x] < 0:
            return x
        else:
            self.ps[x] = self.find(self.ps[x])
            return self.ps[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.ps[x] > self.ps[y]:
            x, y = y, x
        self.ps[x] += self.ps[y]
        self.ps[y] = x
        return True

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

    def size(self, x):
        x = self.find(x)
        return -self.ps[x]


n, m = map(int, input().split())

uf = UnionFind(n)

for _ in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)

print(min(uf.ps) * -1)

Measured memory_bytes: 14336
red_init, green_init, blue_init = map(int, input().split())
k = int(input())
mn = 10
flag = 0
for s in range(k+1) :
    for t in range(k+1-s) :
        for u in range(k+1-s-t) :
            red = red_init
            green = green_init
            blue = blue_init
            red = red_init * (2**s)
            green = green_init * (2**t)
            blue = blue_init * (2**u)
            if red < green < blue :
                flag = 1
                break
if flag == 1 :
    print("Yes")
else :
    print("No")


Measured memory_bytes: 9216
import math

n,p = map(int,input().split())

tmp = math.sqrt(p)

if n == 1:
    print(p)
elif n >=100:
    print(1)
else:
    for i in range(1,int(tmp)+1):
        if p % (i ** n) == 0:
            ans = i
    print(ans)



        

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
    ll N;
    cin >> N;
    vi X(N);
    REP(i,N) cin >> X[i];
    ll answer = pow(100,3);
    sort(X.begin(),X.end());
    
    ll sum = 0;
    
    FOR(i,X[0],X[N-1]+1){
        REP(j,N){
            sum += pow(i-X[j],2);
        }
        answer = min(answer,sum);
        sum = 0;
    }
    cout << answer << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int N = 2e6 + 10;
const ll mod = 1e9 + 7;
int n, m, k;
ll a[3010][3010];
ll dp[3010][3010][4];
int main() {
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 1; i <= k; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		scanf("%lld", &a[x][y]);
	}
	dp[1][1][0] = 0; if (a[1][1] >= 0)dp[1][1][1] = a[1][1];
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (i == 1 && j == 1)continue;
			dp[i][j][0] = max(dp[i][j][0], dp[i][j - 1][0]);
			for (int x = 0; x <= 3; x++)dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][x]), dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][x] + a[i][j]);
			for (int x = 1; x <= min(j, 3); x++) {
				dp[i][j][x] = max(dp[i][j][x], max(dp[i][j - 1][x], dp[i][j - 1][x - 1] + a[i][j]));
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i <= 3; i++)ans = max(ans, dp[n][m][i]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 356296
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0

from bisect import bisect_left
for i in range(n-2):
    for j in range(i+1,n-1):
        ab = l[i]+l[j]
        idx = bisect_left(l,ab)
        ans += max(0, idx-j-1)
print(ans)

Measured memory_bytes: 9304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,t,a,s_i=0;
    cin >> n >> t>> a;
    double s_h = 10000;
    for(int i=0;i<n;i++){
        int h;
        double te;
        cin >> h;
        te =  t-h*0.006;
        if(abs(s_h-a)>abs(te-a)){
            s_h=te;
            s_i=i;
        }
    }
    cout << s_i+1 <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
  
int main(){
  int n;
  ll c, k;
  cin >> n >> c >> k;
  ll t[n];
  for(int i = 0; i < n; i++) cin >> t[i];
  sort(t, t + n);
  ll first = t[0], sum = 1, cnt = 1;
  for(int i = 1; i < n; i++){
    if(first + k >= t[i] && cnt != c) cnt++;
    else if(first + k >= t[i] && cnt == c){
      first = t[i];
      sum++;
      cnt = 1;
    }else if(first + k < t[i]){
      first = t[i];
      sum++;
      cnt = 1;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1024
n= int(input())
from collections import Counter
S = []
for _ in range(n):
  s = input()
  S.append(s)

c= Counter(S)
ans =[]
maxvalue =0
# print(c.most_common())
for values, counts in c.most_common():
  if maxvalue > counts:
    break
  else:
    maxvalue = counts
  ans.append(values)
  # print(values)
  
for i in sorted(ans):
  print(i)
# print(sorted(ans))

Measured memory_bytes: 120272
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265358979
#define NIL -1
#define MAX 100001

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

struct NODE {
	int parent;
	int left;
	int right;
};

NODE tree[MAX];
int D[MAX];

void print(int u) {
	int i, c;

	cout << "node " << u << ": ";
	cout << "parent = " << tree[u].parent << ", ";
	cout << "depth = " << D[u] << ", ";

	if (tree[u].parent == NIL) {
		cout << "root, ";
	}
	else if (tree[u].left == NIL) {
		cout << "leaf, ";
	}
	else {
		cout << "internal node, ";
	}

	cout << "[";
	for (i = 1, c = tree[u].left; c != NIL; i++, c = tree[c].right) {
		if (i != 1) {
			cout << ", ";
		}
		cout << c;
	}
	cout << "]" << endl;
}

void rec(int u, int p) {
	D[u] = p;
	if (tree[u].left != NIL) {
		rec(tree[u].left, p + 1);
	}
	if (tree[u].right != NIL) {
		rec(tree[u].right, p);
	}
}

int main(void) {
	int n;
	int id, k, c, l, r;

	cin >> n;
	FOR(i, 0, n-1) {
		tree[i].parent = tree[i].left = tree[i].right = NIL;
	}

	FOR(i, 0, n-1) {
		cin >> id >> k;
		FOR(t, 0, k-1) {
			cin >> c;
			if (t == 0) {
				tree[id].left = c;
			}
			else {
				tree[l].right = c;
			}
			l = c;
			tree[c].parent = id;
		}
	}

	FOR(i, 0, n-1) {
		if (tree[i].parent == NIL) {
			r = i;
			break;
		}
	}

	rec(r, 0);

	FOR(i, 0, n-1) {
		print(i);
	}

	return 0;
}


Measured memory_bytes: 4576
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string S;
  cin >> S;
  int r=0;
  char l;
  int c=0;
  for(char s: S){
    if(c==0){
      l=s;
      c++;
    }else if(s==l){
      c++;
    }else{
      c--;
      r += 2;
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

struct P{
	string str;
	int u;
	int v;
};

bool comp(const P& p1, const P& p2)
{
	if(p1.v*p2.u == p1.u*p2.v){
		return p1.str < p2.str;
	}
	return p1.u*p2.v > p1.v*p2.u;
}


int main()
{
	int n, p, a, b, c, d, e, f, s, m;
	P pr[51];
	while(cin>>n && n){
		for(int i = 0; i < n; i++){
			cin >> pr[i].str >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			pr[i].u = f*s*m-p;
			pr[i].v = m*(d+e)+(a+b+c);
		}
		
		sort(pr, pr+n, comp);
		for(int i = 0; i < n; i++){
			cout << pr[i].str << endl;
		}
		cout << "#" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

char souti(char a, char b) {
	return a == 'T' && b == 'F' ? 'F' : 'T';
}

int N;
char P[114514];

int main(void) {
	int i;
	char notomamiko;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		char hoge[4];
		if (scanf("%3s", hoge) != 1) return 1;
		P[i] = hoge[0];
	}
	notomamiko = souti(P[0], P[1]);
	for (i = 2; i < N; i++) {
		notomamiko = souti(notomamiko, P[i]);
	}
	printf("%c\n", notomamiko);
	return 0;
}



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

int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	for(int i = 0;i <= A;i++){
		for(int j = 0;j <= B;j++){
			for(int k = 0;k <= C;k++){
				if(i*500+j*100+k*50 == X){
					count++;
				}
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    double n;
    while (cin >> n) {
        double sum = 0;
        sum += n;
        for (int i = 2; i <= 10; i++) {
            if (i % 2 == 0) {
                n *= 2;
            }
            else {
                n /= 3;
            }
            sum += n;
        }
        printf("%.8f\n", sum);
    }

    return 0;
}

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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5;
int x[N];s64 dp[N],mn[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n,e,t;
	cin>>n>>e>>t;
	rep(i,1,n)scanf("%d",x+i);
	mn[n+1]=1e18;
	int j=n;
	for(int i=n;i;--i)
	{
		while(2*(x[j]-x[i])>t)--j;
		dp[i]=min(dp[j+1]+t,mn[j+1]-2*x[i]);
		mn[i]=min(mn[i+1],dp[i+1]+2*x[i]);
	}
	cout<<dp[1]+e;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin>>n>>k;
    vector<vi> cnt(2*k+1,vi(2*k+1,0));
    vi X(n),Y(n);
    rep(i,n){
        ll x,y; cin>>x>>y;
        char c; cin>>c;
        if (c=='B'){
            X[i] = x%(2*k);
            Y[i] = y%(2*k);
        }else{
            X[i] = (x+k)%(2*k);
            Y[i] = y%(2*k);
        }
        cnt[X[i]][Y[i]]++;
    }
    rep(i,2*k+1)rep(j,2*k)
        cnt[i][j+1]+=cnt[i][j];
    rep(j,2*k+1)rep(i,2*k)
        cnt[i+1][j]+=cnt[i][j];
    // rep(i,2*k+1){
    //     rep(j,2*k+1){
    //         cout<<cnt[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    int ans=0;
    rep(i,k)rep(j,k){
        int A = cnt[i][j];
        int B = cnt[i+k][j+k]-cnt[i][j+k]-cnt[i+k][j]+cnt[i][j];
        int C = cnt[2*k][2*k]-cnt[i+k][2*k]-cnt[2*k][j+k]+cnt[i+k][j+k];
        int D = cnt[i][2*k]-cnt[i][j+k];
        int E = cnt[2*k][j]-cnt[i+k][j];
        int cand = A+B+C+D+E;
        chmax(ans, max(cand,n-cand));
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 16768
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 310000
int a[1100];
int main(){
  int n=in(),m=in();
  rep(i,m)a[i]=in();
  if(m==1){
  cout<<n<<endl;
    if(n==1){
    cout<<1<<endl<<1;return 0;}
  cout<<2<<endl;
  cout<<n-1<<" "<<1;return 0;}
  int cnt=0;
  rep(i,m){
  if(a[i]%2){
  cnt++;}}
  if(cnt>2)cout<<"Impossible";
  else{
    int t=0;
    rep(i,m){
      if(t==0&&a[i]%2){
        swap(a[0],a[i]);
        t++;
      }
      else if(a[i]%2)swap(a[m-1],a[i]);
    }
    rep(i,m)cout<<a[i]<<" ";
    cout<<endl<<(a[0]==1?m-1:m)<<endl;
    if(a[0]-1)cout<<a[0]-1<<" ";
    rep2(i,1,m-2)cout<<a[i]<<" ";
    cout<<a[m-1]+1;
  }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        int N;
        N = sc.nextInt();
        String S;
        S = sc.next();
        solve(N, S);
    }

    static void solve(int N, String S) {
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int[] z = z_algorithm(S.substring(i));
            for (int j = i; j < N; j++) {
                ans = Math.max(ans, Math.min(j - i, z[j - i]));
            }
        }
        System.out.println(ans);

    }

    static int[] search(String pattern, String text) {
        return z_algorithm(pattern + "$" + text);
    }

    static int[] z_algorithm(String S) {
        int l = 0;
        int r = 0;
        int[] Z = new int[S.length()];

        for (int i = 1; i < S.length(); i++) {
            if (r < i) {
                l = r = i;
                while (r < S.length() && S.charAt(r) == S.charAt(r - l)) {
                    r++;
                }
                Z[i] = r - i;
                r--;
            } else {
                int k = i - l;
                if (i + Z[k] - 1 < r) {
                    Z[i] = Z[k];
                } else {
                    l = i;
                    while (r < S.length() && S.charAt(r) == S.charAt(r - l)) {
                        r++;
                    }
                    Z[i] = r - i;
                    r--;
                }
            }
        }
        Z[0] = S.length();
        return Z;
    }
}


Measured memory_bytes: 48048
#include <iostream>

using namespace std;

int N, M;
int pinv[100005];

int parent[200005];
void init(){
	for(int i = 1; i <= 2*N; i++){
		parent[i] = i;
	}
}
int root(int i)
{
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}
bool same(int i, int j)
{
	return root(i) == root(j);
}
void unite(int i, int j)
{
	int rooti = root(i), rootj = root(j);
	if(rooti == rootj) return;
	parent[rooti] = rootj;
}

int main(void)
{
	cin >> N >> M;
	init();
	
	int a, b;
	for(int i = 1; i <= N; i++){
		cin >> a;
		pinv[a] = i;
	}
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		unite(a, b);
	}
	for(int i = 1; i <= N; i++){
		unite(i, N+i);
	}
	
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(same(pinv[i], N+i)) ans++;
	}
	cout << ans << endl;
	
	return 0;
}

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

const int maxi=1e6+5;
ll fac[maxi],inv[maxi],finv[maxi];
void cominit(){
  fac[0]=fac[1]=finv[0]=inv[1]=finv[1]=1;
  for(int i=2;i<maxi;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;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

//a^n.mod
ll powmod(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cominit();
  ll n,m,k;cin>>n>>m>>k;
  ll ans=m*powmod(m-1,n-1)%mod;
  for(int i=1;i<=k;i++){
    ll tmp=m*powmod(m-1,n-1-i)%mod;
    ans+=tmp*com(n-1,i);
    ans%=mod;
  }
  cout<<ans<<endl;
  return 0;
  }


Measured memory_bytes: 27088
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int solve(int a, int n)
{
    if(a == 0){
        if(n == 0)
            return 1;
        return 0;
    }

    int ret = 0;
    for(int i=0; i<=9; ++i)
        ret += solve(a-1, n-i);
    return ret;
}

int main()
{
    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        cout << solve(4, n) << endl;
    }
}

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

namespace ConsoleApp1
{

    class Program
    {

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = new List<int> { };
            var b = new List<int> { };

            for (int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                a.Add(int.Parse(input[0]));
                b.Add(int.Parse(input[1]));
            }

            a.Sort();
            b.Sort();
            int midA = 0;
            int midB = 0;
            int count = 0;
            if (n % 2 == 0)
            {
                midA = a[n / 2 - 1] + a[n / 2];
                midB = b[n / 2 - 1] + b[n / 2];
                count = midB - midA + 1;
            }
            else
            {
                midA = a[(n - 1) / 2];
                midB = b[(n - 1) / 2];
                count = midB - midA + 1;
            }

            Console.WriteLine(count);

        }

    }
}



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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;

bool can[N];
int n, m, cnt[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

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

	//cout << setprecision(10) << fixed;
	
	cin >> n >> m;

	can[1] = 1;

	for (int i = 1; i <= n; i++)
		cnt[i] = 1;

	while (m--) {
		int x, y;
		cin >> x >> y;
		if (can[x]) {
			if (cnt[x] == 1)
				can[x] = 0;
			can[y] = 1;
		}
		cnt[x]--;
		cnt[y]++;
	}

	int ans = 0;

	for (int i = 1; i <= n; i++)
		ans += can[i];

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
        elif x != self.__table[x]:
            self.__table[x] = self.__root(self.__table[x])

        return self.__table[x]

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

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x != y:
            self.__size[y] += self.__size[x]
            self.__table[x] = y

    def size(self, x):
        return self.__size[self.__root(x)]

    def table(self):
        return self.__table


@mt
def slv(N, M, XYZ):
    uf = UnionFind()
    for x, y, _ in XYZ:
        uf.union(x, y)

    t = uf.table()
    ans = len(set(v for k, v in t.items() if k == v))
    for i in range(1, N+1):
        if i not in t:
            ans += 1
    return ans


def main():
    N, M = read_int_n()
    XYZ = [read_int_n() for _ in range(M)]
    print(slv(N, M, XYZ))


if __name__ == '__main__':
    main()


Measured memory_bytes: 47504
#include<stdio.h>
int main()
{
	int a,b,c,x;
	scanf("%d %d %d",&a,&b,&c);
	x=a+b+c;
	if(x>=22){
		printf("bust\n");
	}
	if(x<=21){
		printf("win\n");
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			while(a[i] % 2 == 0) {
				a[i] = a[i] / 2;
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 36196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
ll mo = 1000000007;

int main(){
    ll N;
    cin >> N;
    ll a, b, c;
    a = 10;
    b =  9;
    c = 8;
    rep(_,N-1){
        a = (a * 10) % mo;
        b = (b * 9) % mo;
        c = (c * 8) % mo;
    }
    a = (a + c -b- b) % mo;
    if(a<0)
        a += mo;
    cout << a << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
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; }
#define int long long

void solve() {
    string s, t; cin >> s >> t;
    int n = s.size(), m = t.size();
    s = s + s;
    int nex[200200][26];
    rep(j, 26) nex[2 * n][j] = 2 * n;
    per(i, 2 * n) {
        rep(j, 26) nex[i][j] = nex[i + 1][j];
        nex[i][s[i] - 'a'] = i;
    }
    int cur = 0;
    for(auto v : t) {
        int x = cur % n;
        if(nex[x][v - 'a'] == 2 * n) {
            cout << -1 << endl;
            return;
        }
        cur += nex[x][v - 'a'] - x + 1;
    }
    cout << cur << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 41324
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

int main(){
    int n, m, ans = 0, A[3];
    bool flag = true;
    for(int i = 0; i < 3; i++){
        A[i] = -1;
    }
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int s, c;
        cin >> s >> c;
        if(A[n-s] != -1){
            if(A[n-s] == c) continue;
            flag = false;
            continue;
        }
        A[n-s] = c;
        ans += c * pow(10, n-s);
    }

    if(A[n-1] == 0 && n != 1) cout << -1 << endl;
    else if(flag){
        if(A[n-1] == -1 && n != 1) cout << ans + pow(10, n-1) << endl;
        else cout << ans << endl;
    }
    else cout << -1 << endl;
    

    return 0;
}


Measured memory_bytes: 256
from sys import stdin

class Node(object):
    def __init__(self, parent=None, children=None, name=None, depth=None):
        self.parent = parent
        self.children = children
        self.name = name

class Node(object):
    def __init__(self, parent=None, children=None, name=None, depth=None):
        self.parent = parent
        self.children = children
        self.name = name

def print_nodes(nodes, n):
    def get_depth(nodes, u):
        p = nodes[u].parent
        nonlocal d
        if p != None and p != -1:
            get_depth(nodes, p)
            d += 1
        return d

    for i in range(n):
        d = 0
        if nodes[i].parent == None:
            nodes[i].parent = -1
            nodes[i].name = "root"
        print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format(
               i, nodes[i].parent, get_depth(nodes, i), nodes[i].name, nodes[i].children))

def read_rooted_tree(nodes, n):
    for _ in range(n):
        i = [int(i) for i in stdin.readline().strip().split()]
        c = i[2:len(i)]
        nodes[i[0]].children = c
        if c:
            nodes[i[0]].name = "internal node"
        else:
            nodes[i[0]].name = "leaf"
        for j in nodes[i[0]].children:
            nodes[j].parent = i[0]

n = int(input())
nodes = [Node() for _ in range(n)]
read_rooted_tree(nodes, n)
print_nodes(nodes, n)


Measured memory_bytes: 35712
N=int(input())
g=[[-1]*N for _ in range(N)]
ans=0
for i in range(N):
    A=int(input())
    for _ in range(A):
        x,y=map(int,input().split())
        g[i][x-1]=y
for s in range(2**N):
    flag=1
    for i in range(N):
        if (s>>i&1):
            for j in range(N):
                if g[i][j]!=-1 and (s>>j&1)!=g[i][j]:
                    flag=0
    if flag==1:
        t=0
        x=s
        while x>0:
            t+=x%2
            x//=2
        ans=max(ans,t)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
#define INF 1e+14

ll dp[51][5010];

int main() {
    int N,P; cin >> N >> P;
    vecl A(N);
    int W = 0;
    dp[0][0] = 1;
    REP(i, N)
    {
        cin >> A[i];
        W += A[i];
    }
    REP(i,N) REP(j,W) {
        dp[i+1][j] += dp[i][j];
        if(dp[i][j] != 0)
            dp[i+1][j + A[i]] += dp[i][j];
    }
    ll ans = 0;
    REP(j,W+1) {
        if(j%2 == P)
            ans += dp[N][j];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N;
  cin >> N;
  vector<ll> P(N);
  vector<ll> Q(N);
  rep (i, N) cin >> P[i];
  rep (i, N) cin >> Q[i];
  vector<ll> foo(N);
  rep (i, N) foo[i] = i + 1;

  ll a = 0;
  ll b = 0;
  ll i = 0;
  while (true) {
    if (P == foo) a = i;
    if (Q == foo) b = i;
    if (not next_permutation(foo.begin(), foo.end())) break;
    i++;
  }
  cout << abs(a - b) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

using namespace std;
#define ll long long int

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

	unsigned long long int x,tempa,tempb;
	cin>>x;
	for (int i = 0; i <= 1000; ++i)
	{
		bool flag=false;
		tempa=(ll)(pow(i,5)+0.5);
		if (tempa==x)
		{
			cout<<i<<" "<<0;
			break;
		}
		else{
			for (int j = 1; j <= 1000; ++j)
			{
				tempb=(ll)(pow(j,5)+0.5);
				if(tempa-tempb==x){
					cout<<i<<" "<<j<<endl;
					flag=true;
					break;
				}
				else if(tempa+tempb==x){
					cout<<i<<" "<<-j<<endl;
					flag=true;
					break;
				}
			}
			if(flag)
				break;
		}
	}

	return 0;
}


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

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

    int A, B, C, D; cin >> A >> B >> C >> D;
    cout << max(A*B, C*D) << endl;
}


Measured memory_bytes: 256