akhauriyash/Code-Regression huggingface dataset:
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n;
  cin>>n;
  vector<ll>v(n+1,0);
  vector<ll>ans(n+1,0);
  vector<ll>z;
  for(ll i=1;i<=n;i++){
    cin>>v[i];
  }
  ll m=0;
  for(ll i=n;i>=3;i--){
    ans[i]=v[i];
    if(v[i]==1){
      m++;
      z.push_back(i);
      for(ll j=1;j<=sqrt(i);j++){
        if((i%j)==0){
          v[j]^=1;
          if(j!=(i/j)&&(i/j)<i)v[i/j]^=1;
        }
      }
    }
  }
  for(ll i=2;i>1;i--){
    ans[i]=v[i];
    if(v[i]==1){
      m++;
      z.push_back(i);
      for(ll j=1;j<=sqrt(i);j++){
        if((i%j)==0){
          v[j]^=1;
        }
      }
    }
  }
  ans[1]=v[1];
  if(v[1]==1){
    m++;
    z.push_back(1);
  }
  cout<<m<<endl;
  reverse(z.begin(),z.end());
  if(z.size()>0)cout<<z[0];
  for(ll i=1;i<(ll)z.size();i++){
    cout<<" "<<z[i];
  }
  cout<<endl;
}


Measured memory_bytes: 5108
import java.util.Scanner;

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

		int count = 0;
		for (int i = 0; i < n; i++) {
			int v = scn.nextInt();
			boolean bol = true;
			if (v == 2) {
				count++;
				continue;
			} else if (v % 2 == 0) {
				continue;
			}
			for (int j = 3; j <= Math.sqrt((double)v); j++) {
				if (v % j == 0) {
					bol = false;
					break;
				}
			}
			if (bol) {
				count++;
			}
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 40880
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e2 + 7;
const int md = 1e9 + 7;
int isp(string s) {
  string r = s;
  reverse(s.begin(), s.end());
  return r == s;
}
void sol() {
  string s, s1, s2, S;
  cin >> S;
  s += '$';
  int n = S.length();
  for(int i=0; i<n; i++) {
    s += S[i];
  }
  int x = (n-1)/2;
  int y = (n + 3)/2;
  for(int i=1; i<=x; i++) {
    s1 += s[i];
  }
  for(int i=y; i<=n; i++) {
    s2 += s[i];
  }
  //cout << s1 << " " << s2;
  if(isp(S) && isp(s1) && isp(s2)) {
    cout << "Yes";
  }
  else cout << "No";
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<string, int> mp;
    int N; cin >> N;
    string S[N];
    rep(i, N) {
        cin >> S[i];
        mp[S[i]]++;
    }
    int K; cin >> K;
    rep(i, K) {
        string T; cin >> T;
        mp[T]--;
    }
    int ans = 0;
    rep(i, N) ans = max(ans, mp[S[i]]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
int prodmod(vector<int> w);
int summod(vector<int> w);
///CUIDADO COM MAXN
#define N 3050

int n, m, q, k, v[N], ans;
pii w[N];
string s;
const int inf = (int)(2e17);
int dp[N][N][5], mat[N][N];
int solve(int x, int y, int qtd){
	if(x <= 0 or y <= 0 or x > n or y > m or qtd > 3) return -inf;
	if(x == n && y == m){
		if(qtd < 3) return max(mat[x][y], 0LL);
		return 0;
	}
	if(dp[x][y][qtd] != -1) return dp[x][y][qtd];
	int A = solve(x, y + 1, qtd + 1) + mat[x][y];
	int B = solve(x, y + 1,qtd);
	int C = solve(x + 1,y, 0);
	if(qtd < 3) C += max(0LL, mat[x][y]); 
	return dp[x][y][qtd] = max({A, B, C});
}

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>m>>k;
	memset(dp, -1, sizeof dp);
	for(int i = 1;i<=k;i++){
		int x, y, v;
		cin>>x>>y>>v;
		mat[x][y]=v;
	}
	cout<<solve(1, 1, 0)<<"\n";
}
/*
    CUIDADO COM MAXN, MOD, OVERFLOW 
    >Colocar (>DEFINE INT LONG LONG<) no inicio do template
    >mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
    >NAO ESQUECER DEFINE INT LONG LONG
    > N = 1 ? 
*/
int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;}
int prodmod(vector<int> w){int curr = 1;
for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}

Measured memory_bytes: 438996
package main

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

var r = bufio.NewReader(os.Stdin)

func main() {
    var a,b int
    fmt.Fscan(r,&a)
    fmt.Fscan(r,&b)
    if a < b {
        fmt.Println("a < b")
    }
    if a > b {
        fmt.Println("a > b")
    }
    if a == b {
        fmt.Println("a == b")
    }
}



Measured memory_bytes: 1116
#include <stdio.h>

int main( void )
{

	int n1, n2, n3, tmp;
	
	scanf( "%d %d %d", &n1, &n2, &n3 );
	
	if( n1 > n2 ){
		tmp = n2;
		n2 = n1;
		n1 = tmp;
	}
	
	if( n2 > n3 ){
		tmp = n3;
		n3 = n2;
		n2 = tmp;
	}
	
	if( n1 > n2 ){
		tmp = n2;
		n2 = n1;
		n1 = tmp;
	}
	
	printf( "%d %d %d\n", n1, n2, n3 );
	
	return 0;
	
}

Measured memory_bytes: 596
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const pos = (x, y) => {
    return { x : x, y : y};
};

const div = (p1, p2, n) => {
    if (n === 0) return [];
    const cos = Math.cos(Math.PI / 3.0);
    const sin = Math.sin(Math.PI / 3.0);

    const s = pos((2 * p1.x + p2.x) / 3, (2 * p1.y + p2.y) / 3);
    const t = pos((p1.x + 2 * p2.x) / 3, (p1.y + 2 * p2.y) / 3);
    const u = pos( (t.x - s.x) * cos - (t.y - s.y) * sin + s.x
                 , (t.x - s.x) * sin + (t.y - s.y) * cos + s.y
                 );
    
    return div(p1, s, n - 1)
               .concat(s)
               .concat(div(s, u, n - 1))
               .concat(u)
               .concat(div(u, t, n - 1))
               .concat(t)
               .concat(div(t, p2, n - 1));
};

const solve = (n) => {
    if (n === 0) return [pos(0.0, 0.0), pos(100.0, 0.0)];
    return [pos(0.0, 0.0), ...div(pos(0.0, 0.0), pos(100.0, 0.0), n), pos(100.0, 0.0)];
};
solve(parseInt(line[0]))
    .forEach(p => {
        console.log(p.x.toFixed(8), p.y.toFixed(8));
    });



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

Measured memory_bytes: 572
S = list(input())
last = len(S) - 1

S_head = S[0]

S_bothEnd = [S[0],S[1],S[last]]
S_center = list(set(S)-set(S_bothEnd))

S_clone = S
if "A" in S_clone:
  S_clone.remove('A')
if "C" in S_clone:
  S_clone.remove('C')

evalLow = "".join(S_clone)

if S_head == "A" and S_center.count("C")  == 1 and evalLow.islower() == 1:
  print('AC')
else:
  print('WA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int ans, cnt;
    ans = 0;
    cnt = 0;
    vector<char> ACGT = {'A', 'C', 'G', 'T'};
    for(char c: s){
        if(find(ACGT.begin(), ACGT.end(), c) != ACGT.end()){
            cnt++;
            ans = max(ans, cnt);
        } else {
            cnt = 0;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

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

    vector<bool> sieve(1000000, true);
    sieve[0] = sieve[1] = false;
    for (int i = 2; i < 1000000; i++) {
        if (sieve[i]) {
            int j = 2 * i;
            while (j < 1000000) {
                sieve[j] = false;
                j += i;
            }
        }
    }

    int x;
    cin >> x;
    for (int i = x; i < 1000000; i++) {
        if (sieve[i]) {
            cout << i;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000000 + 5;
const ll mod = 1000000007;

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    if(c <= a || c <= b){
    	cout << "No" << endl;
	}
	else{
		ll ans1 = a*b*4,ans2 = (c-a-b)*(c-a-b);
	    if(ans2 > ans1)
	    	cout << "Yes" << endl;
	    else
	    	cout << "No" << endl;	
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int array[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  k--;
  cout << array[k] << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
bool OK[110];
int main()
{
  int N,K;
  cin>>N>>K;
  while(K--)
  {
    int X;
    cin>>X;
    while(X--)
    {
      int Y;
      cin>>Y;
      OK[Y]=true;
    }
  }
  int Ans=0;
  for(int i=1;i<=N;i++)
    if(!OK[i])
      Ans++;
  cout<<Ans<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
    int n,t,x,y,fh=0,i,j;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d %d %d",&t,&x,&y);
        if(x+y<=t)
        {
            if(t%2!=(x+y)%2)
            fh=1;
        }
        else
        {
            fh=1;
        }
    }
    if(fh==1)
        printf("No\n");
        else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 128
K,N = map(int, input().split(" "))
A = list(map(int, input().split(" ")))

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )

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

namespace B___Christmas_Eve_Eve
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            int N = int.Parse(Console.ReadLine());

            var price = new List<int>();

            for (int i = 0; i < N; i++)
                price.Add(int.Parse(Console.ReadLine()));

            sum = price.Sum() - price.Max() / 2;

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11220
#include<set>    // multiset
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  set<pair<int,int>> s;
  rep(i,n){
    int a; cin >>a;
    s.insert(make_pair(a,i+1));
  }
  for(const auto& x: s){
    printf("%d ",x.second);
  }
}

/// confirm df==0 ///


Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    bool f=1;
    if(a!=1&&b!=1&&c!=1&&d!=1){
        f=0;
    }else if(a!=9&&b!=9&&c!=9&&d!=9){
        f=0;
    }else if(a!=7&&b!=7&&c!=7&&d!=7){
        f=0;
    }else if(a!=4&&b!=4&&c!=4&&d!=4){
        f=0;
    }
    cout << (f ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n+1);
    rep(i,n-1){
        int t;
        cin>>t;
        a[t]++;
    }
    REP(i,1,n)cout<<a[i]<<endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	string S, a, b;
	cin >> S;
	a = S.substr(0, 2);
	b = S.substr(2, 2);
	bool am = true, bm = true;
	if ((a[0] > '0' && a[1] > '2') || a == "00") am = false;
	if ((b[0] > '0' && b[1] > '2') || b == "00") bm = false;

	if (am && bm) cout << "AMBIGUOUS" << endl;
	else if (am) cout << "MMYY" << endl;
	else if (bm) cout << "YYMM" << endl;
	else cout << "NA" << endl;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n, d = MAP()
ans = 0
while(1):
    n -= (2 * d + 1)
    ans += 1
    if n <= 0:
        break
print(ans)

Measured memory_bytes: 5688
#include <stdio.h>

int main()
{
  int N,A,ans[100001];
  scanf("%d",&N);
  for (int i=1; i<=N; i++) {
    scanf("%d",&A);
    ans[A]=i;
  }
  for (int i=1; i<=N; i++)
    printf("%d ",ans[i]);
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main(){
    long long h;
    cin>>h;
    
    long long ans=0;
    long long punch=1;
    
    while(h>punch){
        h-=punch;
        ans+=punch;
        punch*=2;
    }
    
    ans+=punch;
    
    cout<<ans<<endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

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

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int a, b;

	cin >> a >> b;

	Out((a + b) % 24);
	
	return 0;
}


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

int main() {
	//入力を受け取る
	int D, T, S;
	cin >> D >> T >> S;

	//高橋君の移動時間を計算する
	int dist = S * T;

	//Dとdistの大小関係に応じて出力をする
	if (dist >= D) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5;
const ll mod = 998244353;
int x[maxn],y[maxn],z[maxn];
int fa[maxn];
int findfa(int p)
{
    return (p == fa[p])?p:fa[p] = findfa(fa[p]);
}
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i = 0; i < m; ++i)
        {
            cin>>x[i]>>y[i]>>z[i];
            z[i] = z[i]&1;
        }
        for(int i = 1; i <= n; ++i)fa[i] = i;
        for(int i = 0; i < m; ++i)
        {
            int xx = findfa(x[i]);
            int yy = findfa(y[i]);
            if(xx == yy)continue;
            fa[xx] = yy;
        }
        for(int i = 1; i <= n; ++i)fa[i] = findfa(i);
        sort(fa+1,fa+n+1);
        int ans = 0;
        int now = -1;
        for(int i = 1; i <= n; ++i)
            if(fa[i] != now)
            {
                ans++;
                now = fa[i];
            }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) * 2;
int id[MAXN][MAXN];
vector<int> to[MAXV];
vector<int> from[MAXV];
int indeg[MAXV];
int table[MAXV];


int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n - 1));
    rep(i, n) rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; }
    
    int c = 0;
    rep(i, n) rep3(j, i + 1, n) {
        id[i][j] = c++;
    }
    
    
    auto toId = [&](int i, int j) {
        if (i > j) swap(i, j);
        return id[i][j];
    };
    
    rep(i, n) {
        rep(j, n - 1) a[i][j] = toId(i, a[i][j]); // a[i][j]を再利用
        rep(j, n - 2) {
            to[a[i][j]].eb(a[i][j + 1]);
            from[a[i][j + 1]].eb(a[i][j]);
        }
    }
    
    int ans = 0;
    
    queue<int> q;
    rep(i, c) {
        if (sz(from[i]) == 0) {
            // cout << i << endl;
            q.push(i);
            table[i] = 1;
        }
    }
    
    if (sz(q) == 0) { cout << -1 << endl; return 0; }
    
    rep(i, c) indeg[i] = sz(from[i]);
    
    while (!q.empty()) {
        int now = q.front();
        // cout << "now " << now << '\n';
        q.pop();
        
        for (int nxt : to[now]) {
            
            // cout << "nxt " << nxt << '\n';
            indeg[nxt]--;
            chmax(table[nxt], table[now] + 1);
            chmax(ans, table[nxt]);
            if (indeg[nxt] == 0) q.push(nxt);
        }
    }
    rep(i, c) if (indeg[i] != 0) { cout << -1 << endl; return 0; }
    cout << ans << endl;
}



Measured memory_bytes: 141440
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const ll INF = 1e18 + 10;

const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ( (x += a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( ( x += mod - a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        ( x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

string S;
mint dp[100005][13];

int main() {
    cin >> S;
    int N = S.size();
    dp[0][0] = 1;
    rep(i,N) {
        rep(k, 13) {
            rep(x,10) {
                if (S[i] != '?' && S[i]-'0' != x) continue;
                int nk = (10*k + x)%13;
                dp[i+1][nk] += dp[i][k];
            }
        }
    }
    cout << dp[N][5] <<endl;
}

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

int main(){
    string s;
    cin>>s;
    string ans;
    int n;
    n=s.length();
    for (int i = 0; i < n; i++){
        if (s[i]!='B'){ans.push_back(s[i]);}
        else{
            if(ans.empty()==0){ans.pop_back();}
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ts=[]
for i in range(N):
  x, l = map(int,input().split())
  s = max(x-l,0)
  t = min(10**9,x+l)
  ts.append([t,s])
ts.sort()

count = 0
lastT = 0
for i in ts:
  if i[1]>=lastT:
    count+=1
    lastT=i[0]
print(count)

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) {
    cin >> vec[i];
  }
  rep(i,n) {
    if( i == 0 ) {
      --vec[i];
    } else if( vec[i-1] < vec[i] ) {
      --vec[i];
    }
    if( i && vec[i-1] > vec[i] ) { puts("No"); return 0; }
  }
  puts("Yes");
  compute();
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long m = n-1LL;
  vector<long long> nFac, mFac;
  for(int i=2;i<=sqrt(n);i++) {
    if(i == sqrt(n)) nFac.emplace_back(i);
    else if(n % i == 0) {
      nFac.emplace_back(i);
      nFac.emplace_back(n/i);
    }
  }
  nFac.emplace_back(n);
  for(int i=2;i<=sqrt(m);i++) {
    if(i == sqrt(m)) mFac.emplace_back(i);
    else if(m % i == 0) {
      mFac.emplace_back(i);
      mFac.emplace_back(m / i);
    }
  }
  mFac.emplace_back(m);
  int ans = mFac.size();
  for(int i=0;i<nFac.size();i++) {
    long long nc = n;
    while(nc >= nFac[i]) {
      if(nc % nFac[i] == 0) nc /= nFac[i];
      else if((nc-1) % nFac[i] == 0) nc = 1;
      else nc = -1;
    }
    if(nc == 1) ans++;
  }
  if(n == 2) cout << 1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

int main() {
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));

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

    int ans = 1000000000;

    for (int i = 0; i < pow(2, n); i++) {
        int b = i;
        int p = 0;
        vector<int> d(m, 0);
        for (int j = 0; j < n; j++) {
            if (b % 2) {
                for (int k = 0; k < m; k++) {
                    d[k] += a[j][k];
                }
                p += c[j];
            }
            b /= 2;
        }
        bool cond = true;
        for (int j = 0; j < m; j++) {
            if (d[j] < x) {
                cond = false;
                break;
            }
        }

        if (cond) ans = min(ans, p);
    }

    if (ans == 1000000000) ans = -1;

    cout << ans << endl;
}


Measured memory_bytes: 4108
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

void Sequence() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	cout << s1[0] << s2[0] << s3[0] << endl;
}
int main() {
	Sequence();
	return 0;
}



Measured memory_bytes: 256
S = input()
Q = int(input())

# print(S, Q)

queries = []
for i in range(Q):
    query = input()
    queries.append(query)

from collections import deque
slist = deque(list(S))
isReversed = False
for query in queries:
    if query == "1":
        isReversed = not isReversed
    else:
        t, f, c = query.split()
        if f == '1':
            if isReversed:
                slist.append(c)
            else:
                slist.appendleft(c)
        else:
            if isReversed:
                slist.appendleft(c)
            else:
                slist.append(c)

if isReversed:
    slist.reverse()
print("".join(slist))


Measured memory_bytes: 21224
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define M 100005
#define rep(i,a,b) for(lli i=a;i<b;i++)
#define pii pair<lli,lli> 
#define Itr vector<lli> :: iterator
void fast()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(0);
}

lli a[M] ; 
int main()
{
	fast();
	lli t,n;
	t=1;
	while(t--)
	{
		cin>>n;
		rep(i,0,n)
			cin>>a[i];
		lli sum=0;
		rep(i,0,n)
		{
			rep(j,i+1,n)
			{
				sum+=(a[i]*a[j]);
			}
		}
		cout<<sum<<"\n";
	}
return 0;
}

Measured memory_bytes: 256
a,b=input().strip().split(" ")
a,b=[int(a),int(b)]
k=0
for i in range(1200):
    aa=(i*8)//100
    bb=(i*10)//100
    if (a==aa and b==bb):
        print(i)
        k=1
        break
if k==0:
    print(-1)
    


Measured memory_bytes: 3060
//  Author : Amit Kumar 

#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;

int main(void){
#ifdef HELL_JUDGE
    auto INITIAL_TIME = high_resolution_clock::now();
#endif 
    int n; cin >> n;
    map<string , int>f; 
    f["AC"] = 0; 
    f["WA"] = 0;
    f["RE"] = 0;
    f["TLE"] = 0;
    while(n--){
        string s; cin >> s; 
        f[s]++;
    }
    printf("AC x %d\n",f["AC"]);
    printf("WA x %d\n",f["WA"]);
    printf("TLE x %d\n",f["TLE"]);
    printf("RE x %d\n",f["RE"]);

#ifdef HELL_JUDGE
    auto FINAL_TIME = high_resolution_clock::now();
    cout << "Time : "
         << duration_cast<milliseconds>(FINAL_TIME-INITIAL_TIME).count() 
         << " ms" << '\n'; 
#endif 
    return 0;
}


Measured memory_bytes: 3724
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int a[N];
LL solve (int l,int r,int lp,int rp)
{
	if (r-l+1<=2) return 0;
	LL ans=1e18;
	for (int p=l+1; p<=r-1; p++)
		chkmin (ans,solve (l,p,lp,lp+rp)+solve (p,r,lp+rp,rp)+(LL)a[p]*(lp+rp));
	return ans;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	int n; sc(n);
	for (int i=1; i<=n; i++)
		sc(a[i]);
	pr(solve (1,n,1,1)+a[1]+a[n]);

    return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  int i,j,m=0;
  for(i=1;i<=n;i++)
  {int k=0;
    j=i;
    while(j!=0)
    {
      k++;
      j=j/10;
    }
      if(k%2!=0)
      m++;
  }
  printf("%d",m);
  return 0;
}

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

using namespace std;


int a,b,ans;
int main()
{
    cin>>a>>b;
    if((a+b)>16){cout<<":(";return 0;}
    else if(a>b && a<=8){cout<<"Yay!";return 0;}
    else if(a==b && a<=8){cout<<"Yay!";return 0;}
    else if(a<b && b<=8){cout<<"Yay!";return 0;}
    else {cout<<":(";return 0;}
   // system("pause");
    return 0;
}  
   

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int prime(int n)
{
	for(int i=n;;i++)
	{
		bool flag=0;
		if(i<2) continue;
		for(int j=2;j*j<=i;j++)
		if(i%j==0)
		{
			flag=1;
			break;
		}
		if(!flag) return i;
	}
}
int main() {
	scanf("%d",&n);
	printf("%d",prime(n));
	return 0;
}

Measured memory_bytes: 256
import math
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))
R = []

for i in range(1, N+1, 1):
  R.append(i)

l = list(itertools.permutations(R))

a = l.index(P)
b = l.index(Q)
print(abs(a - b))



Measured memory_bytes: 8052
using System;
using System.IO;

class Program
{
    static void Main(string[] args) {
        var scan = new Scanner();
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(Solve(scan));
        Console.Out.Flush();
    }
    static object Solve(Scanner scan) {
        var N = scan.NextInt();
        if (N == 1) return "Yes";
        var H = scan.ArrayInt(N);
        if (H[1] - H[0] == -1) H[0]--;
        for (int i = 0; i < N - 1; i++) {
            if (H[i + 1] - H[i] > 0) H[i + 1]--;
            if (H[i + 1] - H[i] < 0) return "No";
        }
        return "Yes";
    }
}

class Scanner
{
    string[] s;
    int i;
    public Scanner() {
        s = new string[0];
        i = 0;
    }
    public string Next() {
        if (i < s.Length) return s[i++];
        string str = Console.ReadLine();
        while (str == "") str = Console.ReadLine();
        s = str.Split(' ', StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return Next();
        i = 0;
        return s[i++];
    }
    public int NextInt() => int.Parse(Next());
    public int[] ArrayInt(int len, int add = 0) {
        var array = new int[len];
        for (int i = 0; i < len; i++) array[i] = NextInt() + add;
        return array;
    }
}

Measured memory_bytes: 37432
H, W = map(int, input().split())
cam = [input() for i in range(H)]
ans = 'Yes'
for i in range(1, H-1):
	for j in range(1, W-1):
		if cam[i][j] == "#":
			if cam[i-1][j] == cam[i+1][j] == cam[i][j-1] == cam[i][j+1] == ".":
				ans = 'No'
				break
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
}



Measured memory_bytes: 2612
import sys

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

a = []

for i in range(n):
    a.append(list(map(int, input().split())))

a.sort()

i = 0
ans = 0

while m > 0:
    if m > a[i][1]:
        ans += a[i][0] * a[i][1]
        m = m - a[i][1]
        i += 1
    else:
        ans += a[i][0] * m
        print(ans)
        sys.exit()


Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
char S[1001][1001];
int inf = 1001001001;
void check(int H, int W, int X_count){
    cout << "The root is..." << endl;
    for(int j=0;j<H;j++){
        for(int k=0;k<W;k++) cout << S[j][k];
        cout << endl;
    }
    cout << "X_count = " << X_count << endl;
}
int main(){
    int H, W, Ch, Cw, Dh, Dw, min_count=inf,count_warp=0;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--;
    Cw--;
    Dh--;
    Dw--;
    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++) cin >> S[i][j];
    int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

    queue<tuple<int,int,int>> que_walk, que_warp;

    tuple<int,int,int> X;
    X = make_tuple(Ch, Cw, 0);
    S[Cw][Ch] = '#';
    que_walk.push(X);
    que_warp.push(X);

    while(1){
        //徒歩での移動
        while(!que_walk.empty()){
            X = que_walk.front(); que_walk.pop();
            que_warp.push(X);
            int Xx = get<0>(X);
            int Xy = get<1>(X);
            int X_count = get<2>(X);
            for(int i=0;i<4;i++){
                int new_x = Xx + dx[i], new_y = Xy + dy[i];
                if(0<=new_x&&new_x<=H-1&&0<=new_y&&new_y<=W-1&&S[new_x][new_y]!='#'){
                    //(new_x,new_y)の位置は訪れたことがない
                    S[new_x][new_y] = '#';
                    if(new_x==Dh&&new_y==Dw) min_count = min(min_count, X_count);
                    X = make_tuple(new_x, new_y, X_count);
                    que_walk.push(X);
                    que_warp.push(X);
                    /*
                    S[new_x][new_y] = 'o';
                    cout <<"Now, walking." << endl;
                    check(H,W,X_count);
                    S[new_x][new_y] = '#';
                    */
                }
            }
        }
        //徒歩で移動できる地点が列挙されたので、それらからワープで移動できる地点を列挙する
        //warpでの移動
        count_warp++;
        while(!que_warp.empty()){
            X = que_warp.front(); que_warp.pop();
            int Xx = get<0>(X);
            int Xy = get<1>(X);
            int X_count = get<2>(X);
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    int new_x = Xx + i;
                    int new_y = Xy + j;
                    if(0<=new_x&&new_x<=H-1&&0<=new_y&&new_y<=W-1&&S[new_x][new_y]!='#'){
                        //(new_x,new_y)の位置は訪れたことがない
                        S[new_x][new_y] = '#';
                        if(new_x==Dh&&new_y==Dw) min_count = min(min_count, X_count+1);
                        X = make_tuple(new_x, new_y, X_count+1);
                        que_walk.push(X);//warpで移動したところからまた徒歩出移動出来る場所を列挙するので、queueに入れとく
                        /*
                        S[new_x][new_y] = 'o';
                        cout << "Now, warping : " << count_warp << endl;
                        check(H,W,X_count+1);
                        S[new_x][new_y] = '#';
                        */
                    }
                }
            }
        }
        if(que_walk.empty()&&que_warp.empty()){
            if(min_count!=inf) cout << min_count << endl;
            else cout << -1 << endl;
            return 0;
        }
        
    }
}

