akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll N, P[100000];
int next_r[2][100000], next_l[2][100000];

int main() {
    cin >> N;
    REP(i, N) {
        cin >> P[i];
        P[i]--;
    }
    REP(i, 2) REP(j, N) {
        next_r[i][j] = next_l[i][j] = -1;
    }

    priority_queue<pii, vector<pii>, greater<pii>> que;
    REP(i, N) {
        vector<pii> vp;
        while (!que.empty() && que.top().first < P[i]) {
            auto p = que.top(); que.pop();
            next_r[p.second][p.first] = i;
            if (p.second == 0) vp.push_back({p.first, 1});
        }
        for (auto p : vp) que.push(p);
        que.push({P[i], 0});
    }
    while (!que.empty()) que.pop();

    RREP(i, N) {
        vector<pii> vp;

        while (!que.empty() && que.top().first < P[i]) {
            auto p = que.top(); que.pop();
            next_l[p.second][p.first] = i;
            if (p.second == 0) vp.push_back({p.first, 1});
        }
        for (auto p : vp) que.push(p);
        que.push({P[i], 0});
    }

    ll ans = 0;
    REP(i, N) {
        int l1 = next_l[0][P[i]], l2 = next_l[1][P[i]];
        int r1 = next_r[0][P[i]], r2 = next_r[1][P[i]];
        if (r1 != -1) {
            int l = (l1 != -1) ? (i - l1) : (i + 1);
            int r = (r2 != -1) ? (r2 - r1) : (N - r1);
            ans += (P[i] + 1) * l * r;
        }
        if (l1 != -1) {
            int l = (l2 != -1) ? (l1 - l2) : (l1 + 1);
            int r = (r1 != -1) ? (r1 - i) : (N - i);
            ans += (P[i] + 1) * l * r;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3704
# 入力
N=int(input())
l=list(map(int,input().split()))

# 先攻：a  後攻：b
a=b=0

# 数字が大きい順にソート
l.sort()
l.reverse()

for i in range(len(l)):
  if i%2==0:
    a+=l[i]
  else:
    b+=l[i]

# 出力
print(a-b)

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

int main(){
    int D,N; cin >> D >> N;
    int jyo=pow(100,D);
    int ans=0;
    if (N==100) ans=jyo*101;
    else ans=jyo*N;
    cout << ans;
}

Measured memory_bytes: 256
H, N = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
limit = H + max(A[i][0] for i in range(N))
dp = [int(1e18) for _ in range(limit+1)]
dp[0] = 0
for i in range(1, limit+1):
  for j in range(N):
    if A[j][0] > i:
      dp[i] = min(dp[i], A[j][1])
    else:
      dp[i] = min(dp[i], dp[i-A[j][0]]+A[j][1])
M = min(dp[i] for i in range(H, limit+1))
print(dp[H])


Measured memory_bytes: 43116
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		List<Integer> list = Arrays.asList(a, b,c);
		Collections.sort(list);
		System.out.println(list.get(0) + " " + list.get(1) + " " + list.get(2));
	}

}

Measured memory_bytes: 17356
from operator import itemgetter
n = int(input())
q = [list(map(int,input().split())) for _ in range(n)]
#print(q)
q.sort(key=itemgetter(1))
#print(q)
w = 0
for i in range(n):
  w += q[i][0]
  if w > q[i][1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 53732
using System;

class MainClass
{
  static readonly int BIT_NUM = 28;

  public static void Main()
  {
    var N = int.Parse(Console.ReadLine());
    var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

    long ans = 0;
    for (var i = 0; i <= BIT_NUM; i++)
    {
      var mask = (1 << i + 1) - 1;
      var maskedA = new int[N];
      var maskedB = new int[N];
      for (var j = 0; j < N; j++)
      {
        maskedA[j] = a[j] & mask;
        maskedB[j] = b[j] & mask;
      }
      Array.Sort(maskedB);

      var T = 1 << i;
      long parity = 0;
      for (var j = 0; j < N; j++)
      {
        var num1 = LowerBound(maskedB, T - maskedA[j]);
        var num2 = LowerBound(maskedB, 2 * T - maskedA[j]);
        var num3 = LowerBound(maskedB, 3 * T - maskedA[j]);
        // var num4 = LowerBound(maskedB, 4 * T - maskedA[j]);
        parity += (num2 - num1) + (N - num3);
      }
      ans |= (parity & 1) << i; // Check if parity is Even or Odd
    }
    Console.WriteLine($"{ans}");
  }

  private static int LowerBound(int[] arr, int val)
  {
    int first = 0, last = arr.Length - 1, mid;
    while (first <= last)
    {
      mid = (first + last) >> 1;
      if (val > arr[mid]) first = mid + 1;
      else last = mid - 1;
    }
    return first;
  }
}


Measured memory_bytes: 58212
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define all(a) a.begin(),a.end()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)

typedef pair<int, int> pii;
typedef vector<pii> vpii;

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

const int inf = 1e9;

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

int R;
int W[2], H[2];
int X[2], Y[2];
int A[2][502][502];

bool used[502][502];

vpii data[2];

void bfs(int num)
{
	typedef pair<int, pii> Data;
	memset(used, false, sizeof(used));

	priority_queue<Data> q;

	q.push(Data(-1, pii(Y[num], X[num])));
	used[Y[num]][X[num]] = true;

	if (num == 0) {
		data[num].PB(pii(1, 0));
	} else {
		data[num].PB(pii(0, 0));
		data[num].PB(pii(0, 1));
	}

	int ma = 1;
	int cnt = 0;

	while (q.size()) {
		Data p = q.top(); q.pop();

		int cur = -p.fst;

		if (ma < cur) {
			if (num == 0) {
				data[num].back().scd = cnt;
				ma = cur;
				data[num].PB(pii(ma, 0));
			} else {
				data[num].back().fst = cnt;
				ma = cur;
				data[num].PB(pii(0, ma));
			}
		}

		cnt++;

		rep(i, 4) {
			int ny = p.scd.fst + dy[i], nx = p.scd.scd + dx[i];

			if (ny < 0 || ny >= H[num] || nx < 0 || nx >= W[num] || used[ny][nx]) continue;
			used[ny][nx] = true;

			q.push(Data(-A[num][ny][nx], pii(ny, nx)));
		}
	}

	if (num == 0) {
		data[num].back().scd = cnt;
	} else {
		data[num].back().fst = cnt;
	}
}

signed main()
{
	omajinai;

	while (cin >> R, R) {
		data[0].clear();
		data[1].clear();

		rep(i, 2) {
			cin >> W[i] >> H[i] >> X[i] >> Y[i];

			--X[i], --Y[i];

			rep(j, H[i]) rep(k, W[i]) {
				cin >> A[i][j][k];
			}
		}

		bfs(0);
		bfs(1);

		int mi = inf;

		data[1].PB(pii(inf, inf));

		rep(i, data[0].size()) {
			pii a = data[0][i];

			chmin(mi, a.fst + lower_bound(all(data[1]), pii(R - a.scd, -inf))->scd);
		}

		cout << mi << endl;
	}
}

Measured memory_bytes: 7624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
ll ans;
map<string, ll> g;
int main () {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		ans += g[s];
		g[s]++;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11136
import java.util.*;

class Main {
    public static void main(String[] args) {

      Scanner scan = new Scanner(System.in);
      String param = scan.nextLine();

      String[] elem = param.split(" ");

      int a, b, c;

      a = Integer.parseInt(elem[0]);
      b = Integer.parseInt(elem[1]);
      c = Integer.parseInt(elem[2]);

      if (c >= a && c <= b){
        System.out.println("Yes");
      }
      else {
        System.out.println("No");
      }

    }
}


Measured memory_bytes: 24916
import sys
readline = sys.stdin.readline

N = int(readline())

A = [None] * N
for i in range(N):
  A[i] = list(map(int,readline().split()))
  
# まずワーシャルフロイド表を作る
# ワーシャルフロイド表より大きな数値が元の表にあったら、最短距離の表ではないので-1
# 最短距離の表になっているのであれば、
# A[1][3]に行くときにA[1][2] + A[2][3]となるのであれば、
# A[1][3]のほうだけansに記録していく

import copy
newA = copy.deepcopy(A)

for k in range(N):
  for i in range(N):
    for j in range(N):
      if i == k or k == j or i == j:
        continue
      if A[i][k] + A[k][j] < A[i][j]:
        print(-1)
        exit(0)
      elif A[i][k] + A[k][j] == A[i][j]:
        # A[i][j]の道路は不要
        newA[i][j] = 0

ans = 0
for a in newA:
  ans += sum(a)
print(ans // 2)

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

namespace _1_5_c
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] str = new string[2];
                str = Console.ReadLine().Split(' ');

                int i = int.Parse(str[0]);//縦
                int n = int.Parse(str[1]);//横

                if (i == 0 && n == 0)//iとnがゼロの時に終了  
                {
                    break;
                }

                for (int a = 0; a < i; a++)//縦の行分ループ
                {
                    for (int b = 0; b < n; b++)//横の行分ループ
                    {

                        if (a % 2 == 1)
                        {
                            if (b % 2 == 1)
                            {
                                Console.Write('#');
                            }
                            else
                            {
                                Console.Write('.');
                            }
                        }
                        else
                        {
                            if (b % 2 == 1)
                            {
                                Console.Write('.');
                            }
                            else
                            {
                                Console.Write('#');
                            }
                        }
                    }
                    Console.Write("\n");  
                }
                Console.Write("\n");
            }
        }
    }
}



