akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
//find_by_order(k) - k is the kth element of the set
//order_of_key(k) - Number of elements striclty samller than k
string findSum(string str1, string str2) 
{ 
    // Before proceeding further, make sure length 
    // of str2 is larger. 
    if (str1.length() > str2.length()) 
        swap(str1, str2); 
  
    // Take an empty string for storing result 
    string str = ""; 
  
    // Calculate length of both string 
    int n1 = str1.length(), n2 = str2.length(); 
  
    // Reverse both of strings 
    reverse(str1.begin(), str1.end()); 
    reverse(str2.begin(), str2.end()); 
  
    int carry = 0; 
    for (int i=0; i<n1; i++) 
    { 
        // Do school mathematics, compute sum of 
        // current digits and carry 
        int sum = ((str1[i]-'0')+(str2[i]-'0')+carry); 
        str.push_back(sum%10 + '0'); 
  
        // Calculate carry for next step 
        carry = sum/10; 
    } 
  
    // Add remaining digits of larger number 
    for (int i=n1; i<n2; i++) 
    { 
        int sum = ((str2[i]-'0')+carry); 
        str.push_back(sum%10 + '0'); 
        carry = sum/10; 
    } 
  
    // Add remaining carry 
    if (carry) 
        str.push_back(carry+'0'); 
  
    // reverse resultant string 
    reverse(str.begin(), str.end()); 
  
    return str; 
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x;
    cin>>n>>x;
    ll arr[n];
    vector<int> v;
    v.pb(0);
    for(int i=0;i<n;i++)
    {
    	cin>>arr[i];
    }
    int prev=0;
    int cnt=1;
    for(int i=0;i<n;i++)
    {
    	ll r=prev+arr[i];
    	if(r>x)
    		break;
    	cnt++;
    	prev=r;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
while True:
    [a, op, b] = [value for value in input().split()]
    if (op == '?'):
        break
    a = int(a)
    b = int(b)
    if (op == '+'):
        print(a + b)
    elif (op == '-'):
        print(a - b)
    elif (op == '*'):
        print(a * b)
    else:
        print(a // b)

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

int main() {
  int n, m;
  cin >> n >> m;
  
  vector<int> a(n);
  vector<int> b(2);
  for (int i = 0; i < m; i++) {
    cin >> b.at(0) >> b.at(1);
    a.at(b.at(0)-1)++;
    a.at(b.at(1)-1)++;
  }
  for (int i = 0; i < n; i++)
    cout << a.at(i) << endl;
}

Measured memory_bytes: 256
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long k = Long.parseLong(sc.next());
		Map<Integer, Long> m = new TreeMap<>();
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			long b = Integer.parseInt(sc.next());
			if (m.get(a) != null) {
				b += m.get(a);
			}
			m.put(a, b);
		}
		long c = 0;
		for (Integer i:m.keySet()) {
			c += m.get(i);
			if (c >= k) {
				System.out.println(i);
				return;
			}
		}
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 64292
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int X,Y,Z,K;
	static long[] A,B,C,cakes;
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		X=sc.nextInt();
		Y=sc.nextInt();
		Z=sc.nextInt();
		K=sc.nextInt();
		A=new long[X];
		B=new long[Y];
		C=new long[Z];
		for(int i=0; i<X; i++) {
			A[i]=sc.nextLong();
		}
		for(int i=0; i<Y; i++) {
			B[i]=sc.nextLong();
		}
		for(int i=0; i<Z; i++) {
			C[i]=sc.nextLong();
		}
		cakes=new long[X*Y];
		for(int i=0; i<X; i++) {
			for(int j=0; j<Y; j++) {
				cakes[i*Y+j]=A[i]+B[j];
			}
		}
		Arrays.sort(cakes);
		if(X*Y<K) {
			for(int i=1; i<=K; i++) {
				pl(bi(i-1));
			}
		}
		else {
			long[] KK=new long[K];
			for(int i=0; i<K; i++) {
				KK[i]=cakes[X*Y-1-i];
			}
			long[] sort2=new long[K*Z];
			for(int i=0; i<K; i++) {
				for(int j=0; j<Z; j++) {
					sort2[i*Z+j]=KK[i]+C[j];
				}
			}
			Arrays.sort(sort2);
			for(int i=0; i<K; i++) {
				pl(sort2[K*Z-1-i]);
			}
		}

	}
	public static long bi(int banme) {
		long max=1000000000002L;
		long min=0;
		int tmp=0;
		int counter=0;
		while(max-min>1) {
			counter=0;
			tmp=0;
			long mid=(max+min)/2;
			for(int i=0; i<Z; i++) {
				tmp=lowerBound(cakes,mid-C[i]+1);
				if(tmp==-1) {
					//pl("!");
					tmp=X*Y;
				}
				counter+=tmp;
				//pl(mid+" "+tmp);
			}
			if(counter>=X*Y*Z-banme) {	//でかすぎるとき
				max=mid;
			}
			else {
				min=mid;
			}
		}
		counter=0;
		for(int i=0; i<Z; i++) {
			tmp=lowerBound(cakes,min-C[i]+1);
			if(tmp==-1) {
				tmp=Z;
			}
			counter+=tmp;
		}
		//pl(banme+" "+max+" "+min);
		if(counter==X*Y*Z-banme) {
			return min;
		}
		else {
			return max;
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	public static final int lowerBound(final long[] arr, final long value) {
		int low = 0;
		int high = arr.length;
		int mid;
		while (low < high) {
			mid =(high+low)/2;
			if (arr[mid] < value) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		if(low<arr.length) {
			return low;
		}
		else {
			return -1;
		}
	}
}

Measured memory_bytes: 59208
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    if max(p[i-1], p[i], p[i+1]) != p[i] and min(p[i-1], p[i], p[i+1]) != p[i]:
        ans += 1
print(ans)

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

using namespace std;
#define INF 100001;

int main()
{
    int n,k; cin >> n >> k;
    int h[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> h[i];
    }

    int dp[n] = {};

    for (int i=n-2; i>=0; i--)
    {
        int res[k];
        for (int j = 1; j <= k; ++j)
        {
            if (i+j<n) res[j-1] = dp[i+j] + abs(h[i] - h[i+j]);
            else res[j-1] = INF;
        }

        dp[i] = *min_element(res, res+k);
    }

    cout << dp[0] <<endl;
}



Measured memory_bytes: 4408
using System;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        while(true)
        {
            int kosu=int.Parse(Console.ReadLine());
            if(kosu==0)break;
            string [] str=Console.ReadLine().Split(' ');
            int[] intArray=str.Select(int.Parse).ToArray();
            double ave=intArray.Average();
            double hensa=0;
            
            for(int i=0;i<intArray.Length;i++)
            {
                hensa+=Math.Pow(intArray[i]-ave,2);
            }
            double bunsan=hensa/intArray.Length;
            Console.WriteLine(Math.Sqrt(bunsan));
        }
    }
}



Measured memory_bytes: 18356
#include <bits/stdc++.h>
#define lli long long int
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define s(n) cin >> n
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) (((a) + (b))/2)
#define INF (1e9 + 7)
using namespace std;
lli x=1e9+7;
vector<vector<lli>>dp;
vector<vector<lli>>f;
vector<lli>visited;
void dfs(int v)
{
    visited[v]=1;
    rep(i,f[v].size())
    {
        if(!visited[f[v][i]])
        {
            dfs(f[v][i]);
            dp[v][1]*=(dp[f[v][i]][0]%x);
            dp[v][1]=dp[v][1]%x;
            dp[v][0]*=((dp[f[v][i]][1]+dp[f[v][i]][0])%x);
            dp[v][0]=dp[v][0]%x;
        }
    }
}
int main()
{
    lli n;
    s(n);
    dp=vector<vector<lli>>(n+1,vector<lli>(2,1));
    f=vector<vector<lli>>(n+1);
    visited=vector<lli>(n+1,0);
    rep(i,n-1)
    {
        lli a,b;
        s(a);s(b);
        f[a].push_back(b);
        f[b].push_back(a);
    }
    dfs(1);
    cout<<(dp[1][1]+dp[1][0])%x;
    
    return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for (int &a : A) {
        cin >> a;
    }
    // MAX := max(a), MIN := min(a)
    // |MAX| ≥ |MIN| -> すべての数に MAX を足せば ai > 0とできる
    // |MAX| < |MIN| -> すべての数に MIN を足せば ai <= 0とできる
    // あとは累積和
    int mx_ind = max_element(A.begin(), A.end()) - A.begin();
    int mi_ind = min_element(A.begin(), A.end()) - A.begin();
    int mx = A[mx_ind], mi = A[mi_ind];
    vector<pii> ans;
    if (abs(mx) >= abs(mi)) {
        // a[i] += mx
        for (int i = 0; i < n; i++) ans.push_back(pii(mx_ind, i));
        // a[i + 1] += a[i]
        for (int i = 0; i < n - 1; i++) ans.push_back(pii(i, i + 1));
    }
    else {
        // a[i] += mi
        for (int i = 0; i < n; i++) ans.push_back(pii(mi_ind, i));
        // a[i - 1] += a[i]
        for (int i = n - 1; i > 0; i--) ans.push_back(pii(i, i - 1));
    }

    cout << ans.size() << '\n';
    for (pii p : ans) {
        cout << p.first + 1 << ' ' << p.second + 1<< '\n';
    }

}


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

