akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

// vector<vector<int>> data(3, vector<int>(4));

typedef pair<double, double> P;
#define MAX_V 200001
struct edge {
    ll to;
    double cost;
};
vector<edge> g[MAX_V];
double d[MAX_V];

void dijkstra(int s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + MAX_V, INF);
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < g[v].size(); i++) {
            edge e = g[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

void solve(long long x_s, long long y_s, long long x_t, long long y_t,
           long long N, vector<long long> x, vector<long long> y,
           vector<long long> r) {
    rep(i, N + 2) {
        rep(j, N + 2) {
            double l = sqrt((x[i] - x[j]) * (x[i] - x[j]) +
                            (y[i] - y[j]) * (y[i] - y[j])) -
                       r[i] - r[j];
            l = max(l, 0.0);
            edge e1 = {j, l};
            g[i].push_back(e1);
            edge e2 = {i, l};
            g[j].push_back(e2);
        }
    }
    dijkstra(N);
    printf("%.16f\n", d[N + 1]);
}

int main() {
    long long x_s;
    long long y_s;
    long long N;
    long long y_t;
    long long x_t;
    scanf("%lld", &x_s);
    scanf("%lld", &y_s);
    scanf("%lld", &x_t);
    scanf("%lld", &y_t);
    scanf("%lld", &N);
    vector<long long> r(N + 2);
    vector<long long> y(N + 2);
    vector<long long> x(N + 2);
    for (int i = 0; i <= N - 1; i++) {
        scanf("%lld", &x[i]);
        scanf("%lld", &y[i]);
        scanf("%lld", &r[i]);
    }
    x[N] = x_s;
    y[N] = y_s;
    r[N] = 0.0;
    x[N + 1] = x_t;
    y[N + 1] = y_t;
    r[N + 1] = 0.0;
    solve(x_s, y_s, x_t, y_t, N, x, y, r);
    return 0;
}


Measured memory_bytes: 44340
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a,b,c,cnt=0;
		a=scan.nextInt();
		b=scan.nextInt();
		c=scan.nextInt();

		for(int i=a;i<=b;i++) {
			if(c%i==0)cnt++;
		}
		System.out.println(cnt);
		scan.close();
	}

}


Measured memory_bytes: 26372
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner input=new Scanner(System.in);
        int i,j,m,n;
        char c;
        char s[]=new char[]{'S','H','C','D'};
        int cards[][]=new int[4][13];
        n=input.nextInt();
        for(i=0;i<n;i++){
            c=input.next().charAt(0);
            m=input.nextInt();
            for(j=0;j<4;j++)
                if(s[j]==c){
                    cards[j][m-1]=1;
                }
            }
        for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(cards[i][j]==0)
                System.out.printf("%c %d\n",s[i],j+1);
        }
    }    
    }
}


Measured memory_bytes: 26364
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(K,X);
    cout << ((500*K>=X)? "Yes":"No") << nn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
const int INF = INT_MAX;
const ll MOD = 998244353;

