akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
    int n, x;
    cin >> n >> x;
    ll i = 0;
    vector<ll>v;
    while (n != 0 || x != 0) {
        ll count = 0;
        for (int i = 1; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int z = j + 1; z <= n; z++) {
                    if (x == i + j + z) {
                        count++;
                    }
                }
            }
        }
        i++;
        v.push_back(count);
        cin >> n >> x;
    }
    for (int j = 0; j < i; j++) {
        cout << v[j] << endl;
    }
    return 0;
}



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

int main(){
    string s,t;
    cin >> s >>t;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    string n;
    cin>>n;
    if(n[1]==n[2]&&(n[1]==n[0]||n[1]==n[3]))cout<<"Yes";
    else cout<<"No";
    
	return 0;
}


Measured memory_bytes: 3556
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var a = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
		sc.close();

		var result = 0L;
		var max = 0;
		for (var i = 0; i < n; i++) {
			max = Math.max(max, a[i]);
			result += max - a[i];
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 60284
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int jump(int a[], int n)
{
    int cost[n];
    int i;

    cost[0]=0;
    cost[1]=abs(a[1]-a[0]);

    for(i=2; i<n; i++)
    {
        cost[i]=min(abs(a[i]-a[i-2])+cost[i-2],abs(a[i]-a[i-1])+cost[i-1]);
    }

    return cost[n-1];
}
int main()
{
    int n;
    cin>>n;

    int a[n];

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

    cout<<jump(a,n)<<endl;
}


Measured memory_bytes: 4384
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 6
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	for i := 1; i < n; i++ {
		ans := make([]string, 0)
		for j := i; j < n; j++ {
			a := 1
			for k := j - i + 1; k%2 == 0; k >>= 1 {
				a++
			}
			ans = append(ans, fmt.Sprintf("%d", a))
		}
		fmt.Fprintln(writer, strings.Join(ans, " "))
	}
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int sum(int n)
{
  if(n == 0)
  {
    return 0;
  }
  int s = sum(n-1);
  return s + n;
}
int main()
{
  cout << fixed << setprecision(10);
  int N,X;
  cin >> N >> X;
  vector<int> L(N),vec(N+1);
  rep(i,N)
  {
    cin >> L[i];
  }
  int su = 0;
  rep(i,N)
  {
    su += L[i];
    vec[i+1] = su;
  }
  int count = 0;
  rep(i,N+1)
  {
    if(vec[i]<=X)
    {
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
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 const INF = 1001001001;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0) return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1) t = t * a;
return t;
}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

// 愚直計算による二項係数計算
mint com(long long n, long long r) {
mint res = 1;
for (long long i = 0; i < r; ++i) {
res *= (n-i);
res /= (i+1);
}
return res;
}

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

ll N,K; cin >> N >> K;

mint ans = 0;
for(ll i = K; i <= N+1; ++i) {
    ll l = ((i-1)*i)/2;
    ll r = ((2*N - i + 1)*i)/2;
    ans += r - l + 1;
}
cout << ans << endl;
return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct kk {
  ll co;
  ll i;
};

ll n, q, k;
vector<vector<kk> > t(100001);
ll l[100001] = {};

int s(ll p, ll c) {
  rep(i, 0, t[p].size()) {
    ll y = t[p][i].i;
    if(l[y]) continue;
    ll cc = c + t[p][i].co;
    l[y] = cc;
    s(y, cc);
  }
}

int main() {
 cin >> n;
 rep(i, 0, n - 1) {
   int a, b, c;
   cin >> a >> b >> c;
   kk g;
   g.co = c;
   g.i = b;
   t[a].pb(g);
   g.i = a;
   t[b].pb(g);
 }

 cin >> q >> k;
 l[k] = -1;
 s(k, 0);

 rep(i, 0, q) {
   ll x, y;
   cin >> x >> y;
   cout << l[x] + l[y] << endl;
 }

}


Measured memory_bytes: 14208
n,x=map(int,input().split())
a=list(map(int,input().split()))+[x]
a.sort()
b=[]
for i in range(n):b.append(abs(a[i+1]-a[i]))
ans=b[0]
def gcd(a,b):
  while b:a,b=b,a%b
  return a
for i in range(1,n):
  ans=gcd(ans,b[i])
print(ans)

Measured memory_bytes: 14224
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define double long double
#define pb push_back
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define diff(a,b) (a>b?a-b:b-a)
const int N=1e6+5;
void pairsort(int a[], int b[], int n){
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++) 
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }
    sort(pairt, pairt + n);
    for (int i = 0; i < n; i++) 
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
int isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r>n-r) 
        r=n-r;
    long long ans=1;
    for(int i=1;i<=r;i++){
        ans*=n-r+i;
        ans/=i;
    }
    return ans;
}
int mod = 1e9+7;
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int n,k=0;
string s;
int32_t main()
{
    IOS;
    cin>>s,n=s.length(),s="#"+s;
    for(int i=1;i<=(n-1)/2;i++)
        if(s[i]!=s[(n-1)/2-i+1])
            k=1;
    for(int i=(n+3)/2;i<=n;i++)
        if(s[i]!=s[n+(n+3)/2-i])
            k=1;
    for(int i=1;i<=n;i++)
        if(s[i]!=s[n+1-i])
            k=1;
    if(k)
        cout<<"No";
    else
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    int card[4][13];

    for(int i=0;i<4;i++){
        for(int j=0;j<13;j++){
            card[i][j]=0;
        }
    }

    char suit;
    int num;

    for(int i=0;i<n;i++){
        cin >> suit >> num;
        if(suit=='S'){
            card[0][num-1] = 1;
        }else if(suit=='H'){
            card[1][num-1] = 1;
        }else if(suit=='C'){
            card[2][num-1] = 1;
        }else{
            card[3][num-1] = 1;
        }
    }

   for(int i=0;i<4;i++){
       for(int j=0;j<13;j++){
           if(card[i][j]==0){
                if(i==0){
                    cout << 'S' << " " << j+1 << endl;
                }else if(i==1){
                    cout << 'H' << " " << j+1 << endl;
                }else if(i==2){
                    cout << 'C' << " " << j+1 << endl;
                }else{
                    cout << 'D' << " " << j+1 << endl;
                }
           }
       }


   }

    return 0;

}


