akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

string solve(string in){
	// sankou
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=499572#1
	string from = "apple";
	string to = "peach";

	for (int i = 0; i < in.length(); i++){
		string sub = in.substr(i, 5);
		if (sub == from)	in.replace(i, 5, to);
		else if (sub == to)	in.replace(i, 5, from);
	}

	return in;
}

int main(){
	string in;
	getline(cin, in);
	cout << solve(in) << endl;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int dx[2][6]={{-1,0,1,0,-1,-1},{0,1,1,1,0,-1}},dy[6]={-1,-1,0,1,1,0};
int fie[104][104];
void func(int x,int y){
    if(fie[y][x]!=0)return;
    fie[y][x]=2;
    for(int i=0;i<6;i++){
        if(0<=x+dx[y%2][i]&&x+dx[y%2][i]<=103&&0<=y+dy[i]&&y+dy[i]<=103){
            if(fie[y+dy[i]][x+dx[y%2][i]]==0)func(x+dx[y%2][i],y+dy[i]);
        }
    }
}
int main(){
    int W,H;
    int ans=0;
    cin>>W>>H;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++)cin>>fie[i][j];
    }
    func(0,0);
    for(int i=0;i<=H+1;i+=2){
        for(int j=0;j<=W+2;j++){
            for(int k=0;k<6;k++){
                if(j!=0&&k==5)break;
                if(0<=j+dx[0][k]&&j+dx[0][k]<=103&&0<=i+dy[k]&&i+dy[k]<=103){
                    if((fie[i+dy[k]][j+dx[0][k]]==1&&fie[i][j]==2)||(fie[i+dy[k]][j+dx[0][k]]==2&&fie[i][j]==1)){
                        ans++;
                    }
                }
            }
        }
    }
    for(int i=1;i<=H+2;i+=2){
        for(int j=1;j<=W+2;j++){
            if((fie[i][j]==1&&fie[i][j-1]==2)||(fie[i][j]==2&&fie[i][j-1]==1))ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

// unsigned long long modpow(long long a,long long n){
//     long long x=1;
//     while(n>0){
//         //nの2進数表記の右端が1
//         if(n&1){
//             x=x*a;
//         }
//         a=a*a;
//         n>>=1; //nを右に1bitずらす
//     }
//     return x;
// }
int main(){
    long long n,p; cin>>n>>p;
    if(n==1){
        cout<<p<<endl;
        return 0;
    }
    long long MAX=1;
    for(long long i=2;;i++){
        if(pow(i,n)>1e13) break;
        MAX=i+1;
    }
    long long ans=1;
    for(long long i=2;i<=MAX;i++){
        long long tmp=pow(i,n);
        if(p%tmp==0){
            ans=i;
        }else if(p<=tmp){
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long int a,b,k;cin>>a>>b>>k;
  	int turn = 0;
  	while(k--){
    	if(!turn){
        	int m = a/2;
          	a/=2; b+=m;
        }
      	else {
        	int m = b/2;
          	b/=2; a+=m;
        }
      	turn++;
      	turn%=2;
    }
  	cout<<a<<" "<<b;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, c) for (int i = 0; i < (int)c;i++)
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> data(N);
  int sum = 0;  
  rep(i,N){
    cin >> data.at(i);
    sum += data.at(i);
  }
  sort(data.begin(), data.end());
  int cnt = 0;
  double tmp = (double)sum / (4 * M);
  rep(i, N)
  {
    if(data.at(i)>=tmp){
      //cout << data.at(i) <<" "<< tmp <<" "<<cnt<< endl;
      cnt++;
    }
  }
  //cout << cnt << endl;
  if (cnt >= M)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
nodes = [[] for i in range(N)]
edges = {}
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
    edges[(a, b)] = [i, -1]

mx = 0
used = [set() for i in range(N)]
ans = [0] * (N-1)
cnt = 0
for u in range(N):
    mx = max(mx, len(nodes[u]))
    color = 1
    for v in nodes[u]:
        a, b = min(u, v), max(u, v)
        if edges[(a, b)][1] == -1:
            while color in used[a] or color in used[b]:
                color += 1
            edges[(a, b)][1] = color
            used[a].add(color)
            used[b].add(color)
            i = edges[(a, b)][0]
            ans[i] = str(color)
            color += 1
            cnt += 1
            if cnt == N-1:
                break
    else:
        continue
    break
print(mx)
print('\n'.join(ans))


Measured memory_bytes: 110112
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

struct point {
	int x;
	int y;
	int id;
};

struct line {
	int fromx;
	int tox;
	int id;
	ld ny;
	ld fromy;
	ld toy;
	ld getdy()const {
		return (toy - fromy) / (tox - fromx);
	}
};
bool operator<(const line&l, const line&r) {
	return abs(l.ny-r.ny)<eps?l.getdy()<r.getdy():l.ny < r.ny;
}
const int aa = 2001;
const int bb = 0;
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<vector<point>>xs(2*aa+1);
		vector<point>ps;
		for (int i = 0; i < N; ++i) {
			int x, y; cin >> x >> y;
			x -= bb;
			x += aa;
			y += aa;
			y = 2 * aa - y;
			xs[x].push_back(point{ x,y,i });
			ps.push_back(point{ x,y,i });
		}

		vector<line>nlines;
		vector<vector<bool>>oks(2 * aa, vector<bool>(2 * aa));
		for (int nx = 0; nx < aa * 2 + 1; ++nx) {
			for (auto p : xs[nx]) {
				for (int i = 0; i < 2; ++i) {
					int tarid;
					if (i == 0)tarid = (p.id + 1) % N;
					else tarid = (p.id + N - 1) % N;
					if (nx < ps[tarid].x) {
						const line aline{ p.x,ps[tarid].x,tarid,ld(p.y),ld(p.y),ld(ps[tarid].y) };
						auto it = lower_bound(nlines.begin(), nlines.end(), aline);
						nlines.insert(it,aline);
					}
					else if (nx>ps[tarid].x) {
						nlines.erase(find_if(nlines.begin(), nlines.end(), [=](const line&l) {return l.id == p.id; }));
					}
				}
			}
			for (auto &l : nlines) {
				const ld dy = (l.toy - l.fromy) / (l.tox - l.fromx);
				int fy, ty;
				if (abs(dy) < eps)continue;
				else if (dy > 0) {
					fy = int(l.ny + eps);
					ty = int(l.ny + dy - eps);
				}
				else {
					fy = int(l.ny + dy + eps);
					ty = int(l.ny - eps);
				}
				l.ny = l.ny + dy;
				for (int y = fy; y <= ty; ++y) {
					oks[y][nx] = true;
				}
			}
			for (int i = 0; i < nlines.size(); i += 2) {
				int fy = int(nlines[i].ny + eps);
				int ty = int(nlines[i + 1].ny - eps);
				for (int y = fy; y <= ty; ++y) {
					oks[y][nx] = true;
				}
			}
		}

		int ans = 0;
		for (int y = 0; y < 2 * aa; ++y) {
			for (int x = 0; x < 2 * aa; ++x) {
				ans += oks[y][x];
				/*if (oks[y][x])cout << "#";
				else cout << ".";*/
			}
			//cout << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5164
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;

int main(){
	map<char,bool> mp;
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		char c;
		cin >> c;
		mp[c] = true;
	}

	if(mp.size() == 4)cout << "Four" << endl;
	else cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
long long n,m,i,j,k,a[200005],cnt=0,ans;
int main(){
	scanf("%lld%lld",&n,&m);
	ans=n;
	for(i=1;i<=m;i++){
		scanf("%lld",&a[i]);
		cnt+=a[i];
	}
	k=ans-cnt;
	if(k>=0){
		printf("%lld\n",k);
	}
	else{
		printf("-1");
	}
	return 0;
}

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
static const int MAX = 10000;
int Count[MAX + 1];

int main(){
  int n, m;
  cin >> n;
  for(int i = 0; i <= MAX; i++)
    Count[i] = 0;
  for(int i = 0; i < n; i++){
    cin >> m;
    Count[m]++;
  }

  for(int i = 0, c = 0; c < n; i++){
    if(Count[i] > 0){
      while(Count[i]--){
        if(c)
          cout << " ";
        cout << i;
        c++;
      }
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = Integer.parseInt(scan.nextLine());
	String input = scan.nextLine();
	String[] sequence = input.split(" ");
	for (int i = n - 1; i > 0; i--) {
	    System.out.print(sequence[i] + " ");
	}
	System.out.println(sequence[0]);
    }
}

Measured memory_bytes: 26232
import java.util.*

val sc = Scanner(System.`in`)
val N = sc.nextInt()
val S: String = sc.next()

fun main(args: Array<String>) {
    var ans = 0

    for (i in 0 until N) {
        val x = S.slice(0..i).toSet()
        val y = S.slice(i + 1 until N).toSet()

        var cnt = 0
        for (c in 'a'..'z') {
            if (c in x && c in y) {
                cnt++
            }
        }
        ans = Math.max(ans, cnt)
    }
    println(ans)
}


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

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var r = vars[0];
        

        System.Console.WriteLine(System.Math.PI * r * 2);
    }
}

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

int main() {
    string N;
    cin >> N;
    int x;
    for(char c : N) {
        x += (c - '0');
         x %= 9;
    }
    if(x == 0){
        cout << "Yes" <<endl;
    } else {
        cout << "No"<< endl;
    }
}

Measured memory_bytes: 3728
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        a: i8,
        b: i8,
        c: i8
    };
    println!("{}", ["No", "Yes"][((a <= c) && (c <= b)) as usize]);
}


Measured memory_bytes: 2168
N, M, K = map(int, input().split())

class UnionFind:
    def __init__(self, n):
        self.table = [-1 for _ in range(n)]
        self.size = [1]*n

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

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

    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.size[r1] += self.size[r2]
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
            self.size[r2] += self.size[r1]

    def group_size(self, x):
        return self.size[self._root(x)]

Friends = [list(map(int, input().split())) for _ in range(M)]
Blocks = [list(map(int, input().split())) for _ in range(K)]

Friendship = UnionFind(N)
Cant = [0]*N

for a in Friends:
    Friendship.union(a[0]-1, a[1]-1)

for b in Friends:
    if Friendship.find(b[0]-1, b[1]-1):
        Cant[b[0]-1] += 1; Cant[b[1]-1] += 1

for c in Blocks:
    if Friendship.find(c[0]-1, c[1]-1):
        Cant[c[0]-1] += 1; Cant[c[1]-1] += 1

print(*[Friendship.group_size(i)-Cant[i]-1 for i in range(N)])

Measured memory_bytes: 120784
while True:
    (a, op, b) = [int(i) if i.isdigit() else i for i in input().split()]

    if op == '?':
        break
    elif op =='+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(a//b)
    else :
        break

Measured memory_bytes: 6720
import java.util.*;

/**
 * Main
 */
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int now = sc.nextInt();
		int next = 0;
		int count = 0;
		int answer = 0;
		for(int i=0; i<N-1; i++){
			next = sc.nextInt();
			if(now >= next){
				count++;
			} else{
				answer=Math.max(answer,count);
				count=0;
			}
			now = next;
		}
		answer=Math.max(answer,count);
		System.out.println(answer);

		sc.close();
	}
};

