akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a)) 
vector<vector<pair<ll,ll>>> edge(110000);
ll seen[110000];
void dfs(ll i,ll co){    
    for(pair<ll,ll> v : edge[i]){
        ll p=v.first,dis=v.second;
        if(seen[p]!=-1)continue;
        seen[p]=(co+dis);
        dfs(p,seen[p]);
    }
}
int main(){
    int n;
    cin>>n;
    rep(i,n)seen[i]=-1;
    rep(i,n-1){
        ll u,v,w;cin>>u>>v>>w;u--;v--;
        edge[u].push_back({v,w});
        edge[v].push_back({u,w});
    }
    int q,k;
    cin>>q>>k;
    k--;
    seen[k]=0;
    dfs(k,seen[k]);
    rep(i,q){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cout<<seen[a]+seen[b]<<endl;
    }

}

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

using namespace std;

typedef long long ll;

ll N, M;
vector<ll> X;

int main(int argc, char const *argv[])
{
    cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        ll x;
        cin >> x;
        X.emplace_back(x);
    }
    sort(X.begin(), X.end());
    ll ans = 0;
    if (N >= M) {
        cout << ans << endl;
        return 0;
    }

    vector<ll> vec;
    for (int i = 1; i < M; ++i) {
        int dist = X[i]-X[i-1];
        vec.emplace_back(dist);
        ans += dist;
    }
    sort(vec.rbegin(), vec.rend());
    vec.erase(vec.begin()+N-1, vec.end());
    for (int i = 0; i < vec.size(); ++i) {
        ans -= vec[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

int main() {
  size_t n;
  int m;
  scanf("%zu %d", &n, &m);

  std::vector<int> a(n);
  for (auto& ai: a) scanf("%d", &ai);

  int sum = std::accumulate(a.begin(), a.end(), 0);

  int res = 0;
  for (auto ai: a)
    if (ai * 4*m >= sum) ++res;

  puts((res >= m)? "Yes": "No");
}


Measured memory_bytes: 256
from itertools import permutations
INF=10**18
n,m,r=map(int,input().split())
dist=[[INF for _ in range(n+1)]for _ in range(n+1)]
dp=[[-1 for _ in range(r+1)]for _ in  range((1<<r)+1)]
r_t=list(map(int,input().split()))
for i in range(n+1):
  dist[i][i]=0
for _ in range(m):
  a,b,c=map(int,input().split())
  dist[a][b]=c
  dist[b][a]=c
for k in range(n+1):
  for i in range(n+1):
    for j in range(n+1):
      dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
r_list=list(permutations(r_t))
fans=INF
for i in r_list:
  ans=0
  for j in range(r-1):
    ans+=dist[i[j+1]][i[j]]
  fans=min(fans,ans)
print(fans)

Measured memory_bytes: 78800
class BIT:
    def __init__(self, n, MOD):
        self.n = n
        self.data = [0] * (n + 1)
        self.MOD = MOD

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            s %= self.MOD
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            self.data[i] %= self.MOD
            i += i & -i

    def diff(self, i, j):
        s = self.sum(j) - self.sum(i)
        s %= self.MOD
        return s


n, k = map(int, input().split())
mod = 998244353
bit = BIT(n + 2, mod)
ranges = []
for _ in range(k):
    l, r = map(int, input().split())
    ranges.append((l, r))

bit.add(1, 1)

for i in range(1, n):
    v = bit.sum(i)
    for l, r in ranges:
        bit.add(i + l, v)
        bit.add(min(n + 1, i + r + 1), -v)
print(bit.diff(n - 1, n))


Measured memory_bytes: 78464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String line = null;
			while ((line = br.readLine()) != null) {
				if (line.equals("0")) {
					break;
				}
				final int n = Integer.parseInt(line);
				int[] ai = new int[n];
				for (int i = 0; i < n; i++) {
					ai[i] = Integer.parseInt(br.readLine());
				}
				System.out.println(solve(ai));
			}
		}	
	}
	public static long solve(int[] list) {
		long maxsum = Long.MIN_VALUE;
		for (int i = 0; i < list.length; i++) {
			long sum = 0;
			for (int j = i; j < list.length; j++) {
				sum += list[j];
				if (maxsum < sum) {
					maxsum = sum;
				}
			}

			if (maxsum < sum) {
				maxsum = sum;
			}
		}
		return maxsum;
	}
}

Measured memory_bytes: 25264
#!/usr/bin/env python3
#ABC128 C

N,M = map(int,input().split())

S = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))
K = [S[i][0] for i in range(M)]
#print("S",S)
#print("P",P)
#print("K",K)

ans = 0