Measured memory_bytes: 3088
s = list(map(int, list(input())))
n = len(s)

even = [(i+1)%2 for i in range(n)]
#print(odd)
#print(even)

neven = 0
nodd = 0
for i in range(n):
    if s[i] == even[i]:
        neven += 1
    else:
        nodd += 1
        
if neven >= nodd:
    ans = n - neven
else:
    ans = n - nodd
    
print(ans)

Measured memory_bytes: 4652
dice = list(map(int,input().split()))


kaisuu = int(input())

lastlist = []
frlist = []
for i in range(kaisuu):
  up,front = list(map(int,input().split()))
  if up == dice[0] :
    frlist = [1,2,4,3,1]
  if up == dice[1]:
    frlist = [0,3,5,2,0]
  if up == dice[2]:
    frlist = [0,1,5,4,0]
  if up == dice[3]:
    frlist = [0,4,5,1,0]
  if up == dice[4]:
    frlist = [0,2,5,3,0]
  if up == dice[5] :
    frlist = [1,3,4,2,1]
 
  k = dice.index(int(front))
  for n in frlist[0:4] :
    if n == k :
      l = frlist.index(int(n))
      m = l + 1
  lastlist.append(dice[frlist[m]])
for g in lastlist :
  print(g)
      


Measured memory_bytes: 5608
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
//#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

const double PI = 3.1415926535897;

int main()
{
	double r;
	scanf("%lf", &r);
	double c = 2 * r * PI;
	
	printf("%.9lf\n", c);
	
	return 0;
}