Measured memory_bytes: 47876
#include<iostream>
#include<vector>
#include<string>

using namespace std;
vector<int> ans;
int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		bool fd = true;
		bool lf = true,rf = true;
		int count = 0;
		for(int i = 0;i < n;i++){
			string f;
			cin >> f;
			if(f == "lu" || f == "ld") lf = !lf;
			else rf = !rf;
			if(lf == rf && lf != fd){
				fd = !fd;
				count++;
			}
		}
		ans.push_back(count);
	}
	for(int i = 0;i < ans.size();i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string ans;
  rep(i, n) {
    ans.push_back(s.at(i));
    ans.push_back(t.at(i));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int>mp[100010],ans;
int low[100010],num=0,vis[100010]={0};bool inq[100010];
void dfs(int pos)
{
	low[pos]=vis[pos]=++num;int cnt=0;
	for(int i=0;i<mp[pos].size();i++)
	{
		if(!vis[mp[pos][i]])
		{
			if(!pos)++cnt;
			dfs(mp[pos][i]);
			if(pos&&!inq[pos]&&low[mp[pos][i]]>=vis[pos])ans.push_back(pos),inq[pos]=1;
			low[pos]=min(low[pos],low[mp[pos][i]]);
		}
		else low[pos]=min(low[pos],vis[mp[pos][i]]);
	}
	if(cnt>=2)ans.push_back(0);
}
int main()
{
	int n,m,a,b;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		mp[a].push_back(b),mp[b].push_back(a);
	}
	dfs(0);sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++)
	printf("%d\n",ans[i]);
}