const ll MX = 1e18;

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

    ll ans = 1;
    bool ng = false;

    for(int i=0; i<n; i++) {
        ll a;
        cin >> a; 

        if (a == 0){
            cout << 0 << endl;
            return 0;
        }

        if (ng || a > MX/ans) {
            ng = true;
        }
        ans *= a;
    }
    if (ng) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import java.util.*;
import java.io.*;

public class Main {
	static int[] f = new int[101];
	static int n;
	private static void solve(){
		//Implement solution here.
		n = ni();
		int result = 0;
		f[1] = 1;
		for(int i = 2; i <= n; i++) {
			primeFactorization(i);						
		}

		for(int i = 2; i <= n; i++) {
			if(f[i] < 2)continue;
			if(f[i] >= 74)result++;
			for(int j = i + 1; j <= n;j++) {
				if(f[j] < 2)continue;			
				if(f[i] >= 24 && f[j] >= 2)result++;
				if(f[j] >= 24 && f[i] >= 2)result++;
				if(f[i] >= 14 && f[j] >= 4)result++;
				if(f[j] >= 14 && f[i] >= 4)result++;
				for(int k = j + 1; k <= n;k++) {
					if(f[k] < 2)continue;
					if(f[i] >= 2 && f[j] >= 4 && f[k] >= 4)result++;
					if(f[i] >= 4 && f[j] >= 2 && f[k] >= 4)result++;
					if(f[i] >= 4 && f[j] >= 4 && f[k] >= 2)result++;
				}
			}
		}
		System.out.println(result);
	}