Measured memory_bytes: 15948
/*input
98765432109876543210
58

*/
/*

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

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  10005
string k;
lld d;
vi val;
lld n;
lld dp[N][2][102];
void init()
{
	rep(i,0,N)
	{
		rep(j,0,102)
		{
			dp[i][0][j]=-1;
			dp[i][1][j]=-1;
		}
	}
}
lld func(lld pos,lld flag,lld divv)
{
	if(pos>n)
	{
		return 0;
	}
	if(pos==n && divv==0)
	{
		return 1;
	}
	if(pos==n)
	{
		return 0;
	}
	if(dp[pos][flag][divv]!=-1)
	{
		return dp[pos][flag][divv];
	}
	lld ans=0;
	lld up;
	if(flag==0)
	{	
		up=val[pos];
	}
	else
	{
		up=9;
	}
	rep(i,0,up+1)
	{
		lld fl=flag;
		lld di=divv;
		if(i<val[pos])
		{
			fl=1;
		}
		di=(divv%d+i%d)%d;
		ans=(ans%hell+func(pos+1,fl,di)%hell)%hell ;
		ans%=hell;
	}
	dp[pos][flag][divv]=ans;
	return ans;
}
inline void solve()
{
	cin >> k;
	cin >> d;
	init();
	rep(i,0,k.size())
	{
		val.pb((lld)(k[i]-'0'));
	}
	//cout << k << endl;
	n=val.size();
	lld ways=0;
	ways=(ways+func(0,0,0))%hell;
	val.clear();
	val.pb(0);
	n=val.size();
	init();
	ways=(ways-func(0,0,0)+hell)%hell;
	cout << ways << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll c = 1000, s = 0;
  rep(i, n-1) {
    if (a[i] < a[i+1]) {
      s += c / a[i];
      c %= a[i];
    }
    if (a[i] > a[i+1]) {
      c += s * a[i];
      s = 0;
    }
  }
  c += s * a[n-1];
  cout << c << endl;
  return 0;
}

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''


n=int(input())
a=list(map(int,input().split()))
s=1000
for i in range(n-1):
    if a[i]<a[i+1]:
        s+=(a[i+1]-a[i])*(s//a[i])
    
print(s)

Measured memory_bytes: 9120
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int  ll;
#define pb push_back
#define mp make_pair
#define N 200005


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

	int k,n,i;
	cin>>k>>n;
	int a[N];
	for(i=1;i<=n;i++)
		cin>>a[i];

	a[0]=0;
	int p=0;
	a[n+1]=k;
	for(i=2;i<=n;i++){
		p=max(a[i]-a[i-1],p);
	}
	p=max(k-a[n]+a[1],p);
	cout<<k-p<<endl;
	return 0;

}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    int answer=0;
    for(int i=0;i<=A;i++){
      for(int j=0;j<=B;j++){
        for(int k=0;k<=C;k++){
          if(X==500*i+100*j+50*k){
            answer++;
          }
        }
      }
    }
    System.out.println(answer);
    
  }
  

  
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
ll N,K;
const ll MOD=1e9+7;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(false);
	cin>>N>>K;
	ll ans=0;
	FOR(k,K,N+2){
		ans+=(N+1-k)*k+1;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3664
from collections import defaultdict

N, M = map(int, input().split())
a = defaultdict(lambda: True)
for i in range(M):
    a[int(input())] = False

dp = defaultdict(int)
dp[0] = 1
for i in range(1, N + 1):
    if a[i]:
        dp[i] = dp[i - 1] + dp[i - 2]
print(dp[N] % (10 ** 9 + 7))


Measured memory_bytes: 486524
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//省略
using vi  = vector<int>;
using vii = vector<vector<int>>;
using vl  = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const ll mo=pow(10,18);

ll cnt_prime_fac(ll A,ll N){
    ll cnt=0;
    while(A%N==0){
        A/=N;
        cnt++;
    }
    return cnt;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    vll fac(50,vl(20,0));

    REP(i,N){
        string S;
        cin>>S;
        ll keta=0;

        ll num=0;
        REP(j,S.size()){
            ll idx=S.size()-1-j;
            if(S[idx]=='.') keta=j;
        }

        ll cnt=0;
        REP(j,S.size()){
            ll idx=S.size()-1-j;
            if(S[idx]!='.'){
                num+=(S[idx]-'0')*pow(10,9-keta+cnt);
                cnt++;
            }
        }
        A[i]=num;
    }

    vl C2(N,0),C5(N,0);
    REP(i,N){
        ll c2=cnt_prime_fac(A[i],2);
        ll c5=cnt_prime_fac(A[i],5);
        C2[i]=c2;
        C5[i]=c5;
        fac[c2][c5]++;
    }

    ll ans=0;
    REP(i,N){
        REP(j,50){
            REP(k,20){
                if(C2[i]+j<18||C5[i]+k<18) continue;
                ans+=fac[j][k];
            }
        }
        if(C2[i]>=9&&C5[i]>=9) ans--;
    }
    ans/=2;
    cout<<ans<<endl;


}

Measured memory_bytes: 8264
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define rrep1(i,x) for(int i = x ; i > 0 ; i --)
#define fr first
#define sc second
#define pb push_back

string tanni[18] = {
	"",
	"Man",
	"Oku",
	"Cho",
	"Kei",
	"Gai",
	"Jo",
	"Jou",
	"Ko",
	"Kan",
	"Sei",
	"Sai",
	"Gok",
	"Ggs",
	"Asg",
	"Nyt",
	"Fks",
	"Mts"
};

int main(){
	while(1){
		int n,m;
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)break;
		int a[20] = {};
		a[0] = 1;
		for(int i = 0 ; i < m ; i ++){
			for(int j = 0 ; j < 18 ; j ++){
				a[j] *= n;
			}
			for(int j = 0 ; j < 18 ; j ++){
				a[j+1] += a[j]/10000;
				a[j] %= 10000;
			}
		}
		for(int i = 17 ; i >= 0 ; i --){
			if(a[i] == 0)continue;
			printf("%d",a[i]);
			cout << tanni[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1252
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    rep(b, 1, N + 1) {
        ans += (N / b) * max(0LL, b - K) + max(0LL, N % b - K + 1);
        if (!K) {
            --ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# 解説AC

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

i=m//n

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

lis=make_divisors(m)

for mm in lis:
    if mm<=i:
        ans=mm
        break

print(ans)

Measured memory_bytes: 3188
#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 100050;

int n, pre[N], to[N * 2], nxt[N * 2], cnt;

inline void addEdge(int x, int y) {
  nxt[cnt] = pre[x];
  to[pre[x] = cnt++] = y;
  nxt[cnt] = pre[y];
  to[pre[y] = cnt++] = x;
}

void dfs(int x, int fa, int dx, int &y, int &d) {
  if (dx > d) {
    d = dx;
    y = x;
  }
  for (int i = pre[x]; i != -1; i = nxt[i])
    if (to[i] != fa)
      dfs(to[i], x, dx + 1, y, d);
}

int s[N], m;
int A[N], B[N];

bool dfs2(int x, int fa) {
  int &t = s[m++] = 0;
  int k = 0;
  for (int i = pre[x]; i != -1; i = nxt[i]) {
    int u = to[i];
    if (u == fa) ;
    else if (nxt[pre[u]] == -1) ++t;
    else if ((++k) > 1) return false;
    else if (!dfs2(to[i], x)) return false;
  }
  return true;
}

int main() {
  scanf("%d", &n);
  memset(pre, -1, sizeof pre);
  for (int i = 1, x, y; i < n; ++i) {
    scanf("%d%d", &x, &y);
    addEdge(x, y);
  }
  int x, d;
  dfs(1, 0, 0, x, d = 0);
  if (!dfs2(x, 0)) {
    puts("-1");
    return 0;
  }
  --s[m - 1];
  s[m++] = 0;
  for (int i = 0, j = 0; i < m; ++i) {
    A[j + s[i]] = j;
    for (int k = 0; k < s[i]; ++k, ++j) A[j] = j + 1;
    ++j;
  }
  for (int i = m - 1, j = 0; i >= 0; --i) {
    B[j + s[i]] = j;
    for (int k = 0; k < s[i]; ++k, ++j) B[j] = j + 1;
    ++j;
  }
  bool ok = false;
  for (int i = 0; i < n; ++i)
    if (A[i] != B[i]) {
      ok = A[i] > B[i];
      break;
    }
  for (int i = 0; i < n; ++i)
    printf("%d ", (ok ? B : A)[i] + 1);
  return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
const int MAXN = 4001;

int main(){
    int N;string S;cin >> N >> S;
    ll count = 0;
    ll red=0,blue=0,green=0;
    for(int i=0;i<N;i++){
        if(S[i]=='R')red++;
        if(S[i]=='B')blue++;
        if(S[i]=='G')green++;
        for(int k=0;k<N;k++){
            int tmp_i = i+1;int tmp_k = k+1;
            int tmp_j = (tmp_i+tmp_k)/2;
            int j = tmp_j - 1;
            if(tmp_j <= N && tmp_i< tmp_j && tmp_j<tmp_k && tmp_j - tmp_i == tmp_k - tmp_j  && S[i]!=S[j] && S[j] != S[k] && S[i] != S[k]){
                count++;
            }
        }
    }
    ll tmp = red*blue*green;
    
    cout << tmp - count << endl;




    return 0;

}

Measured memory_bytes: 3584
import math
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    f_vals = []
    for A in range(1, int(math.sqrt(N))+1):
        if N % A != 0:
            continue
        B = int(N / A)
        f_vals.append(max(len(str(A)), len(str(B))))
    print(min(f_vals))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
package main

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

type rs []rune

func (a rs) Len() int           { return len(a) }
func (a rs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a rs) Less(i, j int) bool { return a[i] < a[j] }

func main() {
	n := getInt()
	ss := make([]string, n)
	for i := range ss {
		s := rs(getString())
		sort.Sort(s)
		ss[i] = string(s)
	}

	sort.Strings(ss)

	now := ss[0]
	cnt := 1
	ans := 0
	for i := 1; i < n; i++ {
		if ss[i] == now {
			cnt++
			if i == n-1 {
				ans += cnt * (cnt - 1) / 2
			}
		} else {
			ans += cnt * (cnt - 1) / 2
			now = ss[i]
			cnt = 1
		}
	}

	fmt.Println(ans)
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

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


Measured memory_bytes: 5760
from copy import deepcopy

N, A, B, C, D = map(int, input().split())
S = list(input())


def start_funuke():
    s = deepcopy(S)
    funuke = s[B - 1 : D]
    for i in range(1, len(funuke)):
        if funuke[i] == "#" and funuke[i - 1] == "#":
            return False
    s[D - 1] = "#"
    sunuke = s[A - 1 : C]
    for i in range(1, len(sunuke)):
        if sunuke[i] == "#" and sunuke[i - 1] == "#":
            return False
    return True


def start_sunuke():
    s = deepcopy(S)
    funuke = s[B - 1 : D]
    f = True
    for i in range(2, len(funuke)):
        if (funuke[i] == "." and funuke[i - 1] == "." and funuke[i - 2] == ".") and (
            i - 1 != C - 1
        ):
            f = False
    s[B - 1] = "%"
    sunuke = s[A - 1 : C]
    for i in range(2, len(sunuke)):
        if sunuke[i] == "." and sunuke[i - 1] == "%" and sunuke[i - 2] == ".":
            f = False
    if f:
        return False
    s = deepcopy(S)
    sunuke = s[A - 1 : C]
    for i in range(1, len(sunuke)):
        if sunuke[i] == "#" and sunuke[i - 1] == "#":
            return False
    s[C - 1] = "#"
    funuke = s[B - 1 : D]
    for i in range(1, len(funuke)):
        if funuke[i] == "#" and funuke[i - 1] == "#":
            return False
    return True


f1 = start_funuke()
f2 = start_sunuke()
if f1 or f2:
    print("Yes")
else:
    print("No")
# ans = "Yes" if (start_funuke() or start_sunuke()) else "No"
# print(ans)


Measured memory_bytes: 10284
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct P {
  string s;
  int p, n;
};

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

  vector<P> v(N);
  REP(i, N){
    cin >> v[i].s >> v[i].p;
    v[i].n = i+1;
  }

  sort(ALL(v), [](P const & l, P const & r){
      if(l.s != r.s) return l.s < r.s;
      return l.p > r.p;
      });

  REP(i, N){
    cout << v[i].n << "\n";
  }


  return 0;
}

Measured memory_bytes: 256
def minindex(arrived,costs):
    mindex = "end"
    curmin = 100000000
    for i in range(10):
        if arrived[i]:continue
        if curmin>costs[i]:
            mindex = i
            curmin = costs[i]
    return mindex

H,W = map(int,input().split())
C = [[int(j) for j in input().split()] for i in range(10)]
#C[i][j]はiをjにするコスト
#のつもりなんだけど、ダイクストラ法の逆打ち計算では逆をやります

arrived = [False] * 10
arrived[1] = True
costs = [1000000] * 10
costs[1] = 0
curpos = 1
for i in range(10):#残り9頂点
    for j,done in enumerate(arrived):
        costs[j] = min(costs[j],costs[curpos] + C[j][curpos])
    if i==9:break
    curpos = minindex(arrived,costs)
    arrived[curpos] = True
A = [[int(i) for i in input().split()] for j in range(H)]

def maryoku(x):
    if x == -1:return(0)
    else:return(costs[x])

print(sum([sum([maryoku(aa) for aa in a]) for a in A]))


Measured memory_bytes: 40284
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	char a, b, c; cin >> a >> b;
	if (a == 'H' && b == 'H') {
		c = 'H';
	}
	else if (a == 'H' && b == 'D') {
		c = 'D';
	}
	else if (a == 'D' && b == 'H') {
		c = 'D';
	}
	else if (a == 'D' && b == 'D') {
		c = 'H';
	}

	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
pair = {}
rank = {}
def root(x):
    if x == pair[x]:
        return x
    else:
        pair[x] = root(pair[x])
    return pair[x]

def unite(x, y):
    rx = root(x)
    ry = root(y)
    if rx > ry:
        pair[rx] = pair[ry]
    else:
        pair[ry] = pair[rx]

for i in range(1, N+1):
    pair.setdefault(i, i)

for i in range(1, N+1):
    rank.setdefault(i, 0)

tmp = []
for i in range(M):
    tmp.append(list(map(int, input().split())))
tmp.sort()
for i in range(M):
    x, y = tmp[i][0], tmp[i][1]
    if x < y:
        unite(x, y)
    else:
        unite(y, x)

cnt = set()
for k, y in pair.items():
    y = root(y)
    cnt.add(y)
print(len(cnt))


Measured memory_bytes: 93668
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
)

var sc *bufio.Scanner

const bufferSize = 1024

func nextString() string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

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

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

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, bufferSize)
	sc.Buffer(buf, 1e+7)
	sc.Split(bufio.ScanWords)
	s := nextString()
	q := nextInt()
	rev := 0

	var pre bytes.Buffer
	var post bytes.Buffer
	for i := 0; i < q; i++ {
		a := nextInt()
		if a == 1 {
			rev++
		} else {
			f := nextInt()
			c := nextString()
			if (f == 1 && rev%2 == 0) ||
				(f == 2 && rev%2 == 1) {
				pre.WriteString(fmt.Sprintf("%s", c))
				//pre += c
			} else {
				post.WriteString(fmt.Sprintf("%s", c))
				//post += c
			}
		}
	}

	if rev%2 == 0 {
		_, _ = fmt.Fprintf(writer, "%s", reverse(pre.String()))
		_, _ = fmt.Fprintf(writer, "%s", s)
		_, _ = fmt.Fprintf(writer, "%s", post.String())
	} else {
		_, _ = fmt.Fprintf(writer, "%s", reverse(post.String()))
		_, _ = fmt.Fprintf(writer, "%s", reverse(s))
		_, _ = fmt.Fprintf(writer, "%s", pre.String())
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> p(n); for (int i = 0; i < n; i++) cin >> p[i];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    if (mp[p[i] - 1] != 0) {
      mp[p[i]] = mp[p[i] - 1] + 1;
    } else mp[p[i]]++;
  }
  int res = -1;
  for (auto&& i : mp) res = max(res, i.second);
  cout << n - res << '\n';
  return 0;
}

Measured memory_bytes: 10368
n = int(input())
h = [int(i) for i in input().split()]
sikiri = [-1, n]
ans = 0

for i in range(max(h)+1): # i は高さ
    sik = [j for j, x in enumerate(h) if x == i]
    sikiri[len(sikiri):len(sikiri)] = sik
    sikiri.sort()
    
    for j in range(len(sikiri)-1):
        if sikiri[j+1] - sikiri[j] > 1:
            ans += 1
        else:
            pass
print(ans)

Measured memory_bytes: 9196
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
H, W = map(int, input().split())
S = []
StartEnd = []
for _ in range(W+2) :
  StartEnd.append("N")
S.append(StartEnd)
for _ in range(H) :
  l = list(str(input()))
  l.insert(0, "N")
  l.append("N")
  S.append(l)
S.append(StartEnd)
#print (S)

for i in range(H+2) : 
  for j in range(W+2) :
    if S[i][j] == "." :
      cnt = 0
      for m in range(-1, 2) :
        for n in range(-1, 2) :
          if S[i+m][j+n] == "#" :
            cnt += 1
      S[i][j] = str(cnt)

for i in range(1, H+1) :
  ans = ""
  for j in range(W+2) :
    if S[i][j] != "N" :
      ans += S[i][j]
  print (ans)
      





Measured memory_bytes: 41584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 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;}

int dp[11100];

int main() {
  int n,w; cin >> n >> w;
  FOR(i,0,n-1){
    int val,wei; cin >> val >> wei;
    FORD(j,10000-wei,0){
      chmax(dp[j+wei],dp[j] + val);
    }
  }
  cout << dp[w] << endl;
}



Measured memory_bytes: 3148
#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 FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#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> >;

V<ll> v(10010);

void solve(long long X){
	for(long long i = -5000; i < 5001; i++) {
		for(long long j = -5000; j < 5001; j++) {
			if(v[i+5000] - v[j+5000] == X) {
				cout << i << " "  << j << endl;
				return;
			}
		}
	}

}

int main(){
	for(long long i = -5000; i < 5001; i++) {
		v[i+5000] = i*i*i*i*i;
	}
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}



Measured memory_bytes: 3856
#include <stdio.h>
#include <stdlib.h>

void bubbleSort(int *,int);
int cnt=0;

int main(){
  int i,n,array[100];
  scanf("%d",&n);
  if(n<1 || n>100) exit(2);
  for(i=0;i<n;i++){
    scanf("%d",&array[i]);
  }
  bubbleSort(array,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",array[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}

void bubbleSort(int *arr,int n){
  int i,j,tmp;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(arr[j-1] > arr[j]){
	tmp=arr[j-1];
	arr[j-1]=arr[j];
	arr[j]=tmp;
	cnt++;
      }
    }
  }
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
const int MAXN=310;
int n,a[4],b;
double dp[MAXN][MAXN][MAXN];

int main(){
	cin>>n;
	for(int i=0;i<n;++i) cin>>b,++a[b];
	for(int i=0;i<=a[3];++i){
		for(int j=0;j<=a[3]+a[2];++j){
			for(int k=0;k<=a[3]+a[2]+a[1];++k){
				if(!(i+j+k)) continue;
				double x=i+j+k;
				if(i) dp[i][j][k]+=1.0*dp[i-1][j+1][k]*i/x;
				if(j) dp[i][j][k]+=1.0*dp[i][j-1][k+1]*j/x;
				if(k) dp[i][j][k]+=1.0*dp[i][j][k-1]*k/x;
				dp[i][j][k]+=1.0*n/x;
			}
		}
	}
	cout<<fixed<<setprecision(10)<<dp[a[3]][a[2]][a[1]]<<endl;
	return 0;
}


Measured memory_bytes: 227584
dhw = [(1,0),(0,-1),(0,1),(-1,0),
( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),
( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),
( 0,-2),                        ( 0, 2),
(-1,-2),(-1,-1),        (-1, 1),(-1, 2),
(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

H, W = map(int, input().split())
sh, sw = map(lambda x:int(x)-1, input().split())
eh, ew = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(H)]

dst = [[-1]*W for _ in range(H)]

from collections import deque
dq = deque([(sh, sw, 0)])
while dq:
    h, w, d = dq.popleft()
    if dst[h][w] >= 0 or S[h][w] == '#': continue
    if dst[h][w] == -1 or d < dst[h][w]: dst[h][w] = d

    for i in range(4):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] >= 0: continue
        dq.appendleft((nh, nw, d))

    for i in range(4, 24):
        nh = h + dhw[i][0]; nw = w + dhw[i][1]
        if nh < 0 or H <= nh : continue
        if nw < 0 or W <= nw : continue
        if S[nh][nw] == '#': continue
        if dst[nh][nw] >= 0: continue
        dq.append((nh, nw, d+1))

print(dst[eh][ew])


Measured memory_bytes: 176400
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#define pb push_back
#define ii pair<int,int>
#define i3 pair<int, ii>
#define i5 pair<ii, i3>
#define p1 first
#define p2 second
#define _(i) (i&-i)
using namespace std;

const int N = 1e5+5;
int n,h[N],d[N],par[N],chain[N],top[N],w[N],ind[N];
vector<i3> ke[N];
vector<int> Cols[N];
ii bit[N];

int ans[N]; i5 qu[N];

ii operator + (ii a, ii b) { return ii(a.p1 + b.p1, a.p2 + b.p2); }
ii operator - (ii a, ii b) { return ii(a.p1 - b.p1, a.p2 - b.p2); }

void upd(int i, ii x)
{
    for(; i<=n; i+=_(i)) bit[i] = bit[i] + x;
}
ii get(int i)
{
    ii res = ii(0, 0);
    for(; i>0; i-=_(i)) res = res + bit[i];
    return res;
}
void dfs(int u)
{
    int v, z = 0;
    for(auto e: ke[u]) if (e.p1 != par[u]) {
        v = e.p1;
        Cols[e.p2.p1].pb(v);
        h[v] = h[u] +1; d[v] = e.p2.p2;

        par[v] = u; dfs(v);
        if (w[v] > w[z]) z = v;
    }
    chain[u] = z!=0 ? chain[z] : u;
    top[chain[u]] = u;
    w[u] = w[z] + 1;
}
void hld()
{
    int num = 0;
    for(int i=1; i<=n; ++i) if (chain[i] == i)
        for(int u=i; chain[u] == chain[i]; u = par[u])
            ind[u] = ++num;
}
ii lca(int u,int v)
{
    ii res = ii(0, 0);
    int s, t;
    while (chain[u] != chain[v]) {
        s = top[chain[u]];
        t = top[chain[v]];
        if (h[s] > h[t]) {
            res = res + get(ind[s]) - get(ind[u]-1);
            u = par[s];
        }else {
            res = res + get(ind[t]) - get(ind[v]-1);
            v = par[t];
        }
    }
    if (h[u] > h[v]) swap(u, v);
    return res + get(ind[u]-1) - get(ind[v]-1);
}
int main()
{
    //freopen("a.inp","r",stdin);
    int q;
    scanf("%d%d",&n,&q);
    for(int i=1; i<n; ++i) {
        int u, v, c, d;
        scanf("%d%d%d%d",&u,&v,&c,&d);
        ke[u].pb(i3(v, ii(c,d)));
        ke[v].pb(i3(u, ii(c,d)));
    }

    dfs(1); hld();
    for(int i=1; i<=n; ++i) upd(ind[i], ii(d[i], 0));

    for(int i=1; i<=q; ++i) {
        int x, y, u, v;
        scanf("%d%d%d%d",&x,&y,&u,&v);
        qu[i] = i5(ii(x, y), i3(i, ii(u, v)));
    }
    sort(qu+1, qu+1+q);

    for(int i=1; i<=q; ++i) {
        if (qu[i-1].p1.p1 != qu[i].p1.p1) {
            for(int u: Cols[qu[i-1].p1.p1]) upd(ind[u], ii(+d[u],-1));
            for(int u: Cols[qu[i  ].p1.p1]) upd(ind[u], ii(-d[u],+1));
        }
        auto tmp = lca(qu[i].p2.p2.p1, qu[i].p2.p2.p2);
        ans[qu[i].p2.p1] = tmp.p1 + tmp.p2 * qu[i].p1.p2;
    }
    for(int i=1; i<=q; ++i) printf("%d\n",ans[i]);
}


Measured memory_bytes: 22652
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;cin>>n;string s;s=to_string(n); int flag=0;
  for(int i=0;i<s.length();i++){
  	if(s[i]=='7'){flag=1;break;}
  }
  if(flag==0){cout<<"No";}else{cout<<"Yes";}
}

Measured memory_bytes: 3680
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  char S[10];
  char T[11];
  scanf("%s", S);
  scanf("%s", T);
  
  int diff_one_flag = 0; //一文字違いフラグ
   if(strlen(T) == (strlen(S) + 1)){
    for(int i=0; i<strlen(S); i++){
      if(S[i] != T[i]){
        diff_one_flag = 1;
      }
    }
   }
     
   	if(diff_one_flag == 0){
     	printf("Yes");
   	}else{
     	printf("No");
   	} 
}

Measured memory_bytes: 1732
#include <stdio.h>

int main()
{
	int i, N, Q, t, x;
	scanf("%d %d", &N, &Q);
	
	int j, num[2][200001] = {}, l = N - 1, u = N - 1;
	long long ans = (long long)(N - 2) * (N - 2);
	for (i = 2; i <= N - 1; i++) {
		num[0][i] = -1;
		num[1][i] = -1;
	}
	for (i = 1; i <= Q; i++) {
		scanf("%d %d", &t, &x);
		if (t == 1) {
			if (num[0][x] == -1) {
				ans -= u - 1;
				for (j = x + 1; j <= l; j++) num[0][j] = u - 1;
				l = x - 1;
			} else ans -= num[0][x];
		} else {
			if (num[1][x] == -1) {
				ans -= l - 1;
				for (j = x + 1; j <= u; j++) num[1][j] = l - 1;
				u = x - 1;
			} else ans -= num[1][x];
		}
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3296
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int m,d,cnt=0;
    cin >> m >> d;
    for(int i = 4;i<= m;i++){
        for(int j = 21;j<=d;j++){
            int j1,j2;
            j1 = j/10;
            j2 = j%10;
            if(j1*j2==i&&j1 >=2&&j2>=2){
                cnt++;
            }
        }
    }
    
    cout << cnt;
    
}


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

int main() {
  string S;
  cin >> S;
  
  if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
  
  return 0;
}

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

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  sort(a.rbegin(), a.rend());
  int s = 0;
  for (int i = 0; i < n; ++i) {
    long long v = a[i] * 4 * m;
    if (v < sum) {
      break;
    } else s++;
    if (s >= m) break;
  }
  if (s >= m) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A , B , C , D;
    cin >> A >> B >> C >> D;

    if      ((A >= B) && (C >= D)) {cout << B + D;}
    else if ((A <= B) && (C >= D)) {cout << A + D;}
    else if ((A >= B) && (C <= D)) {cout << B + C;}
    else if ((A <= B) && (C <= D)) {cout << A + C;}
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;
const double PIE = 3.14159265358979;

int main()
{
	double r;
	cin >> r;
	printf("%.7lf %.7lf\n",r*r*PIE,2.0*r*PIE);
	return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

int main() {
  llong N;
  vector<llong> a;

  cin >> N;
  a.resize(N);
  for (auto &in: a) {
    cin >> in;
  }

  vector<llong> ans(N + 1, 0);
  llong num = 0;
  bool ok = true;
  for (int i = N; i >= 1; i--) {
    llong sum = 0;
    for (int j = i; j <= N; j += i) {
      sum += ans[j];
    }
    if (sum % 2 != a[i - 1]) {
      ans[i] = 1;
      num++;
    }
  }

  cout << num << endl;
  for (int i = 1; i <= N; i++) {
    if (ans[i]) {
      cout << i << " ";
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 6400
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

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

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, K;
	cin >> N >> K;
	vector<int> P(N), C(N);
	REP(i, N){
		cin >> P[i];
		P[i]--;
	}
	REP(i, N){
		cin >> C[i];
	}

	vector<int> done(N, 0);

	LL ret = -1e18;

	REP(i, N){
		if(done[i]) continue;
		vector<int> loop;
		int cur = i;
		LL total = 0;
		while(!done[cur]){
			done[cur] = 1;
			cur = P[cur];
			total += C[cur];
			loop.push_back(cur);
		}
		// EACH(l, loop) cerr << l << " ";
		// cerr << endl;
		int n = max(0, K / (int)loop.size() - 1);
		int m = K - loop.size() * n;
		LL score = total * n;
		if(score <= 0){
			score = 0;
			m = min(K, 2 * (int)loop.size());
		}
		if(0 < m){
			LL sub_max = -1e18;
			REP(j, loop.size())
			{
				LL sub = 0;
				REP(k, m){
					sub += C[loop[(j + k) % loop.size()]];
					sub_max = max(sub_max, sub);
				}
			}
			score += sub_max;
		}
		ret = max(ret, score);
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		}
		else {
			cout << ng << endl;
		}
	}

	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000007;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.rbegin(), v.rend());
	int Alice = 0, Bob = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0) {
			Alice += v[i];
		}
		else {
			Bob += v[i];
		}
	}
	cout << Alice - Bob << endl;
}


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

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

int n;
int a[1001];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		sort(a,a+n);
		int res=a[1]-a[0];
		for(int i=1;i<n;i++){
			res=min(res,a[i]-a[i-1]);
		}
		printf("%d\n",res);
	}
	return 0;
}

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

using namespace std;

int main(){
 	
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for(int i = 0; i+2 < n; i++)
    if( s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' )
      	cnt++;
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
int n;
int* a = new int[100005];
int* a_copy = new int[100005];
map<int, int> mp;
int cnt;
int ans;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		a_copy[i] = a[i];
	}
	sort(a_copy + 1, a_copy + n + 1);
	for (int i = 1; i <= n; i++)mp[a_copy[i]] = i;
	for (int i = 1; i <= n; i++)
	{
		if (mp[a[i]] % 2 != i % 2)
		{
			cnt++;
		}
	}
	ans = cnt / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9092
N = int(input())

n = int((N ** 0.5) // 1)

ans = 11
for i in range(1,n+1):
    if N % i == 0:
        a = i
        b = N // i
        f = max(len(str(a)), len(str(b)))
        ans = min(ans, f)
    
print(ans)

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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i <= (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll A,B,C,K,N,X,Y,cnt;

int main(){
  cin >> A >> B >> C >> X >>Y;
  rep(c,max(X,Y)*2){
    int a,b;
    a = max(0LL,X-c/2);
    b = max(0LL,Y-c/2);
    if(c==0){
      cnt = a*A+b*B+c*C;
    }else{
      cnt = min(cnt,a*A+b*B+c*C);
    }
  }
  print(cnt);
}


Measured memory_bytes: 3632
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int d[10];

int main() {
	fast_cin();
	for (int i = 0; i < 3; ++i) {
		int a, b;
		cin >> a >> b;
		++d[a]; ++d[b];
	}
	for (int i = 1; i <= 4; ++i) {
		if (d[i] > 2) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}

Measured memory_bytes: 256