Measured memory_bytes: 6888
#include <stdio.h>

void parser();

int main(int argc, const char *argv[])
{
	parser();	
	return 0;
}

void parser()
{
	int i, cnt, ch = getchar();
	while(ch != EOF){
		if(ch=='@'){
		 	cnt = getchar() - '0';
			ch = getchar();
			for(i=0; i<cnt; i++)
				putchar(ch);
		}else{
			putchar(ch);
		}
		ch = getchar();
	}
}

Measured memory_bytes: 0
N = gets.to_i

(1 .. 3500).each do |a|
  (1 .. 3500).each do |b|
    next if (4 * a * b  - N * b  - N  * a).zero?
    c,m = (N * a * b).divmod(4 * a * b  - N * b  - N  * a ) 
    
    next if m > 0 || c <= 0

    puts [a,b,c].join(' ')
    exit
  end
end


Measured memory_bytes: 14360
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN=100;
int const MAXV=1000;
uint64_t const MAXW=1000000000;
uint64_t const INF=MAXW*2;

int N, W;

uint64_t w[MAXN];
uint32_t v[MAXN];

uint64_t dp[MAXN+1][MAXV*MAXN+1];

int main() {
  std::cin >> N >> W;
  for(int i = 0; i < N; ++i) std::cin >> w[i] >> v[i];

  dp[0][0] = 0;
  for(int i = 1; i<=MAXV*N; ++i) dp[0][i] = INF;

  for(int i = 0; i < N; ++i) {
    for(int vv = 0; vv < v[i]; ++vv) dp[i+1][vv] = dp[i][vv];
    for(int vv = v[i]; vv <= MAXV*N; ++vv) {
      dp[i+1][vv] = std::min(dp[i][vv], dp[i][vv-v[i]]+w[i]);
    }
  }
  for(int vv=MAXV*N; vv>0; --vv) if(dp[N][vv]<=W) {
    std::cout << vv << std::endl;
    return 0;
  }
  std::cout << "0" << std::endl;
  return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
typedef long long ll;

#define pll pair<ll,ll>
#define ff first
#define snd second
#define pb push_back
#define vll vector<ll>
#define vpll vector<pll>
#define endl "\n"
#define MOD 1000000007
using namespace std;

ll const N = 1e5+1;


void solve()
{
   ll n;
   cin>>n;
   vll v(n);
   for(int i=0;i<n;i++)
   {
           cin>>v[i];
   }
   
   map<ll,ll>m;
   ll ans = 0;
   for(int i=0;i<n;i++)
   {
        //cout<<i<<" "<<v[i]<<" ";   
        if(i==0)
        {
                m[i+v[i]]++;
        }
        else
        {
                if(i>v[i])
                {
                        ans+=m[i-v[i]];
                }
                m[i+v[i]]++;
        }
        //cout<<ans<<endl;
   }
   cout<<ans;
}
 
int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
	    int t=1;
	    //cin>>t;
	    while(t--)
	    {
	            solve();
	    }
	    return 0;
}