	static int pattern(int cnt) {
		int result = 0;
		if(cnt <= 2) {

			for(int i = 2; i <= n; i++) {

			}
		}
		return result;
	}

	static void primeFactorization(int a){
		for(int i = 2; i <= Math.sqrt(a) + 1; i++) {
			if(a % i == 0) {
				while(a % i == 0) {
					f[i]++;
					a /= i;
				}		
			}				
		}
		if(a > 1) {
			f[a]++;
		}
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second

using namespace std;

int main() {
  int A, B,C;
  cin>>A>>B>>C;
  if(A<=C && C<=B) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


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

int main() {
  int n,a,b;cin>>n>>a>>b;
  vector<int> c(n);
  int p=0,q=0,r=0;
  for(int i=0;i<n;++i) {
    cin>>c[i];
    if(c[i]<=a) ++p;
    else if(c[i]<=b) ++q;
    else ++r;
  }

  int ans = min(p,min(q,r));

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*(b/gcd(a, b)); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
ll keta(ll num){ ll k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


int n, aa, bb, cc;
    int l[10];

ll rec(int pos, int a, int b, int c){
    if(pos == n){
        if(min(min(a, b), c) > 0){
            ll res = abs(aa-a)+abs(bb-b)+abs(cc-c);
            return res-30;
        }else return inf;
    }

    ll var1 = rec(pos+1, a, b, c);
    ll var2 = rec(pos+1, a+l[pos], b, c)+10;
    ll var3 = rec(pos+1, a, b+l[pos], c)+10;
    ll var4 = rec(pos+1, a, b, c+l[pos])+10;

    return min(min(var1, var2), min(var3, var4));
}

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

    cin >> n >> aa >> bb >> cc;
    rep(i, n){
        cin >> l[i];
    }

    cout << rec(0, 0, 0, 0) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++){cin>>arr[i];}
	int ans=INT_MAX;
	for(int i=0;i<=200;i++){
		int c=0;
		for(int j=0;j<n;j++){
			c+=((i-arr[j])*(i-arr[j]));
		}
		ans=min(ans,c);
	}
	cout<<ans;
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


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

using ll = long long;

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

    string S;
    ll K;
    cin >> S >> K;

    char ans = 'X';
    for (ll i = 0; i < S.size(); i++) {
        if ((S[i] == '1' && i == K-1) || (S[i] >= '2')) {
            ans = S[i];
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

ll N;
int d[3] = {3, 5, 7};

ll dfs(ll x) {
    if (x > N) return 0;

    ll ret=0LL;
    int c3=0, c5=0, c7=0;
    ll t=x;
    while (t > 0) {
        ll tmp = t % 10;
        if (tmp == 3LL) c3++;
        if (tmp == 5LL) c5++;
        if (tmp == 7LL) c7++;
        t /= 10;
    }

    if (c3 * c5 * c7 > 0) ret++;

    for (int i = 0; i < 3; i++) {
        ret += dfs(x*10+d[i]);
    }
    return ret;
}

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

    cin >> N;

    cout << dfs(0) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int t1 = H1 * 60 + M1, t2 = H2 * 60 + M2;
    write(t2 - t1 - K);
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
constexpr ll INF = 1LL<<60;

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

    ll ret = 0;
    for(ll i=1; i*i<=n; ++i) {
        if(n%i==0) {
            if(i!=1) {
                ll t=n, div = i;
                while(t%div==0) t /= div;
                t %= div;
                if(t==1) ret++;
            }
            if(i!=n/i && n/i!=1) {
                ll t=n, div = n/i;
                while(t%div==0) t /= div;
                t %= div;
                if(t==1) ret++;
            }
        }
    }
    for(ll i=1; i*i<=n-1; ++i) {
        if((n-1)%i==0) {
            if(i!=1 && n%i!=0) {
                ret++;
            }
            if(i!=(n-1)/i && n%((n-1)/i)!=0) {
                ret++;
            }
        }
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())


for i in range(n + 1):
    for j in range(n -i + 1):
        k = n - i - j
        val = 10000*i + 5000*j + 1000*k
        if val == y:
            print(i, j, k)
            exit()
        elif i == n:
            print(-1, -1, -1)

Measured memory_bytes: 40428
N,K=list(map(int,input().split()))
l=[0]*(K+1)
ans=0
mod=10**9+7

for x in range(K,0,-1):
    l[x]=pow((K//x),N,mod)
    for y in range(2*x,K+1,x):
        l[x]-=l[y]
        l[x]=pow(l[x],1,mod)
    ans+=l[x]*x
    ans=pow(ans,1,mod)
print(ans)

Measured memory_bytes: 11296
#include <iostream>
#include <string>
#include <vector>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;


int main() {
    int h, w;
    cin >> h >> w;

    vector<string> m(h);
    rep (i, h) cin >> m[i];

    rep (i, h+2) {
        if (i == 0 or i == h+1) {
            rep (j, w+2) cout << '#';
            cout << endl;
        }
        else {
            cout << '#';
            rep (j, w) cout << m[i-1][j];
            cout << '#' << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int dp[4001][4001];
int main(){
	string s1, s2;
	while(cin >> s1 >> s2){
	s1 = " " + s1;s2 = " " + s2;
	fill((int*)dp, (int*)(dp+4001), 0);
	int ans = 0;
	for(int i = 1;i < s1.size();i++){
		for(int j = 1;j < s2.size();j++){
			if(s1[i] == s2[j])dp[i][j] = dp[i-1][j-1]+1;
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int a[n - 1];
    rep(i, n - 1) cin >> a[i];

    int sv[n];
    rep(i, n) sv[i] = 0;

    rep(i, n - 1)
    {
        sv[a[i] - 1]++;
    }

    rep(i, n)
    {
        cout << sv[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 5200
package main

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

// カードゲーム
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	tac := 0
	hac := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		ary := strings.Split(sc.Text(), " ")
		// wc := len([]rune(w))
		ta := ary[0]
		ha := ary[1]
		if ta < ha {
			hac += 3
		} else if ha < ta {
			tac += 3
		} else {
			tac++
			hac++
		}
	}
	fmt.Printf("%v %v\n", tac, hac)
}



Measured memory_bytes: 1120
#include <bits/stdc++.h>
using namespace std;
char c[100];
bool palin(int start,int end)
{
    while(start<end)
    {
        if(c[start]!=c[end])
        {
            return false;
        }
        start++;
        end--;
    }
    return true;
}
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        c[i]=s[i];
    }
    bool a = palin(0,n-1);
    bool b = palin(0,(n-3)/2);
    bool c = palin((n+1)/2,n-1);
    if(a and b and c)
        cout<<"Yes\n";
    else
        cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
signed main(){
    int N;
    int L[205];
    cin >> N;
    REP(i,2*N){
        cin >> L[i];
    }
    sort(L,L+2*N);
    int Ans=0;
    REP(i,N){
        Ans+=L[2*i];
    }
    cout << Ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;


#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
// maekarataosu
int main() {
	int n, k;
  vector<int> a, b;
	cin >> n;
  rep(i,n+1) {
    cin >> k;
    a.push_back(k);
  }
  rep(i,n) {
    cin >> k;
    b.push_back(k);
  }
  b.push_back(0);

  ll sum = 0;
  int nextp = 0;
  rep(i,n+1) {
    int diff_i = nextp - a.at(i);
    if (diff_i >= 0) {
      sum += a.at(i);
      nextp = b.at(i);
    } else if (diff_i + b.at(i) >= 0) {
      sum += a.at(i);
      nextp = diff_i + b.at(i);
    } else {
      sum += nextp + b.at(i);
      nextp = 0;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main() {
  string O, E;
  cin >> O >> E;
  rep(i, O.size()) {
    cout << O[i];
    if(i==E.size())
      break;
    cout << E[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
N , Y  = map(int, input().split())
for x in range(0,(N+1)):
    for y in range(0,(N-x+1)): 
        total = 10000 * x + 5000 * y + 1000 * (N - x - y)
        if total == Y:
            print(x,y,N-x-y)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
T = "keyence"
S = input()
N = len(S)

def check(start, end):
    if N - (end - start) != 7:
        return False
    #print("start")
    j = 0
    for s in S[:start]:
        #print(s, T[j])
        if T[j] != s:
            return False
        j += 1
    #print("here")
    for s in S[end:]:
        #print(s, T[j])
        if T[j] != s:
            return False
        j += 1
    return True
    
def solve():
    for start in range(N-1):
        for end in range(start, N):
            #print("!!", start, end)
            if check(start, end):
                return True
    return False

print("YES" if solve() else "NO")
    


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

int main(){
  int a,b,d;
  while(cin >> a >> b >> d,a){
    int x=-1,y=-1;
    for(int i=0;a*i<=d;i++){
      if(!((d-a*i)%b)){
	int s = i, t = (d-a*i)/b;
	if(x<0){
	  x = s; y = t;
	}else if(x+y > s+t){
	  x = s; y = t;
	}else if(x+y == s+t && a*x+b*y > a*s+b*t){
	  x = s; y = t;
	}
      }
    }
    
    for(int i=d/a+1;;i++){
      if(!((a*i-d)%b)){
	int s = i, t = (a*i-d)/b;
	if(x<0){
	  x = s; y = t;
	}else if(x+y > s+t){
	  x = s; y = t;
	}else if(x+y == s+t && a*x+b*y > a*s+b*t){
	  x = s; y = t;
	}
	break;
      }
    }

    for(int i=d/b+1;;i++){
      if(!((b*i-d)%a)){
	int s = (b*i-d)/a, t = i;
	if(x<0){
	  x = s; y = t;
	}else if(x+y > s+t){
	  x = s; y = t;
	}else if(x+y == s+t && a*x+b*y > a*s+b*t){
	  x = s; y = t;
	}
	break;
      }
    }

    cout << x << " " << y << endl;
  }
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
string a,b;
int l,cnt;
int main()
{
    cin>>a>>b;
    l =min(a.size(),b.size());
    while(cnt<l)
    {
        printf("%c%c",a[cnt],b[cnt]);
        cnt++;
    }
    if(a.size()>b.size()) printf("%c",a[a.size()-1]);
    cout<<endl;
    return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

//0 to n-1 でも1 to nでもOK
struct UnionFind{
    int n;
    vector<int> p;
    UnionFind(int nn) {
        n = nn;
        p.resize(n);
        rep(i, n) p[i] = i;
    }
    int root(int x) {
        return p[x] == x ? x : (p[x] = root(p[x]));
    }
    void unite(int x,int y) {
        x = root(x); y = root(y);
        if(x != y) p[y] = x;
    }
    bool query(int x,int y){
        return root(x) == root(y);
    }
    vector<set<int>> make_group() {
        vector<set<int>> tree(n);
        rep(i, n) tree[root(i)].insert(i);
        return tree;
    }
};


class Solver {
  public:
    bool solve() {
        int N, K, L; cin >> N >> K >> L;
        UnionFind road(N), train(N);
        rep(i, K) {
            int a, b; cin >> a >> b;
            road.unite(a - 1, b - 1);
        }
        rep(i, L) {
            int a, b; cin >> a >> b;
            train.unite(a - 1, b - 1);
        }
        vector<int> ans(N, -1);
        auto road_group = road.make_group();
        auto train_group = train.make_group();

        rep(i, N) {
            if(ans[i] >= 0) continue;
            int rr = road.root(i), tr = train.root(i);
            set<int> &gs = road_group[rr].size() <= train_group[tr].size() ? road_group[rr] : train_group[tr];
            set<int> &gl = road_group[rr].size() >  train_group[tr].size() ? road_group[rr] : train_group[tr];
            vector<int> u;
            for(int j : gs) {
                if(gl.count(j)) u.push_back(j);
            }
            for(int j : u) ans[j] = u.size();
        }
        rep(i, N) cout << ans[i] << (i == N - 1 ? "\n" : " ");
        return 0;
    }
};

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


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

int main() {
    int A, B, C, D;
    int k = 0;
    cin >> A >> B >> C >> D;
    if(A + B > C + D) cout << "Left" << endl;
    else if(A + B < C + D) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char) 
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
    
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let (w, h): (f64, f64) = (read(), read());
  println!("{}",
    if w == 1f64 || h == 1f64 { 1i64 }
    else { (w * h / 2f64).round() as i64 }
  );
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<vector<lli> > vvi;
typedef vector<ii> vii;
 
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define FF first
#define SS second

lli mod = 1e9 +7;
lli n, arr[410][410], inp[410], presum[410];

inline lli min(lli a, lli b)
{
	if(a<b)	return a;
	else return b;
}

lli dp(int l, int r)
{
	if(arr[l][r]<1e18) return arr[l][r];
	else if(l==r) return arr[l][r]=0;
	else
	{
		for(int i=l; i<r; i++)
			arr[l][r] = min(dp(l,i)+dp(i+1,r)+presum[r]-presum[l-1], arr[l][r]);
		return arr[l][r];
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	for(int i=0; i<410; i++)
	{
		for(int j=0; j<410; j++)
			arr[i][j]=1e18;
	}
	cin >> n;
	for(int i=1; i<=n; i++)
		cin >> inp[i], presum[i]=presum[i-1]+inp[i];
	cout << dp(1, n);
}

Measured memory_bytes: 4996
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll x;
	ll b = 500, s = 5;
	cin >> x;
	ll cb = x / b;
	x -= cb * b;
	ll cs = x / s;
	ll ans = cb * 1000 + cs * 5;
	cout << ans << endl;
	return 0;
}

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int dp[100006] = {(int)INF};

int main(){
  int N;
  cin >> N;
  vector<int> h(N+1);
  REP(i, N){
    cin >> h[i];
  }
  h[N] = INF;
  REP(i, N){
    dp[i] = INF;
  }
  dp[0] = 0;
  REP(i, N-1){
    dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i] - h[i+2]));
  }

  cout << dp[N-1] << endl;
  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int index = 1;
    int count = 0;
    while (true) {
        if (a[index] == -1) {
            cout << -1 << endl;
            break;
        }
        count++;
        if (a[index] == 2) {
            cout << count << endl;
            break;
        }
        int tmp = index;
        index = a[index];
        a[tmp] = -1;
    }
}


Measured memory_bytes: 640
from math import factorial
n,p=map(int,input().split())
A=list(map(int,input().split()))

a,b=0,0
for i in A:
    if i%2==0:a +=1
    else:b +=1

cnt=0 if p==1 else 1
for i in range(p,b+1,2):
    if i==0:continue
    cnt +=factorial(b)//(factorial(i)*factorial(b-i))

print(cnt*(2**a))

Measured memory_bytes: 62220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
 
int main() {
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<int> veca(a);
  vector<int> vecb(b);
  vector<int> vecc(c);
  rep(i, a) {
    cin >> veca.at(i);
  }
      rep(i, b) {
    cin >> vecb.at(i);
  }
  rep(i, c) {
    cin >> vecc.at(i);
  }
  sort (veca.begin(),veca.end());
  reverse(veca.begin(),veca.end());
    sort (vecb.begin(),vecb.end());
  reverse(vecb.begin(),vecb.end());
    sort (vecc.begin(),vecc.end());
  reverse(vecc.begin(),vecc.end());
vector<int> vec;
  rep(i, x) {
  vec.push_back(veca.at(i));
  }
  rep(i, y) {
    vec.push_back(vecb.at(i));
  }
  rep(i, c) {
vec.push_back(vecc.at(i));
  }
  int64_t sum = 0;
   sort (vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  rep(i, x+y) {
    sum+=vec.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll x[n+5];
    ll sum=0;
    map<ll,ll>mp;
    for(ll i=0;i<n;i++)
    {
        cin>>x[i];
        sum+=x[i];
        mp[x[i]]++;
    }
    ll k;
    cin>>k;
    for(ll i=0;i<k;i++)
    {
        ll c,d;
        cin>>c>>d;
        ll t=mp[c];
        mp[c]=0;
        mp[d]+=t;
        sum=sum-(t*c);
        sum=sum+(t*d);
        cout<<sum<<endl;
    }

}


Measured memory_bytes: 10148
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define all(A) A.begin(),A.end()
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
typedef std::vector<int> vi;
typedef std::pair<int,int> pi;
typedef std::vector<pi> vp;
typedef long long ll;
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
#define what_is(x) cerr << #x << " is " << x << endl
#define bit_lg(x) (assert(x > 0),__builtin_ffsll(x) - 1)
const double PI = acos(-1);
template<class A,class B>
std::ostream& operator << (std::ostream& st,const std::pair<A,B> p) {
	st << "(" << p.first << ", " << p.second << ")";
	return st;
}
using namespace std;

char txt[1 << 20];
int n;



int main(){
#ifdef HOME
	freopen("in.in", "r", stdin);
#endif
	cin >> txt;
	n = strlen(txt);
	loop(i, n) if(txt[i] == '?') txt[i] = 'D';
	cout << txt << endl;
	return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,s,a[100005],p[100005];
int main()
{
	scanf("%lld%lld",&n,&s);
	for(int i=1;i<=n;i++)scanf("%lld%lld",&a[i],&p[i]);
	ll l=1,r=n,ans=0;
	while(l<=r)
	{
		if(a[l]>=s){ans+=a[r]-s;break;}
		if(a[r]<=s){ans+=s-a[l];break;}
		ans+=a[r]-a[l];
		if(p[l]>=p[r]){while(p[l]>=p[r]&&l<r)p[l]+=p[r],r--;}
		else {while(p[r]>p[l]&&l<r)p[r]+=p[l],l++;}
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1792
_n = gets.to_i
as = gets.split.map(&:to_i)
sum = 0
calc = as.map { |num|
  sum += num
}

# calc[0]、つまりevenを正とする場合
change = 0
moved = 0
calc.map.with_index { |num, i|
  if i.even?
    if num + change > 0
      # 問題なし
    else
      diff = 1 - (num+change)
      change += diff
      moved += diff.abs
    end
  else # i.odd?
    if num + change < 0
      # 問題なし
    else
      diff = -1 - (num+change)
      change += diff
      moved += diff.abs
    end
  end
}
even_moved = moved

# calc[1]、つまりoddを正とする場合
change = 0
moved = 0
calc.map.with_index { |num, i|
  if i.odd?
    if num + change > 0
      # 問題なし
    else
      diff = 1 - (num+change)
      change += diff
      moved += diff.abs
    end
  else # i.even?
    if num + change < 0
      # 問題なし
    else
      diff = -1 - (num+change)
      change += diff
      moved += diff.abs
    end
  end
}
odd_moved = moved

puts [even_moved, odd_moved].min


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

int d[200000],t[200000];
ll sum[200000];

int dat[400000],N;
void init(int n_){
	N=1;while(N<n_)N<<=1;
	for(int i=2*N-2;i>=0;i--){
		if(i>=N-1)dat[i]=(i-N+1>=n_?0:t[i-N+1]);
		else dat[i]=max(dat[i*2+1],dat[i*2+2]);
	}
}
int query(int a,int b,int k,int l,int r){
	if(b<=l||r<=a)return 0;
	if(a<=l&&r<=b)return dat[k];
	return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
}

int main(){
	int n,h;scanf("%d%d",&n,&h);
	rep(i,n-1){
		scanf("%d%d",&d[i],&t[i]);
		sum[i]=d[i];
		if(i)sum[i]+=sum[i-1];
	}
	init(n);
	int p=h;
	ll cnt=0;
	rep(i,n-1){
		//増加分がtになるとき
		int l=i,r=n-1;
		while(r-l>1){
			int mid=(l+r)/2;
			if(query(i+1,mid+1,0,0,N)<t[i])l=mid;
			else r=mid;
		}
		//そこまでに必要な体力
		ll b=sum[l]-(i?sum[i-1]:0);
		int a=min((h-p)/(ll)t[i],max(0LL,(b+t[i]-1-p)/t[i]));
		cnt+=a;
		p=min(h,p+a*t[i]);
		//あまり
		int c=min(h-p,t[i]);
		int j=lower_bound(sum,sum+n-1,(i?sum[i-1]:0)+p)-sum;
		if(j==n-1){
			cout<<cnt<<endl;
			return 0;
		}
		if(i==j||query(i+1,j+1,0,0,N)<c){
			cnt++;
			p+=c;
		}
		p-=d[i];
	}
	cout<<cnt<<endl;
}


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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    int n, tmp;
    cin >> n;
    vector<int> in;
    REP(i, n) {
        cin >> tmp;
        in.push_back(tmp);
    }
    sort(in.begin(), in.end());
    for(int i=1; i<n; i++) {
        if (in[i] == in[i-1]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 1400
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int s = 0, const int d = 0, const Weight w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;
  using iterator = std::vector<Edges>::iterator;
  using const_iterator = std::vector<Edges>::const_iterator;

public:
  Graph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  const Edges &operator[](const int i) const { return g[i]; }
  void addArc(const int src, const int dst, const Weight w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int node1, const int node2, const Weight w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

std::vector<int> tsort(const Graph &g) {
  int n = g.size(), k = 0;
  std::vector<int> ord, in(n);
  ord.reserve(n);
  for (auto &es : g) {
    for (auto &e : es) in[e.dst]++;
  }
  std::queue<int> q;
  rep(i, n) if (in[i] == 0) q.push(i);
  while (q.size()) {
    int v = q.front();
    q.pop();
    ord.emplace_back(v);
    for (auto &e : g[v])
      if (--in[e.dst] == 0) q.push(e.dst);
  }
  return ord.size() == n ? ord : std::vector<int>();
}

main {
  int n, m;
  cin >> n >> m;
  Graph g(n);
  while (m--) {
    int s, t;
    cin >> s >> t;
    g.addArc(s, t);
  }
  vi v = tsort(g);
  for (auto &x : v) cout << x << endl;
}

Measured memory_bytes: 4848
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final char[] chs = sc.next().toCharArray();
			for(final char ch : chs) {
				System.out.print((char)((((ch - 'A') + N) % 26) + 'A'));
			}
			System.out.println();
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23508
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if (R < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

void a()
{
    int A,B;
    cin >>A>>B;
    if(abs(A-B)%2==0)
    {
        cout<<(A+B)/2;

    }
    else
    {
        cout<<"IMPOSSIBLE";
    }
    return;
    
}
void b()
{
    int N;
    cin >>N;
    int count=0;
    for(int i=0;i<N;i++)
    {
        int temp;
        cin>>temp;
        if(temp!=(i+1))
        {
            count++;
        }

    }
    if(count>2)
    cout<<"NO";
    else
    {
        cout<<"YES";
    }
    return;


}
int main()
{
    //a();
    b();
    return 0;

}

Measured memory_bytes: 888