Measured memory_bytes: 4616
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm(a, b):
	return a * b // gcd (a, b)

a,b,c,d = map(int,input().split())
ac_can = int((a-1)//c)
ad_can = int((a-1)//d)
acd_can = int((a-1)//lcm(c,d))
bc_can = int(b//c)
bd_can = int(b//d)
bcd_can = int(b//lcm(c,d))
print(b-a+1-(bc_can+bd_can-bcd_can-(ac_can+ad_can-acd_can)))

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

int main(){
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int suma = 0;
    rep(i,n) suma += a[i];
    if(suma >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include<iostream> 
#include<cstring>
#include<string>
using namespace std;
int main()
{
    string a;
    bool v[2]={0};
    cin>>a;
    for(int i=0;i<a.length();i++){//a[0]==>a[n-1] 
        if(a[i]=='C') v[0]=1; 
        if(a[i]=='F'&&v[0])  v[1]=1;
    }
    if(v[1]) cout<<"Yes"; 
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
hlist=list(map(int,input().split()))

graph=[set() for _ in range(N+1)]
for _ in range(M):
  a,b=map(int,input().split())
  graph[a].add(b)
  graph[b].add(a)
#print(graph)

answer=0
for i in range(1,N+1):
  h=hlist[i-1]
  for s in graph[i]:
    if h<=hlist[s-1]:
      break
  else:
    answer+=1

print(answer)

Measured memory_bytes: 45228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    string s;
    cin >> s;
    vector<bool> che(26);
    rep(i,s.size()) che[s[i]-'a'] = 1;
    if(s.size() <= 25){
        rep(i,26){
            if(!che[i]){
                s += 'a' + i;
                cout << s << endl;
                return 0;
            } 
        }
    }else{
        for(int i=s.size()-1;i>=0;i--){
            che[s[i] - 'a']=0;
            for(int j=s[i]-'a'+1;j<26;j++){
                if(!che[j]){
                    s[i] = (char)j + 'a';
                    s = s.substr(0,i+1);
                    cout << s << endl;
                    return 0;
                }
            }
        }
        cout << -1 << endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    st S;
    cin >> S;
    bool YM = 0, MY = 0;
    if(S.at(0) == '0' && S.at(1)!= '0') YM = 1;
    else if(S.at(0) == '1' && (S.at(1) == '0' || S.at(1) == '1' || S.at(1) == '2')) YM = 1;
    if(S.at(2) == '0' && S.at(3)!= '0') MY = 1;
    else if(S.at(2) == '1' && (S.at(3) == '0' || S.at(3) == '1' || S.at(3) == '2')) MY = 1;

    if(YM && MY) cout << "AMBIGUOUS" << endl;
    if(YM && !MY) cout << "MMYY" << endl;
    if(!YM && MY) cout << "YYMM" << endl;
    if(!YM && !MY) cout << "NA" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
// #define DEBUG

int main (void) {
	int N, x, a1, a2, i, nc;
	long long int re;
	scanf (" %d %d", &N, &x);
	if (N == 1) {
		scanf (" %d", &a1);
		if (a1 > x) printf("%lld\n", x - a1);
		else printf("0\n");
	} else {
		re = 0;
		scanf (" %d %d", &a1, &a2);
		if((a1 + a2) > x) {
			re = a1 + a2 - x;
			a2 -= re;
			if (a2 < 0) a2 = 0;
		}
		#ifdef DEBUG
			printf("%4d%4d", a1, a2);
		#endif

		for (i = 2; i < N; i++) {
			a1 = a2;
			scanf(" %d", &a2);
			if((a1 + a2) > x) {
				nc = a1 + a2 - x;
				re += nc;
				a2 -= nc;
				// if (a2 < 0) a2 = 0;
			}
			#ifdef DEBUG
				printf("%4d", a2);
			#endif
		}
		#ifdef DEBUG
			printf("\n");
		#endif
		printf ("%lld\n", re);
	}

	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <unordered_map> 
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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 main() {
	int n;
	cin >> n;
    
	vector<pair<string, int>> vp(n);

	for (int i = 0; i < n; i++) {
		int num;
		string s;
		cin >> s >> num;
		vp[i]=make_pair(s, num);
	}

	string x;
	cin >> x;

	ll ans = 0;
	bool flg = false;

	for (auto a : vp) {
		if (flg) {
			ans += a.second;
		}else if (a.first == x) {
			flg = true;
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
const int M=998244353;
const int inv2=(M+1)/2;
const int inv3=(M+1)/3;
const int maxn=3e5+3;
vector <int> h[maxn];
int dis[maxn],n,pre[maxn],p,q,d[maxn],m;
ll dp[maxn][4];
void dfs(int u,int fa){
    pre[u]=fa; dis[u]=dis[fa]+1;
    for (auto v:h[u]){
        if (v==fa) continue;
        dfs(v,u);
    }
}
void dfs2(int u,int fa){
    d[u]=d[fa]+1;
    if (d[u]==m){
        dp[u][0]=2; // none
        dp[u][1]=1; // exactly one
        dp[u][2]=3; // all
        dp[u][3]=1; // at least one
        return;
    }
    ll r1=1,r2=0,r3=1,r4=0;
    for (auto v:h[u]){
        if (v==fa) continue;
        dfs2(v,u);
        ll nr1=r1*dp[v][0]%M;
        ll nr2=(r1*dp[v][1]+r2*dp[v][0])%M;
        ll nr3=r3*dp[v][2]%M;
        ll nr4=((r3*dp[v][3]+r4*dp[v][2]-r4*dp[v][3])%M+M)%M;
        r1=nr1; r2=nr2; r3=nr3; r4=nr4;
    }
    dp[u][0]=(r1*3+r4*2)%M;
    dp[u][1]=r2;
    dp[u][2]=r3*3%M;
    dp[u][3]=r4;
    
}
int main(){
    scanf("%d",&n); dis[0]=-1;
    for (int i=1;i<n;i++){
        int u,v; scanf("%d%d",&u,&v);
        h[u].pb(v); h[v].pb(u);
    }
    //puts("B");
    dfs(1,0);
    int s=1;
    for (int i=2;i<=n;i++) if (dis[i]>dis[s]) s=i;
    dfs(s,0);
    int t=s;
    for (int i=1;i<=n;i++) if (dis[i]>dis[t]) t=i;
    m=dis[t]/2; p=t;
    for (int i=0;i<m;i++) p=pre[p];
    if (dis[t]&1){
        q=pre[p];
        d[q]=-1; dfs2(p,q);
        d[p]=-1; dfs2(q,p);
        printf("%lld\n",dp[p][1]*dp[q][1]%M);
    } else {
        ll ans0=1,ans1=0,ans2=0;
        for (auto u:h[p]){
            d[u]=0; dfs2(u,p);
            ll nans0,nans1,nans2,has,none;
            has=dp[u][1]; none=(dp[u][2]+2*(M-dp[u][3]))%M;
            //cout<<has<<' '<<none<<endl;
            //cout<<dp[u][2]<<' '<<dp[u][3]<<endl;
            nans0=ans0*none%M;
            nans1=(ans0*has+ans1*none)%M;
            nans2=(ans1*has+ans2*none)%M;
            ans0=nans0; ans1=nans1; ans2=nans2;
        }
        printf("%lld\n",ans2);
    }
    return 0;
}


Measured memory_bytes: 31232
def f():
 from heapq import heappop, heappush
 N=int(input())
 r=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  r[a-1]+=3*(c>d)+(c==d)
  r[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[r[i]]+=[i]
 pq = []
 for i, s in enumerate(r):heappush(pq,[-s,i])
 rank=1
 display_rank=1
 prev_score=float('inf')
 while pq:
  s,i=heappop(pq)
  if s!=prev_score:rank=display_rank
  r[i]=rank
  display_rank+=1
  prev_score=s
 print(*r,sep='\n')
f()




########################################################################################################################
##################################################v
################################################################################
##########v####################v##############################v##########v


Measured memory_bytes: 5724
import sys
readline = sys.stdin.readline
li = []
for i, s in enumerate(readline().strip()):
    if s == "\\":
        li.append([i, 0])
    elif s == "/":
        if li:
            if li[-1][1] == 0:
                li[-1][1] = i - li[-1][0]
            else:
                for j in range(len(li) - 1, -1, -1):
                    if li[j][1] == 0:
                        li = li[:j] + [[li[j][0], sum(tuple(zip(*li[j + 1:]))[1]) + i - li[j][0]]]
                        break
ans = []
for a in li:
    if a[1] != 0:
        ans.append(a[1])
print(sum(ans))
print(len(ans), *ans)



Measured memory_bytes: 7896
#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define ft first
#define st second
#define mp make_pair
#define pb push_back
#define sz(n) int(n.size())
#define all(n) n.begin(), n.end()


using namespace std;

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

const int N = 1e5 + 123;
const int inf = 1e9 + 7;
const ll INF = 1e18 + 7;

ll n, a[200010], p[200010], pos[200010], sz[200010], ans;

int get(int x)
{
	if (x == p[x]) return x;
	return p[x] = get(p[x]);
}

void unite(int a, int b)
{
	a = get(a);
	b = get(b);
	if (a == b) return;
	if (rand() & 1) swap(a, b);
	p[a] = b;
	sz[b] += sz[a];
}

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

	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i], pos[a[i]] = i, p[i] = i, sz[i] = 1;

	for (ll i = n; i > 0; i --)
	{
		ll l = 0, r = 0, sl = 0, sr = 0;
		if (pos[i] != 1)
		{
			if (i < a[pos[i] - 1]) l = get(pos[i] - 1);
		}
		if (pos[i] != n)
		{
			if (i < a[pos[i] + 1]) r = get(pos[i] + 1);
		}

		ll cur = 1;
		sl = sz[l];
		sr = sz[r];
		if (sl > 0) cur *= (sl + 1), unite(l, pos[i]);
		if (sr > 0) cur *= (sr + 1), unite(r, pos[i]);
		ans += cur * i;
		//cout << i << " " << l << " " << r << " " << sl << " " << sr << " " << cur << " " << ans << "\n";
	}                

	cout << ans;           
}



Measured memory_bytes: 6528