Measured memory_bytes: 18512
#include <iostream>
#include <algorithm>

using namespace std;

const int inf = 1e8;
int s[1111];
int l[222][222], w[222][222];
int dp[1111][222];

int main(int argc, char const *argv[])
{
	// freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	while(cin >> n >> m && n){
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				if(i == j) {l[i][j] = 0, w[i][j] = 0;}
				else{l[i][j] = inf, w[i][j] = inf;}
			}
		}
		for(int i = 0; i < m; i++){
			int u, v, t;
			char op[2];
			cin >> u >> v >> t >> op;
			if(op[0] == 'L'){
				l[u][v] = min(l[u][v], t);
				l[v][u] = l[u][v];
			} else {
				w[u][v] = min(w[u][v], t);
				w[v][u] = w[u][v];
			}
		}
		for(int k = 1; k <= n; k++){
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					l[i][j] = min(l[i][j], l[i][k]+l[k][j]);
					w[i][j] = min(w[i][j], w[i][k]+w[k][j]);
				}
			}
		}

		int len; 
		cin >> len;
		// cout << len << endl;
		for(int i = 1; i <= len; i++){
			cin >> s[i];
		}
		for(int i = 1; i <= len; i++){
			for(int j = 1; j <= n; j++){
				dp[i][j] = inf;
			}
		}
		for(int i = 1; i <= n; i++){
			dp[1][i] = w[s[1]][i] + l[i][s[1]];
		}
		for(int i = 2; i <= len; i++){
			for(int j = 1; j <= n; j++){
				for(int k = 1; k <= n; k++){
					dp[i][j] = min(dp[i][j], dp[i-1][k] + l[s[i-1]][k] + w[k][j] + l[j][s[i]]);
					if(j==k) dp[i][j] = min(dp[i][j], dp[i-1][k] + l[s[i-1]][s[i]]);
				}
			}
		}
		/*for(int i = 1; i <= len; i++){
			for(int j = 1; j <= n; j++){
				cout << dp[i][j] << ' ';
			}
			cout << endl;
		}*/
		cout << *min_element(dp[len]+1, dp[len]+n+1) << endl;
	}
	return 0;
}


Measured memory_bytes: 4328
#####################################################################################################
##### トポロジカルソート
#####################################################################################################

import sys
input = sys.stdin.buffer.readline


class DiGraph:
    def __init__(self, n, decrement=True, destroy=False, edges=[]):
        """
        incs[p]: 頂点 p に流入するリンク数
        """
        self.n = n
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.incs = [0]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        self.incs[y] += 1

    def topological_sort(self):
        next_set = {p for p, inc in enumerate(self.incs) if inc == 0}
        res = []
        while next_set:
            p = next_set.pop()
            res.append(p+self.decrement)
            for q in self.edges[p]:
                self.incs[q] -= 1
                if self.incs[q] == 0:
                    next_set.add(q)
        if len(res) == self.n:
            return res
        else:
            return -1

    def draw(self):
        """
        :return: グラフを可視化
        """
        import matplotlib.pyplot as plt
        import networkx as nx

        G = nx.DiGraph()
        for x in range(self.n):
            for y in self.edges[x]:
                G.add_edge(x + self.decrement, y + self.decrement)

        pos = nx.spring_layout(G)
        nx.draw_networkx(G, pos)
        plt.axis("off")
        plt.show()


