akhauriyash/Code-Regression huggingface dataset:
n=int(input())
#l=[int(input()) for i in range(n)]
l=[]
mydic={}
for i in range(n) :
  s=int(input())
  l.append(s)
  if not s in mydic.keys() :
    mydic[s]=1
  else :
    mydic[s]=mydic[s]+1
l2=sorted(l,reverse=True)
#print(l)
#print(mydic)
mx=l2[0]
for i in range(n) :
  if l[i]==mx :
    if mydic[mx]==1 :
      print(l2[1])
    else:
      print(mx)
  else :
    print(mx)

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

using i64 = long long;
using P = pair<i64, i64>;

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> A){
    vector<vector<i64>> wa(N + 1, vector<i64>(60, 0));
    i64 n = N;
    vector<i64> a = A;
    for(int i = 0; i < n; ++i){
        for(i64 j = 0; j < 60; ++j){
            wa[i + 1][j] = wa[i][j];
            if(a[i] & ((1LL)<<j)) wa[i + 1][j]++;
        }
    }
    i64 ans = 0;
    for(int i = 0; i < n - 1; ++i){
        i64 b = 1;
        for(int j = 0; j < 60; ++j){
            if(a[i] & ((1LL)<<j)) ans = (ans + (b * (n - i - 1 - wa[n][j] + wa[i + 1][j]) % MOD)) % MOD;
            else ans = (ans + (b * (wa[n][j] - wa[i + 1][j]) % MOD)) % MOD;
            b = b * 2 % MOD;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 157312
#include <stdio.h>

void add_BIT(int N, int BIT[], int i, int k)
{
	while (i <= N) {
		BIT[i] += k;
		i += (i & -i);
	}
}

int sum_BIT(int BIT[], int r)
{
	int sum = 0;
	while (r > 0) {
		sum += BIT[r];
		r -= (r & -r);
	}
	return sum;
}

int main()
{
	int i, N, a, pos[2][2001];
	char c;
	scanf("%d", &N);
	for (i = 1; i <= N * 2; i++) {
		scanf(" %c %d", &c, &a);
		if (c == 'B') pos[0][a] = i;
		else pos[1][a] = i;
	}
	
	const int sup = 1 << 30;
	int j, BIT[4001] = {}, dp[2001][2001];
	for (i = 0; i <= N; i++) for (j = 0; j <= N; j++) dp[i][j] = sup;
	for (i = 0, dp[0][0] = 0; i < N; i++) {
		for (j = 1; j <= i; j++) add_BIT(N * 2, BIT, pos[0][j], 1);
		for (j = 0; j < N; j++) {
			if (dp[i][j] + pos[0][i+1] - sum_BIT(BIT, pos[0][i+1]) - 1 < dp[i+1][j]) dp[i+1][j] = dp[i][j] + pos[0][i+1] - sum_BIT(BIT, pos[0][i+1]) - 1;
			if (dp[i][j] + pos[1][j+1] - sum_BIT(BIT, pos[1][j+1]) - 1 < dp[i][j+1]) dp[i][j+1] = dp[i][j] + pos[1][j+1] - sum_BIT(BIT, pos[1][j+1]) - 1;
			add_BIT(N * 2, BIT, pos[1][j+1], 1);
		}
		if (dp[i][N] + pos[0][i+1] - sum_BIT(BIT, pos[0][i+1]) - 1 < dp[i+1][N]) dp[i+1][N] = dp[i][N] + pos[0][i+1] - sum_BIT(BIT, pos[0][i+1]) - 1;
		for (j = 1; j <= N * 2; j++) BIT[j] = 0;
	}
	for (i = 1; i <= N; i++) add_BIT(N * 2, BIT, pos[0][i], 1);
	for (j = 0; j < N; j++) {
		if (dp[N][j] + pos[1][j+1] - sum_BIT(BIT, pos[1][j+1]) - 1 < dp[N][j+1]) dp[N][j+1] = dp[N][j] + pos[1][j+1] - sum_BIT(BIT, pos[1][j+1]) - 1;
		add_BIT(N * 2, BIT, pos[1][j+1], 1);
	}
	printf("%d\n", dp[N][N]);
	fflush(stdout);
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(1 <= a && a <= 9 && 1 <= b && b <= 9){
    cout << a * b << '\n';
    return 0;
  }
  cout << -1 << '\n';
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, M = map(int, sys.stdin.readline().rstrip().split(" "))
Lmax, Rmin = 0, N
for _ in range(M):
    L, R = map(int, sys.stdin.readline().rstrip().split(" "))
    Lmax = max(L, Lmax)
    Rmin = min(R, Rmin)
if Rmin >= Lmax:
    print(Rmin - Lmax + 1)
else:
    print(0)
exit(0)

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

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

using namespace std;

int main(){
	int n; cin>>n;
	vector<int> a(n),p(n),q(n);
	iota(a.begin(),a.end(),1);
	rep(i,n) cin>>p[i];
	rep(i,n) cin>>q[i];

	int cnt=0,res1,res2;
	do{
		if(a==p) res1=cnt;
		if(a==q) res2=cnt;
		cnt++;
	}while(next_permutation(a.begin(),a.end()));
	cout<<abs(res1-res2)<<'\n';

	return 0;
}


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

int main() {
    int n, result = 0;
    cin >> n;
    string s[n];
    for (int i = 0; cin >> s[i]; i++) {
    }
    for (int b = 0; b < n; b++) {
        bool symetric = true;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (s[i][(j + b) % n] != s[j][(i + b) % n]) {
                    symetric = false;
                }
            }
        }
        if (symetric) {
            result++;
        }
    }
    cout << result * n;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]d = new int[n];

    int all = 0;
    int hiku = 0;
    for(int i=0; i<n; i++) {
    	d[i] = sc.nextInt();
    	hiku += d[i]*d[i];		
    }
    for(int i=0; i<n; i++) {
    for(int j=0; j<n; j++) {	
    	all += d[i]*d[j];
    }
    }
    	System.out.println((all-hiku)/2);
      }
}

