akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<string>
#include<numeric>
#define int long long
#define all(x) x.begin(),x.end()
#define maxn 1000000
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);

void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
void solve() {
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;++i) cin>>arr[i];
    int sum=0;
    set<pair<int,int>> s;
    for(int i=0;i<n;++i)
    {
        for(int j=0;j<n;++j)
        {
            if(i!=j) {
                int x=min(i,j);
                int y=max(i,j);

                s.insert(make_pair(x,y));
            }
        }

    }
    for(auto &i:s) sum+=arr[i.first]*arr[i.second];
    cout<<sum;
}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //cout<<"Hello World"<<"\n";
    //int t;cin>>t;while(t--)
    solve();

}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG //GCC環境での[]デバッグ
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
using namespace std;
using ll = long long;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k , a, b;
    cin >> k >> a>> b;
    for(int i = a; i <= b; i++ ){
        if(i % k == 0){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =  new BufferedReader(new InputStreamReader(System.in));
		
		int max = Integer.MIN_VALUE;
		ArrayList<Integer> arr =  new ArrayList<Integer>();
		
		
		for(int i = 0; i < 10; i++){
			String input = br.readLine();
			if(!input.equals("")){
				int inputAngka = Integer.parseInt(input);
				arr.add(inputAngka);
			}
		}
		
		int[] arrayResult = new int[arr.size()];
		
		for(int i = 0; i < arr.size(); i++){
			arrayResult[i] = arr.get(i);
		}
		
		Arrays.sort(arrayResult);
		
		int max1 = arrayResult[arrayResult.length-1];
		int max2 = arrayResult[arrayResult.length-2];
		int max3 = arrayResult[arrayResult.length-3];
		
		System.out.println(max1);
		System.out.println(max2);
		System.out.println(max3);

	}

}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int y = in.nextInt();
        int z = in.nextInt();

        out.println(z + " " + n + " " + y);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 23124
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
r=[[] for i in range(n+1)]
ans=[-1 for i in range(n+1)]
for i in l:
  u,v,w=i
  r[u].append((v,w))
  r[v].append((u,w))
q=[1]
ans[1]=0
while(len(q)>0):
  t=q.pop()
  for i in r[t]:
    V,W=i
    if(ans[V]!=-1):
      continue
    q.append(V)
    c=ans[t]
    if(W%2==0):
      ans[V]=c
    else:
      ans[V]=c^1
for i in ans[1:]:
  print(i)

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

int n, a;