################################################################################

def main():
    N, M = map(int, input().split())

    M = N - 1 + M
    graph = DiGraph(N, decrement=True, destroy=False)
    for _ in range(M):
        A, B = map(int, input().split())
        graph.add_edge(A, B)

    temp = graph.topological_sort()
    res = [0]*N
    for p in temp:
        for q in graph.edges[p-1]:
            res[q] = p
    print(*res, sep="\n")

if __name__ == '__main__':
    main()


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

typedef pair<int, int> P;
typedef long long ll;
int N, W;
int v, w;
vector<vector<P> > luggage(4);

ll knapsack(int n1, int n2, int n3, int n4) {
  ll w_sum, v_sum;
  w_sum = v_sum = 0;
  for (int i=0; i<n1; i++) {
    w_sum += luggage[0][i].first;
    v_sum += -luggage[0][i].second;
  }
  for (int i=0; i<n2; i++) {
    w_sum += luggage[1][i].first;
    v_sum += -luggage[1][i].second;
  }
  for (int i=0; i<n3; i++) {
    w_sum += luggage[2][i].first;
    v_sum += -luggage[2][i].second;
  }
  for (int i=0; i<n4; i++) {
    w_sum += luggage[3][i].first;
    v_sum += -luggage[3][i].second;
  }
  if (w_sum <= W) return v_sum;
  else return 0;
}

int main() {
  cin >> N >> W;
  cin >> w >> v;
  luggage[0].push_back(P(w, -v));
  int base = w;
  for (int i=1; i<N; i++) {
    cin >> w >> v;
    luggage[w-base].push_back(P(w, -v));
  }
  for (int i=0; i<4; i++) sort(luggage[i].begin(), luggage[i].end());
  ll maxi = 0;
  // 重さは高々4種類なので、全探索して価値の総和を計算する
  for (int i=0; i<=luggage[0].size(); i++) {
    for (int j=0; j<=luggage[1].size(); j++) {
      for (int k=0; k<=luggage[2].size(); k++) {
        for (int l=0; l<=luggage[3].size(); l++) {
          maxi = max(maxi, knapsack(i, j, k, l));
        }
      }
    }
  }
  cout << maxi << endl;
  return 0;
}


Measured memory_bytes: 256
//Be Name Khoda
//man az biganegan  hargez  nanalam
//ke harche kard ba man ashena kard
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma optimize O3
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); }
#define MKP make_pair
#define RETD(x) { cout << fixed << setprecision(15) << x; exit(0); }
#define GEI(x) scanf("%d",&x)
#define GEL(x) scanf("%lld",&x)
#define ALL(x) x.begin(),x.end()
const ll M=1e6+5,LG=32,SM=600+5,inf=1e18+5;
ll mod=1e9+7;

ll n,m;
ll cent;
ll sz[M];
vector<pll> g[M];
ll res;

void dfs(ll x,ll p)
{
    sz[x]=1;
    for (pll id:g[x])
    {
        ll y=id.X;
        if (y==p) continue;
        dfs(y,x);
        sz[x]+=sz[y];
        res+=2*sz[y]*id.Y;
    }
}

int main()
{
    GEL(n);
    For(i,1,n)
    {
        ll u,v,w;
        GEL(u);GEL(v);GEL(w);
        u--;v--;
        g[u].PB({v,w});
        g[v].PB({u,w});
    }
    dfs(0,0);
    cent=0;
    bool b=1;
    while (b)
    {
        b=0;
        for (pll id:g[cent])
        {
            ll y=id.X;
            if (sz[y]<sz[cent] && sz[y]>n/2)
            {
                cent=y;
                b=1;
                break;
            }
        }
    }
    ll mi=inf;
    res=0;
    dfs(cent,cent);
    for (pll id:g[cent])
    {
        if (sz[id.X]==n/2 && !(n%2)) RET(res-id.Y);
        smin(mi,id.Y);
    }
    RET(res-mi);
}

Measured memory_bytes: 35456
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	while (cin >> n)
	{
		int num[5001] = {};
		int maxim = -100001;
		if (n == 0) break;
		for (int i = 0; i < n; i++) cin >> num[i];
		for (int i = 0; i < n ; i++)
		{
			int sum = 0;
			for (int j = i; j < n; j++)
			{
				sum += num[j];
				maxim = (maxim >= sum) ? maxim : sum;
			}
		}
		cout << maxim << endl;
	}
	return 0;
}


Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;

