akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import deque

S = deque(sys.stdin.readline().rstrip())
Q = int(sys.stdin.readline().rstrip())
flip = False

for i in range(Q):
    Que = sys.stdin.readline().rstrip()
    if Que == "1":
        flip = not(flip)
    else:
        Query = Que.split()
        F = Query[1]
        if (F == "1") ^ flip:
            S.appendleft(Query[2])
        else:
            S.append(Query[2])
print("".join(S) if not flip else "".join(S)[::-1])


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


template<class T>
struct segment_tree {
	using value_type = T;
	using F = function<T(T, T)>;
private : 
	int n;
	const F f;
	const value_type ie;
	vector<value_type> node;

public : 
	segment_tree (const F &f, const value_type &ie) : f(f), ie(ie) { }

	void resize (int _n) noexcept {
		n = 1;
		while (n < _n) n <<= 1;
		node.resize(2 * n);
		fill(node.begin(), node.end(), ie);
	}

	void resize (int _n, const value_type &e) noexcept {
		n = 1;
		while (n < _n) n <<= 1;
		node.resize(2 * n);
		fill(node.begin(), node.end(), ie);
		for (int i = n; i < 2 * n; i++) node[i] = e;
		for (int i = n; i--> 0;) {
			node[i] = f(node[i << 1 | 0], node[i << 1 | 1]);
		}
	}

	template<class iter>
	void build (iter l, iter r) {
		resize(r - l);
		for (int i = n; l != r; i++, l++) node[i] = *l;
		for (int i = n; i--> 0;) {
			node[i] = f(node[i << 1 | 0], node[i << 1 | 1]);
		}
	}

	void set_val (int i, const value_type &x) {
		i += n;
		node[i] = x;
		for (i >>= 1; i > 0; i >>= 1) {
			node[i] = f(node[i << 1 | 0], node[i << 1 | 1]);
		}
	}

	constexpr value_type fold (int l, int r) {
		value_type vl = ie, vr = ie;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) vl = f(vl, node[l++]);
			if (r & 1) vr = f(node[--r], vr);
		}
		return f(vl, vr);
	};

	constexpr const value_type& fold_all() const {
		return (node[1]);
	}

	constexpr const value_type& operator[] (int i) const {
		return node[i + n];
	}

};


int main() {
	int n, q;
	cin >> n >> q;
	auto f = [](const int &a, const int &b) { return (a + b); };
	segment_tree<int> seg(f, 0);
	seg.resize(n);
	
	while (q--) {
		int type;
		cin >> type;
		
		if (type == 0) {
			int i, x;
			cin >> i >> x;
			i--;
			seg.set_val(i, seg[i] + x);
		} else {
			int l, r;
			cin >> l >> r;
			l--; r--;
			cout << seg.fold(l, r + 1) << '\n';
		}
	}
	
	return 0;
}


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

using namespace std;

const int maxn = 100010;

typedef long long ll;

ll ans = 0;

int ok = 1, ty = 0, cnt_e = 0;
int cdeg[maxn], rdeg[maxn];
int l[maxn], vis[maxn], col[maxn], cnt[3], e;

int n, m;

struct Edge {
	int v, w, x;
} E[maxn<<1];

inline void addEdge(int u, int v, int w) {
	E[e].v = v; E[e].x = l[u]; E[e].w = w; l[u] = e++;
}

void dfs(int u) {
	if (cdeg[u] && rdeg[u]) ty = 1;
	cnt_e += cdeg[u];
	cnt[col[u]] ++;
	vis[u] = 1;
	for (int p = l[u]; p >= 0; p = E[p].x) {
		int v = E[p].v;
		if (!vis[v]) {
			col[v] = (col[u] + E[p].w + 3) % 3;
			dfs(v);
		} else {
			if (col[v] != (col[u] + E[p].w + 3) % 3) {
				ok = 0;
			}
		}
	}
}

int main() {
	memset(l, -1, sizeof(l));
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		addEdge(u, v, 1);
		addEdge(v, u, -1);
		++ cdeg[u]; ++ rdeg[v];
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			ok = 1; ty = 0; cnt_e = 0;
			cnt[0] = cnt[1] = cnt[2] = 0;
			dfs(i);
			if (!ok) {
				ans += 1LL*(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);
			} else {
				if (!ty) {
					ans += cnt_e;
				} else ans += 1LL*cnt[0]*cnt[1]+1LL*cnt[1]*cnt[2]+1LL*cnt[2]*cnt[0];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

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

  string ans;
  rep(i, n-1) {
    if(s[i] != s[i+1]) ans+=s[i];
  }
  ans+=s[n-1];
  cout << ans.size() << endl;
  return 0;
}

Measured memory_bytes: 3696
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i, 0, n)
        cin >> a[i];
    ll ans = 0;
    REP(i, 1, n)
    if (a[i - 1] > a[i])
    {
        ans += a[i - 1] - a[i];
        a[i] = a[i - 1];
    }

    cout << ans << endl;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

