akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
	static int res = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] cnt = new int[2];
		String s = sc.nextLine();
		
		for(int i = 0; i < s.length(); i++) {
			cnt[s.charAt(i) - '0']++;
		}
		
		int ans = Math.min(cnt[0], cnt[1]) * 2;
		
		System.out.println(ans);	
	}
}

Measured memory_bytes: 27084
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(N: int, Q: int, a: "List[int]", b: "List[int]", p: "List[int]", x: "List[int]"):
    G = [[] for _ in range(N)]
    for i in range(N-1):
        G[a[i]-1].append(b[i]-1)
        G[b[i]-1].append(a[i]-1)
    w = [0] * N
    for i in range(Q):
        w[p[i]-1] += x[i]
    stack = [0]
    visited = [0] * N
    while len(stack) > 0:
        t = stack.pop()
        visited[t] = 1
        adj = G[t]
        for a in adj:
            if visited[a] == 0:
                stack.append(a)
                w[a] += w[t]
    print(' '.join([str(ww) for ww in w]))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]" 
    x = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        p[i] = int(next(tokens))
        x[i] = int(next(tokens))
    solve(N, Q, a, b, p, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 99556
n = int(input())
S = list(map(int, input().split(' ')))
S.sort()
q = int(input())
T = list(map(int, input().split(' ')))

def binarySearch(key):
  left = 0
  right = n - 1
  mid = (left + right) // 2
  while S[mid] != key:
    if left == right:
      return 0
    if S[mid] > key:
      right = mid
    elif S[mid] < key:
      left = mid + 1
    mid = (left + right) // 2
  return 1
  
count = 0
for t in T:
  count += binarySearch(t)
print(count)


Measured memory_bytes: 16716
s = gets.chomp
if (s.include?("N") && s.include?("S") && !s.include?("E") && !s.include?("W")) || (!s.include?("N") && !s.include?("S") && s.include?("E") && s.include?("W")) || (s.include?("N") && s.include?("S") && s.include?("E") && s.include?("W")) then
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int P[50];
int main(){
  int i, j, k;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(P[Lj4PdHRW]);P[Lj4PdHRW] += (-1);
    }
  }
  k = 0;
  for(i=0;i<N;i++){
    if(P[i]!=i){
      k++;
    }
  }
  if(k <= 2){
    wt_L("YES");
    wt_L('\n');
  }
  else{
    wt_L("NO");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, P[50];
// {
//   int i, j, k;
//   rd(N,(P--)(N));
// 
//   k = 0;
//   rep(i,N) if(P[i]!=i) k++;
//   wt( if[k <= 2, "YES", "NO"] );
// }


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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back

typedef long long LL;
typedef  pair<int,int > PII;

const double PI = acos(-1.0);
//const int INF = 1000 * 1000 * 1000 + 1;
const LL INF = 1e15 + 7;
const int MAS =4e5; //5;
const int MOD = 998244353;
const double EPS = 1e-8;


typedef vector<int > VI;
typedef vector<LL> VL;





struct str  {
    int sol ,val, vag;
};
bool cmp (str a , str b)
{
  return a.vag + a.sol < b.vag + b.sol ;
}
int main() {
    //freopen("sum.in","r",stdin);
    //freopen("sum.out","w",stdout);
    IOS;
     int n;
     cin >> n;
     vector<str> el(n);
     rep(i,n)
     {
         cin >> el[i].vag >> el[i].sol >> el[i].val  ;
     }
     sort(ALL(el),cmp);
  //   reverse(ALL(cmp));
    
     vector<LL > dp ( MAS);
     int mx = 20100 ;
     rep(i,n)
     {
         for(int w= min (el[i].sol , mx - el[i].vag);w >=0 ; w--)
         {
             dp[w  + el[i].vag] = max(dp[w+el[i].vag] ,dp[w]+el[i].val)  ;
         }

     }
     LL ans = 0;
     rep(i,20100)
     {
         ans =max(ans,dp[i]);
     }
     cout << ans << endl;

}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;


int main(){

    string S,T;
    cin >> S >> T;

    map<char,int> mp_s;
    map<char,int> mp_t;


    rep(i,S.size()) mp_s[S[i]]++;
    rep(i,T.size()) mp_t[T[i]]++;
    vector<ll> char_s;
    vector<ll> char_t;
    rep(i,26){
        if(mp_s['a' + i] != 0)  char_s.push_back(mp_s['a' + i]);
    } 
    rep(i,26){
        if(mp_t['a' + i] != 0)  char_t.push_back(mp_t['a' + i]);
    } 
    sort(all(char_s));
    sort(all(char_t));
    rep(i,char_s.size()){
        if(char_s[i] != char_t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3912
h,w = map(int,input().split())
maze = [list(input()) for _ in range(h)]

check = [['.'] * w for _ in range(h)]
check[0][0] = '#'

def dfs(x,y):
  global flag,check
  if x == h-1 and y == w-1:
    flag = True
    return
  if x != h-1 and maze[x+1][y] == '#':
    check[x+1][y] = '#'
    dfs(x+1,y)
    return
  if y != w-1 and maze[x][y+1] == '#':
    check[x][y+1]= '#'
    dfs(x,y+1)
    return
  return
dfs(0,0)
if maze == check:
    print('Possible')
else:
    print('Impossible')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;

struct edge {
    int u, v;
    double cost;
};

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

bool comp(const edge &e1, const edge &e2)
{
    return e1.cost > e2.cost;
}

int N, M;
vector<edge> es;

double kruskal()
{
    sort(es.begin(), es.end(), comp);
    UnionFind uf(N);
    double res = 0;

    for (int i = 0; i < M; i++) {
        edge e = es[i];
        if (!uf.findSet(e.u, e.v)) {
            uf.unionSet(e.u, e.v);
            res += e.cost;
        }
    }

    return res;
}

inline double distance(double x1, double y1, double x2, double y2)
{
    return sqrt(abs(x1 - x2) * abs(x1 - x2) + abs(y1 - y2) * abs(y1 - y2));
}

int main()
{
    int p, q;
    double all_distance = 0.0;

    cin >> N >> M;
    vector<int> x(N), y(N);
    es.resize(M);

    for (int i = 0; i < N; i++)
        cin >> x[i] >> y[i];
    for (int i = 0; i < M; i++) {
        cin >> p >> q;
        p--, q--;

        es[i].u = p;
        es[i].v = q;
        all_distance += es[i].cost = distance(x[p], y[p], x[q], y[q]);
    }
    cout << setprecision(4) << setiosflags(ios::fixed);
    cout << all_distance - kruskal() << endl;
    
    return 0;
}

Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a;
  string op;
  cin >> op;
  cin >> b;
if (op=="+")
{
    cout << a+b << endl;
}
if (op=="-")
{
    /* code */
    cout << a-b << endl;
}


}

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

int main(){
    char s[105];
    int k;
    scanf("%d", &k);
    scanf(" %s", &s);
    for (int i=0; i<k; ++i){
        if (s[i]==(char)0) return 0;
        printf("%c", s[i]);
    }
    if (s[k]!=(char)0) printf("...");
    return 0;
}


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

using namespace std;

int main(){
  int W, a, b;

  cin >> W >> a >> b;

  if(a + W < b){
    cout << b-(a+W)<< endl;
  }else if(b + W < a){
    cout << a-(b+W) << endl;

  }else if(a+W <= b || b + W >= a){
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3572
package main

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

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	K := getInt()
	H := make([]int, N)
	for i := 0; i < N; i++ {
		H[i] = getInt()
	}
	sort.Ints(H)

	ans := 0
	for i := 0; i < N-K; i++ {
		ans += H[i]
	}

	out(ans)
}


Measured memory_bytes: 4736
N = int(input())
# x の y 乗を d で割った余りを求める
def powmod(x, y, d):
    ret = 1
    for _ in range(1, y+1):
        ret = ret * x % d
    return ret
ans = powmod(10, N, 10**9+7) - powmod(9, N, 10**9+7)*2 + powmod(8, N, 10**9+7)

print(ans % (10**9+7))




Measured memory_bytes: 9136
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ll h, w, z = 1e10;
	cin >> h >> w;
	if (h % 3 == 0) z = min(z, (ll)0);
	else z = min(z, w);
	if (w % 3 == 0) z = min(z, (ll)0);
	else z = min(z, h);
	for ( int i = 1 ; i < h ; i++ ) {
		ll a = w * i, b, c;
		if (w % 2 == 0) b = (w / 2) * (h - i), c = (w / 2) * (h - i);
		else b = (w / 2) * (h - i), c = (w / 2 + 1) * (h - i);
		z = min(z, max({a, b, c}) - min({a, b, c}));
	}
	for ( int i = 1 ; i < w ; i++ ) {
		ll a = h * i, b, c;
		if (h % 2 == 0) b = (h / 2) * (w - i), c = (h / 2) * (w - i);
		else b = (h / 2) * (w - i), c = (h / 2 + 1) * (w - i);
		z = min(z, max({a, b, c}) - min({a, b, c}));
	}
	cout << z;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, K, tmp;
	scanf("%d", &K);
	if (K % 2 == 0 || K % 5 == 0) printf("-1\n");
	else {
		for (i = 1, tmp = 7 % K; tmp != 0; i++, tmp = (tmp * 10 + 7) % K);
		printf("%d\n", i);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1700
#include<iostream>
#include<string>
#include<math.h>
#include<iomanip>
using namespace std;


int main(){


  int n;

  cin >> n;

  int *a = new int[n];

  int *b = new int[n];

  int c[10001];

  for(int i = 0; i <= 10000; i++){
    c[i] = 0;
  }

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

  for(int i = 1; i <= 10000; i++){
    c[i] = c[i - 1] + c[i];
  }

  for(int i = n - 1; i >= 0; i--){
    b[c[a[i]] - 1] = a[i];
    c[a[i]]--;
  }

  for(int i = 0; i < n; i++){
    if(i == 0) cout << b[i];
    else cout << ' ' << b[i];
  }
  cout << endl;

  delete[] a, b;
  return 0;
}



Measured memory_bytes: 18332
import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
l = []
for i in range(1, n+1):
    l.append(i)
ll = list(itertools.permutations(l))
for i in range(len(ll)):
    if ll[i] == p:
        pre = i
    if ll[i] == q:
        pos = i
print(abs(pre-pos))

Measured memory_bytes: 45040
#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 = 0; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;

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

	if (n%10 == 9 || n/10 == 9)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


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

using namespace std;

int main()
{
    int N,i,r,w,sum=0,j;
    string s;
    cin>>N>>s;
    r=w=j=0;
    for(i=0; i<s.length(); i++)
    {
        if(s[i]=='W')
            w++;
        else
        {
            r++;
            j=i;
        }
    }
    for(i=0; i<s.length(); i++)
    {
        if(r==0)
            break;
        if(s[i]=='W')
        {
            r--;
            sum++;
        }
        else
            r--;
    }
    cout<<sum<<endl;
    return 0;
}


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

int main(){
  int64_t H, N, sum=0;

  cin >> H >> N;
  for(int i=0; i<N; i++){
    int64_t A; cin >> A;
    sum += A;
  }

  if(sum >= H){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<vector>
#include<string> 
#include<queue>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],ans;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	sort(a,a+3);
	a[0]=a[2]-a[0];
	a[1]=a[2]-a[1];
	if(a[0]%2==a[1]%2)
	{
		ans=(a[0]+a[1])/2;
	}
	else{
		ans=a[0]/2+a[1]/2+2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(float,input().split()))
ans=1000000
count=0
for i in range(n):
  h[i]=t-h[i]*0.006
  b=abs(h[i]-a)
  if ans>b:
    ans=b
    count=i+1
    
print(count)
  

Measured memory_bytes: 3060
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if (a + b + c >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    dp[0] = 0;dp[1] = abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i] = min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, sum, ans;
  cin >> A >> B;
  sum = A + B;
  if(sum == 3){
    ans = 3;
  }
  else if(sum == 4){
    ans = 2;
  }
  else if(sum == 5){
    ans = 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, M;
  string ans;
  string s;

  cin >> s;

  int fl = 0;
  int ct = 0;
  char tmp;
  N = s.size();
  if(s[0] != 'h'){
    cout << "No" << endl;
    return 0;
  }else{
    tmp = s[0];
  }

  if(s[0] == 'h' && N == 1){
    cout << "No" << endl;
    return 0;
  }
  if(N %2 == 1){
    cout << "No" << endl;
    return 0;
  }
  for(int i = 1; i < N; i++){
    if(tmp == 'h' && s[i] == 'i'){
      fl++;
    }else if(tmp == 'i' && s[i] == 'h'){
      fl++;
    }
    tmp = s[i];
  }
  //   if(s[i-1] == 'h' && s[i] != 'i' && ct%2 == 0){
  //     fl++;
  //   }
  //   ct++;
  // }

  // cout << fl << endl;
  if(fl == (s.size() -1)){
    ans = "Yes";
  }else{
    ans = "No";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

const ll mod = 1e9 + 7;

vector<ll> sieve(ll n) {
    vector<bool> is_prime(n+1);
    fill(ALL(is_prime), true);
    is_prime[0] = is_prime[1] = false;
    for (ll j = 4; j <= n; j += 2) {
        is_prime[j] = false;
    }
    vector<ll> prime = {2};
    for (ll i = 3; i <= n; i++) {
        if (is_prime[i]) {
            prime.push_back(i);
            for (int j = i*i; j <= n; j += 2*i) {
                is_prime[j] = false;
            }
        }
    }
    return prime;
}

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

    int N;
    cin >> N;
    vector<ll> prime = sieve(N);
    ll ans = 1;
    for (ll p : prime) {
        int cnt = 0;
        int n = N;
        while (n) {
            cnt += n / p;
            n /= p;
        }
        ans = ans * (cnt + 1) % mod;
    }
    cout << ans << endl;
}

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

int main(){
    string a;
    cin >> a;
    vector<int> vec(100);
    for (int i = 0; i<4; i++){
        vec.at(a.at(i)) += 1;
    }
    int count = 0;
    for (int i = 0; i<100; i++){
        if (vec.at(i) == 2) count++;
    }
    if (count == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define mod 1e9+7
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
 
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(c/b + (c%b !=0) <= a/d + (a%d!=0)) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
//MACROS
#define _crt_secure_no_warnings
#define FREEELO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define INF 0x3F3F3F3F
#define MAX 1000001
#define MOD 1000000007
#define ALPHABET 128
#define loop(i, n) for (int i = 1; i <= (n); i++)
#define loop0(i, n) for (int i = 0; i < (n); i++)
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llll;
typedef pair<int, int> ii;
typedef unordered_map<int, int> umii;
typedef unordered_map<ll, ll> umll;
typedef unordered_set<int> usi;
typedef unordered_multiset<int> usmi;

int main(){
    FREEELO
    string s; cin >> s;
    int sum = 0;
    for (int i = 0; i < sz(s); i++){
        sum += (s[i] - '0');
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;



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

   vector <int> a(0);

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

   int ans=0;
   int now = -1;

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

       if(now != a[i]){
           now = a[i];
       } else {
           ans++;
           now = -1;
       }
   }

   cout<<ans<<endl;
   
    return 0;
}

 



Measured memory_bytes: 256
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


N,M = map(int,input().split())
S = input()
T = input()

c = gcd(N,M)

d = M * (N // c)

a1 = d // N
a2 = d // M

#print(a1,a2)
for i in range(min(N//a2,M//a1)):
    if S[a2*i] != T[a1*i]:
        print(-1)
        exit()

print(d)






Measured memory_bytes: 3316
//#define MYDEBUG
#define _CRT_SECURE_NO_WARNINGS
#define TASK "c1"
#pragma comment(linker, "/STACK:67108864")
#include <cstdio>
#include <iostream>
#include <iomanip> 
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <cassert>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>

const int MOD = 1000000007;
const int INF = 1000000001;
const int MAXN = 400;
const long double EPS = 1e-9;
const int HASH_POW = 29;
const long double PI = acos(-1.0);

using namespace std;

double workTime()
{
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code)
{
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int f[200010], r[200010];

int bin_pow(int a, int n)
{
	int ans = 1;
	while (n)
	{
		if (n & 1)
			ans = ans * 1ll * a % MOD;
		n >>= 1;
		a = a * 1ll * a % MOD;
	}
	return ans;
}

int C(int n, int k)
{
	int ans = f[n];
	ans = ans * 1ll * r[k] % MOD;
	ans = ans * 1ll * r[n - k] % MOD;
	return ans;
}

int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	mt19937 mt_rand(time(0));
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "rt", stdin);
	freopen(TASK".out", "wt", stdout);*/
	/*freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);*/
#endif

	int h, w, a, b;
	scanf("%d %d %d %d", &h, &w, &a, &b);

	f[0] = 1;
	for (int i = 1; i <= 200000; ++i)
		f[i] = i * 1ll * f[i - 1] % MOD;
	for (int i = 0; i <= 200000; ++i)
		r[i] = bin_pow(f[i], MOD - 2);

	int ans = 0;
	for (int i = 1; i <= h - a; ++i)
		ans = (ans + C(b + i - 2, i - 1) * 1ll * C(h - i + w - b - 1, h - i)) % MOD;
	printf("%d\n", ans);

	my_return(0);
}

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

int main(){
	int x,y,z;
	cin >> x>>y>>z;
	
	if(y<z){
	}else{
		swap(y,z);
	}
	if(x<y){
	}else{
		swap(x,y);
	}
	if(y<z){
	}else{
		swap(y,z);
	}
	
	printf("%d %d %d\n",x,y,z);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {

    int n;
    cin >> n;
    int m = 0;
    long tool = 0;
    while (n--) {
        int val;
        cin >> val;
        m = max(m, val);
        if (m > val) tool += m - val;
    }
    cout<<tool;
}

Measured memory_bytes: 3552
#754
s = gets.split('').map(&:to_i)
ans = []
(s.size - 3).times do |i|
	x = 0
	vessel = []
	vessel << s[i]
	vessel << s[i + 1]
	vessel << s[i + 2]
	x = vessel.join.to_i

	ans << (753 - x).abs
end

puts ans.min

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] tmp = br.readLine().split(" ");
		int r = Integer.parseInt(tmp[0]);
		int D = Integer.parseInt(tmp[1]);
		long x = Integer.parseInt(tmp[2]);

		for(int i = 1;i<=10;i++){
			x = r*x - D;
			System.out.println(x);
		}
	}
}


Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
int add(int x, int y) {
	x += y;
	if (x >= mod) {
		x -= mod;
	}
	return x;
}
int sub(int x, int y) {
	x -= y;
	if (x < 0) {
		x += mod;
	}
	return x;
}
int mult(int x, int y) {
	return 1ll * x * y % mod;
}
int bin_pow(int x, int y) {
	if (y == 0) {
		return 1;
	}
	if (y % 2 == 0) {
		return bin_pow(mult(x, x), y / 2);
	}
	return mult(x, bin_pow(x, y - 1));
}
int inv(int x) {
	return bin_pow(x, mod - 2);
}
const int maxn = 1e6;
vector<int> fact(maxn), inv_fact(maxn);
int C(int x, int y) {
	return mult(mult(fact[x], inv_fact[x - y]), inv_fact[y]);
}
int A(int x, int y) {
	return mult(fact[x], inv_fact[x - y]);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, m;
	cin >> n >> m;
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i < maxn; ++i) {
		fact[i] = mult(fact[i - 1], i);
		inv_fact[i] = inv(fact[i]);
	}
	debug(fact[0]);
	int answer = 0;
	for (int i = 0; i <= n; ++i) {
		int cur = mult(mult(C(n, i), A(m, i)), mult(A(m - i, n - i), A(m - i, n - i)));
		if (i % 2 == 0) {
			answer = add(answer, cur);
		} else {
			answer = sub(answer, cur);
		}
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 10968
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;
vector<ll> A;

void input() {
  cin >>N;
  A.assign(N, 0); rep(i, N) cin >>A[i];
}

int main() {
  input();
  ll sum = 0;
  vector<ll> Asum(N+1, 0);
  rep(i, N){
    sum += A[i];
    Asum[i+1] = Asum[i] + A[i*2 % N];
  }
  ll res;
  rep(i, N){
    if (i%2 == 0){
      // 0 ... 4 ... 8 := all - (0-3) - (5-8)
      //  = all - Asum[i/2]*2 - (all - Asum[N/2+1+i/2])*2
      //  = Asum[N/2+1+i/2]*2 - Asum[i/2]*2 - all
      res = Asum[N/2+1+i/2]*2 - Asum[i/2]*2 - sum;
    }else{
      // 0 ... 5 ... 8
      // res = 4
      // (res - (4,5)) * (-1)
      res = res - 2 * A[i-1];
      res *= -1;

    }
    cout <<res;
    if (i == N-1) cout <<endl;
    else cout <<" ";
  }
}


Measured memory_bytes: 2944
#include<iostream>

using namespace std;

int main(){
  int A;
  int B;
  cin >> A >>B;
  if(A < 1 || A > 3 || B < 1 || B > 3){
return 0;
  }
  else if(A == 2 || B == 2){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
       while(true){
           int m = scan.nextInt();
           int f = scan.nextInt();
           int r = scan.nextInt();
           if(m == -1 && f == -1 && r == -1)break;

           if(m == -1 || f == -1){
            System.out.println("F");
            continue;
           }
           if(m+f >= 80){
            System.out.println("A");
            continue;
            }
            if(m+f >= 65){
                System.out.println("B");
                continue;
            }
            if(m+f >= 50){
                System.out.println("C");
                continue;
            }
            if(m+f >= 30){
                if(r >= 50)System.out.println("C");
                else System.out.println("D");
                continue;
            }
            System.out.println("F");

            
       }
       scan.close();
    }
}


Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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++)

/*void find(int T[], int A[], ll TT[], ll AA[], int i) {
  int j = 2;
  while(1) {
    if (T[i] < TT[i-1] || A[i] < AA[i-1]) {
      T[i] *= j; A[i] *= j++;
    }
  }
  TT[i] = T[i]; AA[i] = A[i];
}*/
int main(void) {
  int n; cin >> n;
  int T[n], A[n];
  rep(i,n) {cin >> T[i] >> A[i];}
  ll TT[n],AA[n]; //実際の数値
  TT[0] = T[0]; AA[0] = A[0];

  rep2(i,1,n) {
    ll j, k;
    /*
        int j = 1;
      while(1) {
        if (T[i] * j < TT[i-1] || A[i] * j < AA[i-1]) {
          j++;
        } else {
          break;
        }
      }
      TT[i] = T[i]*j; AA[i] = A[i]*j;
      */
      //cout << TT[i] << " " << AA[i] << endl;
      if(TT[i-1] % T[i] == 0) j = TT[i-1] / T[i];
      else j = TT[i-1] / T[i] + 1;
      if(AA[i-1] % A[i] == 0) k = AA[i-1] / A[i];
      else k = AA[i-1] / A[i] + 1;
      TT[i] = T[i] * max(j, k);
      AA[i] = A[i] * max(j, k);
  }
  cout << TT[n-1]+AA[n-1] << endl;

}

Measured memory_bytes: 3628
/********** BiSmIlLaHiR rAhMaNiR rAhIm ***********\
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
\*************** DIIT(17th batch) ****************/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define endl "\n"
#define pb push_back
#define makep make_pair
#define MOD 1000000007
#define PI acos(-1.0)
#define PII pair<string , ll> 
#define SIZE 1000005
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
ll fx[]={1,0,-1,0,-1,-1,1,1};
ll fy[]={0,1,0,-1,-1,1,-1,1};

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    fio();
    ll n,m,i,num;
    cin>>n>>m;
    map<ll,ll>mp,mp1;
    for(i=1;i<=1250;i++)
    {
        num=(double)(i)*0.08;
        if(num==n)
            mp[i]++;
    }
    for(i=1;i<=1250;i++)
    {
        num=(double)(i)*0.1;
        if(num==m)
            mp1[i]++;
    }
    ll ans;
    bool ok=false;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(mp1[it->first]>0)
        {
            ok=true;
            ans=it->first;
            break;
        }
    }
    if(ok)
        cout<<ans<<endl;
    else
        cout<<-1<<endl;
    return 0;
}
// ! () &

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int q = int.Parse(str[1]);
        var queue = new PriorityQueue<int>[n];
        for(int i=0; i<n; i++){
            queue[i] = new PriorityQueue<int>();
        }
        for(int i=0; i<q; i++){
            int[] line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            switch(line[0]){
                case 0:
                    queue[line[1]].Enqueue(line[2]);
                    break;
                case 1:
                    if(queue[line[1]].Count != 0){
                        Console.WriteLine(queue[line[1]].Peek());
                    }
                    break;
                case 2:
                    if(queue[line[1]].Count != 0){
                        queue[line[1]].Dequeue();
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
public class PriorityQueue<T> { //: IEnumerable<T>{
    private readonly List<T> _data = new List<T>();
    private readonly IComparer<T> _comparer;
    private readonly bool _isDecending;
    public PriorityQueue(IComparer<T> comparer, bool isDecending = true){
        _comparer = comparer;
        _isDecending = isDecending;
    }
    public PriorityQueue(Comparison<T> comparision, bool isDecending = true)
        : this(Comparer<T>.Create(comparision), isDecending){
    }
    public PriorityQueue(bool isDecending = true)
        : this(Comparer<T>.Default, isDecending){
    }

    public void Enqueue(T item){
        int left = 0;
        int right = _data.Count;
        while(left < right){
            int mid = (left + right)/2;
            if(Compare(_data[mid], item) < 0){
                left = mid+1;
            }
            else{
                right = mid;
            }
        }
        _data.Insert(left, item);
    }

    public T Dequeue(){
        T ret = _data[0];
        _data.RemoveAt(0);
        return ret;
    }

    public T Peek(){
        return _data[0];
    }

    public int Count => _data.Count;

    public void PrintQueue(){
        Console.WriteLine(string.Join(" ",_data));
    }

    private int Compare(T a, T b){
        return _isDecending ? _comparer.Compare(b,a) : _comparer.Compare(a,b);
    }
}



Measured memory_bytes: 27676
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		int num = i;
		int sum = 0;
		while (num > 0)
		{
			sum += num % 10;
			num /= 10;
		}
		if (a <= sum && sum <= b)
			ans += i;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	int n;
	string ans;
	cin >> n;

	bool flag = false;
	for(int i = 1; i < 10; i++){
		if(n%i == 0 && n/i < 10)flag = true;
	}
	ans = (flag)? "Yes": "No";
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	string s,t;
	cin>>s>>t;
	int cnt=0;
	REP(i,3){
		if(s[i]==t[i])cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

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

  string s;

  cin >> s;

  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
}

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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  rep(i, n) cin >> x[i] >> y[i] >> h[i];

  rep(cx, 101) rep(cy, 101) {
    vector<tuple<ll, ll, ll>> cand;
    rep(i, n) {
      if (h[i] <= 0) continue;
      ll H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
      cand.emplace_back(cx, cy, H);
    }

    rep(i, cand.size()) {
      bool flag = true;
      ll cx = get<0>(cand[i]), cy = get<1>(cand[i]), H = get<2>(cand[i]);
      rep(j, n) {
        ll hh = max(H - abs(x[j] - cx) - abs(y[j] - cy), 0LL);
        flag &= (hh == h[j]);
      }
      if (flag) {
        cout << cx << " " << cy << " " << H << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3568
import math

while True:
    n = int(input())
    if n == 0:
        break
    point = list(map(int, input().split()))
    ave = sum(point)/n
    p_list = [(x-ave)**2 for x in point]
    stdv = math.sqrt(sum(p_list) / n)
    print('{:.8f}'.format(stdv))



Measured memory_bytes: 5712
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

int main() {
  uint32_t N, M;
  cin >> N >> M;
  priority_queue<uint32_t> Que;
  uint32_t tmp;
  for (uint32_t i = 0; i < N; ++i) {
    cin >> tmp;
    Que.push(tmp);
  }
  for (uint32_t i = 0; i < M; ++i) {
    tmp = Que.top();
    Que.pop();
    tmp >>= 1;
    Que.push(tmp);
  }
  uint64_t res = 0;
  for (uint32_t i = 0; i < N; ++i) {
    tmp = Que.top();
    Que.pop();
    res += tmp;
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<cmath>
using namespace std;
long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}
int main(){
	long long n,p,x,g=0,k=0,sum=0,kazu,kazu2;
	cin >> n >> p;
	for(int i=0;i<n;i++){
		cin >> x;
		if(x%2==0)	g++;
		else k++;
	}
	for(int i=1;i<=k;i+=2)	sum+=combi(k,i);
	kazu2 = pow(2,k);
	kazu = pow(2,g);
	if(p)
		cout << kazu*sum << endl;
	else
		cout << kazu*(kazu2-sum) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    int ans[n-1];
    for(int i = 0; i < n-1; i++){
        ans[i] = n-1-i;
    }
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            if(abs(x-i) + 1 + abs(y-j) < j - i){
                ans[j-i-1]--;
                ans[abs(x-i) + 1 + abs(y-j)-1]++;
            }
        }
    }
    for(int i = 0; i < n-1; i++)cout << ans[i] << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int h,w,i,j;
	for(;;){
		scanf("%d%d",&h,&w);
		if(h<1&&w<1)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++)printf("%s",i!=0&&i!=h-1&&j!=0&&j!=w-1?".":"#");
			puts("");
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	k--;
	string s; cin >> s;
	if (s[k] == 'A')s[k] = 'a';
	else if (s[k] == 'B')s[k] = 'b';
	else s[k] = 'c';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define long long long long
using namespace std;
long long n,i,j,rt,cnt,l[200005],r[200005],sz[200005],rnd[200005];
long long ans,m,a[200005],val[200005];
long long nwnd(long long x)
{
	cnt++;
	l[cnt]=r[cnt]=0;
	sz[cnt]=1;val[cnt]=x;rnd[cnt]=rand()*32768+rand();
	return cnt;
}
void pushup(long long x)
{
	sz[x]=1+sz[l[x]]+sz[r[x]];
}
void split(long long x,long long y,long long &sl,long long &sr)
{
	if (!x)
	{
		sl=sr=0;
		return;
	}
	if (val[x]<=y)
	{
		split(r[x],y,r[x],sr);
		sl=x;
		pushup(x);
		return;
	}
	else
	{
		split(l[x],y,sl,l[x]);
		sr=x;
		pushup(x);
		return;
	}
}
long long merge(long long x,long long y)
{
	if (!x||!y) return x+y;
	if (rnd[x]>rnd[y])
	{
		r[x]=merge(r[x],y);
		pushup(x);
		return x;
	}
	else
	{
		l[y]=merge(x,l[y]);
		pushup(y);
		return y;
	}
}
int main()
{
	cin>>n>>m;
	fz1(i,n)
	{
		cin>>a[i];
		a[i]-=m;
		a[i]+=a[i-1];
	}
	rt=nwnd(0);
	fz1(i,n)
	{
		long long t1,t2;
		split(rt,a[i],t1,t2);
		ans+=sz[t1];
		rt=merge(merge(t1,nwnd(a[i])),t2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    ll H,N;
    cin >> H >> N;
    vector<ll> A(N);
    REP(i,N)cin >> A[i];
    REP(i,N)H-=A[i];
    if(H<=0){
        cout <<"Yes"<< "\n";
    }else{
        cout <<"No"<<"\n";
    }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N;
string S;

int main(){
	cin >> N >> S;
	int t = 0, MIN = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] == '(')++t;
		else --t;
		MIN = min(MIN, t);
	}
	for (int i = 0; i < -MIN; ++i) {
		cout << '(';
	}
	cout << S;
	for (int i = 0; i < t - MIN; ++i) {
		cout << ')';
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 384
n,m,d=map(int,input().split())
s=[]
for i in range(n):
   s.append(list(input()))
count=0
for i in range(n):
    for j in range(m):
        if s[i][j]==".":
            for k in range(1,d):
                if j+d>m:
                    break
                elif s[i][j+k]=="#":
                    break
            else:
                count+=1
for j in range(m):
    for i in range(n):
        if s[i][j]==".":
            for k in range(1,d):
                if i+d>n:
                    break
                elif s[i+k][j]=="#":
                    break
            else:
                count+=1             
    
print(count)
    



Measured memory_bytes: 5640
function main(input) {
  var inputArray = input.split(' ').map(item => Number(item));
  var r = inputArray[0];
  var D = inputArray[1];
  var x2000 = inputArray[2];
  var result = [x2000];
  for (var i = 0; i < 10; i++) {
    result.push(r * result[i] - D);
  }
  result.shift();
  result.forEach(item => {
    console.log(item);
  });
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628