int main(void){
    
    scanf("%d", &N);
    if(N <= 111) printf("111\n");
    else if(N <= 222) printf("222\n");
    else if(N <= 333) printf("333\n");
    else if(N <= 444) printf("444\n");
    else if(N <= 555) printf("555\n");
    else if(N <= 666) printf("666\n");
    else if(N <= 777) printf("777\n");
    else if(N <= 888) printf("888\n");
    else printf("999\n");
    
    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N;

  cin >> N;

  //4, 7
  string ans = "No";
  for (int i = 0; i <= N; i += 4) {
    if((N-i) % 7 == 0){
      ans = "Yes";
    }
  }
  
  cout << ans << endl;

  return 0;
}


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

vector<string> split(const string &str, char sep) {
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while( getline(ss, buffer, sep) ) {
    v.push_back(buffer);
  }
  return v;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  list<int> ls;
  for (int i = 0; i < n; ++i) {
    string com; cin >> com;
    if (com == "deleteFirst") ls.pop_front();
    if (com == "deleteLast") ls.pop_back();
    if (com == "insert") {
      int x; cin >> x;
      ls.push_front(x);
    }
    if (com == "delete") {
      int x; cin >> x;
      for (auto itr = begin(ls); itr != end(ls); ++itr) {
        if (*itr == x) {
          ls.erase(itr);
          break;
        }
      }
    }
  }
  copy(begin(ls), prev(end(ls), 1), ostream_iterator<int>(cout, " "));
  cout << ls.back() << endl;
  return 0;
}



Measured memory_bytes: 34292
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    bool ans = false;
    for (int i = 1; i < 10; i++)
        for (int j = 1; j < 10; j++)
            if (i * j == N) ans =true;
    if (ans) print(YES);
    else print(NO);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int h, m;
    string s;

    while (1)
    {
        deque<char> deck;
        cin >> s;
        if (s == "-")
            break;
        rep(i, s.size()) deck.push_back(s[i]);

        cin >> m;
        rep(i, m)
        {
            cin >> h;
            rep(j, h)
            {
                char a = deck.front();
                deck.pop_front();
                deck.push_back(a);
            }
        }
        rep(i, deck.size()) cout << deck[i];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n, m; cin >> n >> m;
  vvii lists(n);
  char ans[m][13];
  rep(i,m) {
    ll p, y; cin >> p >> y;
    lists[p-1].pb(mp(y, i));
  }
  rep(i,n) {
    sort(all(lists[i]));
    rep(j,lists[i].size()) {
      sprintf(ans[lists[i][j].ss], "%06d%06d", i+1, j+1);
    }
  }

  rep(i,m) {
    cout << ans[i] << endl;
  }
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int ctoi(char c) {
  return c - '0';
}

template <class C>
void printContainer(C &container, const char *delim=",") {
  for(const auto &e : container) {
    std::cout << e << delim;
  }
  std::cout << "\n";
}

// Greatest common divisor
template<class T>
T gcd(T x, T y) {
  if(x < y) {
    std::swap(x, y);
  }
  T r = x % y;
  while(r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

// Least common multiple
template<class T>
T lcm(T x, T y) {
  return (x*y)/gcd(x,y);
}

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  string ans {toupper(a[0]), toupper(b[0]), toupper(c[0])};
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#EDPC L メモ化再帰じゃTLEで通らないのでやり直し

N=int(input())
a=list(map(int,input().split()))

#dp[l][r]:=区間[l,r]が残っている時の(直後の人の最終的な得点-そうじゃない方の最終的な得点）

dp=[[-1]*N for _ in range(N)]

for k in range(N):
    dp[k][k]=a[k]

for r in range(1,N):
    for l in reversed(range(r)):
        dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1])

print(dp[0][N-1])

Measured memory_bytes: 113116
#include<cstdio> 
#include<iostream>
using namespace std;
int main(){
	int K,S;
	cin >> K >> S;
	int ans = 0;
	for(int x = 0; x <= K; ++x){
		for(int y = 0; y <= K; ++y){
 			int z = S - x - y;
			if(0 <= z and z <= K){
				ans = ans + 1;
			}
		}
 	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;


int main(){

    ios::sync_with_stdio(false);

    int n, i, x, T = 0, aux;
    vector <int> v;

    cin >> n;

    v.push_back(0);
    for(int i = 1; i <= n; ++i){
        cin >> x;
        v.push_back(x);
        T += abs(v[i] - v[i - 1]);
    }
    T += abs( v[n] );

    for(int i = 1; i < n; ++i){
        aux = T;
        aux -= abs(v[i] - v[i - 1]) + abs(v[i] - v[i + 1]);
        aux += abs(v[i - 1] - v[i + 1]);
        cout << aux << endl;
    }
    T -= abs(v[n] - v[n - 1]) + abs(v[n]);
    T += abs(v[n - 1]);
    cout << T;
}


Measured memory_bytes: 1784
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    H = [int(input()) for i in range(N)]
    H = sorted(H)
    ans = float("inf")
    for i in range(N-K+1):
        tmp = H[i+K-1] - H[i]
        if tmp < ans:
            ans = tmp
    print(ans)
    

main()

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

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b+c>=22) cout << "bust" << endl; 
	else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    d = dict()
    for i in range(1, 13):
        if i == 2:
            d[i] = 'a'
        elif i in [4, 6, 9, 11]:
            d[i] = 'b'
        else:
            d[i] = 'c'

    x, y = map(int ,input().split())
    if d[x] == d[y]: print("Yes")
    else: print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val S = sc.next
    println("" + S.head + (S.length - 2) + S.last)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 27308
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A;
	int ans = 0;
	cin >> N;
	int ma = INF;
	rep(i, 0, N)
	{
		cin >> A;
		chmin(ma, A);
		if (ma >= A)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int m, d, c = 0;
  cin >> m >> d;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= d; j++) {
      int d1 = j % 10, d10 = j / 10;
      c += d1 >= 2 && d10 >= 2 && d1 * d10 == i;
    }
  cout << c << "\n";
}


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

int main(void) 
{
   int k, a, b;
   cin >> k >> a>> b;
   for(int i = a; i <= b; i++){
      if(i%k == 0){
         cout << "OK" << endl;
         return 0;
      }
   }
   cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int h,w,i,j;
	char a[200][200],b[200][200];
	scanf("%d%d",&h,&w);
	for(i=0;i<h+2;i++){
		for(j=0;j<w+2;j++) b[i][j]='#';
	}
	for(i=0;i<h;i++) scanf("%s",a[i]);
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			b[i+1][j+1]=a[i][j];
		}
	}
	for(i=0;i<h+2;i++)printf("%s\n",b[i]);
	return 0;
}