Measured memory_bytes: 35816
#include <iostream>

int main(int argc, char const* argv[])
{
    int dp[35] = {0};



    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 1;

    for (int i = 1; i < 31; i++) {
        if(i >= 1) dp[i] += dp[i-1];
        if(i >= 2) dp[i] += dp[i-2];
        if(i >= 3) dp[i] += dp[i-3];
    }

    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) break;

        int year = 0;
        year = dp[n-1] / 3650;
        if ((dp[n-1] % 3650) > 0) year +=1;
        std::cout << year << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1160
n,m = map(int,input().split())
a = []
for i in range(m):
  a.append(int(input()))
c = [0]*(n+1)
c[0] = 1
j  = 0
for i in range(1,n+1):
  if j < m and a[j] == i:
    j += 1
  elif i == 1:
    c[i] = 1
  else:
    c[i] = c[i-1]+c[i-2]
print(c[-1]%(10**9+7))

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


int main()
{
  int N, count = 0;
  cin >> N;

  for (int i = 0; i < 27; i++)
  {
    for (int k = 0; k < 15; k++)
    {
      if(N == 4 * i + 7 * k){
        ++count;
      }
    }
  }
  if(count > 0){
    cout << "Yes" << endl;
  }else if(count == 0){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

template <std::uint_fast64_t Modulus>
class modint {
  using u64 = std::uint_fast64_t;

 public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  using mint = modint<MOD>;

  cin >> x >> y;
  if ((x + y) % 3 != 0)
    Cout(0);
  else {
    cnt = x + y;
    cnt /= 3;
    tmp = -1;
    rep(i, cnt + 1) {
      ll nowx = 2 * i;
      nowx += (cnt - i);
      if (nowx == x) {
        tmp = i;
        break;
      }
    }
    if (tmp == -1) {
      Cout(0);
      return 0;
    }
    mint ans = mint(1);
    rrep(i, 1, cnt + 1) { ans *= i; }
    rrep(i, 1, tmp + 1) { ans /= i; }
    rrep(i, 1, cnt - tmp + 1) { ans /= i; }
    Cout(ans.value());
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> c(8, 0);
    int god = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (1 <= a && a <= 399) c[0] = 1;
        if (400 <= a && a <= 799) c[1] = 1;
        if (800 <= a && a <= 1199) c[2] = 1;
        if (1200 <= a && a <= 1599) c[3] = 1;
        if (1600 <= a && a <= 1999) c[4] = 1;
        if (2000 <= a && a <= 2399) c[5] = 1;
        if (2400 <= a && a <= 2799) c[6] = 1;
        if (2800 <= a && a <= 3199) c[7] = 1;
        if (a >= 3200) god++;
    }
    int ans = 0;
    for (int i = 0; i < 8; i++) ans += c[i];
    cout << max(ans, 1) << " " << ans + god << endl;
    return 0;
}

Measured memory_bytes: 256
S = int(input())
l = len(str(S)) #Sの桁数
li = list(str(S))

S_a = l - 1 #あいだの個数

result = S

for i in range(1, 2**S_a):
  L = list(bin(i))
  del L[0:2]
  while len(L) < S_a:
    L.insert(0, "0")
#  print(L)
  indexes = [i for i, x in enumerate(L) if x == "1"]
#  print(indexes)
  li2 = li.copy()
  for j in indexes:
    li2[j] += "+"
#  print(li2)
  result += eval("".join(li2))
  
#  print("--------------")

print(result)


Measured memory_bytes: 3064
#include<cstdio>
#include<cctype>
#include<cstring>
#define For(i,j,k) for(int i=j;i<=k;i++)
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
using namespace std;
int main(){
	char ch[1005],l; scanf("%s",ch+1); l=strlen(ch+1);
	For(i,1,l-8) printf("%c",ch[i]);
	return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)
from collections import deque
from heapq import heappush, heappop
def solve():
    H,W = map(int, input().split())
    A = [ list(input()) for _ in range(H)]
    HMANY = [ [10**9] * W for _ in range(H)]

    
    
    # q = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == "#" :
                HMANY[h][w] = 0
    for w in range(W):
        for h in range(H-1):
            if HMANY[h][w]+1 < HMANY[h+1][w]:
                HMANY[h+1][w] = HMANY[h][w] + 1
        for h in range(H-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h-1][w]:
                HMANY[h-1][w] = HMANY[h][w] + 1
    
    for h in range(H):
        for w in range(W-1):
            if HMANY[h][w]+1 < HMANY[h][w+1]:
                HMANY[h][w+1] = HMANY[h][w] + 1
        for w in range(W-1, 0, -1):
            if HMANY[h][w]+1 < HMANY[h][w-1]:
                HMANY[h][w-1] = HMANY[h][w] + 1        
    #             q.append((h,w))
    #             A[h][w] = "."
    # ans = 0
    # while q:
    #     nextQ = deque()
    #     for h,w in q:
    #         A[h][w] = "#"
    #         if h+1 <H and A[h+1][w] == ".":
    #             nextQ.append( (h+1,w))
    #         if w+1 <W and A[h][w+1] == ".":
    #             nextQ.append((h,w+1))
    #         if 0<=h-1 and A[h-1][w] == ".":
    #             nextQ.append((h-1,w))
    #         if 0<=w-1 and A[h][w-1] == ".":
    #             nextQ.append((h,w-1))        
    #     ans += 1
    #     q = nextQ
        # num,h,w = q.popleft()        
        # if HMANY[h][w] > num and A[h][w] == ".":
        #     HMANY[h][w] = num
        #     A[h][w] = "#"
        #     if h+1 <H and A[h+1][w] == ".":
        #         q.append( (num+1,h+1,w))
        #     if w+1 <W and A[h][w+1] == ".":
        #         q.append((num+1,h,w+1))
        #     if 0<=h-1 and A[h-1][w] == ".":
        #         q.append((num+1,h-1,w))
        #     if 0<=w-1 and A[h][w-1] == ".":
        #         q.append((num+1,h,w-1))

    ans = 0
    for h in range(H):
        ans = max(ans, max(HMANY[h]))
    # print(ans-1)
    print(ans)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 90096
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

int n, r;
int sum[2][10010];
bool a[2][10010];
vector<pair<int, pi> > q;

int main(){
	while(cin >> n >> r, n){
		memset(a, 0, sizeof(a));
		memset(sum, 0, sizeof(sum));
		q.clear();
		
		rep(i, n){
			int x, y, X, Y;
			cin >> x >> y >> X >> Y;
			q.pb(mp(y, mp(x, 1)));
			q.pb(mp(y, mp(X, -1)));
			q.pb(mp(Y, mp(x, -1)));
			q.pb(mp(Y, mp(X, 1)));
		}
		sort(all(q));
		int cur = 0, next = 1, ii = 0;
		int area = 0, per = 0;
		
		rep(i, 10005){
			memset(a[cur], 0, sizeof(a[cur]));
			
			for(; ii < q.size() && q[ii].first == i; ii++){
				sum[cur][q[ii].second.first] += q[ii].second.second;
			}
			rep(j, 10005) sum[next][j] = sum[cur][j];
			rep(j, 10005){
				sum[cur][j + 1] += sum[cur][j];
				a[cur][j + 1] = sum[cur][j] > 0;
			}
			rep(j, 10005){
				if(a[cur][j]) area++;
				rep(d, 2){
					int ny = d ? cur : next, nx = d ? j + 1 : j;
					if(a[cur][j] != a[ny][nx]) per++;
				}
			}
			swap(cur, next);
		}
		cout << area << endl;
		if(r == 2) cout << per << endl;
	}
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int a = sc.nextInt();
        out.println(a + a * a + a*a*a);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32796
from math import atan,atan2,degrees

a, b ,x = map(int ,input().split())

# 半分より多いとき
if a * a * b / 2 < x:
  print(degrees(atan(2*b/a -2*x/(a*a*a))))
else:
  # 半分より少ないとき
  print(90-degrees(atan(2*x/(a*b*b))))


Measured memory_bytes: 2940
package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scan(&n)
	fmt.Scan(&a)
	fmt.Scan(&b)

	if a * n < b {
		fmt.Println(a*n)
	} else {
		fmt.Println(b)
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
#define MOD 1000000007
vector <ll> g[10];
ll visited[10];
int main(){
    ll x;
    cin >> x;
    ll ans=0;
    ans+=(x-1)/11*2;
    if((x-1)%11>=6)ans+=2;else ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
   
int main()
{
	char nc;
	int ni=0;
		scanf("%c", &nc);
		while(1) {
			ni += ((int)nc)-48;
			if(nc=='\n'){
				ni += 38;
				printf("%d\n", ni);
				ni = 0;
				scanf("%c", &nc);
				if(nc=='0')
					break;
			}
			else
				scanf("%c", &nc);
		}
	return 0;
}

Measured memory_bytes: 3204
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <unordered_map>
using namespace std;


vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

bool compare_by_b(tuple<int, string, int> a, tuple<int, string, int> b) {
    if(get<2>(a) != get<2>(b)){
        return get<2>(a) > get<2>(b);
    }
}

bool compare_by_string(tuple<int, string, int> a, tuple<int, string, int> b) {
    if(get<1>(a) != get<1>(b)){
        return get<1>(a) < get<1>(b);
    }else{
      	return get<2>(a) > get<2>(b);
    }
}



int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
  	const long div = 1000000007;
	int N, M;
  	cin >> N >> M;
  	int idx = 0;
  	vector<int> a(M+1);
  	while(cin >> a[idx])
    {
      if(idx != 0 && a[idx] == a[idx-1] +1)
      {
        cout << 0 << endl;
        return 0;
      }
      idx++;
    }
  	int broken_step = 0;
  	long step[N+1];
  	step[0] = 1;
  	for(int i=1;i<=N;i++)
    {

      if(i == a[broken_step])
      {
        cerr << "broken step:" << i << endl;
        broken_step++;
        step[i] = 0;
        continue;
      }
      if(i == 1) step[i] = 1;
      else
      {
        step[i] = (step[i-1] + step[i-2]) % div;
      }
    }
  	cout << step[N] << endl;
  	return 0;
}


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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;
const double PI = acos(-1);

#define rep(i, n)  for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()


int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int>> is(26);
    rep(i, n) is[s[i] - 'a'].push_back(i);
    rep(i, n) is[s[i] - 'a'].push_back(i+n);
    ll ans = 0;
    int p = 0;
    rep(i, m) {
        int c = t[i] - 'a';
        if (is[c].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
        if (p >= n) {
            p -= n;
            ans += n;
        }
    }

    ans += p;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1724
n=int(input())
m=len(str(n))
k=int(input())
N=[int(i) for i in str(n)]
dp0=[[0]*(k+1) for _ in range(m+1)]
dp1=[[0]*(k+1) for _ in range(m+1)]
dp1[0][0]=1
for i,e in enumerate(str(n)):
    e = int(e)
    for j in range(k+1):
        dp1[i+1][j]+=dp1[i][j]*(e==0)
        dp0[i+1][j]+=dp0[i][j]+dp1[i][j]*(e>0)
        if j<k:
            dp1[i+1][j+1]+=dp1[i][j]*(e>0)
            dp0[i+1][j+1]+=dp0[i][j]*9+dp1[i][j]*max(0,e-1)
print(dp1[m][k]+dp0[m][k])

Measured memory_bytes: 3064
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    from collections import deque
    H, W = MI()
    C = LI()
    D = LI()
    C = [i - 1 for i in C]
    D = [i - 1 for i in D]
    S_ = []
    for i in range(H):
        s = S()
        S_.append(s)
    cost = [[10 ** 10] * W for _ in range(H)]
    cost[C[0]][C[1]] = 0
    queue = deque()
    queue.append(C)
    while len(queue) != 0:
        a = queue.popleft()
        a_cost = cost[a[0]][a[1]]
        for i in range(-2, 3):
            if a[0] + i < 0 or a[0] + i >= H:
                continue
            for j in range(-2, 3):
                if a[1] + j < 0 or a[1] + j >= W:
                    continue
                if i == j == 0:
                    continue
                b = [a[0] + i, a[1] + j]
                b_cost = cost[b[0]][b[1]]
                if S_[b[0]][b[1]] == '#':
                    continue
                if (abs(i) == 1 and j == 0) or (abs(j) == 1 and i == 0):
                    if a_cost < b_cost:
                        cost[b[0]][b[1]] = a_cost
                        queue.appendleft(b)
                else:
                    if a_cost + 1 < b_cost:
                        cost[b[0]][b[1]] = a_cost + 1
                        queue.append(b)
    ans = cost[D[0]][D[1]]
    if ans != 10 ** 10:
        print(ans)
    else:
        print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 126524
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        
        while (true) {
            String line = in.nextLine();
            if (line.equals("END OF INPUT")) break;
            
            String ans = "";
            
            String[] splat = line.split(" ");
            for (String str : splat) {
                int n = str.length();
                if (n < 10) ans += "" + n;
            }
            
            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 25948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

ll a[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  ll sum = 0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  ll ret = sum;
  ll cur = 0;
  for(int i=0;i<n-1;i++){
    cur += a[i];
    ret=min(ret, abs(cur + cur - sum));
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
vector<set<int> > alpha(26);
string S;
/* function */
void op1(int i, char c) {
    alpha[S[i] - 'a'].erase(i);
    S[i] = c;
    alpha[S[i] - 'a'].insert(i);
}
void op2(int l, int r) {
    int cnt = 0;
    for (int i = 0; i < 26; i++) {
        auto itr = alpha[i].lower_bound(l);
        if (itr != alpha[i].end() && r >= *itr ) cnt++;
    }
    cout << cnt << '\n';
}
/* main */
int main(){
    int N, Q;
    cin >> N >> S >> Q;

    for (int i = 0; i < N; i++) { alpha[S[i] - 'a'].insert(i); }

    int op, l, r, ind;
    char c;
    for (int i = 0; i < Q; i++) {
        cin >> op;
        if (op == 2) { cin >> l >> r; l--, r--; op2(l, r); }
        else { cin >> ind >> c; ind--; op1(ind, c); }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> l(2*n);
  for (int i = 0; i < 2*n; i++) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());
  int ans = 0;
  for (int i = 0; i < 2*n; i += 2) {
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <list>
#include <string.h>
using namespace std;
#define pb push_back
#define po pop_back
#define INF 1e9+9
pair<long long int, long long int> dfs(vector<vector<long long int> >& graph, long long int start, vector<long long int>& visited, vector<pair<long long int, long long int> >& dp) {
	visited[start] = true;
	pair<long long int, long long int> ans;
	ans.first = INT_MAX;
	ans.second = INT_MAX;
	for (long long int i = 0;i<graph[start].size();++i) {
		if (graph[start][i] == 1) {
			return make_pair(1, 1);
		}
		if (!visited[graph[start][i]]) {
			//min_dist = min(dfs(graph,graph[start][i],visited,next,dp));
			pair<long long int, long long int> p = dfs(graph, graph[start][i], visited, dp);
			if (p.first<ans.first) {
				ans.first = p.first;
				ans.second = graph[start][i];
			}
		}
		else {
			if (dp[graph[start][i]].first + 1<ans.first) {
				ans.first = dp[graph[start][i]].first + 1;
				ans.second = graph[start][i];
			}
		}
	}
	dp[start].first = ans.first;
	dp[start].second = ans.second;
	return ans;
}
void bfs(vector<vector<long long int> >& graph,int i,vector<int>& next) {
	vector<bool> visited(graph.size() + 1, false);
	vector<long long int> dist(graph.size() + 1, INT_MAX);

	queue<int> q;
	q.push(1);
	dist[1] = 0;
	visited[1] = true;
	while (!q.empty()) {
		int root = q.front();
		q.pop();
		//int n = q.size();
		for (int i = 0;i < graph[root].size();++i) {
			if (!visited[graph[root][i]]) {
				dist[graph[root][i]] = dist[root] + 1;
				visited[graph[root][i]] = true;
				q.push(graph[root][i]);
				next[graph[root][i]] = root;
			}
		}
	}

	for (int i = 2;i < next.size();++i) {
		if (next[i] == -1) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
	for (int i = 2;i < next.size();++i) {
		cout << next[i] << endl;
	}
}
void solve() {
	long long int n, m, a, b;
	//vector<vector<long long int> > graph(n+1,vector<long long int>());
	cin >> n >> m;
	vector<vector<long long int> > graph(n + 1, vector<long long int>());
	for (long long int i = 0;i<m;++i) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	vector<int> next(n + 1, -1);
	bfs(graph, 1, next);
	/*vector<long long int> visited(n + 1, false);
	vector<pair<long long int, long long int> > dp(n + 1, make_pair(INT_MAX, -1));
	for (long long int i = 2;i <= n;++i) {
		if (!visited[i]) {
			dfs(graph, i, visited, dp);
		}
	}
	for (long long int i = 2;i <= n;++i) {
		cout << dp[i].second << " ";
	}*/
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#endif // !ONLINE_JUDGE
	solve();
	return 0;
}


Measured memory_bytes: 12884
N,M = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)

from collections import deque
tmpdist = N
ans = None
for to in range(N):
    for fr in es[to]:
        dist = [N] * N
        dist[fr] = 0
        prev = [-1] * N
        q = deque([fr])
        while q:
            v = q.popleft()
            if v==to: break
            for w in es[v]:
                if dist[w] < N: continue
                if v==to and w==fr: continue
                dist[w] = dist[v] + 1
                prev[w] = v
                q.append(w)
        else:
            continue
        if dist[to] < tmpdist:
            tmpdist = dist[to]
            ans = set()
            v = to
            while 1:
                ans.add(v+1)
                if prev[v] < 0: break
                v = prev[v]
if ans is None:
    print(-1)
else:
    print(len(ans))
    print(*ans, sep='\n')

Measured memory_bytes: 3956
N,M=map(int,input().split())
A,a=[],[]
for _ in range(N):
    a=list(map(int,input().split())) 
    del a[0]
    A.extend(a)

ans=0
for i in range(1,M+1):
    if A.count(i)==N:
        ans+=1

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

    int assinementTime = 0 ;
    for(int i = 0; i < M ; i++){
        int timeOfAssinement;
        cin>>timeOfAssinement;
        assinementTime += timeOfAssinement;
    }
    if(N  >= assinementTime){
        cout<<N - assinementTime<<endl;
    }else{
        cout<<"-1"<<endl;
    }
    return 0;
}


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

int main() {
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
		for(int j=i+1;j<s.size();j++){
			if(s[i]==s[j]) {
				cout<<"no";
				return 0;
				
			}
		}
	cout<<"yes";	
	return 0;
}

Measured memory_bytes: 256
import Data.Fixed

main = getContents >>= putAns.calc.getTestCase

putAns :: (Int, Int, Micro) -> IO()
putAns (x,y,z) = putStrLn $unwords [show x,show y,show (z::Micro)]

getTestCase :: String -> [Int]
getTestCase =  map (read :: String -> Int).words

calc :: [Int] -> (Int, Int, Micro)
calc (a:b:_) = ( fst s, snd s, f a / f b )
    where s   = quotRem a b
          f x = fromIntegral (x :: Int)

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    rep (i, n) {
        rep (j, m) {
            if (j == 0) cin >> c[i];
            cin >> a[i][j];
        }
    }
    int ans = inf;
    //bit全探索
    for (int bit = 0; bit < (1 << n); bit++) {
        int sum[m] = {};
        vector<int> vec;
        for (int i = 0; i < n; i++) {
            if (bit & (1 << i)) vec.push_back (i);
        }
        for (auto p : vec) {
            rep (i, m) {
                sum[i] += a[p][i];
            }
        }
        bool chk = 1;
        rep (i, m) {
            if (sum[i] < x) {
                chk = 0;
                break;
            }
        }
        int ans_sum = 0;
        if (chk) {
            for (auto i : vec) ans_sum += c[i];
            ans = min (ans, ans_sum);
        }
    }
    if (ans == inf) ans = -1;
    cout << ans << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int p = 1000000007;
long long modsub(long long a, long long b){
	if (a >= b){
		return (a - b) % p;
	} else {
		return p - (b - a) % p;
	}
}
long long modpow(long long a, long long b){
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % p;
		a = a * a % p;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a,p - 2);
}
vector<long long> mf;
long long modfact(long long n){
	if (n < mf.size()){
		return mf[n];
	} else {
		if (mf.empty()) mf.push_back(1);
		long long res = mf.back();
		for (int i = mf.size(); i <= n; i++){
			res = res * i % p;
			mf.push_back(res);
		}
		return res;
	}
}
long long modbinom(long long n, long long r){
	long long res;
	res = modfact(n);
	res = res * modinv(modfact(r)) % p;
	res = res * modinv(modfact(n - r)) % p;
	return res;
}
int main(void){
  long long N,K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  if (N == K){
    sort(A.begin(),A.end());
    long long m = A.front();
    long long M = A.back();
    cout << modsub(M,m);
  } else {
    //最大値
    sort(A.begin(),A.end());
    long long maxtot = A[K - 1];
    for (long long i = K; i < N; i++){
      maxtot = (maxtot + (A[i] + p) % p * modbinom(i,K - 1)) % p;
    }
    //最小値
    reverse(A.begin(),A.end());
    long long mintot = A[K - 1];
    for (long long i = K; i < N; i++){
      mintot = (mintot + (A[i] + p) % p * modbinom(i,K - 1)) % p;
    }
    cout << modsub(maxtot,mintot);
  }
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using P = pair<int,int>;
int n, m, v, u, d[100005], ans[200005];
char ans2[100005];
vector<P> G[100005], G2[100005];
void dfs(int u, int p, int c){
	ans2[u] = c ? 'B' : 'W';
	for(P nx: G2[u]) if(nx.first != p) dfs(nx.first, u, c ^ nx.second);
}
int main(){
	scanf("%d%d", &n, &m);
	fill(ans, ans+m, (int)1e9);
	rep(i,n) scanf("%d", d+i);
	rep(i,m){
		scanf("%d%d", &v, &u);
		v--; u--;
		G[v].push_back(P{u,i});
		G[u].push_back(P{v,i});
	}
	rep(i,n){
		bool ok = false;
		for(P p: G[i]) if(d[p.first] <= d[i]){
			int tmp = d[p.first] == d[i];
			ans[p.second] = d[i] - (1-tmp) * d[p.first];
			G2[p.first].push_back({i,tmp});
			G2[i].push_back({p.first,tmp});
			ok = true;
			break;
		}
		if(!ok) return puts("-1") * 0;
	}
	rep(i,n) if(ans2[i] == '\0') dfs(i,i,0);
	printf("%s\n", ans2);
	rep(i,m) printf("%d\n", ans[i]);
}

Measured memory_bytes: 17664
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		Arrays.sort(arr);
		int min = Integer.MAX_VALUE;
		for (int val = arr[0]; val <= arr[arr.length - 1]; val++) {
			int m = 0;
			for (int i = 0; i < n; i++) {
				m += (arr[i] - val) * (arr[i] - val);
			}
			min = Math.min(min, m);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
a=int(input())
b=int(input())
c=int(input())
x=int(input())

ans = 0
for _a in range(a+1):
    for _b in range(b+1):
        for _c in range(c+1):
            if _a*500 + _b*100 + _c*50 == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
  int a[256],b=0,i=0;
  scanf("%d",&a[b]);
  while(a[b]!=0){
    i++;
    printf("Case %d: %d\n",i,a[b]);
    scanf("%d",&a[b]);
  }
  return(0);
}

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

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy";
    }
    else if (S == "Cloudy") {
        cout << "Rainy";
    }
    else if (S == "Rainy") {
        cout << "Sunny";
    }
    return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as C

main = (snd . C.foldl' (\(c,ac) w -> f c ac w) (0,0) ) <$> C.getLine
    >>= print

f 0 ac 'g' = (1,    ac)
f c ac 'g' = (c-1,  ac+1)
f 0 ac 'p' = (1,    ac-1)
f c ac 'p' = (c-1,  ac)

Measured memory_bytes: 4732
# eval is evil
S = input()


def f(i, c):
    # i番目まで / 現在の式
    if i == len(S):
        if c[-1] == "+":
            return int(eval(c[:-1]))
        else:
            return int(eval(c))
    # i番目で区切る or 区切らない ただし+は連続しない
    if i == 0 or c[-1] == "+":
        return f(i + 1, c + S[i])
    else:
        return f(i, c + "+") + f(i + 1, c + S[i])


print(f(0, ""))


Measured memory_bytes: 38512
import java.util.*;

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

		int n = sc.nextInt();
		HashSet<String> set = new HashSet<String>();

		String prev = sc.next();
		set.add(prev);
		for(int i = 1; i < n; i++){
			String tmp = sc.next();

			if(set.contains(tmp) || prev.charAt(prev.length() - 1) != tmp.charAt(0)){
				System.out.println("No");
				return;
			}
			set.add(tmp);
			prev = tmp;
		}
	System.out.println("Yes");
	}
}


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

using ll=long long;
const ll MOD=1000000007;

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

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

int main(){
    int d, g, p[11], c[11];
    cin >> d >> g;
    for(int i=0; i<d; i++){
        cin >> p[i] >> c[i];
    }
    int ans = 1e9;
    for(int mask = 0; mask < (1 << d); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < d; ++i){
            if(mask >> i & 1){
                s += 100 * (i + 1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < g){
            int s1 = 100 * (rest_max + 1);
            int need = (g - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X = ri()
q, r = divmod(X, 100)
bool = True
if q * 5 < r:
    bool = False
elif X > 105 * 10 ** 6:
    X -= 105 * 10 ** 6
    #パソコン使い果たす
    q, r = divmod(X, 100)
    if q * 4 < r:
        bool = False
    elif X > 104 * 10 ** 6:
        X -= 104 * 10 ** 6
        q, r = divmod(X, 100)
        if q * 3 < r:
            bool = False
        elif X > 103 * 10 ** 6:
            X -= 103 * 10 ** 6
            q, r = divmod(X, 100)
            if q * 2 < r:
                bool = False
            elif X > 102 * 10 ** 6:
                X -= 102 * 10 ** 6
                #クッキー使い果たす
                q, r = divmod(X, 100)
                if q * 1 < r:
                    bool = False
                elif X > 101 * 10 ** 6:
                    X -= 101 * 10 ** 6
                    #サンドイッチ使い果たす
                    q, r = divmod(X, 100)
                    if q * 0 < r:
                        bool = False
                    if X > 100 * 10 ** 6:
                        #おにぎり使い果たす 数が多すぎる
                        bool = False
                        
print(1 if bool else 0)



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

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


int main(){
    int n,g;
    cin >> n;
    vector<int> a(n),r(n),l(n);
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    for(int i = 0;i < n;i ++){
        l[i] = i?gcd(l[i-1],a[i]):a[0];
    }
    for (int i = n-1;i >= 0;i --){
        r[i] = i!=n-1?gcd(r[i+1],a[i]):a[n-1];   
    }
    g = max(l[n-2],r[1]);
    for(int i = 0;i < n-2;i ++){
        g = max((int)gcd(l[i],r[i+2]),g);
    }
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int N,i,j,l=0,r,m,x,y;
    bool done[123456];
    char s[10];
    fill(done,done+123456,false);
    scanf("%d", &N);
    r = N-1;
    printf("0\n",&m);
    fflush(stdout);
    scanf("%s",s);
    if(s[0]=='M'){
        x = 0;
        y = 1;
    }else if(s[0]=='F'){
        x = 1;
        y = 0;
    }else{
        return 0;
    }
    done[0] = true;
    for(i=0; i<20; i++){
        m = (l+r)/2;
        if(done[m]){
            m++;
        }
        printf("%d\n",m);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='M'){
            if((m-l)%2==0){
                if(x == 0){
                    l = m;
                    x = 0;
                }else{
                    r = m;
                    y = 0;
                }
            }else{
                if(x == 1){
                    l = m;
                    x = 0;
                }else{
                    r = m;
                    y = 0;
                }
            }
        }else if(s[0]=='F'){
            if((m-l)%2==0){
                if(x == 1){
                    l = m;
                    x = 1;
                }else{
                    r = m;
                    y = 1;
                }
            }else{
                if(x == 0){
                    l = m;
                    x = 1;
                }else{
                    r = m;
                    y = 1;
                }
            }
        }else{
            return 0;
        }
        done[m] = true;
    }
}

Measured memory_bytes: 980
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
const int INF=int(1e9);
#define ll long long
int main() {
	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll Min=x*a+y*b;
	ll mi=min(x,y);
	ll ma=max(x,y);
	Min=min(Min,2*mi*c+(x-mi)*a+(y-mi)*b);
	Min=min(Min,2*ma*c);
	cout<<Min<<endl;
}

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

int w[2 * 100000 + 5];

int main() {
  std::string S;
  cin >> S;

  int n = S.length();
  memset(w, 0, sizeof(w));
  int w_cnt = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (S[i] == 'W') w_cnt++;
    w[i] = w_cnt;
  }

  long long ans = 0;
  for (int i = 0; i < n; ++i)
    if (S[i] == 'B') ans += w[i];

  cout << ans << endl;

  return 0;
}


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

void checker(int &AC , int &WA) {
  int n , m;
  cin >> n >> m;
  int problem , current = 0;
  string result;
  vector<int> correct(n + 1 , 0);
  vector<int> wrong(n + 1 , 0);

  for (int i = 0 ; i < m ; i ++) {
    cin >> problem >> result;

    if (correct[problem] == 1) {
      continue;
    }

    if (result == "AC") {
      correct[problem] = 1;
    } else {
      wrong[problem] ++;
    }
  }
  for (int i = 1 ; i < n + 1 ; i ++) {
    if (correct[i] == 1) {
      AC ++;
      WA += wrong[i];
    }
  }
}

int main(){
  int AC = 0 , WA = 0;
  checker(AC , WA);
  cout << AC << ' ' << WA << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

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

  if((N % K) != 0){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,cnt,sz,ed,st;
int fir[101010],nxt[202020],to[202020],d[101010];
int du[101010];
char S[10][10]={"No","Yes"};
void add(int x,int y)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;
	to[cnt]=y;
}
void dfs(int x,int fa)
{
	if(x==ed) return ;
	if(x==st&&fa)
	{
		puts("Yes");exit(0);
	}
	for(int i=fir[x];i;i=nxt[i])
	if(to[i]!=fa)
		dfs(to[i],x);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
		du[x]++;du[y]++;
	}
	for(int i=1;i<=n;i++)
	if(du[i]&1)
	{
		puts("No");
		return 0;
	}
	for(int i=1;i<=n;i++)
	if(du[i]>4)
	{
		puts("Yes");
		return 0;
	}
	else if(du[i]==4)
	{
		if(!st) st=i;
		else if(ed)
		{
			puts("Yes");
			return 0;
		}
		else ed=i;
	}
	if(!ed) puts("No");
	else
	{
		dfs(st,0);
		puts("No");
	}
	return 0;
}
	

Measured memory_bytes: 3328
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# import random
# N = random.randint(0, 2*100000)
# X = ""
# for i in range(N):
#     if random.random() < 0.5:
#         X += "0"
#     else:
#         X += "1"
# print(N, X)


N = INT()
X = input()

def popcount(n):
    cnt = 0
    while n:
        n %= "{:b}".format(n).count("1")
        cnt += 1
    return cnt

pl = [0]*(N+1)
for i in range(N+1):
    pl[i] = popcount(i)
bn = X.count("1")

modp = [0]*N
modm = [0]*N

for i in range(N):
    if X[i] == "1":
        modp[i] = pow(2, N-1-i, bn+1)
        if not bn == 1:
            modm[i] = pow(2, N-1-i, bn-1)

sp = sum(modp)
sm = sum(modm)
ans = [0]*N
for i in range(N):
    if X[i] == "1":
        if bn == 1:
            ans[i] = 0
            continue
        s = sm
        s -= modm[i]
        s %= bn-1
        ans[i] = pl[s]+1
    else:
        s = sp
        s += pow(2, N-1-i, bn+1)
        s %= bn+1
        ans[i] = pl[s]+1

print(*ans, sep="\n")


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

int main(){
  int n;cin >> n;
  int a[n];
  rep(i,n)cin >> a[i];
  a[n]=0;
  while(1){
    rep(i,n){
      if(a[i]%2==0)a[i]/=2;
      else {cout << a[n];return 0;}
    }
    a[n] ++;
  }
  cout <<a[n];
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;

int n, m;
vector<vector<int> > g;
vector<int> dmin[2];

int bfs(){
    for(int i=0;i<2;i++) dmin[i].resize(n,IINF);
    dmin[0][0] = 0;
    queue<P> que;
    que.push({0,0});
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int b = p.first, cur = p.second;
        for(auto nxt : g[cur]){
            if(dmin[b^1][nxt] > dmin[b][cur]+1){
                dmin[b^1][nxt] = dmin[b][cur] + 1;
                que.push({b^1, nxt});
            }
        }
    }
    dmin[0][0] = 2;
    int res = IINF;
    for(int i=0;i<2;i++){
        int tmp = 0;
        for(int j=0;j<n;j++){
            tmp = max(tmp, dmin[i][j]);
        }
        res = min(res, tmp);
    }
    return res;
}

int main() {
    cin >> n >> m;
    g.resize(n);
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int ans = bfs();
    cout << (ans < IINF ? ans : -1) << endl;
    return 0;
}



Measured memory_bytes: 10996