vector<vector<P>> G;
vector<int> loc;
vector<bool> seen;
bool dfs(int v) {
    if (loc[v]==INF) loc[v] = 0;
    seen[v] = true;
    for(const auto& p: G[v]) {
        int nv = p.fi, tmp = loc[v]+p.se;
        debug(seen[nv], v, nv, tmp);
        if (!seen[nv]) {
            loc[nv] = tmp;
            dfs(nv);
        }
    }
    return true;
}

int main() {
    int n, m; cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int u, v, cost; cin >> u >> v >> cost;
        u--; v--;
        G[u].emplace_back(v, cost);
        G[v].emplace_back(u, -cost);
    }
    loc.assign(n, INF);
    seen.assign(n, false);
    rep(i, n) {
        if (seen[i]) continue;
        dfs(i);
        debug(seen);
        debug(loc);
    }
    rep(i, n) {
        for(const auto& p: G[i]) {
            if (loc[p.fi]!=loc[i]+p.se) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12032
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int N = GetInt();
		double[] a = new double[N];
		for(int i = 0; i < N; i++)
			a[i] = GetDouble();
		double avr = a.Sum() / N;

		double[] b = new double[N];
		for(int i = 0; i < N; i++)
			b[i] = Math.Abs(a[i] - avr);
		double dif = b[0];
		int ans = 0;
		for(int i = 1; i < N; i++)
		{
			if(b[i] >= dif)
				continue;
			dif = b[i];
			ans = i;
		}

		Console.WriteLine(ans);		
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n;
int a[200009];
int cnt[200009];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    ll sum=0;
    for(int i=1;i<=n;i++){
        if(cnt[i]){
            sum+=1ll*cnt[i]*(cnt[i]-1)/2;
        }
    }
    for(int i=1;i<=n;i++){
        cout<<sum-1ll*(cnt[a[i]]-1)<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
// AOJ
#include<stdio.h>
#include<math.h>

int main(){
	int x, y, s, i;
	while(scanf("%d %d", &x, &y) != EOF){
		i = 1;
		while(1){
			s = x+y;
			s -= pow(10.0, (double)i);
			if(s < 0)
				break;
			i++;
		}
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 644
#include<iostream>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if(a==b) cout << "Draw";
  else{
    if(a==1) cout << "Alice";
    else if(b==1) cout << "Bob";
    else if(a>b) cout << "Alice";
    else cout << "Bob";
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int counter = 0;
        int x;
        int[] array = new int[10000];
        while((x = scanner.nextInt())!=0){
            array[counter] = x;
            counter++;
        }
        for(int i = 0; i < counter; i++){
            System.out.println("Case "+(i+1)+": "+array[i]);
        }
    }
}



Measured memory_bytes: 42908
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&c<48)c=getchar();if(c=='-')f=-1,c=getchar();while(c>47)x=x*10+(c^48),c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    int d=read(), t=read(), s=read();
    if(t*s>=d) printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3628
N, W = map(int, input().split())
dp = [0] * (W + 1)
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W - w, -1, -1):
        dp[j + w] = max(dp[j + w], dp[j] + v)
print(dp[W])

Measured memory_bytes: 41708
#include<iostream>
    #include<vector>
    using namespace std;
    int main()
    {
    int s,i=0;
    cin>>s;
    if(s==1)
    cout<<4;
    else if(s==2)
    cout<<4;
    else
    {
    while(s!=4)
    {
    	if(s%2==0)
    	s=s/2;
    	else
    	s=(3*s)+1;
    	i++;
    }
    cout<<i+4;
   }
	}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = map(int, input().split())
ok = [0] * 10
for a in A: ok[a] = 1

dp = [-1] * (N + 1)
dp[0] = 0
cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

for i in range(N):
    for num in range(1, 10):
        c = cost[num]
        if ok[num] == 0 or i + c > N: continue
        dp[i+c] = max(dp[i+c], dp[i] * 10 + num)

ans = dp[N]
print(ans)


Measured memory_bytes: 14692
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int p_MAX = 110000;
vector<int> prime;
int calc_prime()
{
  bool notPrime[p_MAX];
  int n = sqrt(p_MAX)+1;
  notPrime[0]=1;
  notPrime[1]=1;
  for(int i=0;i<=n;i++){
    if(notPrime[i])
      continue;
    int m = p_MAX/i;
    for(int j=2;j<=m;j++)
      notPrime[j*i]=1;
  }
  for(int i=0;i<p_MAX;i++)
    if(!notPrime[i])
      prime.push_back(i);
  return 0;
}
int main()
{
  int x,res;
  cin >> x;
  calc_prime();
  res=*lower_bound(prime.begin(),prime.end(),x);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 512
H, W, A, B = map(int, input().split())

w1 = ''.join(['1'] * A + ['0'] * (W-A))
w2 = ''.join(['0'] * A + ['1'] * (W-A))
for i in range(B):
    print(w1)
for i in range(H-B):
    print(w2)

Measured memory_bytes: 39664
n = int(input())
num_list = list(map(int,input().split()))
sorted_num_list = sorted(num_list)
cnt = 0
for i in range(len(num_list)):
	if num_list[i] != sorted_num_list[i]:
		cnt += 1
if cnt < 3:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;
int N, M;
int D2M[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int A[20];
int dp[10099];

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

  cin >> N >> M;
  for (size_t i = 0; i < M; i++) {
    cin >> A[i];
  }
  sort(A, A + M, greater<int>());

  // dp[i] maximum digits in the number formed using i matchstick
  for(int i = 1;i <= N;i++) {
    dp[i] = -1;
    for(int j = 0;j < M;j++) {
      if((i - D2M[A[j]]) >= 0 and dp[i - D2M[A[j]]] != -1) {
        dp[i] = max(dp[i], 1 + dp[i - D2M[A[j]]]);
      }
    }
  }

  while(N > 0) {
    for(int i = 0;i < M;i++) {
      if((N - D2M[A[i]]) >= 0 and (dp[N]-1) == dp[N - D2M[A[i]]]) {
        N -= D2M[A[i]];
        cout << A[i];
        break;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1000000009;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
struct SegmentTree{
    int siz;
    vector<int> node;
    SegmentTree(int n,int init){
        siz=1;
        while(siz<n)siz<<=1;
        node.assign(2*siz,init);
    }

    void update(int k,int x){
        k+=siz-1;
        node[k]=x;
        while(k>0){
            k=(k-1)/2;
            node[k]=min(node[2*k+1],node[2*k+2]);
        }
    }

    int query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=siz;
        if(r<=a||b<=l)return INT_MAX;
        if(a<=l&&r<=b)return node[k];
        int vl=query(a,b,2*k+1,l,(l+r)/2);
        int vr=query(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};
int main(){
	int n,q;cin>>n>>q;
	SegmentTree seg(n,INT_MAX);
	while(q--){
		ll com,x,y;cin>>com>>x>>y;
		if(com){
			cout<<seg.query(x,y+1)<<endl;
		}else{
			seg.update(x,y);
		}
	}
    return 0;
}



Measured memory_bytes: 3824
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <deque>

#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;



signed main() {
	deque<int> b;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (i % 2 == 0) b.push_back(t);
		else b.push_front(t);
	}

	if (n % 2) for (int i = 0; i < n; i++) cout << b[n - i - 1] << ' ';
	else for (int i = 0; i < n; i++) cout << b[i] << ' ';
	cout NL;

	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
const int maxn=404;
const ll modn=1e9+7;
const int inf=2e9+7;
const double PI = acos(-1.0);
const double eps=1e-8;
inline int lowbit(int x){return x&-x;}
inline ll lowbit(ll x) {return x&-x;}
inline int CountOneBinary(ll num){int ans=0;while(num){if(num&1) ans+=1;num>>=1;}return ans;}
inline void read(int &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline void read(ll &x){char c;x=0;for(c=getchar();c>'9'||c<'0';c=getchar());for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';}
inline ll qpow(ll x,ll y){ll ans=1;while(y){if(y&1) ans=ans*x%modn;x=x*x%modn;y>>=1;}return ans;}
inline double qpow(double x,ll y){double ans=1;while(y){if(y&1) ans=ans*x;x=x*x;y>>=1;}return ans;}
ll n,c,a[maxn],b[maxn],x[maxn][maxn],dp[maxn][maxn],pre[maxn][maxn];
inline ll mod(const ll &tmp)
{
    return (tmp%modn+modn)%modn;
}
int main()
{
    for(ll i=1;i<maxn;i++)
    {
        x[i][0]=1;
        x[i][1]=i;
        for(ll j=2;j<maxn;j++) x[i][j]=x[i][j-1]*i%modn;
    }
    for(int i=1;i<maxn;i++)
    {
        for(int j=0;j<maxn;j++) pre[i][j]=(pre[i-1][j]+x[i][j])%modn;
    }
    while(scanf("%lld%lld",&n,&c)==2)
    {
        memset(dp,0,sizeof(dp));dp[0][0]=1;
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=c;j++)
            {
                for(int k=0;k<=j;k++)
                {
                    dp[i][j]=(dp[i][j]+dp[i-1][j-k]*mod(pre[b[i]][k]-pre[a[i]-1][k]))%modn;
                }
            }
        }
        printf("%lld\n",dp[n][c]);
    }
}


Measured memory_bytes: 4096
H,W,A,B = map(int,input().split())

s = [['0']*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if i>=B and j<A:
            s[i][j] = '1'
        elif i<B and j>=A:
            s[i][j] = '1'

for ss in s:
    tmps = ''.join(ss)
    print(tmps)


Measured memory_bytes: 11892
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>

int		main(void)
{
	int		a, b, c;
	int		tmp;

	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);

	if( a < b )
	{
		if( c < b )
		{
			tmp = b;
			b = c;
			c = tmp;
		}
		if( b < a )
		{
			tmp = a;
			a = b;
			b = tmp;
		}
	}
	else
	{
		tmp = a;
		a = b;
		b = tmp;

		if( c < b )
		{
			tmp = c;
			c = b;
			b = tmp;

			if( b < a )
			{
				tmp = a;
				a = b;
				b = tmp;
			}
		}
	}
	printf("%d %d %d\n",a,b,c);

	return 0;
}

Measured memory_bytes: 596
from collections import deque
def resolve():
    N, MOD = map(int, input().split())
    G = [[] for i in range(N)]
    for i in range(N - 1):
        x, y = map(lambda x:int(x)-1, input().split())
        G[x].append(y)
        G[y].append(x)

    P = [-1]*N
    q = deque([0])
    R = []
    while q:
        i = q.popleft()
        R.append(i)
        for to in G[i]:
            if to != P[i]:
                P[to] = i
                G[to].remove(i)
                q.append(to)

    unit = 1 # 単位元
    merge = lambda a, b: a * b % MOD
    adj_bu = lambda a, i: a + 1
    adj_td = lambda a, i, p: a + 1
    adj_fin = lambda a, i: a # 最終結果。本問では、全部白みたいなのが認められないので、最終結果では1を足さないようにしています。

    # Bottom-Up 部分
    ME = [unit] * N
    dp1 = [0] * N
    for i in R[1:][::-1]:
        dp1[i] = adj_bu(ME[i], i)
        p = P[i]
        ME[p] = merge(ME[p], dp1[i])
    dp1[R[0]] = adj_fin(ME[R[0]], R[0])

    # Top-Down 部分
    TD = [unit] * N
    for i in R:
        # 左からDP（結果はTDに入れている）
        ac = TD[i]
        for j in G[i]:
            TD[j] = ac
            ac = merge(ac, dp1[j])
        # 右からDP（結果はacに入れている）
        ac = unit
        for j in G[i][::-1]:
            TD[j] = adj_td(merge(TD[j], ac), j, i)
            ac = merge(ac, dp1[j])
            dp1[j] = adj_fin(merge(ME[j], TD[j]), j)

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


if __name__ == "__main__":
    resolve()


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N;
  cin >> N;
  int count = 0;
  for(int i = 1; i <= N; ++i){
    int p;
    cin >> p;
    if(i != p){
      count++;
    }
  }
  if(count > 2){
    cout << "NO" <<endl;
  } else{
    cout << "YES" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    ll N;
    cin >> N;
    string ans = "";
    while(N > 0){
        N--;
        ans += char('a' + N % 26);
        N /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


ll l[35];

ll power(ll m, ll n){

    l[0]=m;
    for(ll i=1; i<35; i++){
        l[i] = (l[i-1]*l[i-1]) % MOD;
    }

    ll tmp = n;
    ll ans = 1;
    rep(i,35){
        if(tmp%2==1){
            ans = (ans*l[i]) % MOD;
        }
        tmp /= 2;
    }
    return ans%MOD;

}


void solve(){

    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = (power(2,n)-1 + MOD)%MOD;
    ll tmp1 = 1;

    for(ll i = n; i>=n-a+1; i--){
        tmp1 = (tmp1 * i) % MOD; 
    }
    for(ll i = a; i>=1; i--){
        tmp1 = (tmp1 * (power(i, MOD-2)%MOD)) % MOD; 
    }

    ll tmp2 = 1;
    for(ll i = n; i>=n-b+1; i--){
        tmp2 = (tmp2 * i) % MOD; 
    }
    for(ll i = b; i>=1; i--){
        tmp2 = (tmp2 * (power(i, MOD-2)%MOD)) % MOD; 
    }

    cout << (ans - tmp1 - tmp2 + 100*MOD)%MOD << endl;

}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;

int main() {
	string s; cin >> s;
	bool x;

	if (s.size() == 1) { cout << "0" << endl; return 0; }

	if (s[0] == 'B') { x = true; }
	else { x = false; }

	int  change = 0;

	for (int i = 1; i < s.size(); i++) {
		if (x) {
			if(s[i]=='B'){}
			else { change++; x = false; }
		}
		else {
			if(s[i]=='W'){}
			else { change++; x = true; }
		}
	}
	
	cout << change << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    long long X, Y;
    cin >> X >> Y;
    if(abs(X-Y)<=1){
        cout << "Brown" << endl;
    }else{
        cout << "Alice" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
int main()
{
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

int main()
{
	string s;
	cin >> s;

	cout << s.substr(0, 4) << " " << s.substr(4) << endl;
}


Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, K = (int(_) for _ in input().split())
    ans = 0
    if K%2 ==0:
        d = N // K
        cnt = 0
        for i in range(1,N+1):
            if i % K == K/2: cnt+=1
        ans = d ** 3 + cnt ** 3
    else:
        d = N // K     
        ans = d ** 3
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <map>

using namespace std;

int main() {
  int N, R;
  cin >> N >> R;
  int ir;
  if (10 <= N) {
    ir = R;
  } else {
    ir = R + 100 * (10 - N);
  }
  cout << ir << endl;
  return 0;
}


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

int main() {
    int n, l, r, ans = 0;
    cin >> n;
    rep(i, n) {
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3552
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
long long read() {
  long long x = 0, w = 1;
  char ch = getchar();
  while (!isdigit(ch)) w = ch == '-' ? -1 : 1, ch = getchar();
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * w;
}
const int Max_n = 605, mod = 1e9 + 7;
int n, K, m, ans;
int to[Max_n], s[Max_n];
int f[Max_n][Max_n], g[Max_n];
int F(int l, int r) { 
  if (l > r) return 0;
  return r - l + 1 - s[r] + s[l - 1]; 
}
int main() {
  n = read() << 1, m = read() << 1, g[0] = 1;
  int u, v;
  for (int i = 1; i <= (m >> 1); i++) {
    u = read(), v = read();
    to[u] = v, to[v] = u, s[u] = s[v] = 1;
  }
  for (int i = 1; i <= n; i++) s[i] += s[i - 1];
  for (int i = 2; i <= n; i += 2)
    g[i] = 1ll * (i - 1) * g[i - 2] % mod;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if ((j - i) & 1) {
        bool fl = 0;
        for (int k = i; k <= j; k++)
          if (to[k] && (to[k] < i || to[k] > j)) fl = 1;
        if (fl) continue;
        f[i][j] = g[F(i, j)];
        for (int k = i + 1; k < j; k++)
          f[i][j] = (f[i][j] - 1ll * f[i][k] * g[F(k + 1, j)] % mod + mod) % mod;
        //cout << i << " " << j << " " << f[i][j] << " " << F(1, i - 1) + F(j + 1, n) << endl;
        ans = (ans + 1ll * f[i][j] * g[F(1, i - 1) + F(j + 1, n)] % mod) % mod;
      }
  cout << ans;
}


Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC152A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, M;
            var word = Console.ReadLine().Split(' ');
            M = int.Parse(word[0]);
            N = int.Parse(word[1]);
            if (N==M)
                Console.WriteLine("Yes");
            else 
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000007
#define inf 1e18
#define end "\n"
#define inp(arr,n) for(int i=0;i<n;i++) cin>>arr[i]
#define soa(arr,n) sort(arr,arr+n)
#define sov(arr) sort(arr.begin(),arr.end())
#define fr(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (b == 0){
        *x = 1, *y = 0;
        return a;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b, a%b , &x1, &y1);
    *x = y1;
    *y = x1-(a/b)*y1;
    return gcd;
}
ll modInverse(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    while(t--){
        int n;
        string s;
        cin>>n>>s;
        int w=0,r=0;
        fr(i,0,n-1){
            if(s[i]=='W') w++;
            else r++;
        }
        int c=0;
        for(int i=n-1;i>=n-w;i--){
            if(s[i]=='W') c++;
        }
        int ans=min(w-c,r);
        cout<<ans<<end;
    }
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define MAXN 2550
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    int n, k, rep = 1;
    char aux, last;
    cin >> n >> k;
    vector<int> dp;

    cin >> last;

    for (int i=0; i<n-1; i++){
        cin >> aux;
        if (aux == last) rep++;
        else last = aux, dp.push_back(rep), rep = 1;
    }
    dp.push_back(rep);

    while (k--){
        if (dp.size() <= 2){
            cout << n-1 << endl;
            return 0;
        }

        int tmp = dp.back();
        dp.pop_back();
        tmp += dp.back(), dp.pop_back();
        tmp += dp.back(), dp.pop_back();
        dp.push_back(tmp);
    }
    int ans = 0;
    for (auto x: dp) ans += x-1;


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

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

bool isPrime(int x){
  if(x==2){
    return true;
  }
  if(x<2 || x%2==0){
    return false;
  }

  int i=3;
  while(i<=sqrt(x)){
    if(x%i==0){
      return false;
    }
    i = i+2;
  }

  return true;
}

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

  int N[n];
  int c=0;
  for(int i=0;i<n;i++){
    cin >> N[i];
    if(isPrime(N[i])){
      c++;
    }
  }
  cout << c << endl;

  return 0;
}



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

int main(){
  int n, m, l;
  long long a[100][100], b[100][100], c[100][100];
  cin >> n >> m >> l;
  for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < m; i++) for (int j = 0; j < l; j++) cin >> b[i][j];
  for (int i = 0; i < n; i++){
    for (int j = 0; j < l; j++){
      c[i][j] = 0;
      for (int k = 0; k < m; k++){
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = 0; j < l; j++){
      if (j) cout << " ";
      cout << c[i][j];
    }
    cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
int main(){
  int64_t X,K,D;
  
  cin>>X>>K>>D;
  if(X<0){
    X=-X;
  }
  if(X/D>=K){
    cout<<X-K*D<<endl;
  }   //原点に届かないとき
  
   else if(X>=D){
     int count=0;
    while(X>=D){
      X-=D;
      count++;
    }  //Xが原点に正方向から最接近するときの回数
    X=X+D*count;
    int64_t nokori=K-count;
     
    
      if(nokori%2==1){
       cout<<D-X%D<<endl;
      }
      else{
       cout<<X%D<<endl;
      }
   }
  
  
  if(X<D){
     if(K%2==0){
       cout<<X<<endl;
      }
      else{
       cout<<D-X<<endl;
      }
   }
  
}
   

Measured memory_bytes: 3620
#include <iostream>                                                  
#include <cstring>                                                   
using namespace std;                                                 
char c[128];                                                         
                                                                     
int main() {                                                         
  while(true){                                                       
    int n;                                                           
    cin >> n;                                                        
    if (n==0) {                                                      
      break;                                                         
    }                                                                
    memset(c,0,sizeof(c));                                           
    for(int i=0;i<n;i++){                                            
      char a, b;                                                     
      cin >> a >> b;                                                 
      c[a] = b;                                                      
    }                                                                
    int m;                                                           
    cin >> m;                                                        
    for (int i=0; i<m; i++) {                                        
      char a;                                                        
      cin >> a;                                                      
      if (c[a]) {                                                    
        cout << c[a] << flush;                                       
      } else {                                                       
        cout << a << flush;                                          
      }                                                              
    }                                                                
    cout << endl;                                                    
  }                                                                  
  return 0;                                                          
}                                                                    
                                                                     
                         

Measured memory_bytes: 3044
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,d,k=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    while(1){
        c-=b;
        if(c<=0){
            k++;
            break;
        }
        a-=d;
        if(a<=0){
            k+=2;
            break;
        }
    }
    if(k==1)printf("Yes\n");
    else printf("No\n");
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define SZ(x)  (int)x.size()
#define all(x) x.begin(),x.end()

using namespace std;

LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
LL powmod(LL a, LL b, LL MOD) {LL ans = 1; while (b) {if (b % 2)ans = ans * a % MOD; a = a * a % MOD; b /= 2;} return ans;}
const int N = 5e5 + 3;
const LL mod = 1e9 + 7;
int n,a[N],pos[N];
set<int>Q,P;
int main() {
	ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i],pos[a[i]]=i;
//    int L=pos[n],R=pos[n];
    LL ans=0;
    Q.insert(pos[n]);
    P.insert(-pos[n]);
    for(int i=n-1;i>=1;i--){
        int l=pos[i];
        int L,R,c=1,d=1;
        auto k=Q.lower_bound(l);
        auto x=P.lower_bound(-l);
        if(x!=P.end()){
            L=-(*x)+1;
        }else {L=1;c=-1;}
        if(k!=Q.end()){
            R=*k-1;
        }else {R=n;d=-1;}
        if(k!=Q.end()){
            auto ne=Q.upper_bound(*k);
            int cl,cr;
            if(ne!=Q.end()){
                cr=(*ne)-1;
            }else cr=n;
            ans+=1ll*(cr-*k+1)*i*(pos[i]-L+1);
        }
        if(x!=P.end()){
            auto ne=P.upper_bound(*x);
            int cl,cr;
            if(ne!=P.end()){
                cl=-(*ne)+1;
            }else cl=1;
            ans+=1ll*(-(*x)-cl+1)*i*(R-pos[i]+1);
        }
       // cout<<i<<' '<<ans<<endl;
        Q.insert(pos[i]);
        P.insert(-pos[i]);
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10368
import bisect, collections
 
 
 
def solution():
    s = input().strip()
    if s == s[::-1] and s[:(len(s)-1)//2] == s[:(len(s)-1)//2][::-1]:
        print("Yes")
    else:
        print("No")
                

def main():    
    # T = int(input().strip())
    for _ in range(1):
        solution()

if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
// ２つの整数 a, b を読み込んで、a と b の大小関係を出力するプログラムを作成して下さい。
// 【入力】
// 入力は空白で区切られた２つの整数 a, b から構成されています。
// 【出力】
// a より b の方が大きければ
//   a < b
// a より b の方が小さければ、
//   a > b
// a と b が等しければ、
//   a == b
// と出力して下さい。
// 【制約】
// -1,000 ≤ a, b ≤ 1,000
// 【例】
// 入力：1 2、出力：a < b
// 入力：4 3、出力：a > b
// 入力：5 5、出力：a == b
#include<iostream>
using namespace std;

int main( void) {
  int a,b;

  cin >> a >> b;

  if ( a < b) cout << "a < b" << endl;
  else if ( a > b) cout << "a > b" << endl;
  else cout << "a == b" << endl;

  return 0;
}



Measured memory_bytes: 3088
let n = stdin.ReadLine() |> int
let p = stdin.ReadLine().Split() |> Array.map int

let rec resolver s i =
    if i = n - 1 then s
    elif p.[i - 1] < p.[i] && p.[i] < p.[i + 1] || p.[i + 1] < p.[i] && p.[i] < p.[i - 1] then resolver (s + 1) (i + 1)
    else resolver s (i + 1)

resolver 0 1 |> stdout.WriteLine

Measured memory_bytes: 11220
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll n, a, b;
    cin >> n >> a >> b;
    cout << max(0LL, (b * (n - 1) + a) - (a * (n - 1) + b) + 1) << endl;
}


Measured memory_bytes: 256
s = input()
t = input()
sli = list(s)
tli = list(t)
sli.sort()
tli.sort()
tli.reverse()
def tostr(lis):
    hoge = ""
    for i in lis:
        hoge += i
    return hoge
tstr = tostr(tli)
sstr = tostr(sli)
if tstr > sstr:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

int n;
vec<vec<char>> s(302,vec<char>(302)), t(302,vec<char>(302));
bool unko(ll a, ll b){
	bool ok = true;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			ll ni = (i - a + n) % n;
			ll nj = (j - b + n) % n;
			t[ni][nj] = s[i][j];
		}
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(t[i][j] != t[j][i])ok = false;
		}
	}
	return ok;
}

signed main(){
	IOS;
	cin >> n;
	REP(i, n)REP(j, n)cin >> s[i][j];
	ll ans = 0;
	for(int i = 0;i < n;i++){
		if(i == 0){
			if(unko(0,0))ans += n;
		}
		else{
			if(unko(i,0))ans += n - i;
			if(unko(0,i))ans += n - i;
		}
	}
	dump(ans);
}

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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

const long long INF = 1e10;
const int MAXV = 2550;

bool bad = false;

struct Edge {
    long long from, to, cost;
};

long long shortest(vector<Edge> &edges, int n, int s, int t) {
    long long d[MAXV];
    for (int i=0; i<MAXV; ++i) d[i] = INF;
    d[s] = 0;
    long long pret = d[t];
    for (int i=0; i<6*n; ++i) {
        for (Edge e: edges) {
            if (d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
            }
        }
        if (i >= 3*n && pret != d[t]) {
            bad = true;
            return -1;
        }
        pret = d[t];
    }
    return d[t];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N, M, P;
    cin >> N >> M >> P;

    vector<Edge> edges;
    for (int i=0; i<M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        edges.push_back((Edge){ A, B, -(C-P) });
    }

    long long score = shortest(edges, N, 1, N);
    if (bad) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, -score) << endl;
    }

    return 0;
}


Measured memory_bytes: 576
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define INF 1<<9

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

	S.pop_back();
	while (1) {
		if (S.size() % 2 == 0) {
			bool flag = true;
			REP(i, 0, S.size() / 2) {
				if (S[i] != S[i + S.size() / 2]) {
					flag = false;
					break;
				}
			}

			if (flag) {
				cout << S.size() << endl;
				break;
			}
		}

		S.pop_back();
	}

	return 0;
}

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

uint_fast64_t N, K, ans;

int main(){
    cin >> N >> K;
    for(uint_fast64_t i = K + 1; i <= N; ++i){
        ans += (N / i) * (i - K) + (N % i >= K ? N % i - K + 1 : 0);
    }
    if(K == 0)ans -= N - K;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
n = int(input())
G = [[] for _ in range(n+1)]
for i in range(n-1):
    v,w,dist = map(int, input().split())
    G[v].append((w,dist))
    G[w].append((v,dist))
color = [-1]*(n+1)


def dfs(a, col):
    tmp = -1
    if color[a] == -1:
        color[a] = col

    for next_V,dis in G[a]:
        if color[next_V] == -1:
            tmp = col
            if dis%2 !=0:
                tmp = 1-col
            dfs(next_V, tmp)
dfs(1,0)
[print(color[i]) for i in range(1,n+1)]

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

using namespace std;

#define sz(a) (int)(a).size()
#define pb push_back
typedef long long ll;

void solve() {
    string s;
    cin >> s;

    ll k;
    cin >> k;
    --k;

    ll time = -1;
    for (auto ch : s) {
        time++;

        if (time >= k || ch != '1') {
            cout << ch;
            return;
        }
    }

    cout << -1;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,k,x,ans=0;

	cin >> n >> k;
	for (int i=0;i<n;i++ ) {
		cin >> x;
		if (x > k - x){
			ans += 2*(k-x);
		}else{
			ans += 2*x;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
class BIT():#1-indexed
	def __init__(self, size):
		self.table = [0 for _ in range(size+2)]
		self.size = size

	def Sum(self, i):#1からiまでの和
		s = 0
		while i > 0:
			s += self.table[i]
			i -= (i & -i)
		return s

	def Add(self, i, x):#
		while i <= self.size:
			self.table[i] += x
			i += (i & -i)
		return

n = int(input())
s = [input().split() for _ in range(2*n)]
costb = [[0 for _ in range(n+1)] for _ in range(n+1)]
costw = [[0 for _ in range(n+1)] for _ in range(n+1)]
bitb, bitw = BIT(n), BIT(n)
for i in range(2*n-1, -1, -1):
	c, x = s[i][0], int(s[i][1])
	if c == "B":
		base = bitb.Sum(x-1)
		for j in range(n+1):
			costb[x-1][j] = base + bitw.Sum(j)
		bitb.Add(x, 1)
	else:
		base = bitw.Sum(x-1)
		for j in range(n+1):
			costw[j][x-1] = base + bitb.Sum(j)
		bitw.Add(x, 1)

dp = [[0 for _ in range(n+1)] for _ in range(n+1)]
for i in range(n+1):
	for j in range(n+1):
		if i+j == 0:
			continue
		if i == 0:
			dp[i][j] = dp[i][j-1] + costw[i][j-1]
		elif j == 0:
			dp[i][j] = dp[i-1][j] + costb[i-1][j]
		else:
			dp[i][j] = min(dp[i][j-1] + costw[i][j-1], dp[i-1][j] + costb[i-1][j])

print(dp[n][n])

Measured memory_bytes: 140164
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define dup(x) x.erase(unique(x.begin(), x.end()),x.end())
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
// https://atcoder.jp/contests/abc172/tasks/abc172_d
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n;
    cin >> n;
    ll ans = 0;
    for(int i = 1;i<=n;i++){
        ans += (n/i) * (n/i+1) * i/2;
    }
    cout << ans;

	return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
for i in range(2,int(n**.5) + 1):
  if n % i == 0:
    tmp = n
    while tmp % i==0:
      tmp //= i
    if (tmp-1) % i == 0:ans += 1

    if n//i != i:
      tmp = n;i = n//i
      while tmp % i==0:
        tmp //= i
      if (tmp-1) % i == 0:ans += 1

for i in range(2,int((n-1)**.5 )+ 1):
  if (n-1) % i == 0:
    if (n-1) // i == i: ans += 1
    else: ans += 2
# print(ans)
print(ans+1 + int(n != 2))

Measured memory_bytes: 40172
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
T lread(T = long)()
{
    return readln.chomp.to!T();
}
 
T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}
 
void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long a,b;
    scan(a,b);
    (a - b + 1).writeln();
}

Measured memory_bytes: 256
# coding: utf-8
import sys
from heapq import heapify, heappop, heappush

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# vertexごとに3つの状態数を持つ
N, M = lr()
graph = [[] for _ in range((N+1)*3)]  # 1-indexed
for _ in range(M):
    a, b = lr()
    a *= 3; b *= 3
    for i in range(3):
        j = i+1 if i < 2 else 0
        graph[a+i].append(b+j)

INF = 10 ** 15

def dijkstra(start):
    dist = [INF] * (N+1) * 3
    dist[start] = 0
    que = [(0, start)]
    while que:
        d, prev = heappop(que)
        if dist[prev] < d:
            continue
        for i in graph[prev]:
            #print(graph[prev],dist[next],next)
            d1 = d + 1
            if dist[i] > d1:
                dist[i] = d1
                heappush(que, (d1, i))
    return dist

S, T = lr()
dist = dijkstra(S*3)
answer = dist[T*3]
if answer == INF:
    answer = -1
else:
    answer //= 3
print(answer)


Measured memory_bytes: 91300
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	a := ReadInts(N)
	b := make([]int, 0)
	s := make([]int, N)
	for i := N; i >= 1; i-- {
		if s[i-1]%2 != a[i-1] {
			b = append(b, i)
			nums := Divisors(i)
			for _, num := range nums {
				s[num-1]++
			}
		}
	}
	if len(b) == 0 {
		fmt.Println(0)
		return
	}
	fmt.Println(len(b))
	for i, bi := range b {
		if i > 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%d", bi)
	}
	fmt.Println()
}

func Divisors(n int) []int {
	ret := make([]int, 0)
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			ret = append(ret, i)
			if i*i != n {
				ret = append(ret, n/i)
			}
		}
	}
	return ret
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 11456
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let nk = read_vec::<i64>();
    let dn :Vec<char>= read_vec::<i64>().iter().map(|&x| x.to_string().chars().collect::<Vec<char>>()[0]).collect();
    for j in nk[0]..{
        if j.to_string().chars().all(|x| !dn.contains(&x)){
            println!("{}",j );
            return;
        }
    }
}

Measured memory_bytes: 4352