Measured memory_bytes: 256
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 1000005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    // ll tt;
    // w(tt){

    // }
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		int max = 0;
		int ans = 0;
		for(int i = 0; i < n; i++){
			h[i] = sc.nextInt();
			max = Math.max(h[i],max);
			if(h[i] >= max){
				ans++;
			}
		}
		System.out.print(ans);
	}
}


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

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);


int main(){
	IOS;
	int d,n;
	while(cin>>d>>n){
		if(d == 0){
			if(n == 100){
				cout<<"101"<<endl;
			}
			else{
				cout<<n<<endl;
			}
		}
		else if(d == 1){
			if(n == 100){
				cout<<"10100"<<endl;
			}
			else{
				cout<<n*100<<endl;
			}
		}
		else {
			if(n == 100){
				cout<<"1010000"<<endl;
			}
			else{
				cout<<n*10000<<endl;
			}
		}
		
	}
	return 0;
}

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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;	
//    cin t;
   while(t--){
       string s , t;
       cin >> s >> t;
       int l = s.length();
       int ans = 0;
       for(int i = 0 ; i < l ; i ++)
       {
           if(s[i] != t[i])
           ans ++;
       }      
       cout << ans << endl;
   }
}


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

int main() {
	// your code goes here
	string s; cin>>s;
	int n=s.size();
	if(s[n-1]!='s'){
	    cout<<s+'s'<<endl;
	}else{
	    cout<<s+'e'+'s'<<endl;
	}
	return 0;
}


Measured memory_bytes: 3632
def swapStr(S, i, new):
    return S[:i] + str(new) + S[i+1:]

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

flag_false = 0
ans = 'n'*n
for i in range(m):
    s, c = map(int, input().split())
    s = s-1
    if ans[s] == 'n':
        ans = swapStr(ans, s, c)
    elif ans[s] != str(c):
        flag_false = 1
        break

        
if n == 1:
    if ans[0] == 'n':
        ans = swapStr(ans, 0, 0)
else:
    if ans[0] == 'n':
        ans = swapStr(ans, 0, 1)

    for i in range(1, len(ans)):
        if ans[i] == 'n':
            ans = swapStr(ans, i, 0)

    if int(ans)//10**(n-1) == 0:
        flag_false = 1


if flag_false:
    print(-1)
else:
    print(int(ans))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;