for i in range(2**N):
    switch = [0]*N
    for j in range(N):
        if (i >> j)  & 1:
            switch[j] = 1
    #print(switch)
    flag = 0
    for j in range(M):
        tmp = 0
        for k in range(1,K[j]+1):
            if switch[S[j][k] - 1] == 1:
                tmp += 1#switch on の数
        #print("tmp",tmp)
        if tmp % 2 != P[j]:
            flag = 1
            break
    if not flag:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#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	
	double r,p = 3.141592;
	cin >> r;
	double ans = 2.0*p * r;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3784
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

a = int(input())

if a//100 == 7 or  (a//10)%10 == 7 or a%10 == 7:
	print("Yes")
else:
	print ("No")


Measured memory_bytes: 9744
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;

ll d[51][5001];

int main(){
	int n, a, x[50];
	scanf("%d %d", &n, &a);
	int m = a;
	for(int i = 0; i < n; i++){
		scanf("%d", &x[i]);
		m = max(m, x[i]);
		x[i] -= a;
	}
	d[0][n * m] = 1;
	for(int i = 0; i < n; i++) for(int j = 0; j <= 2 * n * m; j++){
		d[i + 1][j] = d[i][j];
		if(0 <= j - x[i] && j - x[i] <= 2 * n * m) d[i + 1][j] += d[i][j - x[i]];
	}
	printf("%lld\n", d[n][n * m] - 1);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

// oxxoxo
// xoxoxo
// xxooxo
// xxoxoo
// xxxooo

ll solve(){
  string s; cin>>s;
  ll N = s.size();
  ll ans = 0;
  ll cumu[N+1]; cumu[0] = 0;
  REP(i,N){
    cumu[i+1] = cumu[i];
    if(s[i]=='W'){
      ans += cumu[i];
    }else{
      ++cumu[i+1];
    }
  }
  return ans;
}


int main(){
  ll ans = solve();
  cout << ans <<"\n";
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner br = new FastScanner();
		HashSet<Integer> caca = new HashSet<Integer>();
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
		for(int i = 0;i<3;i++) caca.add(br.ni());
		pw.println(caca.size());
		pw.close();
	}
}