int main() {
    ios::sync_with_stdio(false);
    
    cin >> n >> a;
    
    n = n % 500;
    
    
    if (n <= a)
        cout << "Yes\n";
    else
        cout << "No\n";
    
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main () {
  int a,b,c,n;

  scanf("%d%d%d\n",&a,&b,&c);
  
  if (a>b) {
    n=a;
    a=b;
    b=n;
  }

  if (b>c) {
    n=b;
    b=c;
    c=n;
  }

  if (a>b) {
    n=a;
    a=b;
    b=n;
  }

  printf("%d %d %d\n",a,b,c);
  return 0;

}

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

int main() {
    int A,B,M,cost,mina=1000000000,minb=1000000000;
    cin >> A >> B >> M;
    vector<int> a(A),b(B);

    for(int i=0;i<A;i++){
        cin >> a.at(i);
        if(mina>a.at(i)) mina=a.at(i);
    }
    for(int j=0;j<B;j++){
        cin >> b.at(j);
        if(minb>b.at(j)) minb=b.at(j);
    }
    
    cost=mina+minb;
    
    for(int k=0;k<M;k++){
        int x,y,z,c;
        cin >> x >> y >> c;
        z=a.at(x-1)+b.at(y-1)-c;
        if(cost>z) cost=z;
    }
    cout << cost << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include<algorithm>
using namespace std;

bool canDraw(int a, int b, int c, int d)
{
    return (bool)max((a - b - c - d), 0);
}
int main ()
{
    int n;
    cin >> n;

    int a[n];
    for (int i = 0; i < n; ++i) {
        scanf("%i", &a[i]);
    }
    int max = 0;
    int sum = 0;
    for (int i = 0; i < n; ++i){
        sum+=a[i];
        if (a[i] > max) {
            max = a[i];
        }
    }
    sum -= max;
    if (sum - max > 0){
        cout << "Yes";
        return 0;
    }
    else {
        cout << "No";
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n,0);
    vector<int> cnt(1000005, 0);
    for(int i =0; i < n; i++){
        cin >> a[i];
    }

    for(int i = 0; i< n; i++){
        if(cnt[a[i]] == 0){
            for(int j = a[i]; j<1000005; j += a[i]){
                cnt[j]++;
            }
        }else{
            cnt[a[i]] = 2;
        }
    }
    int ans = 0;
    for(int i = 0; i<n;i++){
        if(cnt[a[i]] == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef long long l;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	fprintf(stderr, "Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

char s[27];
int pres[27] = {0};


int main() {
	start = clock();

	scanf("%s", s);
	int l = strlen(s);

	for (int i = 0 ; i < l ; ++i) ++pres[s[i] - 'a'];
	if (l <= 25) {
		char c;
		for (int i = 0 ; i < 26 ; ++i) {
			if (!pres[i]) {
				c = (char)(i +  'a');
				break;
			}
		}
		printf("%s", s);
		printf("%c", c);
		printf("\n");
	}
	else {
		int j = l - 2;
		vector<char> vec;
		vec.PB(s[l - 1]);
		while (s[j] > s[j + 1]) {
			vec.PB(s[j]);
			--j;
		}
		if (j == -1) cout << -1 << endl;
		else {
			char c = s[j];
			vec.PB(s[j]);
			sort(vec.begin(), vec.end());
			s[j] = 0;
			printf("%s", s);

			char ch = c;
			for (int i = 0 ; i < vec.size() ; ++i) {
				if (vec[i] > ch) {
					ch = vec[i];
					break;
				}
			}
			printf("%c", ch);
			/*
			for (int i = 0 ; i < vec.size() ; ++i) {
				if (vec[i] != ch) printf("%c", vec[i]);
			}
			*/
			printf("\n");
		}
	}



	Time(true);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<pair<ll, ll>> xl(n);
    rep(i, n) cin >> xl[i].first >> xl[i].second;
    sort(all(xl), [](const pair<ll, ll> &a, const pair<ll, ll> &b){ return (a.first - a.second) < (b.first - b.second); });
    ll right = LONG_LONG_MIN;
    ll ans = 0;
    rep(i, n) {
        ll l = xl[i].first - xl[i].second;
        ll r = xl[i].first + xl[i].second;
        if (l < right) {
            if (r < right) {
                ans++;
                right = r;
            }
            else {
                ans++;
            }
        }
        else {
            right = r;
        }
        // printf("i=%lld, right=%lld, ans=%lld\n", i, right, ans);
    }
    cout << (n - ans) << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  char b; cin >> b;
  char p;
  switch(b) {
    case 'A': p = 'T'; break;
    case 'T': p = 'A'; break;
    case 'C': p = 'G'; break;
    case 'G': p = 'C'; break;
  }
  cout << p << endl;
}


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

using namespace std;

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    
    if(a>=b) cout<<"delicious"<<endl;
    else if(b-a<=x) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
N, P = map(int,input().split())
if N >= 41 or N >= P:
    print(1)
    exit(0)
if N == 1:
    print(P)
    exit(0)

ans = 1
k = 1
while pow(k,N) <= P:
    if P%pow(k,N)==0:
        ans = k
    k += 1

print(ans)


Measured memory_bytes: 40848
#include<cstdio>
#include<vector>

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

using namespace std;

typedef	vector<int>	vi;

vi pr;

int calcKeynum(int a){
	int pmax,pf=0;
	rep(i,pr.size()){
		if(a==1)	break;
		if(a%pr[i]==0){
			do{
				a/=pr[i];
			}while(a%pr[i]==0);
			pmax=pr[i];
			pf+=pr[i];
		}
	}
	return 2*pmax-pf;
}

int main(){
	bool era[1000000]={};	era[0]=era[1]=true;
	rep(i,1000) if(!era[i]) for(int j=i*i;j<1000000;j+=i) era[j]=true;
	rep(i,1000000) if(!era[i]) pr.pb(i);

	for(int a,b;scanf("%d%d",&a,&b),a;)	printf("%c\n",calcKeynum(a)>calcKeynum(b)?'a':'b');

	return 0;
}

Measured memory_bytes: 2220
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

struct UnionFind {
    vector<ll> par;

    UnionFind(ll N) : par(N) {
        Rep (i, N) par[i] = i;
    }

    ll root (ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite (ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same (ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

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

    ll N, K;
    cin >> N >> K;
    vec P(N);
    Rep (i, N) {
        cin >> P[i];
    }

    vec stable(N, -1);
    stable[N-1] = 1;
    for (ll i = N-1; i > 0; i--) {
        if (P[i-1] < P[i]) {
            stable[i-1] = stable[i] + 1;
        } else {
            stable[i-1] = 1;
        }
    }

    // Rep (i, N) {
    //     cout << stable[i] << " \n"[i==N-1];
    // }

    vec a;
    Rep (i, N) {
        if (stable[i] >= K) a.push_back(i);
    }

    UnionFind ans(N-K+1);
    Rep (i, (ll)a.size()-1) {
        ans.unite(a[i], a[i+1]);
    }

    set<ll> tmp;
    for (ll i = 1; i < K; i++) {
        tmp.insert(P[i]);
    }

    Rep (i, N-K) {
        // cout << "i:" << i << "\n";
        // for (ll e : tmp) {
        //     cout << e << " ";
        // }
        // cout << "\n";
        ll tmpmin = *tmp.begin(), tmpmax = *(--tmp.end());
        // cout << P[i] << " " << tmpmin << " " << tmpmax << " " << P[i+K] << "\n";
        if (P[i] < tmpmin and tmpmax < P[i+K]) {
            ans.unite(i, i+1);
        }
        tmp.erase(P[i+1]);
        tmp.insert(P[i+K]);
    }

    // Rep (i, N-K) {
    //     if (stable[i] >= K+1) {
    //         ans.unite(i, i+1);
    //     }
    // }

    set<ll> root;
    Rep (i, N-K+1) {
        root.insert(ans.root(i));
    }

    cout << root.size() << endl;

}

Measured memory_bytes: 14336
#include <iostream>
using namespace std;
string s;
int main() {
    cin >> s;
    string poss[] = {"KIHBR", "KIHBRA", "KIHBAR", "KIHBARA", "KIHABR", "KIHABRA", "KIHABAR", "KIHABARA",
        "AKIHBR", "AKIHBRA", "AKIHBAR", "AKIHBARA", "AKIHABR", "AKIHABRA", "AKIHABAR", "AKIHABARA"};
    
    for(int i = 0 ; i < 16 ; i++){
        if(s == poss[i]){
            cout << "YES";
            return 0;
        }
    }
    cout << "NO";
	return 0;
}


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int A[110000];
signed main() {
    cin>>N;
    int odd=0;
    for(int i=0;i<N;i++){cin>>A[i];if(A[i]%2==1)odd++;}
    if(odd%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 1532
N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  G[a - 1].append([i, b - 1])
  G[b - 1].append([i, a - 1])
cnt = 0
for i in range(M):
  D = [N] * N
  D[0] = 0
  Q = [0]
  while Q:
    s = Q[0]
    Q = Q[1:]
    for idx, adj in G[s]:
      if idx != i and D[adj] == N:
        D[adj] = D[s] + 1
        Q.append(adj)
  cnt += 1 if max(D) == N else 0
print(cnt)

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

int main(){
    int a;
    cin >> a;
  
    cout << a+pow(a,2)+pow(a,3) << endl;
    return 0;
}

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

int main(){
	double N,D;
	cin>>N;
	cin>>D;
	int count=0;
	while(N--){
		double p,q;
		cin>>p;
		cin>>q;
		double dov=sqrt(p*p+q*q);
		if(dov<=D){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 3780
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    string s; cin>>s;
    int cnt = 0;

    rep(i,s.size()/2){
        if(s[i]!=s[s.size()-1-i]) cnt++;
    } 

    cout << cnt << ln;
    return 0;
 }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int[][][] rooms=new int[4][3][10];
		int n=scan.nextInt();
		int b,f,r,v;
		for(int i=0;i<n;i++){
			b=scan.nextInt();
			f=scan.nextInt();
			r=scan.nextInt();
			v=scan.nextInt();
			rooms[b-1][f-1][r-1]+=v;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
					System.out.print(" "+rooms[i][j][k]);
				}
				System.out.println();
			}
			if(i==3) break;
			System.out.println("####################");
		}
		scan.close();
	}
}

Measured memory_bytes: 21068
#include <iostream>
#include <string>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

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


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000001;
int n,l,t,x,w,m,ans[maxn],len[maxn],q,c[maxn];
void work(int x,int val)
{
	if(!x)return;
	int pos=upper_bound(len+1,len+m,x)-len-1;
	if(pos==0)c[1]+=val,c[x+1]-=val;
	else ans[pos]+=(x/len[pos])*val,work(x%len[pos],val);
}
signed main()
{
    cin>>n>>q;
    len[++m]=n;
    for(int i=1;i<=q;i++)
    {
    	cin>>x;
    	while(m&&len[m]>=x)m--;	
    	len[++m]=x;
	}
	ans[m]=1;
	for(int i=m;i>=2;i--)
	{
		ans[i-1]+=ans[i]*(len[i]/len[i-1]);
		work(len[i]%len[i-1],ans[i]);
	}
    c[1]+=ans[1],c[len[1]+1]-=ans[1];
    for(int i=1;i<=n;i++)c[i]+=c[i-1],cout<<c[i]<<" ";
    
}

Measured memory_bytes: 5960
import sys

def solve():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1
    L = [0] * (N - 1)
    for i in range(N - 1):
        for j in range(i + 1, N):
            if j <= X or Y <= i:
                L[j - i - 1] += 1
            elif i <= X and Y <= j:
                L[j - i - (Y - X)] += 1
            elif X <= i < j <= Y:
                L[min(j - i - 1, i - X + Y - j)] += 1
            elif i <= X and X <= j < Y:
                L[min(j - i - 1, X - i + Y -j)] += 1
            else:
                L[min(j - i - 1, j - Y + i - X)] += 1
    print("\n".join(map(str, L)))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 42480
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int a[n]={};
    int cnt = 0;
    if(s[0]=='W'){a[0]=1;cnt++;}
    else a[0]=0;
    for(int i=1;i<n;i++){
        if(s[i]=='W') {cnt++;a[i]=1;}
        else a[i]=0;
    }
    int ans = 1e9;
    int e = 0,w=0,c;
    fol(i,n){
        if(a[i])cnt--;
        c = w+(n-cnt-i-1);
        ans = min(c,ans);
        if(a[i]){
            w++;
        }else{
            e++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1796
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
p = -1
for i in range(n):
    q = t-(h[i]*0.006)
    if p == -1 or p > abs(a-q):
        p = abs(a-q)
        ans = i+1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

struct X
{
	lnt a,b,c;
	X(lnt a, lnt b, lnt c) : a(a),b(b),c(c) {}
};

int main() {
	lnt n,k;
	std::cin >> n >> k;
	std::vector<lnt> a(2*n);
	std::iota(all(a),0);
	std::set<lnt> set(all(a));
	if(2*k>n+1) {
		print(-1);
		return 0;
	}
	std::vector<X> ans;
	if(n&1) {
		rep(i,(n+1)/2) {
			ans.emplace_back(k+2*i,k+n+n/2-i,k+2*n+i);
		}
		rep(i,n/2) {
			ans.emplace_back(1+k+2*i,k+2*n-1-i,k+2*n+i+(n+1)/2);
		}
	} else {
		rep(i,n/2) {
			ans.emplace_back(k+2*i,k+n+n/2-i,k+2*n+i);
		}
		ans.emplace_back(k+n-1,k+n,k+2*n+n/2);
		rep(i,n/2-1) {
			ans.emplace_back(1+k+2*i,k+2*n-1-i,k+2*n+i+n/2+1);
		}
	}
	for(auto x:ans) std::cout << x.a << ' ' << x.b << ' ' << x.c << EL;
}


Measured memory_bytes: 17228
// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

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

type (
	in struct {
		Scanner *bufio.Scanner
	}
	str string
	lm  struct{}
	su  struct{}
)

func (in *in) s() string {
	in.Scanner.Scan()
	return in.Scanner.Text()
}

func (in *in) i() int64 {
	return in.irad(10)
}

func (in *in) irad(base int) int64 {
	i, _ := strconv.ParseInt(in.s(), base, 64)
	return i
}

func (in *in) ss(n int64) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = in.s()
	}
	return a
}

func (in *in) is(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = in.i()
	}
	return a
}

func stdin() in {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	max := 200000
	buf := make([]byte, max)
	scn.Buffer(buf, max)
	return in{Scanner: scn}
}

func (*lm) max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func (*lm) min(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func (*lm) abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func (*lm) zero() int64 {
	return int64(0)
}

func (*lm) mod() int64 {
	return int64(1000000007)
}

func (*su) arr(slice []int64) string {
	ret := make([]string, len(slice))
	for i, x := range slice {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, " ")
}

func (*su) bool(b bool) str {
	if b {
		return "Yes"
	}
	return "No"
}

func (s str) upper() string {
	return strings.ToUpper(string(s))
}

func (s str) lower() string {
	return strings.ToLower(string(s))
}

func main() {
	// utilities.
	const zz int64 = 0
	const mod int64 = 1000000007
	in, lm, su := stdin(), lm{}, su{}
	_, _, _ = in, lm, su

	// read here.
	n, k := in.i(), in.i()
	a := in.is(n)

	// solve here.
	ans := zz
	for i := zz; i < n; i++ {
		bef := zz
		for j := zz; j < i; j++ {
			if a[i] > a[j] {
				bef++
			}
		}
		aft := zz
		for j := i + 1; j < n; j++ {
			if a[i] > a[j] {
				aft++
			}
		}
		ans += aft * k % mod
		ans %= mod
		ans += k * (k - 1) / 2 % mod * ((bef + aft) % mod) % mod
		ans %= mod
	}

	printable := ans
	// print here.
	fmt.Println(printable)
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <math.h>

using namespace std;

long long int gcd(long long int x, long long int y) {
	if (x < y){
      return gcd(y, x);
    }
	long long int r;
	while (r = x % y) {
		x = y;
		y = r;
	}
	return y;
}

int main(void){
  long long int n,i,j;
  cin >> n;
  long long int h[n];
  long long int maxH=0;
  int count = 0;
  for(i=0;i<n;i++){
    cin >> h[i];
    if(h[i]>=maxH){
      maxH=h[i];
      count++;
    }
  }
  cout << count << endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    for (int i = 0; i < 10000; i++) {
        if (i % 2 == 0) {
            c -= b;
            if (c <= 0) return !printf("Yes\n");
        }
        else {
            a -= d;
            if (a <= 0) return !printf("No\n");
        }

    }
}

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

void pv(vector<int>& v) {
    cout << "{ ";
    for (auto el: v) {
        cout << el << ", ";
    }
    cout << " }" << endl;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int x, n;
    cin >> x >> n;
    int num;
    unordered_set<int> s;
    for (int i = 0; i < n; i++) {
        cin >> num;
        s.insert(num);
    }
    
    int diff = 0;
    while (true) {
        int r = x + diff;
        int l = x - diff;
        if (!s.count(l)) {
            cout << l << endl;
            return 0;
        } else if (!s.count(r)) {
            cout << r << endl;
            return 0;
        }
        diff++;
    }
    
    return 0;
}

Measured memory_bytes: 3628
import numpy as np

M = 998244353

n = int(input())
xs = [0] * n
ds = [0] * n
for i in range(n):
    x, d = (int(c) for c in input().split())
    ds[i] = d
    xs[i] = x
xs = np.array(xs)
ds = np.array(ds)

import sys
sys.setrecursionlimit(max(1000,n))

index = xs.argsort()
xs = xs[index]
ds = ds[index]

def _sub(i):
    # 深さ優先探索しながらi番目以下の組み合わせと、次に調べるべき番号を返す
    if i==n-1:
        return 2, n
    res = 1
    ind = i+1
    while True:
        if (xs[i]+ds[i] <= xs[ind]):
            break
        o, ind = _sub(ind)
        res *= o
        res %= M
        if ind>=n:
            break
    return res+1, ind
out = []
done = 0
while True:
    o, done = _sub(done)
    out.append(o)
    if done>=n:
        break
result = 1
for o in out:
    result *= o
    result %= M
print(result)

Measured memory_bytes: 190120
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    tx -= sx;
    ty -= sy;
    char u     = ty > 0 ? 'U' : 'D';
    char d     = ty > 0 ? 'D' : 'U';
    char l     = tx > 0 ? 'L' : 'R';
    char r     = tx > 0 ? 'R' : 'L';
    tx         = abs(tx);
    ty         = abs(ty);
    string ret = "";
    ret += string(tx, r);
    ret += string(ty, u);
    ret += string(tx, l);
    ret += string(ty, d);
    ret += string(1, d);
    ret += string(tx + 1, r);
    ret += string(ty + 1, u);
    ret += string(1, l);
    ret += string(1, u);
    ret += string(tx + 1, l);
    ret += string(ty + 1, d);
    ret += string(1, r);
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
D = list(input())

A, B = [D[i] for i in range(0, len(D), 2)], [D[i] for i in range(1, len(D), 2)]
iA,iB = list("RUD"),list("LUD")

for v in A:
    if v not in iA:
        print("No")
        exit(0)
for v in B:
    if v not in iB:
        print("No")
        exit(0)
print("Yes")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long mx1=max(a,b)*max(c,d);
	long long mx2=min(a,b)*max(c,d);
	long long mx3=max(a,b)*min(c,d);
	long long mx4=min(a,b)*min(c,d);
	cout<<max(max(mx1,mx3),max(mx2,mx4))<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
    int i,j;
    while(1){
        int n;
        cin>>n;
        if(n==0) return 0;
        map<char,char> m;
        for(i=0;i<n;i++){
            char c,d;
            cin>>c>>d;
            m[c]=d;
        }
        int k;
        cin>>k;
        for(i=0;i<k;i++){
            char x;
            cin>>x;
            if(m.count(x)) cout<<m[x];
            else cout<<x;
        }
        cout<<endl;
        
    }
}


Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()
#define y1 omg
#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)
#define ini(x, n) memset(x, n, sizeof(x));
#define MOD ((int)1e9 + 7)
#define atoi(x) ((x)-'0')
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;

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

int n, dp[2010];

int f(int n) {
	if (n < 3) return 0;
	int& ret = dp[n];
	if (ret != -1) return ret;
	ret = 1;
	for (int i = 3; i <= n; i++) {
		ret += f(n - i);
		ret %= MOD;
	}
	return ret % MOD;
}

signed main() {
	ini(dp, -1);
	cin >> n;
	cout << f(n);
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
class MainClass
{
	static void Main(string[] args)
	{
		AnswerC();
	}
	public static void AnswerC()
		{
			int N = int.Parse(Console.ReadLine());
			var arrs = new int[2, N];
			for(int i = 0; i < 2; i++)
			{
				var row = Console.ReadLine().Split(' ');
				for(int j=0;j<row.Length;j++)
				{
					arrs[i, j] = int.Parse(row[j]);
				}
			}
			var lst_amecn = new List<int>();
			int p_turn = 0;
			while (true)
			{
				int ameSum = arrs[0, 0];
				int r_i = 0;

				bool isbreak = false;
				for(int j=0;j<N;j++)
				{
					if(!(r_i==0&&j==0))
						ameSum += arrs[r_i, j];
					if(j == p_turn)
					{
						r_i += 1;
						for (int j2 = j; j2 < N; j2++)
						{
							ameSum += arrs[r_i, j2];
							if (j2 == N - 1)
							{
								isbreak = true;
							}
						}
						if (isbreak)
							break;
					}
				}
				lst_amecn.Add(ameSum);
				if (lst_amecn.Count == N)
					break;
				p_turn++;
			}

			Console.WriteLine(lst_amecn.Max().ToString());
			Console.ReadKey();
		}
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define ll	long long

int main() {
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	int		tmp = INF;
	string	str;

	cin >> a >> b >> c;

	swap(a,b);
	swap(a,c);
	cout << a << " " << b << " " << c << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
using namespace std;

const double pi=4*atan(1.0);

constexpr long long mod=static_cast<long long>(1e9+7);

using cEdges=vector<vector<int>>;

int main() {
	long long H,W,N;
	cin>>H>>W>>N;

	auto compare=[](pair<int,int> x,pair<int,int> y)->bool{return x.first<y.first?true:(x.first==y.first?x.second<y.second:false);};
	set<pair<int,int>,decltype(compare)> Set(compare);
	for(int i=0;i<N;++i){
		int a,b;
		cin>>a>>b;
		--a,--b;
		Set.insert(make_pair(a,b));
	}

	array<long long,10> ans;
	ans.fill(0);

	for(const auto& p:Set){
		bool arr[5][5];
		for(int i=0;i<5;++i){
			for(int j=0;j<5;++j){
				if(Set.find(make_pair(p.first+i-2,p.second+j-2))!=Set.end())arr[i][j]=true;
				else arr[i][j]=false;
			}
		}

		for(int i=0;i<3;++i){
			for(int j=0;j<3;++j){
				if(0<=p.first+i-2 && p.first+i<H && 0<=p.second+j-2 && p.second+j<W){
					int num=0;
					for(int k=0;k<3;++k){
						for(int l=0;l<3;++l){
							if(arr[i+k][j+l])++num;
						}
					}
					++ans[num];
				}
			}
		}
	}
	long long sum=0;
	for(int i=1;i<10;++i){
		ans[i]/=i;
		sum+=ans[i];
	}
	
	ans[0]=(H-2)*(W-2)-sum;
	for(const auto& val:ans)
		cout<<val<<endl;

	return 0;
}

Measured memory_bytes: 4992
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)

#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)

#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
			<< " , " << #y << " = " << (y) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

ll n,m;
ll k;
string s[3];
int p[3];

int main() {
	REP(i,3)cin >> s[i];

	int turn = 0;
	while(true){
		if(s[turn].size() == p[turn])break;
		int old = turn;
		turn = s[turn][p[turn]] - 'a';
		p[old]++;
	}

	cout << char('A' + turn);
	cout << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 100000000 

char c[14];
int x[N];
int n;
 
int a(void);
int b(char);
void insert(void);
int find(void);
 
int main(){
char str[7];
int i;
 
 scanf("%d",&n);
 for(i=0;i<n;i++){
   scanf("%s%s",str,c);
   if(str[0]=='i'){
     insert();
   }
   else if(str[0]=='f'){
     if(find())printf("yes\n");
     else printf("no\n");
   }
 } 
 return 0;
}

int a(void){
  int x=0,i,p=1;
  for(i=0;i<strlen(c);i++){
    x+=p*(b(c[i]));
    p*=5;
  }
  return x;
}
 
int b(char c){
 
  if(c=='A'){
    return 1;
  }
  else if(c=='C'){
    return 2;
  }
  else if(c=='G'){
    return 3;
  }
  else return 4;
 
}

void insert(){
  x[a()]=1;
}
int find(){
    int key =a();
     
    if(x[key]){
   return 1;
    }
    else return 0;
} 
 
 

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

int main(void){
  string s;
  char c;
  int n1,n2,n;

  while(cin>>s){
    n=0;
    n1=10000;
    for(int i=0;i<s.size();i++){
      c=s[i];
      if(c=='I')n2=1;
      else if(c=='V')n2=5;
      else if(c=='X')n2=10;
      else if(c=='L')n2=50;
      else if(c=='C')n2=100;
      else if(c=='D')n2=500;
      else n2=1000;
      if(n1<n2){
        n-=2*n1;
        n+=n2;
      }
      else{
        n+=n2;
      }
      n1=n2;
    }
    cout<<n<<endl;
  }
  return 0;
}



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

#pragma GCC optimize("O3")

using namespace std;

#define MAXN 200005

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORR(j, i, n) for (int i = j; i < n; i++)
#define FORD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOBIR(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define DUEHOANG                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(NULL);                \
	cout.tie(NULL)

#define JaydenXia(in, out) \
	freopen(in, "r", stdin); \
	freopen(out, "w", stdout);

#define long long long

typedef set<int> si;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef priority_queue<int> pqi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef deque<int> di;
typedef map<int, int> mii;
#define f first
#define s second

string a, b;
int main()
{
    cin >> a >> b;
    int n=0;
    FOR(i, a.length())
    {
        if(a[i] == b[i]) n++;
    }
    cout << n << endl;
}

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

def warshal_floyd(d,N):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

    return d

def main():
    N, M, L = map(int, input().split())
    d = [[float('inf')] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A -= 1
        B -= 1
        d[A][B] = C
        d[B][A] = C

    e = warshal_floyd(d,N)
    f = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if e[i][j] <= L:
                f[i][j] = 1

    g = warshal_floyd(f,N)
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if g[s][t] == float('inf'):
            print(-1)
        else:
            print(g[s][t]-1)
    



if __name__ == "__main__":
    main()

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

public class Main {
 public static void main(String[] args) {
    hayami saori = new hayami();
    long N = saori.saorihayami();
    long n = N - 1;
    for(long i = 1; i <= N; i++) {
        if(i > N / i) {
            break;
        }
        if(N % i == 0 && i + (N / i) - 2 <= n) {
            n = i + (N / i) - 2;
        }
    } 
    System.out.println(n);
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23508
#include <stdio.h>

int main(void)
{
	int a,b,c,d = 0;
	
	scanf("%d %d %d", &a,&b,&c);
	
	if (a > b) {
		d = a;
		a = b;
		b = d;
	} if (b > c) {
		d = b;
		b = c;
		c = d;
	} if (a > b) {
		d = a;
		a = b;
		b = d;
	} 
	
	printf("%d %d %d\n", a,b,c);
	
	return 0;
	
}




Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
#define PI 3.141592653589

int main(){
    int n, x, a, b, c, num = 0;
	while(1){
		cin >> n >> x;
		if(n == 0 && x == 0)break;
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= n;j++){
				for(int k = 1;k <= n;k++){
					if(i + j + k == x){
						
						if(i != j && j != k && i != k){
							//cout << i << j << k << endl;
						num++;
						}
					}
				}
			}
		}
		cout << num / 6 << endl;
		num = 0;
	}
	
    return 0;
}

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

int main()
{

	int n, x3, y3, z3, w3, ACnt;
	int Quat[2][4], A[16];

	while( cin >> n, n ) {

		ACnt = 0;

		for( int k = 0; k < n; k++ ) {

			ACnt = 0;

			for( int i = 0; i < 2; i++ ) {
				for( int j = 0; j < 4; j++ ) cin >> Quat[i][j];
			}

			for( int i = 0; i < 4; i++ ) {
				for( int j = 0; j < 4; j++ ) {

					A[ACnt] = Quat[0][i] * Quat[1][j];
					ACnt++;

				}
			}

			x3 = A[0] - A[5] - A[10] - A[15];
			y3 = A[1] + A[4] + A[11] - A[14];
			z3 = A[2] - A[7] + A[8]  + A[13];
			w3 = A[3] + A[6] - A[9]  + A[12];

			printf( "%d %d %d %d\n", x3, y3, z3, w3 );
		}
	}

	return 0;

}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  ll k;
  cin >> n >> k;
  int a[n];
  REP(i, n) cin >> a[i];
  ll cnt1 = 0, cnt2 = 0;
  REP(i, n) for (int j = i + 1; j < n; ++j) {
    if (a[i] > a[j]) cnt1++;
  }
  cnt1 *= k;
  cnt1 %= MOD;
  REP(i, n) REP(j, n) {
    if (a[i] > a[j]) cnt2++;
  }
  ll t = k * (k - 1) / 2;
  t %= MOD;
  cnt2 *= t;
  cnt2 %= MOD;
  cout << (cnt1 + cnt2) % MOD << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i, n, a, b, c, d;
    char s[5];

    scanf("%s", s);

    a = s[0]-'0';
    b = s[1]-'0';
    c = s[2]-'0';
    d = s[3]-'0';

    if (a+b+c+d==7)         printf("%d+%d+%d+%d=7\n", a, b, c, d);
    else if (a+b+c-d==7)    printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a+b-c+d==7)    printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a+b-c-d==7)    printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a-b+c+d==7)    printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a-b+c-d==7)    printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a-b-c+d==7)    printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if (a-b-c-d==7)    printf("%d-%d-%d-%d=7\n", a, b, c, d);

    return 0;
}

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

int main(){
    int A[5][4][11], n;
    for(int i = 1; i <= 4; i++)
        for(int j = 1; j <= 3; j++)
            for(int k = 1; k <= 10; k++) A[i][j][k] = 0;
            
            cin >> n;
            for(int i = 0; i < n; i++){
                int b, f, r, v;
                cin >> b >> f >> r >> v;
                A[b][f][r] += v;
            }
            
            for(int f = 1; f <= 4; f++){
                if(f > 1) cout << "####################\n";
                for(int b = 1; b <= 3; b++){
                    for(int r = 1; r <= 10; r++){
                        cout << " " << A[f][b][r];
                    }
                    cout << endl;
                }
            }
    return 0;
}

Measured memory_bytes: 1164
def main():
    """
    2 <= K <= 2500
    0 <= S <= 3K = 7500
    0 <= X,Y,Z <= K
    X+Y+Z=S

    2500**3: 15625 * (10^6) => 1.5625 * (10^10)
    Z = S - x - y
    x * y: 2500^2
    """
    K, S = map(int, input().split())

    ans = 0
    for x in range(0, K + 1):
        for y in range(0, K + 1):
            z = S - x - y
            if 0 <= z <= K:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
n, k = map(int, input().split())

a = [0] + list(map(int, input().split()))

cheak = [0] * (2*(10**5) + 1)

point = 1

dev = [1]
flag = 0

for i in range(1, k + 1):
    if cheak[point]:
        loop = i -cheak[point]
        pre_loop = cheak[point]
        flag = 1
        break
    else:
        cheak[point] = i
        point = a[point]
        dev.append(point)

if flag:
    rest = (k + 1- pre_loop) % loop
    for j in range(rest):
        point = a[point]
        dev.append(point)

print(point)

Measured memory_bytes: 32416
/* *>>>>>Anshit_Bhardwaj<<<<<* */
#include <bits/stdc++.h>
#define ll long long
#define f(i, x, n) for(int i = x; i < n; i++)
#define dbg(x) cout << x << endl
#define dbg2(x, y) cout << x << ' ' << y << endl
#define dbg3(x, y, z) cout << x << ' ' << y << ' ' << z << endl
#define mod 1000000007
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, b;
    double d;
    cin >> a >> d;
    b = d * 100 + 0.001;
    a *= b;
    cout << a / 100 << endl;
}

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

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  int sum = 0;
  
  for (int i=A; i<=B; i++){
    int keta_num = 0;
    int temp = i;
    while(temp > 0){
      temp /= 10;
      keta_num++;
    }
    
    int temp_l = i;
    int temp_r = keta_num - 1;
    bool kaibun = true;
    while(temp_l > 0 && kaibun){
      int right = temp_l % 10;
      
      int pow = 1;
      for(int j=0; j<temp_r; j++)
        pow *= 10;
      int left = i / pow  % 10;
      
      if(right != left)
        kaibun = false;
      temp_l /= 10;
      temp_r--;
    }
    if(kaibun)
      sum++;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256