int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  
  string S; cin>>S;
  int N=S.length();
  if(S[0]=='0'||S[N-1]=='1'||S[N-2]=='0'){
    cout<<-1<<endl;
    return 0;
  }
  
  bool flag=1;
  for(int i=1;i<N-1;i++){
    if(S[i]!='1') flag=0;
  }
  if(flag){
    for(int i=1;i<N;i++){
      cout<<i<<" "<<i+1<<endl;
    }
    return 0;
  }
  flag=1;
  for(int i=1;i<=N/2;i++){
    if(S[i]!=S[N-2-i]){
      cout<<-1<<endl;
      return 0;
    }
  }
  int p=0;
  for(int i=1;i<=N/2;i++){
    if(S[i]=='0') break;
    else p++;
  }
  int v=1;
  while(p--){
    cout<<v<<" "<<v+1<<endl;
    v++;
  }
  v++;
  cout<<1<<" "<<v<<endl;
  int pre=v,cur=v+1;
  for(int i=v-1;i<N-1;i++){
    if(S[i]=='0') cout<<pre<<" "<<cur++<<endl;
    else{
      cout<<pre<<" "<<cur++<<endl;
      pre=cur-1;
    }
  }
  return 0;
}


Measured memory_bytes: 1616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ_Practice
{
    class Program
    {
        static void Main(string[] args)
        {

            var list = new List<string>();
            while (true)
            {
                var str = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(str))
                {
                    break;
                }
                list.Add(str);
            }

            var dic = new Dictionary<char, int>();
            for (int i = (char)'a'; i <= (char)'z'; i++)
            {
                dic.Add((char)i, 0);
            }

            foreach (var str in list)
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (char.IsLetter(str[i]))
                    {
                        dic[char.ToLower(str[i])]++;
                    }
                }
            }

            for (int i = (char)'a'; i <= (char)'z'; i++)
            {
                Console.WriteLine($"{(char)i} : {dic[(char)i]}");
            }
        }
    }
}



Measured memory_bytes: 17916
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

int main(){
    cin >> n;
    vi v(n);
    REP(i, n) {
        cin >> v[i];
    }
    REP(i,n) {
        FOR(j,i+1,n) {
          //cout << v[i] << ' ' << v[j] << endl;
          ans = chmax(ans, abs(v[i] - v[j]));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int H,W,i,j,k,l;
  for(k=0;;k++){
  scanf("%d %d",&H,&W);
    if(H==0 && W==0){break;}
  for(i=0;i<H ;i++ )
    {
      if(i==0 || i==H-1)
	{
      for(j=0;j<W;j++)
	{ printf("#");}
      printf("\n");
	}
      else
	{
	  printf("#");
	  for(l=1 ;l<(W-1) ;l++)
	    {printf(".");}
	  printf("#\n");
	}
    }
  printf("\n");
  }
  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep01(i, n) for(int i = 0; i < (n) + 1; i++)
#define rep10(i, n) for(int i = 1; i < (n); i++)
#define rep11(i, n) for(int i = 1; i < (n) + 1; i++)
#define all(a) (a).begin(), (a).end()
typedef long long int ll;
typedef struct { int x; int y; } Pos;
using namespace std;

int main()
{
    int x;
    cin >> x;
    if (x == 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}

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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;

int h1, m1, h2, m2, k;

int main(){
	scanf("%d%d%d%d%d", &h1, &m1, &h2, &m2, &k);
	printf("%d\n", max(0, h2 * 60 + m2 - h1 * 60 - m1 - k));
	return 0;
}


Measured memory_bytes: 3828
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 7*17*(1<<23) + 1;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() { //DINIC ORZ, FFT ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, x, ok = 0, mx = 0, g = 0;
	cin >> n >> x;
	vi a;
	a.resize(n);
	for(auto &i : a) {
		cin >> i;
		g = __gcd(g, i);
		if(i==x) ok = 1;
		mx = max(mx, i);
	}
//	cout << g << "\n";
	if(ok) return cout << "POSSIBLE", 0;
	if(x>mx) return cout << "IMPOSSIBLE", 0;
	for(auto &i : a) {
		if((i-x)%g==0) return cout << "POSSIBLE", 0;
	}

	cout << "IMPOSSIBLE";
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int mmin(int a,int b) {
	if(a < b) {
		return a;
	}
	return b;
}

int mmax(int a,int b) {
	if(a > b) {
		return a;
	}
	return b;
}


int main() {
	int k, x;

    cin >> k >> x;

	int mi = -1000000;
	int ma =  1000000;

	int s = mmax(mi, x-k+1);
	int e = mmin(ma, x+k-1);

	FOR(i, s, e+1) {
		cout << i << " ";
	}
	cout << endl;

	

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int i,j,k,a,b;

    cin>>a>>b;
    k=b;
    j=0;
    while(k!=0)
    {
        j++;
        k=k/10;
    }
   // cout<<j;

    k=1;
    for(i=0;i<j;i++)
    {
        k*=10;
    }
   // cout<<k;
    a=a*k+b;
    //cout<<a;
    double kk=sqrt(a);
    if(kk==(long long )kk)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}



Measured memory_bytes: 256