Measured memory_bytes: 1752
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var dp=new long[s[0]+2][][];
		var h=new int[s[0]+2][];
		for(int i = 0;i<=s[0]+1;i++) {
			dp[i]=new long[s[1]+2][];
			for(int j = 0;j<=s[1]+1;j++) {
				dp[i][j]=new long[5];
			}
			h[i]=new int[s[1]+1];
		}
		for(int i = 0;i<s[2];i++) {
			var e=sc.Ia;
			h[e[0]][e[1]]=e[2];
		}
		for(int i = 1;i<=s[0];i++) {
			for(int j = 1;j<=s[1];j++) {
				for(int l = 0;l<=3;l++) {
					dp[i][j+1][l]=Max(dp[i][j+1][l],dp[i][j][l]);
					if(l==3){
						dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][l]);
						continue;
					}
					dp[i][j+1][l+1]=Max(dp[i][j+1][l+1],dp[i][j][l]+h[i][j]);
					dp[i+1][j][0]=Max(dp[i+1][j][0],dp[i][j][l]+h[i][j]);
				}
			}
		}
		long ans=dp[s[0]][s[1]][3];
		for(int i = 0;i<=3;i++) {
			ans=Max(ans,dp[s[0]][s[1]][i]+(i==3?0:h[s[0]][s[1]]));
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 729600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  map<ll,ll> mp;
  vector<ll> list;
  rep(i,N)
  {
    ll a; cin>>a;
    if(mp.count(a))
    {
      mp.at(a)++;
      continue;
    }
    mp[a]=1;
    list.push_back(a);
  }
  if(mp.size()==1&&mp.count(0)) {cout<<"Yes"<<endl; return 0;}
  if(mp.size()==2&&mp.count(0)&&N==mp.at(0)*3) {cout<<"Yes"<<endl; return 0;}
  if(mp.size()==3)
  {
    ll a=mp.at(list.at(0));
    ll b=mp.at(list.at(1));
    ll c=mp.at(list.at(2));
    if(a==b&&b==c&&(list.at(0)^list.at(1))==list.at(2))
    {
      cout<<"Yes"<<endl; return 0;
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 8548
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    int ans = 0;
    bool ok = false;
    rep(i,n) {
        if (ok) ans += t[i];
        if (s[i]==x) ok = true;
    }
    cout << ans << endl;
    return 0;


}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
n = int(input())
visited = [0]*n
def dfs(edge, dist, k):
    visited[k]=1
    for i in edge[k]:
        if visited[i[0]]==0:
            dist[i[0]]=i[1]+dist[k]
            dfs(edge, dist, i[0])


    return dist
def main():
    edge = [[] for _ in range(n)]
    for i in range(n-1):
        a,b,c=map(int, input().split())
        edge[a-1].append([b-1,c])
        edge[b-1].append([a-1,c])

    q,k=map(int, input().split())
    #頂点kから各頂点への距離を最初に求めておくdist[i]:頂点kから頂点iまでの距離　 dist[k]=0
    dist = [0]*n
    visited[k-1]=1
    dist = dfs(edge, dist, k-1)

    res = [0]*q
    for i in range(q):
        x,y=map(int, input().split())
        res[i]=dist[x-1]+dist[y-1]


    for i in range(q):
        print(res[i])
if __name__ == '__main__':
    main()


Measured memory_bytes: 139728
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  int64_t ans=0;
  for(int i=0;i<k;i++) ans+=a[i];
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3632
stoi :: String -> Int 
stoi x = read x :: Int


dfs :: Int -> Int -> String -> Int
dfs sum buff rest
    | length rest == 0 = sum + buff
    | otherwise = use + unuse
    where
        head' = stoi [head rest]
        rest' = (tail rest)
        use = dfs (sum + buff) 0 rest'
        unuse = dfs sum (buff * 10 + head') rest'

main :: IO ()
main = do
    x <- getLine
    print $ dfs 0 0 x

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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n;

int main(){
	scanf("%d", &n);
	int digit_sum = 0;
	while(n > 0){
		digit_sum += n % 10;
		n /= 10;
	}
	if(digit_sum == 1){
		digit_sum = 10;
	}
	printf("%d\n", digit_sum);
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

order = [int(input()) for _ in range(5)]
ans = 0
last = INF
for i in range(5):
    ans += ((order[i]-1)//10+1) * 10
    last = min(last,(order[i]-1)%10+1)

print(ans-10+last)


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    string S;
    cin >> S;
    if(S == "zyxwvutsrqponmlkjihgfedcba") {
        cout << -1 << endl;
        return 0;
    }
    if(S.size() < 26) {
        vector<int>cnt(26);
        for(int i = 0; i < S.size(); i++) {
            cnt[S[i]-'a']++;
        }
        cout << S;
        for(int i = 0; i < 26; i++) {
            if(cnt[i] == 0) {
                cout << (char)('a'+i);
                break;
            }
        }
        cout << endl;
        return 0;
    }
    char mx = S.back();
    for(int i = S.size()-1; i >= 0; i--) {
        if(S[i] >= mx) {
            mx = max(mx,S[i]);
            continue;
        }
        else {
            for(int j = 0; j < i; j++) {
                cout << S[j];
            }
            char mi = mx;
            for(int j = i+1; j < S.size(); j++) {
                if(S[i] < S[j]) {
                    mi = min(mi,S[j]);
                }
            }
            cout << mi << endl;
            break;
        }
    }
}


Measured memory_bytes: 3656
def readinput():
    n=int(input())
    p=list(map(int,input().split()))
    return n,p

def main(n,p):
    count=0
    pmin=p[0]
    for i in range(n):
        pmin=min(p[i],pmin)
        if pmin>=p[i]:
            count+=1
    return count

if __name__=='__main__':
    n,p=readinput()
    ans=main(n,p)
    print(ans)


Measured memory_bytes: 32104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 998244353;

template<int MOD> struct Fp {
	long long val;
	Fp(long long v = 0) noexcept : val(v % MOD) {
		if (val < 0) v += MOD;
	}
	int getmod() { return MOD; }
	Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
		return is >> x.val;
	}
	friend Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

using mint = Fp<MOD>;

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

	ll sum = 0, keta = 0;
	for (int i = 0; i < m; ++i) {
		ll c, d; cin >> c >> d;
		sum += c * d;
		keta += d;
	}
	ll ans = keta - 1 + (sum-1) / 9L;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

a,b=getis
puts a > 0 ? 'Positive' : b >= 0 ? 'Zero' : (b - a) % 2 == 1 ? 'Positive' : 'Negative'


Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        int n=s.length();
        boolean res=check(s,0,n-1)&&check(s,0,(n-1)/2-1)&&check(s,(n+3)/2-1,n-1);
        if(res)System.out.println("Yes");
        else System.out.println("No");
    }
    public static boolean check(String s,int start, int end)
    {
        int i=start,j=end;
        while(i<j)
        {
            if(s.charAt(i)!=s.charAt(j))return false;
            i++;
            j--;
        }
        return true;
    }
}

Measured memory_bytes: 23124
void main() {
	writefln("%(%d %)", readAs!(int[]).sort.array);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }
    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e) {
        long long a = 1, p = x;
        while (e > 0) {
            if (e % 2 == 0) { p = (p * p) % mod; e /= 2; }
            else { a = (a * p) % mod; e--; }
        }
        return ModInt(a);
    }

    friend ostream& operator<<(ostream& os, const ModInt<mod>& p) {
        return os << p.x;
    }
    friend istream& operator>>(istream& is, ModInt<mod>& a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
using modint = ModInt<mod>;

int main() {
    init();

    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    FOR(i, 0, h)cin >> a[i];

    vector<vector<modint>> dp(h, vector<modint>(w, 0));
    dp[0][0] = 1;
    FOR(i, 0, h)FOR(j, 0, w) {
        if (a[i][j] == '#')continue;
        if (i)dp[i][j] += dp[i - 1][j];
        if (j)dp[i][j] += dp[i][j - 1];
    }
    cout << dp[h - 1][w - 1] << "\n";
}


Measured memory_bytes: 5248
from collections import deque

N=int(input())
g=[[] for _ in range(N)]
visit=[0]*N
dist=[0]*N

for _ in range(N-1):
    a,b,c=list(map(int,input().split()))
    a-=1
    b-=1

    g[a].append([b,c])
    g[b].append([a,c])


Q,K=list(map(int,input().split()))
K-=1

q=deque([K])
visit[K]=1

while len(q)>0:
    p=q.popleft()
    
    for c,d in g[p]:
        if visit[c]==0:
            dist[c]=d+dist[p]
            visit[c]=1
            q.append(c)
    
for _ in range(Q):
    x,y=list(map(int,input().split()))
    x-=1
    y-=1
    print(dist[x]+dist[y])

Measured memory_bytes: 111064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>k(m);
    vector<int>s[m];
    vector<int>p(m);
    vector<int>power(n);
    bool AllLightUp;
    int answer=0;
    REP(i,m){
        cin >> k[i];
        REP(j,k[i]){
            int tmp;
            cin >> tmp;
            s[i].push_back(tmp);
        }
    }
    REP(i,m){
        cin >> p[i];
    }
    for (int bit = 0; bit < (1<<n); ++bit) {
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                power[i] = 1;
            }
            else{
                power[i] = 0;
            }
        }
        AllLightUp = true;
        REP(i,m){
            int tmp=0;
            REP(j,k[i]){
                tmp += power[s[i][j]-1];
            }
            if(tmp%2!=p[i]){
                AllLightUp = false;
            }
        }
        if(AllLightUp){
            answer++;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6;
ll q[N];
ll n;
ll qian,sum = 0;

int main(int argc, char** argv) {
	cin>>n;
	scanf("%lld",&q[0]);
	qian = q[0];
	for(int i=1;i<n;i++) {
		scanf("%lld",&q[i]);
		sum += q[i];
	}
	ll ans = abs(qian-sum);
	for(int i=1;i<n-1;i++) {
		qian += q[i];
		sum -= q[i];
		ans = min(ans, abs(qian - sum));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  
  int N,K; cin>>N; cin>>K;
  vector<pair<int,int> > vp;
  vp.emplace_back(-1,0);
  for (int i = 0; i < N; i++)
  {
    char X;cin>>X;

    int x = X - '0';
    if(vp.empty() || vp.back().first != x)
    {
      vp.push_back(make_pair(x,1));
    }
    else
    {
      vp.back().second++;
    }
  }

  for (int i = 0; i < vp.size(); i++)
  {
    vp[i+1].second += vp[i].second;
  }
  //   for (int i = 0; i < vp.size(); i++)
  // {
  //   cout<<vp[i].first<<" "<<vp[i].second<<endl;
  // }
  int ANS = 0;
  for (int i = 1; i <= (int)vp.size()-1; i++)
  {
    int l = i;
    int r;
    if(vp[i].first == 1)
    {
      r = l + 2*K;
    }
    else
    {
      r = l + 2*(K) - 1;
    }
    l--;
    if(r >= vp.size())r = (int)vp.size()-1;
    if(l >= vp.size())l = (int)vp.size()-1;
    
    chmax(ANS,vp[r].second - vp[l].second);
  }
  cout<<ANS<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int i,j;
    int n = 26;
    string s;
    vector<int> x(26);
    while(getline(cin,s)){
        REP(i,s.size()) {
            if(s[i]>='a'&&s[i]<='z') x[s[i]-'a']++;
            else if(s[i]>='A'&&s[i]<='Z') x[s[i]-'A']++;
        }
    }
    REP(i,n) cout<<(char)(i+'a')<<" : "<<x[i]<<endl;
}



Measured memory_bytes: 3100
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(a) inp(b) inp(c)
	if(c-a-b<0)
	{
		cout<<"No\n";
		return 0;
	}
	if(4*a*b<c*c+a*a-2*a*c+2*a*b-2*b*c+b*b)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	printclock;
}


Measured memory_bytes: 256
#import numpy as np
#import math
#from fractions import gcd

def main():

    ##get int
    first_input = list(map(lambda x:int(x), input().split(" ")))
    #second_input = list(map(lambda x:int(x), input().split(" ")))

    ##get float
    #first_input = list(map(lambda x:float(x), input().split(" ")))
    #second_input = list(map(lambda x:float(x), input().split(" ")))

    ##get string
    #first_input = input().split(" ")

    X = first_input[0]
    N = first_input[1]
    if N!=0:
        p_list = list(map(lambda x:int(x), input().split(" ")))
    else:
        print(X)
        return

    if X not in p_list:
        print(X)
        return

    x = X
    for i in range(1,52):
        if x-i not in p_list:
            print(x-i)
            return
        if x+i not in p_list:
            print(x+i)
            return



if __name__ == '__main__':
    main()


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

long long n;
string s="";
long long r;

int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	while(n--)
	{
		r=n%26;
		n/=26;
		s+=char('a'+r);
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3652
from collections import deque

def main():
    H, W = map(int, input().split())
    field = "#"*(W+2)
    field += "#" + "##".join([input() for _ in range(H)]) + "#"
    field += "#"*(W+2)

    INF = 10**9
    cost = [INF]*len(field)
    move = [-1, 1, -(W+2), W+2]
    def bfs(s, g):
        q = deque()
        dequeue = q.popleft
        enqueue = q.append
        cost[s] = 0
        enqueue(s)

        while q:
            now = dequeue()
            now_cost = cost[now]
            for dx in move:
                nv = now + dx
                if nv == g:
                    cost[g] = now_cost + 1
                    return
                if field[nv] == "#" or cost[nv] < INF:
                    continue
                else:
                    cost[nv] = now_cost + 1
                    q.append(nv)
    
    ans = 0
    for si in range(H):
        for sj in range(W):
            for gi in range(H):
                for gj in range(W):
                    start = (si+1)*(W+2)+sj+1
                    goal = (gi+1)*(W+2)+gj+1
                    if field[start] == "#" or  field[goal] == "#" or start == goal:
                        continue
                    cost = [INF] * len(field)
                    bfs(start, goal)
                    ans = max(ans, cost[goal])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 76912
n,k=map(int,input().split())
k_list=[]

for i in range(k):
    l,r=map(int,input().split())
    k_list.append([l,r])

dp=[0]*(n+1)
dp[1]=1
dpsum=[0]*(n+1)
dpsum[1]=1

for i in range(1,n):
    dpsum[i]=dp[i]+dpsum[i-1]
    for j in range(k):
        l,r=k_list[j]
        li=i+l
        ri=i+r+1
        if li<=n:
            dp[li]+=dpsum[i]
            dp[li]=dp[li]%998244353
        if ri<=n:
            dp[ri]-=dpsum[i]
            dp[ri]=dp[ri]%998244353

print(dp[n])


Measured memory_bytes: 76876
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAXN = 2e5 + 7;
int a[MAXN], b[MAXN], ans[MAXN];
int L[MAXN], R[MAXN];
int main() {
    int n; scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    for (int l = 1, r; l <= n; l = r + 1) {
        r = l; while (a[r + 1] == a[l] && r < n) r++;
        L[a[l]] = l; R[a[l]] = r;
    }
    int MAX = 0;
    for (int l = 1, r; l <= n; l = r + 1) {
        r = l; while (b[r + 1] == b[l] && r < n) r++;
        if (L[b[l]]) {
            MAX = max(MAX, R[b[l]] - l + 1);
        }
    }
    bool fail = 0;
    for (int i = 1; i <= n; i++) {
        ans[(i + MAX - 1) % n + 1] = b[i];
    }
    for (int i = 1; i <= n; i++)
        if (ans[i] == a[i]) fail = 1;
    if (fail) puts("No");
    else {
        puts("Yes");
        for (int i = 1; i <= n; i++) printf("%d%c", ans[i], " \n"[i == n]);
    }
    return 0;
}

Measured memory_bytes: 7660
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
def dfs(v,p):
    size[v]=len(G[v])
    dp[v]=[0]*size[v]
    res=1
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            p_i[v]=i
            continue
        R=dfs(nv,v)
        dp[v][i]=R
        res=res*(R+1)%MOD
    return res
    
def reroot(v,res_p,p):
    if p!=-1:
        dp[v][p_i[v]]=res_p
    for i in range(size[v]):
        ans[v]=ans[v]*(dp[v][i]+1)%MOD
    dp_L=[1]*(size[v]+1)
    dp_R=[1]*(size[v]+1)
    for i in range(size[v]):
        dp_L[i+1]=dp_L[i]*(dp[v][i]+1)%MOD
    for i in reversed(range(size[v])):
        dp_R[i]=dp_R[i+1]*(dp[v][i]+1)%MOD
        
    for i in range(size[v]):
        nv=G[v][i]
        if nv==p:
            continue
        reroot(nv,dp_L[i]*dp_R[i+1]%MOD,v)

N,MOD=map(int,input().split())
G=[[] for i in range(N)]
for i in range(N-1):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)
    G[y].append(x)
dp=[[] for i in range(N)]
size=[-1]*N
p_i=[-1]*N
dp_L=[[] for i in range(N)]
dp_R=[[] for i in range(N)]
ans=[1]*N

z_root=dfs(0,-1)
reroot(0,0,-1)
print(*ans,sep='\n')

Measured memory_bytes: 147508
#include<stdio.h>
#include<stdlib.h>
int c=0;

int* Selection(int *A, int N){
  int i, j, minj, num;
  for(i=0 ; i<N ; i++){
    minj=i;
    for(j=i ; j<N ; j++){
      if(A[j]<A[minj]){
        minj=j;
      }
    }
    num=A[i];
    A[i]=A[minj];
    A[minj]=num;
    if(A[i]!=A[minj])c++;
  }
  return A;
}

int main(void){
  int N,i;
  int *A;
  scanf("%d",&N);
  A = (int*)malloc(sizeof(int)*N);
  for(i=0 ; i<N ; i++){
    scanf("%d",&A[i]);
  }
  A=Selection(A,N);
  printf("%d",A[0]);
  for(i=1 ; i<N ; i++){
    printf(" %d",A[i]);
  }
  printf("\n%d\n",c);
  return 0;
}


Measured memory_bytes: 2136
x1,y1,x2,y2=list(map(int,input().split()))

v1=(y1-y2,x2-x1)
v2=(-x2+x1,y1-y2)


x3=x2+v1[0]
y3=y2+v1[1]

x4=x3+v2[0]
y4=y3+v2[1]

print(x3,y3,x4,y4)

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll X, A, B;
    cin >> X >> A >> B;
    ll d = B - A;
    if (d <= 0) {
        cout << "delicious" << endl;
    }
    else if (d <= X) {
        cout << "safe" << endl;
    }
    else {
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005];
char str[1000005];
int main() {
	scanf("%d %s", &n, str);
	for (int i = 0; i < n; i++) a[i] = str[i] - '1';
	int flag1 = 0;
	for (int i = 0; i < n; i++) if (a[i] == 2) a[i] = 0; else if (a[i] == 1) flag1 = 1;
	int ans = 0;
	for (int i = 0; i < n; i++) if (((n - 1) & i) == i) ans ^= a[i];
	if (!ans && !flag1) {
		for (int i = 0; i < n; i++) a[i] = (str[i] - '1') / 2;
		for (int i = 0; i < n; i++) if (((n - 1) & i) == i) ans ^= a[i];
		ans *= 2;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 5120
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};

struct node {
    int x, y, step;
    node(const int &x = 0 , int const &y = 0, int const &step = 0) :
        x(x), y(y), step(step) { }
    bool operator<(const node &obj) const {
        return step > obj.step;
    }
};
int vis[maxn][maxn];
int vis2[maxn][maxn];
char mp[maxn][maxn];
int n, m;
int sx, sy, ex, ey;
vector<int> e;
int check(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m;
}

int bfs(int x, int y) {
    deque<node> q;
    q.emplace_back(node(x, y));
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        x = p.x, y = p.y;
        if (vis[p.x][p.y]) continue;
        vis[p.x][p.y] = 1;
        if (ex == p.x && ey == p.y) return  p.step;
        for (int i = 0; i < 4; i++) {
            int tx = p.x + dir[i][0];
            int ty = p.y + dir[i][1];
            if (check(tx, ty) && mp[tx][ty] == '.') {
                q.emplace_front(tx, ty, p.step);
            }
        }

        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                if (i == j && i == 0) continue;
                int tx = x + i, ty = y + j;
                if (check(tx, ty) && mp[tx][ty] == '.') {
                    q.emplace_back(tx, ty, p.step + 1);
                }
            }
        }
    }
    return -1;
}