vector<ll> list_mod_inverse(ll n, ll mod)
{
    vector<ll> inv(n + 1);
    inv[1] = 1;
    for (int i = 2; i <= n; ++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    return inv;
}

ll C(const vector<ll> &fact,const vector<ll> &finv,ll n,ll k,ll mod){
    ll ret = 1;
    ret = ret*fact[n]*finv[k]%mod;
    ret = ret*finv[n-k]%mod;
    return ret;
}

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    ll N,A,B,K;
    cin >> N >> A >> B >> K;
    vector<ll> fact(N+1,1);
    repeat(i, N){
        fact[i+1] = fact[i]*(i+1)%MOD;
    }
    vector<ll> inv = list_mod_inverse(N+1, MOD);
    vector<ll> finv(N,1);
    repeat(i, N){
        finv[i+1] = finv[i]*inv[i+1]%MOD;
    }
    ll ans = 0;
    repeat(a, N+1){
        ll bb = K - A*a;
        if(bb<0) break;
        if(bb%B != 0) continue;
        ll b = bb/B;
        if(b > N) continue;
        ll x = C(fact,finv,N,a,MOD)*C(fact,finv,N,b,MOD)%MOD;
        ans = (ans + x)%MOD;
        
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int s[100050];
int x[100050];
const ll mod=998244353;
ll ksm(ll a,ll n)
{
    ll ans=1,base=a;
    while(n)
    {
        if(n&1)
            ans=(ans*base)%mod;
        base=(base*base)%mod;
        n>>=1;
    }
    return ans%mod;
}
int main()
{
    int n;
    memset(s,0,sizeof(s));
    scanf("%d",&n);
    int mx=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x[i]);
        s[x[i]]++;
        mx=max(mx,x[i]);
    }
    ll sum=1;
    if(s[0]!=1||x[0]!=0)
        printf("0\n");
    else
    {
        for(int i=1;i<=mx;i++)
            sum=(sum*ksm(s[i-1],s[i]))%mod;
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,N,M,Q,P,X,Y;
    cin>> a ;
    if(a==1){
        cout<<"Hello World"<<endl;
    }else{
        cin>>b;
        cin>>c;
        cout<<b+c<<endl;
    }
    return 0;
}

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

int main(){
	int N, L, i, ans = 0;
	cin >> N >> L;
	if (L > 0){
		for (i = 2; i <= N; i++){
			ans = ans + L + i - 1;
		}
	}
	else if (L + N - 1 < 0){
		for (i = 1; i < N; i++){
			ans = ans + L + i - 1;
		}
	}
	else{
		for (i = 1; i <= N; i++){
			ans = ans + L + i - 1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static final long MOD = (long)Math.pow(10, 9) + 7l;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int res = Math.max(a*b, d*c);
		System.out.println(res);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      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: 20820
#include <iostream>
#include <vector>
#include <string>
using namespace std;

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

int H, W;
vector<string> v;

long long numb = 0, numw = 0;
bool seen[MAX][MAX];

void dfs(int x, int y) {
  seen[x][y] = true;
  if(v[x][y] == '#') numb++;
  else numw++;

  for(int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
    if(v[x][y] == v[nx][ny]) continue;
    if(seen[nx][ny]) continue;
    dfs(nx, ny);
  }
}

int main() {
  cin >> H >> W;
  v.resize(H);
  for(int i = 0; i < H; i++) cin >> v[i];

  long long ans = 0;

  for(int x = 0; x < H; x++) {
    for(int y = 0; y < W; y++) {
      if(v[x][y] == '.') continue;
      if(seen[x][y]) continue;
      numb = numw = 0;
      dfs(x, y);
      ans += numb * numw;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 16448
#include<cstdio>
#include<algorithm>
using namespace std;
struct stu
{
	int h,p;
}a[5005];
int n,i,j,dp[5005];
bool cmp(stu a,stu b){return a.h+a.p<b.h+b.p;}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d%d",&a[i].h,&a[i].p);
	sort(a+1,a+n+1,cmp);
	dp[0]=0;
	for(i=1;i<=n;i++)dp[i]=2000000007;
	for(i=1;i<=n;i++)for(j=n-1;j>=0;j--)if(dp[j]<=a[i].h)dp[j+1]=min(dp[j+1],dp[j]+a[i].p);
	for(i=0;i<=n;i++)if(dp[i]==2000000007)break;
	printf("%d\n",i-1);
	return 0;
}

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}
int main()
{

    double H, A;

    cin >> H >> A;

    cout << ceil(H / A) << endl;
    return 0;
}

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

int main() {
    char s[1201];
    int i, n = 0;

    while(scanf("%c", &s[n]) != EOF) {
        n++;
    }

    for (i = 0; i <= n; i++) {
        if (s[i] >= 'a' && s[i] <= 'z') {
            s[i] = s[i] - 32; 
        }
        else if (s[i] >= 'A' && s[i] <= 'Z') {
            s[i] = s[i] + 32;
        }
    }
    for (i = 0; i < n; i++) {
        printf("%c", s[i]);
    }
    //printf("\n");

    return 0;
}



Measured memory_bytes: 2144
N,K = map(int, input().split())
H = list(map(int, input().split()))

import numpy as np

cost = np.zeros(N,dtype=int)
H = np.array(H)

for n in range(1,N):
  start = max(0, n-K)
  cost[n] = min(cost[start:n] + 
          abs(H[n]-H[start:n])
         )

 
print(cost[-1])

Measured memory_bytes: 17188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3025,p=998244353,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int ans,n,k,C[N][N];
void check(int &x,int y){x=(x+y<p) ? (x+y) : (x+y-p);}
int calc(int n,int k){
	int res=(k&1)|(n*2<k);
	for (int i=n;i<n*2;i++)
	if (i<k) check(res,C[n][i-n]);
	else if ((i-k)&1){
		int cnt=(i-k+1)/2;
		if (cnt*2>=n) break;
		int len=n-cnt*2,s=i-cnt*4;
		if (s>=len) check(res,C[len][s-len]);
	}
	return res;
}
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();k=read();
	for (int i=0;i<=n;i++){
		C[i][0]=1;
		for (int j=1;j<=i;j++)
		C[i][j]=(C[i-1][j]+C[i-1][j-1])%p;
	}
	for (int i=0;i<=n;i++)
	ans=(ans+(ll)C[n][i]*calc(i,k))%p;
	printf("%d\n",ans);
	return 0;
}

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

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

  ll h;
  cin >> h;
  int count = 0;
  while (h > 0) {
    h /= 2;
    count++;
  }

  ll ans = 1, multi = 1;
  rep(i, 1, count) {
    ans += 2 * multi;
    multi *= 2;
  }

  cout << ans << endl;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int X,t; cin>>X>>t;
	cout << max(0,X-t) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
const int INF = 1 << 30;

int main(){
    int n;
    cin >> n;
    vi a(n), b(n), c(n);
    rep(i, n){
        cin >> a.at(i) >> b.at(i) >> c.at(i);
    }
    vi d_a(n, INF), d_b(n, INF), d_c(n, INF);
    d_a.at(0) = a.at(0);
    d_b.at(0) = b.at(0);
    d_c.at(0) = c.at(0);
    REP(i, n){
        d_a.at(i) = a.at(i) + max(d_b.at(i-1), d_c.at(i-1));
        d_b.at(i) = b.at(i) + max(d_c.at(i-1), d_a.at(i-1));
        d_c.at(i) = c.at(i) + max(d_a.at(i-1), d_b.at(i-1));
    }
    
    cout << max({d_a.at(n-1), d_b.at(n-1), d_c.at(n-1)}) << endl;
    return 0;
}

Measured memory_bytes: 2560
H, W = map(int, input().split())
n = int(input())
a = map(int, input().split())

alist = []
i = 1
for ai in a:
  alist.extend([str(i)]*ai)
  i += 1

i = 0
for h in range(H):
  start = h * W
  end = start + W
  if h % 2 == 0:
    print(' '.join(alist[start:end]))
  else:
    print(' '.join(alist[end-1:start-1:-1]))

  


Measured memory_bytes: 3700
N = int(input())
s = 'MARCH'
count = [0 for _ in range(len(s))]
for _ in range(N):
    t = input()[0]
    for i,c in enumerate(s):
        if c==t:
            count[i] += 1
            break

ans = 0
for i in range(len(s)):
    for j in range(i+1,len(s)):
        for k in range(j+1,len(s)):
            ans += count[i]*count[j]*count[k]

print(ans)

Measured memory_bytes: 3064
N,K=map(int,input().split())
L=list(map(int,input().split()))
P=[]
M=[]
Z=[]
mod=10**9+7
for i in L:
    if i>0:
        P.append(i)
    elif i<0:
        M.append(i)
    else:
        Z.append(i)

P.sort(reverse=True)
M.sort()

if len(P)==0:
    if K%2==0:
        M+=Z
        ans=1
        #print(M)
        for i in range(K):
            ans*=M[i]
            ans%=mod
        print(ans)
    else:
        if len(Z)>0:
            print(0)
        else:
            M.sort(reverse=True)
            ans=1
            for i in range(K):
                ans*=M[i]
                ans%=mod
            print(ans)
else:
    if N==K:
        ans=1
        for i in range(N):
            ans*=L[i]
            ans%=mod
        print(ans)
    elif K%2==0:
        P+=[0,0]
        P+=Z
        M+=[0,0]
        M+=Z
        ans=1
        p=0
        m=0
        for i in range(K//2):
            if P[p*2]*P[p*2+1]>M[m*2]*M[m*2+1]:
                ans*=(P[p*2]*P[p*2+1])
                ans%=mod
                p+=1
            else:
                ans*=(M[m*2]*M[m*2+1])
                ans%=mod
                m+=1
        print(ans)
    else:
        P+=[0,0]
        P+=Z
        M+=[0,0]
        M+=Z
        ans=P[0]
        p=1
        m=0
        for i in range(K//2):
            if P[p*2]*P[p*2-1]>M[m*2]*M[m*2+1]:
                ans*=(P[p*2]*P[p*2-1])
                ans%=mod
                p+=1
            else:
                ans*=(M[m*2]*M[m*2+1])
                ans%=mod
                m+=1
        print(ans)

Measured memory_bytes: 105020
from math import ceil

N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for i in range(N-1):
	C[i],S[i],F[i] = map(int, input().split())


for i in range(N-1):
	t = 0
	for j in range(i,N-1):
		if t<=S[j]:
			t = S[j] + C[j]
		else:
			k = ceil((t-S[j])/F[j])
			t = S[j] + F[j]*k +C[j]
	print(t)
print(0)


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

int main() {
  int h,w;
  string str;
  cin >> h >> w;
  
  for(int k = 0; k < w + 2; k++) cout << "#";
  cout << endl;
  
  for(int i = 0; i < h; i++){
    cin >> str;
    cout << "#" << str << "#" << endl;
  }  
  for(int k = 0; k < w + 2; k++) cout << "#";
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	ll ans = 0;
	int tmp;
	string s;
	int h, w;
	cin >> h >> w;
	REP(i, h){
		cin >> s;
		cout << s << endl << s << endl;
	}
	//cout << ans << endl;
}

Measured memory_bytes: 3608
def d_practical_skill_test(H, W, D, A, Q, I):
    # クエリが1-indexedなため、配列もそれに従う
    px = [0 for _ in range(H * W + 1)]
    py = [0 for _ in range(H * W + 1)]  # (px[i],py[j])にAijの値が入っている
    d = [0 for _ in range(H * W + 1)]
    for i in range(H):
        for j in range(W):
            px[A[i][j]] = i
            py[A[i][j]] = j
    for i in range(D + 1, H * W + 1):
        d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D])
    ans = []
    for l, r in I:
        ans.append(str(d[r] - d[l]))
    return '\n'.join(ans)

H,W,D = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(H)]
Q = int(input())
I = [[int(i) for i in input().split()] for j in range(Q)]
print(d_practical_skill_test(H, W, D, A, Q, I))

Measured memory_bytes: 37120
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	n := make([]int, 4)
	for i := range n {
		n[i] = int(s[i] - 48)
	}
	op := []string{"+++", "-++", "+-+", "--+", "++-", "-+-", "+--", "---"}
	for _, o := range op {
		ans := n[0]
		for i, r := range o {
			if r == '+' {
				ans += n[i+1]
			} else {
				ans += -n[i+1]
			}
		}
		if ans == 7 {
			fmt.Printf("%d%s%d%s%d%s%d=7\n", n[0], o[0:1], n[1], o[1:2], n[2], o[2:3], n[3])
			return
		}
	}
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 10000000

using namespace std;

int main(){
  int n,u,v; cin>>n>>u>>v; u--; v--;
  vector<vector<pi>> g( n, vector<pi>() );
  rep(i, n-1){
    int a,b; cin>>a>>b; a--; b--;
    g[a].push_back( {1,b} );
    g[b].push_back( {1,a} );
  }

  if(g[u].size()==1 && g[u][0].second==v) { cout<<0<<endl; return 0; }

  set<int>s;
  vector<int>d(n);
  rep(i, n)d[i]=INF; 
  d[u]=0;

  priority_queue<pi, vector<pi>, greater<pi>> pq;
  pq.push( {0, u} );
  while( pq.size() ){
    auto cn = pq.top(); pq.pop();
    if(d[cn.second] < cn.first)continue;
    for(auto nn :g[cn.second]){
      if(cn.first+1 >= d[nn.second] || nn.second==v)continue;

      d[nn.second]=cn.first+1;
      pq.push( {d[nn.second], nn.second} );
    }
  }

  rep(i, n)if(d[i]!=INF)s.insert(i);
  s.insert(v);

  vector<int>d2(d);
  rep(i, n)d[i]=INF; 
  d[v]=0;
  pq.push( {0, v} );
 
  while( pq.size() ){
    auto cn = pq.top(); pq.pop();
    if(d[cn.second] < cn.first)continue;

    for(auto nn :g[cn.second]){
      if(cn.first+1 >= d[nn.second] || s.count(nn.second)==0 )continue;

      d[nn.second]=cn.first+1;
      pq.push( {d[nn.second], nn.second} );
    }
  }

//for(auto t: d2)cout<<t<<' ';cout<<endl;
//for(auto t: d)cout<<t<<' ';cout<<endl;

bool f=true;
rep(i, n)if((d[i]==1 || d2[i]==1) && d[i]!=d2[i])f=false;
if(f) { cout<<1<<endl; return 0; }

  int result=0;
  rep(i, n)if(d[i]!=INF && d2[i]!=INF){
    if(d[i]<=d2[i])continue;
    result = max(result, d[i]-1);
  }

  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 11904
S = input()
N = len(S)
a = 0
b = 0
for i in range (0,N):
  if (i % 2 == 0) and (int(S[i]) == 1):
    a = a + 1
  elif (i % 2 == 1) and (int(S[i]) == 0):
    a = a + 1
 
for i in range (0,N):
  if (i % 2 == 0) and (int(S[i]) == 0):
    b = b + 1
  elif (i % 2 == 1) and (int(S[i]) == 1):
    b = b + 1
ans = min(a,b)
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  ll r,d,x;
  cin >> r >> d >> x;
  for(int i=1;i<=10;i++){
    x = r*x -d;
    cout << x << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
In = list(input().split())
stack = []

for x in In:
#まずは数字のときにstackに収納する
    if x.isdigit():
        stack.append(x)
#文字の時はその演算を行う
    else:
        second = stack.pop()
        first = stack.pop()
        tmp = eval(first + x + second)
        stack.append(str(tmp))

print(int(stack.pop()))


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

int main(){
  long n,k;
  cin >> n >>k;
  long ans1,ans2;
  ans1=0;
  ans2=0;
  for(int i=1;i<=n;i++){
    if(i%k==0){
      ans1++;
    }
    if (2*(i%k)==k){
      ans2++;
    }
  }
  
  cout << ans1*ans1*ans1+ans2*ans2*ans2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int N,M;
  cin >> N >> M;
  multiset<ll,greater<ll>> a;
  for(int i=0;i<N;i++){
    ll val;
    cin>>val;
    a.insert(val);
  }
  long long sum = 0;
  while(M>0){
    if(a.size()==0){
      break;
    }
    auto it=a.begin();
    ll val=*it;
    a.erase(it);
    val/=2;
    M--;
    if(val>0){
      a.insert(val);
    }
  }
  for(auto it:a){
    sum+=it;
  }
  cout << sum << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  ll num = 1;
  bool z = false;
  rep(i, n){
    ll a;
    cin >> a;
    if(a==num){
      num++;
      z = true;
    }
    else{
      ans++;
    }
  }
  if(z){
    print(ans);
  }
  else{
    print(-1);
  }
}

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


int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	ll n, k, s;
	while (cin >> n >> k >> s) {
		for (int i = 0; i < k; ++i) cout << s << ' ';
		for (int i = k; i < n; ++i) {
			if (s == 1000000000ll) cout << 1 << ' ';
			else cout << s+1 << ' ';
		}
		cout << '\n';
	}
	return 0;
}


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




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

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

    sort(a, a + n);

    if (n % 2 == 1) {
        if (a[0] != 0) {
            cout << 0 << endl;
            return 0;
        }
        int num = 0;
        for (int i = 1; i < n; i++) {
            if (i % 2 == 1)
                num += 2;
            if (a[i] != num) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    else {
        int num = -1;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0)
                num += 2;
            if (a[i] != num) {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    int x ;
    if (n % 2 == 1)
        x = (n-1) / 2;
    else
        x = n / 2;

    int ans = 1;
    for (int i=0; i<x; i++) {
        ans = (ans * 2) % 1000000007;
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

def main():
    a = input().strip() + "w"
    b = input().strip() + "w"
    c = input().strip() + "w"

    i, j, k = 0, 0, 0
    now = "a"
    while True:
        # print(now, i, j, k)
        if now == "a":
            now = a[i]
            i += 1
            if now == "w":
                win = "a"
                break
        elif now == "b":
            now = b[j]
            j += 1
            if now == "w":
                win = "b"
                break
        else:
            now = c[k]
            k += 1
            if now == "w":
                win = "c"
                break

    if win == "a":
        print("A")
    elif win == "b":
        print("B")
    else:
        print("C")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

VVI g;
VI ans;

void dfs(int v, int p){
    int res = 0;
    for(int u : g[v]){
        if(u == p) continue;
        dfs(u,v);
        res++;
    }
    ans[v] = res;
}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    g.resize(N);
    ans.resize(N);
    REP(i,N-1){
        int a; cin >> a;
        a--;
        g[i+1].eb(a);
        g[a].eb(i+1);
    }
    dfs(0,-1);
    REP(i,N){
        cout << ans[i] << endl;
    }

    

}


Measured memory_bytes: 27388
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=1e6+10;
typedef long long LL;

int main() {
	LL A,B,N;
	cin>>A>>B>>N;
	LL ans;
	if(N>=B-1){
		ans=(A*(B-1))/B;
	}
	else{
		ans=(A*N)/B-A*(N/B);
	}
	cout<<ans<<endl;
    return 0;
}

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  vector<int> Ans(A+1, 0);
  rep(i, A+1) if(A%i==0 && B%i==0) Ans.at(i)=i;
  sort(Ans.begin(), Ans.end());
  reverse(Ans.begin(), Ans.end());
  cout << Ans.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

ll N, A, B;
vll H;
bool check(ll turn) {
	ll dis = A - B;
	ll cnt = 0;
	REP(i, N) {
		ll crt = H[i] - B * turn;
		if (crt > 0) {
			cnt += (crt + dis - 1) / dis;
		}
	}
	return cnt <= turn;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> A >> B;
	H = vll(N);
	REP(i, N)cin >> H[i];
	int ok = 10e9;
	int ng = 0;
	bool c = check(1);
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;
		if (check(mid))ok = mid;
		else ng = mid;
	}
	cout << ok << endl;
	PAU;
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N;
	cin >> N;
	vector<int64_t> a(N);
	for (auto& ai : a)
		cin >> ai;
	vector<int64_t> dp = a, dp2(N);
	if (N % 2 == 0)
	{
		for (auto& di : dp)
			di = -di;
	}
	fore(i, 2, N)
	{
		fill(all(dp2), 0);
		if ((N - i) & 1)
		{
			//minimize
			forn(j, N - i + 1)
			{
				dp2[j] = min(-a[j] + dp[j + 1], dp[j] - a[j + i - 1]);
			}
		}
		else
		{
			//maximize
			forn(j, N - i + 1)
			{
				dp2[j] = max(a[j] + dp[j + 1], dp[j] + a[j + i - 1]);
			}
		}
		dp.swap(dp2);
	}
	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	// nm
	var nm string
	if sc.Scan() {
		nm = sc.Text()
	}
	slice := strings.Split(nm, " ")
	n, _ := strconv.Atoi(slice[0])
	m, _ := strconv.Atoi(slice[1])

	ma := make(map[int]int)
	for i := 0; i < m; i++ {
		ma[i+1] = 0
	}

	for i := 0; i < n; i++ {
		var str string
		if sc.Scan() {
			str = sc.Text()
		}
		s := strings.Split(str, " ")
		for i, v := range s {
			if i == 0 {
				continue
			}
			vint, _ := strconv.Atoi(v)
			ma[vint]++
		}
	}

	res := 0
	for _, v := range ma {
		if v == n {
			res++
		}
	}
	fmt.Println(res)
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) {if (a > b) a = b;}
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) {if (a < b) a = b;}
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
// const int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };

void solve() {
	int N, L, T; cin >> N >> L >> T;
	vector<int>X(N), W(N);
	REP(i, N)cin >> X[i] >> W[i];
	vector<int>tmp(N);
	REP(i, N) {
		if (W[i] == 1)tmp[i] = (X[i] + T) % L;
		else tmp[i] = ((X[i] - T) % L+L) % L;
	}
	VSORT(tmp);
	int cnt = 0;
	REP(i, N) {
		if (W[i] == 1)cnt -= (T - (L - X[i]) + L) / L;
		else cnt += (T - (X[i] + 1) + L) / L;
	}
	cnt = (cnt%N + N) % N;
	vector<int>res(N);
	REP(i, N) {
		res[(cnt + i) % N] = tmp[i];
	}
	REP(i, N)print(res[i]);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// mt.seed((int)(time(0)));
	// int q;
	// cin >> q;
	// while (q--)
	solve();
}


Measured memory_bytes: 6360
#include<iostream>
#include<cmath>

using namespace std;


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

  int X[N][D];

  for(int i = 0; i < N; i++){
    for(int j = 0; j < D; j++){
      cin >> X[i][j];
    }
  }


  int cnt = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      int distance2 = 0;
      for(int k = 0; k < D; k++){
        distance2 += ((X[i][k] - X[j][k]) * (X[i][k] - X[j][k]));
      }
      float distance = sqrt(distance2);
      float distancei = floor(distance);
      if(distance == distancei){
        cnt++;
      }
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = {}
n.times do
  _sort = gets.chomp.chars.sort.join
  s[_sort] = 0 if s[_sort].nil?
  s[_sort] += 1
end
ans = 0
s.each do |str, num|
  ans += num * (num-1) / 2
end
puts ans

Measured memory_bytes: 17020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,inf=0x3f3f3f3f;
string s;
int cnt[3]={0};
int main()
{
	cin>>s;
	for(int i=0;s[i];i++)
		cnt[s[i]-'a']++;
	sort(cnt,cnt+3);
	cnt[1]-=cnt[0];
	cnt[2]-=cnt[0];
	bool flag=true;
	if(cnt[1]>1||cnt[2]>1)
		flag=false;
	puts(flag?"YES":"NO");
    return 0;
}




Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc043/tasks/arc059_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(s):
    ans = [-1, -1]
    if len(s) == 2:
        if s[0] == s[1]:
            return [1, 2]
        else:
            return ans

    for i, s0, s1, s2 in zip(range(1, 10**5+1), s, s[1:], s[2:]):
        if s0 == s1 or s0 == s2:
            ans = [i, i+2]
            break
    return ans


def main(args):
    s = input().strip()
    ans = solve(s)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3316
from re import finditer
from bisect import bisect_left
from bisect import bisect_right
a,b=map(int,input().split())
c=input()
d=[]
for _ in range(b):
    n,m=map(int,input().split())
    d.append([n-1,m-1])
n=len(d)
ac1=[m.start() for m in finditer('AC', c)]
ac2=[m.end()-1 for m in finditer('AC', c)]
for i in range(n):
    index1=bisect_left(ac1,d[i][0])
    index2=bisect_right(ac2,d[i][1])
    print(index2-index1)

Measured memory_bytes: 29212
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<n;i++)
using namespace std;
int main(){
    long long N,L1=1,L2=3;
    cin>>N;
    if(N==1)cout<<L1<<endl;
    else if(N==2)cout<<L2<<endl;
    else {
        long long ans=0;
        REP(i,N-1){
            ans=L1+L2;
            L1=L2;
            L2=ans;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
N = int(input())
A = input()
b = []
for i in range(N-1):
    b.append(abs(int(A[i])-int(A[i+1])))
S = 0
p = 0
for i in range(N-1):
    if p == 0:
        S += b[i]
    n = N - 2 - i
    k = i + 1
    if n == 0:
        break
    else:
        while n % 2 == 0:
            p += 1
            n //= 2
        while k % 2 == 0:
            p -= 1
            k //= 2

if S % 2:
    print(1)
else:
    for i in range(N-1):
        if b[i] == 1:
            print(0)
            exit()
    if (S // 2) % 2:
        print(2)
    else:
        print(0)


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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

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

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 1e5 + 5;

int n, a[MAXN], deg[MAXN];
set<point> degrees;
set<int> S;

bool check(vector <int> &v){
  REP(i, n - 1)
    if(a[ v[i] ] == v[i + 1])
      return false;
  return true;
}

void permutiraj(vector <int> &v){
  vector <int> tmp;
  FOR(i, n - 3, n)
    tmp.pb(v[i]);

  REP(i, 3)
    v.pop_back();

  vector <int> ret;
  do{
    REP(i, 3)
      v.pb(tmp[i]);

    if(check(v)){
      if(ret.empty())
        ret = v;
      else
        ret = min(ret, v);
    }

    REP(i, 3)
      v.pop_back();

  } while(next_permutation(tmp.begin(), tmp.end()));
  v = ret;
}

void ubaci(int id){
  S.erase(id);
  if(degrees.find( point(deg[a[id]], a[id]) ) != degrees.end()){
    degrees.erase(point(deg[a[id]], a[id]));
    deg[ a[id] ] --;
    degrees.insert(point(deg[a[id]], a[id]));
  }
  if(degrees.find( point(deg[id], id) ) != degrees.end())
    degrees.erase( point(deg[id], id) );
}

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

  cin >> n;
  FOR(i, 1, n + 1){
    S.insert(i);
    cin >> a[i];
    deg[a[i]] ++;
  }

  if(n == 2){
    if(a[1] == 2 && a[2] == 1)
      cout << -1;
    else{
      if(a[1] == 1 && a[2] == 1)
        cout << 1 _ 2;
      else
        cout << 2 _ 1;
    }
    return 0;
  }

  FOR(i, 1, n + 1){
    degrees.insert(point(deg[i], i));
  }
  vector <int> sol;
  REP(i, n){
    set<int> :: iterator it = S.begin();

    if(degrees.rbegin() -> first == sz(S) - 1 && sz(S) > 2){
      int id = degrees.rbegin() -> second;
      sol.pb(id);
      ubaci(id);
    }
    else{
      int num1 = *it, num2 = *it;
      if(sz(S) > 1){
        it ++;
        num2 = *it;
      }
      int id = MAXN - 1;
      if(i != 0)
        id = sol.back();

      if(a[id] == num1){
        sol.pb(num2);
        ubaci(num2);
      }
      else{
        sol.pb(num1);
        ubaci(num1);
      }
    }
  }

  if(!check(sol))
    permutiraj(sol);

  for(auto it : sol)
    cout << it << " ";
}


Measured memory_bytes: 11008
using System;

class Program
{
    static void Main()
    {
            int i, j, x;
            int[] h = new int[2000];
            int[] w = new int[2000];
            for (i = 0; i < 2000; i++)
            {
                string inp = Console.ReadLine();
                string[] data = inp.Split();
                h[i] = int.Parse(data[0]);
                w[i] = int.Parse(data[1]);
                if (h[i] == 0 && w[i] == 0)
                {
                    break;
                }
            }
            for (x = 0; x < 2000; x++)
            {
                if (h[x] == 0 && w[x] == 0)
                {
                    break;
                }
                for (i = 0; i < h[x]; i++)
                {
                    for (j = 0; j < w[x]; j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
    }
}


Measured memory_bytes: 8980
import math
a,b,h,m = map(int, input().split())

h_angle = 30*h + 0.5*m
m_angle = 6*m
diff_angle = abs(h_angle - m_angle)

if diff_angle > 180:
    diff_angle = 360 - diff_angle

cosC = math.cos(math.radians(diff_angle))
x = a**2 + b**2 - 2*a*b*cosC
ans = math.sqrt(x)
print(ans)


Measured memory_bytes: 9448
#include<bits/stdc++.h>
using namespace std;
 
#define IOS 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sd(n)       scanf("%d", &n)
#define sdd(a,b)    scanf("%d %d", &a, &b)
#define sddd(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define sld(n)      scanf("%lld", &n)
#define slld(a,b)   scanf("%lld %lld", &a, &b)
#define sllld(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define slu(n)      scanf("%llu", &n)
#define sllu(a,b)   scanf("%llu %llu", &a, &b)
#define slllu(a,b,c) scanf("%llu %llu %llu", &a, &b, &c)
#define ss(a)		scanf("%s", a)
#define all(a) 		a.begin(),a.end()
#define unq(x)      x.erase(unique(all(x)), x.end()
#define mp 			make_pair
#define sz(av) 		int((av).size())					//return size of vec
#define CLR(arr)    memset(arr, 0, sizeof(arr))			//assign 0 to whole arr
#define SET(vec)    memset(arr, -1, sizeof(arr))		//assign -1 to whole arr
#define CLRV(vec)	fill(vec.begin(), vec.end(), 0)		//assign 0 to whole vec
#define SETV(vec,n,a) vec.assign(n, a)	
#define vtd(rowsize,colsize,type,name) 		vector < vector <type> > name(rowsize,vector <type> (colsize)); 	//assign to first n elements value a in vec
#define SETB(a)		memset(a, true, sizeof(a))			//boolean array initialize by true value
#define CLRB(a)		memset(a, false, sizeof(a))			//boolean array initialize by false value
#define vintitr 	vector<int>::iterator
#define vlnlnitr 	vector<long long>::iterator
#define sintitr 	set<int>::iterator
#define slnlnitr 	set<long long>::iterator
#define aa			first
#define bb			second
#define mod 		1000000007
#define PI 			acos(-1.00)
#define psb 		push_back
#define ppb			pop_back
#define ppb			pop_back
#define psf			push_front
#define ppf			pop_front
#define in 			inset
#define rep(i, n) 	for(int i=0; i<n; i++)
#define repi(i,j,n) for(int i=j; i<j; i++)
#define rof(i, n)   for(int i=n-1; i>=0; i--)
#define min3(a,b,c) (min((c),min((a),(b))))
#define max3(a,b,c) (max((a),max((b),(c))))
#define __lcm(a, b)	a*b / __gcd(a, b)
#define __builtin_zerocount(a)	8*sizeof(a)-__builtin_popcount(a)-__builtin_clz(a)-__builtin_ctz(a)
#define D(t)        cerr << #t " = " <<t  << '\n'
#define DBG         cerr << "Hi!" << '\n'
 
 
typedef long long	 		ll;
typedef unsigned long long	llu;
typedef long double			ld;
typedef pair<int, int> 		pii;

int main()
{
//	freopen("t.in","r",stdin);
//	freopen("t.out","w",stdout);
	IOS;
	int n;
	cin >> n;
	vector <int> v(n);
	for(auto& x : v)
		cin >> x;
	int i = 0;
	if(n==1)
	{
		cout << "Yes" << endl;
		return 0;
	}
	if(v[0] > v[1])
		v[0]--;
	for(i=0; i<n-1; i++)
	{
		if(v[i+1] - v[i] > 0)
			v[i+1]--;
		if(v[i+1] < v[i])
			break;
	}
	if(i==n-1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 640
import queue

K=int(input())

q=queue.Queue()
for i in range(1,10):
  q.put(i)
  
for i in range(K):
  p=q.get()
  p1=p%10
  
  if p1!=0:
    q.put(10*p+p1-1)
  q.put(10*p+p1)
  if p1!=9:
    q.put(10*p+p1+1)
    
print(p)

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

int main()
{
	map<string, int> cnt;
	string s;
	while (cin >> s) {
		cnt[s]++;
	}
	int ma = 0, le = 0;
	string res1, res2;
	for (auto p : cnt) {
		if (p.second > ma) {
			ma = p.second;
			res1 = p.first;
		}
		if ((int)p.first.size() > le) {
			le = p.first.size();
			res2 = p.first;
		}
	}
	cout << res1 << ' ' << res2 << endl;
	return 0;
}

Measured memory_bytes: 3092
//dp発想
#include <iostream>
using namespace std;
const int mo = 1e9 + 7;
main()
{
    int m,n,f[100010];
    cin >> n >> m;
    bool a[100010];
    for( int i = 0, x; i < m; i++ )
    {
        cin >> x; a[x] = 1;
    }
    f[0] = 1;
    for( int i = 1; i <= n; i++ )
    {
        f[i] = ( f[i - 1] + f[i - 2] ) % mo;
        if( a[i] ) f[i] = 0;
    }
    cout << f[n] << endl;
    return 0;
}

Measured memory_bytes: 768