class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner(String s) {
		try {
			br = new BufferedReader(new FileReader(s));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public FastScanner() {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	ArrayList<Integer>[] ng(int n, int e) {
		ArrayList<Integer>[] adj = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			adj[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < e; i++) {
			int a = ni() - 1;
			int b = ni() - 1;
			adj[a].add(b);
			adj[b].add(a);
		}
		return adj;
	}

	Integer[] nIa(int n) {
		Integer[] arr = new Integer[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	int[] nia(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = ni();
		}
		return arr;
	}

	Long[] nLa(int n) {
		Long[] arr = new Long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	long[] nla(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nl();
		}
		return arr;
	}

	String[] nsa(int n) {
		String[] arr = new String[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nt();
		}
		return arr;
	}

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

	int ni() {
		return Integer.parseInt(nt());
	}

	long nl() {
		return Long.parseLong(nt());
	}

	double nd() {
		return Double.parseDouble(nt());
	}

}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
using namespace std;
int h[10001], p[10001];
vector<int>prime;

int main(){

    for(int i=2; i<=10000; i++){
        int s = sqrt(i), flag=0;
        for(int j=2; j*j<=i; j++){
            if(i%j==0){
                flag=1;
                break;
            }
        }
        if(!flag){
            prime.push_back(i);
        }
    }

    for(int i=0; i<prime.size(); i++){
        int sum=0;
        for(int j=i; j<prime.size(); j++){
            sum+=prime[j];
            if(sum>10000){
                break;
            }
            h[sum]++;
        }
    }

    int q;
    //scanf("%d", &q);
    while(1){
        int n;
        cin>>n;
        if(!n) return 0;
        cout<<h[n]<<"\n";
    }
    return 0;
}

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

int main(){
  int K,S; cin>>K>>S;
  int count =0;
  for (int x=0;x<=K;++x){
    for (int y=0;y<=K;++y){
      int z=S-x-y;
      if (z>=0 && z<=K){
        ++count;
      }
    }
  }
  cout<<count<<endl;
}
    

Measured memory_bytes: 256
X, N = map(int, input().split())
A = set([int(a) for a in input().split()]) if N else []
mi = 105
mii = -1
for i in range(-1, 110):
    if i in A: continue
    if abs(i - X) < mi:
        mi = abs(i - X)
        mii = i
print(mii)

Measured memory_bytes: 61776
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sort(x) sort(x.begin(),x.end())
#define reverse(x) reverse(x.begin(),x.end())
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int> >
#define vb vector<bool>
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

void solve(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vi A(a),B(b),C(c);
    rep(i,a) cin>>A[i]; rep(i,b) cin>>B[i]; rep(i,c) cin>>C[i];
    sort(A);    sort(B);    sort(C);
    reverse(A);    reverse(B);    reverse(C);
    vi arr(x+y+c);
    rep(i,x) arr[i]=A[i];
    rep(i,y) arr[x+i]=B[i];
    rep(i,c) arr[x+y+i]=C[i];
    sort(arr);
    reverse(arr);
    ll ans=0;
    rep(i,x+y) ans+=arr[i];
    cout<<ans<<" ";
    
}
signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

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

int main(){
	int n,i,j,min,max,num1,tmp;
	clock_t start,end;
	cin>>n;
	int a[n];

	for(i=0; i<n; i++){
		cin>>a[i];
	}
	/*
	for(i=0; i<n; i++){
		a[n-i-1]=i+19;
	}
*/
	//start=clock();
	min=a[0];
	max=a[1]-a[0];
	for(i=1; i<n; i++){
		if(max<a[i]-min) max=a[i]-min;
		if(min>a[i]) min=a[i];
	}

	//end=clock();
	//cout<<"時間"<<end-start<<"ms\n";
	
	cout<<max<<"\n";
	return 0;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
#include <cstdlib>  //abs()で絶対値を取得する（整数）
#include <cmath>    //abs()かfabs()で絶対値を取得する（少数）
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n, x , t;
    cin >> n >> x >> t;
    int a = n / x;
    int b= n % x;
    if (b > 0){
        a++;
    }
    a = a * t;
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


int main(){
    int k;
    string s;
    cin >> k >> s;

    int len = (int)s.size();
    if(len<=k){
        cout(s);
        return 0;
    }
    if(len>k){
        string t;
        t = s.substr(0,k);
        t += "..." ;
        cout(t);
    }

    return 0;
}





Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define MOD 1000000007
int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll> a(m),b(m-1);
  for(int i=0;i<m;i++) cin>>a[i];
  if(n>=m){
    cout<<0;
    return 0;
  }
  sort(a.begin(),a.end());
  for(int i=0;i<m-1;i++) b[i]=a[i+1]-a[i];
  sort(b.begin(),b.end());
  ll c=0;
  for(int i=0;i<m-n;i++) c+=b[i];
  cout<<c;
}


Measured memory_bytes: 1792
#include <iostream>
#include <typeinfo>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <chrono>
//絶対値の取得
#include <cmath>

using namespace::std;


int main() {

    //試行回数Nを取得
    int n;
    cin >> n;

    //補正温度Tと目標温度Aを取得
    int t, a;
    cin >> t >> a;

    //N回分ループして、H1からHnまでを取得する
    int h, i=0, szh[n-1];
    while(n > i)
    {
        cin >> h;
        szh[i] = h;
        //cout << szh[i] << endl;
        i++;
    }

    //bestTemperatureにAを代入
    double bestTemperature = 999, bestPoint = 1, tempTemperature;
    //Nかいループ
    for(int i=0, j= 0; n > i; i++, j++)
    {
        tempTemperature = t - (szh[j] * 0.006);
        //cout << "tempTemperature is " << tempTemperature << endl;

        if(bestTemperature > abs(a - tempTemperature))
        {
            
            bestTemperature = abs(a- tempTemperature);

            bestPoint = j;

            //cout << "bestTemperature is " << bestTemperature << endl;
            //cout << "bestPoint(+1) is " << bestPoint+1 << endl;
        }
    }


    cout << bestPoint+1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    string s; cin >> s;
    s[3] = '8';
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
    int x, a; std::cin >> x >> a;
    std::cout << (x >= a) * 10 << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2435&lang=jp
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	int m; cin >> m;
	string op = "+-/*";
	map<string, int> name_idx;
	vector<pair<int, int>> name(m + 1);
	for (int i = 1; i <= m; i++) {
		string _name; int lb, ub;
		cin >> _name >> lb >> ub;
		name_idx[_name] = i;
		name[i].first = lb; name[i].second = ub;
	}
	int n; cin >> n;
	stack<int> st_idx;
	vector<vector<int>> st(n, vector<int>(256, 0));
	for (int i = 0; i < n;i++) {
		string e; cin >> e;
		/* +-/* or value */
		if (name_idx[e] == 0) {
			if (e == "+") {
				int b_idx = st_idx.top(); st_idx.pop();
				int a_idx = st_idx.top(); st_idx.pop();
				for (int a = 0; a < 256;a++) {
					if (st[a_idx][a] == 0) continue;
					for (int b = 0; b < 256; b++) {
						if (st[b_idx][b] == 0) continue;
						st[i][(a + b) % 256] = 1;
					}
				}
			}
			else if (e == "-") {
				int b_idx = st_idx.top(); st_idx.pop();
				int a_idx = st_idx.top(); st_idx.pop();
				for (int a = 0; a < 256;a++) {
					if (st[a_idx][a] == 0) continue;
					for (int b = 0; b < 256; b++) {
						if (st[b_idx][b] == 0) continue;
						st[i][(a - b + 256) % 256] = 1;
					}
				}
			}
			else if (e == "*") {
				int b_idx = st_idx.top(); st_idx.pop();
				int a_idx = st_idx.top(); st_idx.pop();
				for (int a = 0; a < 256;a++) {
					if (st[a_idx][a] == 0) continue;
					for (int b = 0; b < 256; b++) {
						if (st[b_idx][b] == 0) continue;
						st[i][(a*b) % 256] = 1;
					}
				}
			}
			else if (e == "/") {
				int b_idx = st_idx.top(); st_idx.pop();
				int a_idx = st_idx.top(); st_idx.pop();
				for (int a = 0; a < 256;a++) {
					if (st[a_idx][a] == 0) continue;
					for (int b = 0; b < 256; b++) {
						if (st[b_idx][b] == 0) continue;
						if (b == 0) {
							cout << "error" << endl;
							return 0;
						}
						else {
							st[i][(a / b) % 256] = 1;
						}
					}
				}
			}
			else {
				st[i][atoi(e.c_str())] = 1;
			}
		}
		else {
			auto pii = name[name_idx[e]];
			for (int v = pii.first; v <= pii.second;v++) {
				st[i][v] = 1;
			}
		}
		st_idx.push(i);
	}
	cout << "correct" << endl;
	return 0;
}

Measured memory_bytes: 3336
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;

int main() {
	string s;
	cin >> s;
	rep(i, 3) {
		cout << s[i];
	}
}


Measured memory_bytes: 3628
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#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, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
int main() {

  int n, m;
  cin >> n >> m;
  if(n==m) yes();
  else no();

  return 0;
}


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

int main()
{
    int h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    
    int ans;
    ans = h2*60+m2 - (h1*60+m1+k);
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int d[MAXn],bit[MAXn];
map<int,int> pos;
int main(){
    IOS();
    int n;
    cin >> n;
    vector<int> a,b;
    for (int i=0;i<n;++i) {
        cin >> d[i];
        pos[d[i]] = i;
    }
    sort(d,d+n);
    int ans = 0;
    for (int i=0;i<n;++i) {
        if (i&1) {
            if (pos[d[i]] % 2 == 0) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8768
a=[]
for i in range(5):
  a.append(int(input()))
bs=[]
cs=[]
cnt=0
for i in range(5):
    if a[i]%10!=0:
        b=int(a[i]/10)*10+10
        c=str(a[i])[-1]
        cs.append(int(c))
    else:
        b=a[i]
        cnt+=1
    bs.append(b)
if cnt==5:
  	print(sum(a))
else:
	print(sum(bs)+min(cs)-10)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main(void) {
  int n;
  cin >> n;
  ll cnt[10][10];
  rep(i, 10) rep(j, 10) {
    cnt[i][j] = 0;
  }
  rep(i, n + 1) {
    if(i == 0)
      continue;
    int k = 1;
    int p = 0;
    while(i / k >= 10) {
      ++p;
      k *= 10;
    }
    int rd = i % 10;
    int ld = i / k;
    ++cnt[rd][ld];
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) ans += cnt[i][j] * cnt[j][i];
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

#define BIGNUMBER 1000000007

using namespace std;

int main(void) {
    string S;
    cin >> S;

    vector<vector<ll>> dp(S.size()+1, vector<ll>(4, 0));
    dp[S.size()][3] = 1;
    int m, m1, m2;
    for (int i = S.size()-1; i >= 0; i--) {
        if (S[i] == '?') {
            m = 3;
            m1 = 3;
        }
        else {
            m = 1;
            m1 = 1;
        }
        dp[i][3] = (m * dp[i+1][3]) % BIGNUMBER;
        for (int j = 2; j >= 0; j--) {
            if (S[i] == '?' || S[i] == "ABC"[j]) {
                m2 = 1;
            }
            else {
                m2 = 0;
            }
            dp[i][j] = ((m1 * dp[i+1][j]) % BIGNUMBER + (m2 * dp[i+1][j+1]) % BIGNUMBER) % BIGNUMBER;
        }
    }

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

    return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[60];
int ans[2][200];

int main() {
   int n;
   cin >> n;
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }
   int Max = 0;
   for (int i = 1; i < n; i++) {
      if ( abs(a[i]) > abs(a[Max]) ) {
         Max = i;
      }
   }

   // 全要素に足す
   cout << 2 * n - 1 << endl;
   int cnt = 0;
   for (int i = 0; i < n; i++) {
      a[i] += a[Max];
      ans[0][cnt] = Max+1, ans[1][cnt] = i+1;
      cout << Max + 1 << " " << i + 1 << endl;
      cnt++;
   }
   
   // 累積和
   if (a[Max] >= 0) {
      for (int i = 1; i < n; i++) {
         a[i] += a[i] + a[i-1];
         ans[0][cnt] = i, ans[0][cnt] = i+1;
         cout << i << " " << i + 1 << endl;
         cnt++;
      }
   } else {
      for (int i = n-2; i >= 0; i--) {
         a[i] += a[i] + a[i+1];
         ans[0][cnt] = i+2, ans[0][cnt] = i+1;
         cout << i + 2 << " " << i + 1 << endl;
         cnt++;
      }
   }

   return 0;
}

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

int main() {
	int prime[10001] = { false };
	for (int i = 2; i <= sqrt(10000); i++) {
		if(!prime[i])
			for (int j = 2; i*j <= 10000; j++) {
				prime[i*j] = true;
			}
	}
	int n;
	while (cin >> n&&n) {
		int p1=0, p2=0;
		for (int i = n;i>=0;i--) {
			if (!prime[i]) {
				p2=p1;
				p1 = i;
			}
			if (p2 - p1 == 2)break;
		}
		cout << p1 << " " << p2 << endl;
	}
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
const int MAX = 300005;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ll Pow(ll a , ll b){
	if(b == 0) return 1 ;
	ll c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c)% mod )) % mod ;
	return (c * c) % mod ;
}

//check modulo
int main(){
	IOS;
	cout.precision(50) ;
	string s  ; cin >> s ;
	int k ; cin >> k;
	int n = s.size() ;
	map<string , bool> maap ;
	for(int i = 0 ; i < n ; i++){
		string t  = "" ;
		for(int j = i ; j < min(n , i + k) ; j++){
			t += s[j] ;
			maap[t] = true ;
		}
	}
	map<string , bool> :: iterator i = maap.begin() ;
	int nb = 0 ;
	while(nb < k - 1) {i++;nb++;}
	cout << i->x << endl ;
	return 0;
}


Measured memory_bytes: 1920
n,m=map(int ,input().split())
a=[[None]*m for i in range(n)]
for i in range(n):
    a[i]=list(map(int,input().split()))
b=[None]*m
for i in range(m):
    b[i]=int(input())
for i in range(n):
    c=0
    for j in range(m):
        c+=a[i][j]*b[j]
    print(c)



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

int n;
vector<pair<lint, lint>> lr;

int main() {
    cin >> n;
    lr.resize(n);
    for (int i = 0; i < n; i++) {
        int x, tl;
        cin >> x >> tl;
        lr[i].first = x - tl;
        lr[i].second = x + tl;
    }
    sort(lr.begin(), lr.end(),
         [](const pair<lint, lint> a, const pair<lint, lint> b) {
             return a.first == b.first ? a.second < b.second
                                       : a.first > b.first;
         });
    auto now = lr.front();
    lint ans = 0;
    for (int i = 1; i < n; i++) {
        if (lr[i].second > now.first) {
            ans++;
        } else {
            now = lr[i];
        }
    }
    cout << n - ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		int result = 0;
		for(int i = 0; i < s.length(); i++){
		    if(s.charAt(i) == '1') result++;
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21716
/**********************************
Sometimes the people whom no one ever imagines anything of,
do the things that no one can ever imagine.
***********************************/
#include <bits/stdc++.h>
using namespace std;

#define EPS (1e-12)
#define li long int
#define ll long long int
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pi 3.141592653589
#define prlia(a,L,R) for(li i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define prli2d(a,r,c) for(li i=0;i<r;i++) for(li j=0;j<c;j++) cout<<a[i][j]<<(j==c-1?'\n':' ')
#define pcase cout<<"Case "<<++cs<<": "
const int mod=1e9+7;
ll gcd(ll a,ll b){while(b){ll x=a%b;a=b;b=x;}return a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}


// C++ program to demonstrate sorting in vector of
// pair according to 1st element of pair in
// descending order


// Driver function to sort the vector elements by
// first element of pair in descending order
bool sortinrev(const pair<int,int> &a,
			const pair<int,int> &b)
{
	return (a.second  < b.second);
}

int main()
{
	// declaring vector of pairs
	int i,n=5,k,j,ans=0,ck=0;
	vector< pair <int,int> > vect;


	// initializing 1st and 2nd element of
	// pairs with array values

	// Entering values in vector of pairs
	for (int i=0; i<n; i++){
            cin >> k;
               j=k%10;
		vect.push_back( make_pair(k,j) );
	}

//	// Printing the original vector(before sort())
//	cout << "The vector before applying sort is:\n" ;
//	for (int i=0; i<n; i++)
//	{
//		// "first" and "second" are used to access
//		// 1st and 2nd element of pair respectively
//		cout << vect[i].first << " "
//			<< vect[i].second << endl;
//
//	}

	// using modified sort() function to sort
	sort(vect.begin(), vect.end(), sortinrev);

	// Printing the sorted vector(after using sort())
	//cout << "The vector after applying sort is:\n" ;
//	for (int i=0; i<n; i++)
//	{
//		// "first" and "second" are used to access
//		// 1st and 2nd element of pair respectively
//		cout << vect[i].first << " "
//			<< vect[i].second << endl;
//	}
	for(i=0;i<n;i++){
        if(vect[i].second == 0) {ans+=vect[i].first;}
        else if(ck==0) {ans+=vect[i].first;ck=1;}
        else  {
            ans=ans+vect[i].first+(10-vect[i].second);
        }
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long lint;

int n, a[200004];

lint f(int k) {
	lint ans = 0;
	for (int i=0; i<n; i++) ans += abs(a[i] - (k+i+1));
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];

	lint l = -3e6, r = 1e9;
	while (l+3<r) {
		int lm = (l*2+r)/3, rm = (l+r*2)/3;
		if (f(lm) > f(rm)) l = lm;
		else r = rm;
	}

	lint mn = 1e18;
	for (int i=l; i<=r; i++) mn = min(mn, f(i));


	cout << mn;
}


Measured memory_bytes: 1024
n = int(input())
zahyou = list(map(int,input().split()))
loss = 0
ans = 0
minimum = min(zahyou)
maximum = max(zahyou)
for i in range(minimum, maximum+1):
    loss = 0
    for j in zahyou:
        loss += (j-i)**2
        
    if i == minimum:
        ans = loss
    if loss < ans:
        ans = loss
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vi a(m);
    rep(i,m) cin  >> a[i];
    int xleft = 0, xright = 0;
    for(int i =0; i < m; i++) {
        if(a[i] < x) xleft ++;
        else xright ++;
    }
    cout << min(xleft, xright) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <complex>
#include <vector>
#define push push_back
#define sz stack.size()
#define m make_pair
#define N_MAX 100001
#define x second
#define y first
using namespace std;
typedef complex<int> point;
typedef pair<int,int> P;
 
bool ccw(point p0,point p1,point p2){
  point temp;
  p1-=p0;
  p2-=p0;
  temp=p1;
  p1*=conj(temp);
  p2*=conj(temp);
  if(abs(temp)==0) return true;
  p1/=abs(temp);
  if(p2.imag()>0) return false;
  if(p2.imag()<0) return true;
  p2/=abs(temp);
  return true;
}

int main(){
  int n;
  P p[N_MAX];
  vector<P> stack;
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
  sort(p,p+n);
  stack.push(p[0]);
  stack.push(p[1]);
  for(int i=2;i<n;i++){
    point c=point(p[i].x,p[i].y);
    while(sz>=2&&!ccw(point(stack[sz-2].x,stack[sz-2].y),point(stack[sz-1].x,stack[sz-1].y),c)) stack.pop_back();
    stack.push(p[i]);
  }
  for(int i=n-2;i>=0;i--){
    point c=point(p[i].x,p[i].y);
    while(sz>=2&&!ccw(point(stack[sz-2].x,stack[sz-2].y),point(stack[sz-1].x,stack[sz-1].y),c)) stack.pop_back();
    stack.push(p[i]);
  }
  stack.erase(stack.begin());
  cout<<stack.size()<<endl;
  for(int i=sz-1;i>=0;i--) cout<<stack[i].x<<' '<<stack[i].y<<endl;
  return 0;
}

Measured memory_bytes: 2828
fun main(args:Array<String>) {
    val (w,h,x,y) = readLine()!!.split(" ").map { it.toLong() }
    val menseki = w*h/2.0
    var isFukusuu = 0
    if(w%2 == 0L && h%2 == 0L) {
        if(w/2 == x && h / 2 == y) {
            isFukusuu = 1
        }
    }
    println("%s %s".format(menseki, isFukusuu))
}


Measured memory_bytes: 37824
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x = Long.parseLong(sc.next());
    long y = Long.parseLong(sc.next());
    long now = x;
    long len = 0L;
    while(now<=y){
      len++;
      now*=2;
    }
    
    System.out.println(len);
	System.out.flush();

  }
}

Measured memory_bytes: 25172
#include<iostream>
#include<math.h>
using namespace std;
#define N 100

int main(){
   int n;
   float a[N];
   cin>>n;
   float sum = 0;
   for(int i = 0; i < n ; ++i){
        cin>>a[i];
        sum+=a[i];
   }
   float avg = sum/n;
   int res = 0;
   float minx = 100000;
   for(int i = 0; i <n ;++i){
        if(fabs(a[i] - avg) < minx){
           res = i;
           minx = fabs(a[i] - avg);
        }
   }
   cout<<res;
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int grid1 = sc.nextInt();
		int grid2 = sc.nextInt();
		int grid3 = sc.nextInt();
		String result ;
		if( grid1 < grid2 ) {
			result = grid1 < grid3 && grid3 < grid2 ? "Yes" : "No";
		} else {
			result = grid2 < grid3 && grid3 < grid1 ? "Yes" : "No";
			
		}
		System.out.println(result);
	    
		sc.close();
	}
}


Measured memory_bytes: 22740
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

s = str(input())
g,p = 0,0
ans = 0
for i in range(len(s)):
    if s[i] == "g":
        if g > p:
            ans += 1
            p += 1
        else:
            g += 1
    else:
        if g > p:
            p += 1
        else:
            ans -= 1
            g += 1

print(ans)


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  int64 n, m;
  cin >> n >> m;
  vector<PLL> v(n), rob(m);
  REP(i, n) v[i] = PLL(i, i+1);
  REP(i, m) {
    cin >> rob[i].fs >> rob[i].sc; rob[i].sc--;
  }
  sort(all(rob));
  REP(i, m) {
    int64 idx = rob[i].sc;
    v[idx] = PLL(v[idx].fs, v[idx+1].sc);
    v[idx+1] = PLL(v[idx].fs, v[idx+1].sc);
  }
  REP(i, n) {
    cout << v[i].sc-v[i].fs << (i < n-1 ? " " : "");
  }
  cout << endl;
}


Measured memory_bytes: 7512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int N;
    cin >> N;
    int P[N],Q[N];
    rep(i,N){
        cin >> P[i];
    }
    rep(i,N){
        cin >> Q[i];
    }
    int ref[N]={0};
    reps(i,N){
        ref[i-1] = i;
    }
    int a=0,b=0;
    int count = 0;
    int cona = 0;
    int conb = 0;

    do{
        rep(i,N){
            if(ref[i]==P[i]){
                cona ++;
            }else{
                cona =0;
            }
            if(cona==N){
                a = count;
                cona =0;
            }

            if(ref[i]==Q[i]){
                conb ++;
            }else{
                conb =0;
            }
            if(conb==N){
                b = count;
                conb =0;
            }
        }
        count++;



    }while(next_permutation(ref,ref+N));
    int res=abs(a-b);
    
    cout <<res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool sieve[10000000];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

    int m, n;
    while (cin >> m >> n)
    {
        if (m == 0 && n == 0)
            break;

        for (int i = 0; i < 10000000; ++i)
            sieve[i] = true;
        for (int i = m - 1; i >= 0; --i)
            sieve[i] = false;

        int i = m;
        for (; i < 10000000; ++i)
        {
            if (sieve[i] == true)
            {
                if (n == 0)
                    break;

                n--;

                for (int j = 2; j * i < 10000000; ++j)
                {
                    sieve[i * j] = false;
                }
            }
        }
        cout << i << endl;
    }
    int c;
    cin >> c;
    return 0;
}


Measured memory_bytes: 12820
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,x,y = inpl()
x -= 1; y -= 1
ans = [0] * (n-1)
for i in range(n-1):
    for j in range(i+1,n):
        if i == j: continue
        res = j - i 
        res = min(res, abs(x-i) + abs(y-j) + 1)
        ans[res-1] += 1
print(*ans)


Measured memory_bytes: 71256
import numpy as np
from numba import njit, i8

S = input()
MOD = 10 ** 9 + 7

dp = np.zeros(13, dtype=int)
dp[0] = 1


@njit(cache=True)
def q_mark(dp):
    new_dp = np.zeros(13, dtype=i8)
    for i in range(13):
        new_dp[np.arange(i, i + 10) % 13] += dp[i]
        new_dp %= MOD
    return new_dp


for s in S:
    # 4 == pow(10, -1, 13)
    dp = dp[np.arange(0, 52, 4) % 13]
    if s == '?':
        dp = q_mark(dp)
    else:
        dp = np.roll(dp, int(s))
print(dp[5])


Measured memory_bytes: 114492
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
  
int main () {
    int a,b,n,i;
    char c;
    string str,s,f,g;
    cin >> str;
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> s >>a >> b;
        if(s[2]=='i'){cout << str.substr(a,b-a+1) << endl;}
        else if(s[2]=='v'){
            f=str.substr(a,b-a+1);
            reverse(f.begin(),f.end());
            str = str.replace(a,b-a+1,f);
        }
        else if(s[2]=='p'){
            cin >> g;
            str = str.replace(a,b-a+1,g);
        }
    }
}

Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5e5 + 10;
#define fi first
#define se second
#define pb push_back
char a[N];
int b[N];
int L[N],R[N];
int main() {
    ios::sync_with_stdio(false);
    cin>>a+1;
    int n=strlen(a+1);
    L[n+1]=0;R[n+1]=1e9;
    for(int i=n;i>=1;i--){
        if(a[i]=='>'){
            L[i]=L[i+1]+1;
            R[i]=1e9;
        }else{
            L[i]=0;
            R[i]=R[i+1]-1;
        }
    }
    LL ans=0;
    ans+=L[1];int pre=L[1];
    for(int i=1;i<=n;i++){
        //cout<<pre<<' ';
        if(a[i]=='>'){
            pre=max(L[i+1],0);
            ans+=pre;
        }else {
            pre=max(L[i+1],pre+1);
            ans+=pre;
        }

    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    string s;
    int q;
    cin >> s >> q;
    deque<char> chars{s[0]};
    for(int i=1; i < (int)s.length(); i++){
        chars.push_back(s[i]);
    }
    int rev = 0;
    for (int i = 0; i < q; i++)
    {
        int t;
        cin >> t;
        if(t == 1)rev++;
        else if(t == 2){
            int f;
            char c;
            cin >> f >> c;
            if(rev%2 == 0 && f == 1)chars.push_front(c);
            else if(rev%2 == 0 && f == 2)chars.push_back(c);
            else if(rev%2 == 1 && f == 1)chars.push_back(c);
            else chars.push_front(c);
        }
    }
    string ans = "";
    if(rev%2 == 0){
        for(auto c :chars)ans += c;
        // for(auto itr = chars.begin(); itr != chars.end(); ++itr){
        //     ans += *itr;
        // }
        // ans += *chars.end(); 
    }
    else if(rev%2 == 1){
        reverse(chars.begin(), chars.end());
        for(auto c :chars)ans += c;
        // for(auto itr = chars.end(); itr != chars.begin(); --itr){
        //     ans += *itr;
        // }
        // ans += *chars.begin(); 
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,m;
    cin >> n >> m;
    vector<ll>h(n);
    for(ll i=0;i<n;i++){
        cin >> h[i];
    }
    vector<ll>g(n,1);
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        a--;
        b--;
        if(h[a]<=h[b]) g[a]=0;
        if(h[b]<=h[a]) g[b]=0;
    }
    ll cnt=0;
    for(ll i=0;i<n;i++){
        cnt+=g[i];
    }
    cout << cnt << endl;
}

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

int main() {
 ll n,k; cin >> n >> k;
 if(k==0){
   cout << n*n << endl;
   return 0;
 }

 ll cnt=0;
 for(ll i=k+1;i<=n;i++){
   ll p=n/i; ll q=n%i;
   cnt+=p*(i-k);
   cnt+=max(0LL,q-k+1);
 }
 cout << cnt << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n,m;cin>>n>>m;
    vector<pair<int,int>> ba(m);
    rep(i,0,m-1){
        int a, b;
        cin>>a>>b;
        ba[i] = {b, a};
    }
    sort(all(ba));
    int tmp = 0;
    int ans = 0;
    for(pair<int,int> p: ba){
        int l = p.second;
        int r = p.first;
        if(tmp < l){
            ++ans;
            tmp = r - 1;
        }
    }
    
    cout<<ans<<endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int cntDiv(int n){
	int ans = 0;
	for (int i= 1;i*i<=n;i+=2){
		if(n%i==0){
			if(i*i==n)ans++;
			else ans +=2;
		}
	}
	return ans;
}
bool goodx[110],goody[110];
string a[110];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int x1,y1,x2,y2,x3,y3,x4,y4;
	scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
	int x = x2;
	int y = y2;
	int dx = x2-x1;
	int dy = y2-y1;
	REP(i,2){
		swap(dx,dy);
		dx = -dx;
		x+=dx;
		y+=dy;
		cout << x << ' ' << y << ' ';
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[200010];
long long f[200010];
long long g[200010];
long long get(int x) {
    if (x <= 0) return 0;
    return f[x];
}
int main() {
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        if (i) g[i] = g[i-1];
        if (i%2==0) g[i]+= a[i];
    }
    for (i = 0; i < n; i++) {
        if ((i+1)%2==0) {
            f[i]=max(a[i]+get(i-2),g[i-1]);
        } else {
            f[i]=max(a[i]+get(i-2),f[i-1]);
        }
    }
    printf("%lld\n", f[n-1]);
    return 0;
}


Measured memory_bytes: 5616