int main(void) {
    FAST_IO;
    
    cin >> n >> m;
    cin >> sx >> sy;
    cin >> ex >> ey;
    for (int i = 1; i <= n; i++) {
        cin >> mp[i] + 1;
    }
    cout <<bfs(sx, sy) << endl;
    
    return 0;
}

Measured memory_bytes: 10080
#include<iostream>

using namespace std;

typedef long long ll;

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

ll N,S,a[100000];

int main() {
    cin >> N >> S;
    rep(i,N)cin >> a[i];

    ll ans = N + 1;

    ll l = 0,r = 0,sum = 0;//[l,s)

    for(;;) {
        while(r < N && sum < S) {
            sum += a[r++];//条件を満たすまで区間を広げる
        }

        if(sum < S)break;//ｒが後ろまで到達してかつ条件を満たしていない

        ans = min(ans,r - l);
        sum -= a[l++];//lを一つ進める
    }

    if(ans > N) {
        ans = 0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3888
#include <cstdio>
#include <vector>
#include <algorithm>

const int M=9;

int main()
{
  int n;
  scanf("%d",&n);
  std::vector<long long> V(n+1),W(n+1);
  for(int i=1;i<=n;i++){
    scanf("%lld%lld",&V[i],&W[i]);
  }
  std::vector<std::vector<std::pair<long long, long long> > > P(1<<M);
  P[0]=std::vector<std::pair<long long,long long> >(1,std::make_pair(0ll,0ll));
  for(int i=1;i<(1<<M)&&i<=n;i++){
    int p=i/2;
    for(int x=0;x<P[p].size();x++){
      P[i].push_back(P[p][x]);
      P[i].push_back(std::make_pair(P[p][x].first+W[i],P[p][x].second+V[i]));
    }
    std::sort(P[i].begin(),P[i].end());
    int s=0;
    for(int x=0;x<P[i].size();x++){
      if(x==0||P[i][s-1].second<P[i][x].second){
	P[i][s++]=P[i][x];
      }
    }
    P[i].resize(s);
    /*printf("%d %d\n",i,s);
    for(int x=0;x<P[i].size();x++){
      printf("%d %lld %lld\n",i,P[i][x].first,P[i][x].second);
      }*/
  }
  int q;
  scanf("%d",&q);
  for(int t=0;t<q;t++){
    int v;
    long long L;
    scanf("%d%lld",&v,&L);
    std::vector<std::pair<long long, long long> > S(1,std::make_pair(0ll,0ll));
    int u=v;
    for(;u>=(1<<M);u/=2){
      int s=S.size();
      for(int x=0;x<s;x++){
	S.push_back(std::make_pair(S[x].first+W[u],S[x].second+V[u]));
      }
    }
    long long ans=0ll;
    for(int x=0;x<S.size();x++){
      if(S[x].first<=L){
	auto it=std::lower_bound(P[u].begin(),P[u].end(),std::make_pair(L+1-S[x].first,0ll));
	ans=std::max(ans,(--it)->second+S[x].second);
      }
    }
    printf("%lld\n",ans);
  }
  return 0;
}


Measured memory_bytes: 9564
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int ans = 0;

  if (A + B > 2 * C) {
    int sub = min(X, Y);
    X -= sub;
    Y -= sub;
    ans += sub * 2 * C;

    if (X < Y) {
      if (B > 2 * C) {
        ans += Y * 2 * C;
      } else {
        ans += Y * B;
      }
    } else if (X > Y) {
      if (A > 2 * C) {
        ans += X * 2 * C;
      } else {
        ans += X * A;
      }
    }
    cout << ans << endl;
  } else {
    cout << A * X + B * Y << endl;
  }

  return 0;
}

Measured memory_bytes: 256