akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
int main()
{
    Hello
    ll n, k;
    cin >> n >> k;
    n++;
    ll curL = 1, curR = n, l = 1, r = n, ans = 0;
    for(int i = 1; i <= n; i++){
        if(k <= i){
            ans = (ans + (curR - curL + 1)) % mod;
        }
        l++;
        r--;
        curL += l;
        curR += r;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n1) for(int i=0;i<n1;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define yesno(flg) if(flg){cout<<'YES'<<endl;}else{cout<<'NO'<<endl;}
#define vi vector<int>
#define pb push_back
#define i197 1000000007
#define MAX_N 200002
#define PI 3.141592653589793
using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<Pii,int> Piii;
typedef pair<int,ll> Pil;
typedef pair<ll,ll> Pll;
typedef pair<string,int> Psi;
typedef pair<Psi,int> Psii;

const ll inf=1000000007;
struct edge{
	int myc,to,c,cost;
};
struct pos{
	int to,cost,color;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

vi vec[200001];
int x[200001]={};
int dp[200001];

int main() {
	int n;
	string s;
	cin>>n;
	cin>>s;
	rep(i,s.size()){
		int k=(int)s[i]-65;
		cout<<(char)((k+n)%26+65);
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K= sc.nextInt();
		int A [] = new int [N];
	    
	    for(int i = 0; i < N; i++) {
	    	A[i]=sc.nextInt();
	    }
	    sc.close();
	    Arrays.sort(A);
	    
	    int min = 1_000_000_007;
	    for(int i = 0; i < N-K+1; i++) {
	    	min = Math.min(A[i+K-1]-A[i], min);
	    }
	    System.out.println(min);
	}

}


Measured memory_bytes: 52216
/*まずうちさあ屋上あんだけど、焼いてかない？*/
	#include <bits/stdc++.h>
	using namespace std;
	#define IOS ios::sync_with_stdio(false), cin.tie(0)
	#define REP(i, n) for (int i = 0; i < n; i++)
	#define FOR(i, a, b) for (int i = a; i < b; i++)
	#define ALL(x) (x).begin(), (x).end()
	#define dump(x) cout << (x) << endl
	#define LMAX 9223372036854775807LL
	#define LMIN -9223372036854775807LL

	using ll = long long;
	template<typename T>
	using vec = vector<T>;
	using P = pair<ll, ll>;

	template <typename A, size_t N, typename T>
	void Fill(A (&array)[N], const T &val){
		fill((T *)array, (T *)(array + N), val);
	}
	
	const ll INF = 1e18;
	const ll mod = 1e9 + 7;

	//int dx[4] = {1,0,-1,0};
	//int dy[4] = {0,1,0,-1};
	//ll pas[51][52];
	ll dp[114514][4] = {};
	signed main(){
		IOS;
		string s;
		cin >> s;
		ll ans = 0;
		int n = s.size();
		dp[0][0] = 1;
		REP(i,n){
			char x = s[i];
			if(x == 'A' || x == '?'){
				dp[i + 1][0] += dp[i][0];
				dp[i + 1][1] += dp[i][1];
				dp[i + 1][2] += dp[i][2];
				dp[i + 1][3] += dp[i][3];
				dp[i + 1][1] += dp[i][0];
			}
			if(x == 'B' || x == '?'){
				dp[i + 1][0] += dp[i][0];
				dp[i + 1][1] += dp[i][1];
				dp[i + 1][2] += dp[i][2];
				dp[i + 1][3] += dp[i][3];
				dp[i + 1][2] += dp[i][1];
			}
			if(x == 'C' || x == '?'){
				dp[i + 1][0] += dp[i][0];
				dp[i + 1][1] += dp[i][1];
				dp[i + 1][2] += dp[i][2];
				dp[i + 1][3] += dp[i][3];
				dp[i + 1][3] += dp[i][2];
			}
			REP(j, 4)dp[i + 1][j] %= mod;		
		}
		dump(dp[n][3]);
	}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
using sl = signed long;
using sll = signed long long;
using ll = long long;

int main(int argc, char *argv[])
{
	string st;
	cin >> st;
	int length = st.size();
	string ans ="Yes";

	for(int i = 0; i<st.size(); i++){
		if(i%2==1){
			if(st[i]== 'R'){
				ans = "No";
				break;
			}
		}else{
			if(st[i]== 'L'){
				ans = "No";
				break;
			}
		}
	}

	cout << ans ;
	return 0;
}

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

ll gcd(ll a, ll b){
    if(a % b == 0) return b;
    return gcd(b, a % b);
}

int main(){
    ll N; cin >> N;
    ll w;
    for(ll i = 1; i <= 3500; i++){
        for(ll j = 1; j <= 3500; j++){
            ll s = i + j, m = i * j;
            if(gcd(4*m - N*s, N*m) == 4*m - N*s){
                w = N*m/gcd(4*m - N*s, N*m);
                if(w < 0) continue;
                cout << i << " " << j << " " << w << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    string S;
    cin >> S;

    int length = S.length();
    if(S[length-1]!='s') S = S + "s";
    else S = S + "es";

    cout << S << endl;

}

Measured memory_bytes: 3624
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint b(n-1);
    REP(i,n-1)cin >> b[i];
    int ans = 0;
    ans+=b[0];
    for(int i=1;i<n-1;i++){
        ans+=min(b[i-1],b[i]);
    }
    ans+=b[n-2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a, const void *b)
{
    return (*(int *)a)-(*(int *)b);
}

int main()
{
    int n;
    int temp=scanf("%d",&n);
    int a[n];
    for(int i=0; i<n; i++)
        temp=scanf("%d",&a[i]);
    qsort(a,n,sizeof(int),cmp);
    int count=0;
    for(int i=0; i<n-2; i++)
    {
        for(int j=i+1; j<n-1; j++)
        {
            for(int k=j+1; k<n; k++)
            {
                if((a[i]+a[j]>a[k])&&(a[i]!=a[j]&&a[j]!=a[k]))
                    count++;
            }
        }
    }
    printf("%d\n",count);
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
int dp[100005][3];

int sol(int i,int l,int n,int A[][3]){
  if(dp[l][i]!=-1) return dp[l][i];
  if(l==n) return A[n-1][i];

  if(i==0){
    dp[l][i]= A[l-1][i] +max(sol(1,l+1,n,A),sol(2,l+1,n,A));
    return dp[l][i];
  }
  if(i==1){
    dp[l][i]= A[l-1][i] +max(sol(0,l+1,n,A),sol(2,l+1,n,A));
    return dp[l][i];
  }
  if(i==2){
    dp[l][i]= A[l-1][i] +max(sol(0,l+1,n,A),sol(1,l+1,n,A));
    return dp[l][i];
  }

}




int32_t main(){
IOS
int n;
cin>>n;
int A[n][3];
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++){
  for(int j=0;j<3;j++){
    cin>>A[i][j];
  }
}

int mx=0;
for(int i=0;i<3;i++){
  mx = max(mx,sol(i,1,n,A));
}
  cout <<mx<<endl;


 return 0;
}

 

Measured memory_bytes: 13744
s = input()
s = s.split()
n = []

for i in s:
    n.append(int(i))

isSorted = False

while(not isSorted):
    isSorted = True
    for i in range(4):
        if n[i] < n[i + 1]:
            temp = n[i]
            n[i] = n[i + 1]
            n[i + 1] = temp
            isSorted = False

print(n[0],n[1],n[2],n[3],n[4])


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int q[4]={0,1,-1,0};
int e[4]={1,0,0,-1};
int main(){
  ll h,w;
  cin>>h>>w;
  vector<vector<char>> t(h+2,vector<char> (w+2,'.'));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      char a;
      cin>>a;
      t[i][j]=a;
    }
  }
  
  for(int i=1;i<h+1;i++){
    for(int j=1;j<=w;j++){
      if(t[i][j]=='#'){
        ll cu=1;
        rep(u,4){
          int nx=i+q[u];
int ny=j+e[u];
          if(t[nx][ny]=='#'){
            cu=0;
          }
        }
        if(cu){
          COUT("No");
          return 0;
        }
      }
    }
  }
  COUT("Yes");
}


Measured memory_bytes: 256
#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 n,m;
    cin>>n>>m;
    vector<int>to[n];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    for(int u:to[0]){
        if(count(to[u].begin(),to[u].end(),n-1)!=0){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 12016
import java.util.Scanner;
import java.util.HashMap;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        long sum = 0;
        long[] memo = new long[n];
        for (int i = 0; i < n; i++) {
            sum += Integer.parseInt(sc.next());
            memo[i] = sum;
        }

        HashMap<Long, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(memo[i])) {
                map.put(memo[i], map.get(memo[i]) + 1);
            } else {
                map.put(memo[i], 1L);
            }
        }

        long count = 0;
        for (Long key : map.keySet()) {
            long num = map.get(key);
            if (key == 0) {
                count += num;
            }
            count += num * (num - 1) / 2;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 63472
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>

using namespace std;
using llong = long long;
const int MOD=1000000007;


int main(int argc, char**argv){
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    int x = accumulate(l.begin(), l.end(), 0) - l[n-1];

    if (l[n-1] - x < 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}














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

int main(){
	long long A,B,N;
	cin >> A >> B >> N;
	
	long long x=(N+1)/B*B-1,y=N;
	if(x<0)x=1;
	
	cout << max(A*x/B-A*(x/B),A*y/B-A*(y/B));
	
	return 0;
}

Measured memory_bytes: 3568
n,m = map(int,input().split())

students = [[int(i) for i in input().split()] for _ in range(n)]
checkpoints = [[int(i) for i in input().split()] for _ in range(m)]

d = []
for i in range(n) :
    d.clear()
    ans = 0
    for j in range(m) :
        x = abs(students[i][0]-checkpoints[j][0])+abs(students[i][1]-checkpoints[j][1])
        d.append(x)
    ans = d.index(min(d))+1
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

int main() {
  int k, ans = 0;std::cin >> k;
  std::vector<int> num(k+1);
  for(int i=k;i>0;i--){
    int t = k/i;
    num[i] += t*t*t;
    for(int j=2;j*j<=i;j++){
      if(i%j!=0) continue;
      num[j] -= num[i];
      if(j*j!=i) num[i/j] -= num[i];
    }
    if(i!=1) num[1] -= num[i];
    ans += num[i] * i;
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
// #include <math.h>
#include <cmath>
// #include <unordered_map>
using namespace std;
typedef long long int lli;
#define M_PI_H  3.14159265358979323846/2  /* pi by two*/



int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	
	int h1, m1, h2, m2, k;
	cin>>h1>>m1>>h2>>m2>>k;

	int a = 60 - m1;
	int hrs = (h2-h1-1)*60;
	int tot = a + hrs + m2;

	cout<<tot-k;

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[335101];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
//string r;
char r[3];

P u[300101];
queue<P> q;
stack<int> s;
//set<int> s;
map<int,int> p;

vector<int> v[3];


bool as(P a,P b)
{
  //if(a.x!=b.x)
  //return a.x<b.x;
  //return a.y>b.y;
  return a.y-a.x<b.y-b.x;
}

void f(int n,int m)
{
  for(;n<m;)
  {
    if(n%2) o[n++]++;
    else if(m%2==0) o[m--]++;
    else n/=2,m/=2;
  }
  o[n]++;
}

int g(int n)
{
  int k=0;
  for(;n;n/=2)
  {
    k+=o[n];
  }
  return k;
}

int main()
{
  scanf("%d %d",&b,&a);
  for(int t=1;t<=b;t++)
  {
    scanf("%d %d",&n,&m);
    u[t]={n,m};
  }
  sort(u+1,u+b+1,as);
  c=1;
  for(i=1;i<100000;i*=2);
  for(int t=1;t<=a;t++)
  {
    for(;c<=b&&u[c].y-u[c].x<t;c++)
      f(u[c].x+i-1,u[c].y+i-1);
    k=0;
    for(int w=t;w<=a;w+=t)
    {
      k+=g(w+i-1);
    }
    printf("%d\n",k+b+1-c);
  }
}
//0
//21




Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

ll gcd(ll a, ll b) {
    if(b==0)
        return a;
    return gcd(b, a%b);
}
 

 
 
void solve(){
 
  int n,M;
    cin>>n>>M;
    int a,b;
    if(M%2==0){
        a=M/2;
        b=M/2;
    }else{
        a=M/2;
        b=M-a;
    }
    for(int i=1;i<=a;++i){
        cout<<i<<" "<<2*a+2-i<<endl;
    }
    for(int i=1;i<=b;++i){
        cout<<i+2*a+1<<" "<<M*2+2-i<<endl;
    }


}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
   //  cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

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

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

struct Data {
    int x, y, r, c;
    Data(int _x, int _y, int _r, int _c)
        : x(_x), y(_y), r(_r), c(_c) {}
    Data() {}
};

int pw2(int n) {
    return n * n;
}

bool inside(Data &d1, Data &d2) {
    return (pw2(d1.x - d2.x) + pw2(d1.y - d2.y)) < pw2(d1.r + d2.r);
}

int bitcount(int a) {
    int res = 0;
    while (a) {
        res += a % 2;
        a >>= 1;
    }
    return res;
}

int main() {
    int n;
    while (cin >> n, n) {
        vector<Data> circles(n);
        REP(i, 0, n) {
            int x, y, r, c;
            cin >> x >> y >> r >> c;
            circles[i] = Data(x, y, r, c);
        }
        vector<bool> memo(1 << n, false);
        function<bool(int, int, int)> check = [&](int state, int a, int b) -> bool {
            bool ok = true;
            REP(i, 0, a) {
                if (state & (1 << i)) {
                    ok &= (!inside(circles[i], circles[a]));
                }
            }
            REP(i, 0, b) {
                if (state & (1 << i)) {
                    ok &= (!inside(circles[i], circles[b]));
                }
            }
            return ok;
        };
        function<void(int)> rec = [&](int state) {
            if (memo[state]) return;
            memo[state] = true;
            REP(i, 0, n) {
                REP(j, i + 1, n) {
                    if (circles[i].c == circles[j].c) {
                        int a = 1 << i, b = 1 << j;
                        if (((state & a) != a) || ((state & b) != b)) continue;
                        if (check(state, i, j)) {
                            rec(state ^ a ^ b);
                        }
                    }
                }
            }
        };
        rec((1 << n) - 1);
        int ans = 0;
        REP(i, 0, 1 << n) {
            if (memo[i]) {
                ans = max(ans, n - bitcount(i));
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5016
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>

using namespace std;

int main ()
{
  string str;
  cin >> str;
  int count[26] = {0};

  for(auto ch : str) {
    if (count[ch - 'a'] == 1) {
      printf("no\n");
      return 0;
    }
    count[ch - 'a'] ++;
  }
  printf ("yes\n");
}


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

#define INF 100000000




int main(){
    int x,y,z;
    cin>>x>>y>>z;

    x -= z;
    int ans = 0;

    while(x>=y+z){
        x -= y + z;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <numeric>
#include <iomanip>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>

///////////////////////////////////////////////////////////////
// namespace
///////////////////////////////////////////////////////////////
using namespace std;
// namespace mp = boost::multiprecision;

///////////////////////////////////////////////////////////////
// types
///////////////////////////////////////////////////////////////
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
// using mpi = mp::cpp_int;
// using mpf = mp::number<mp::cpp_dec_float<1024>>;

/////////////////////////////////////////////////////////////////
// https://github.com/atcoder-live/library/blob/master/mint.cpp
/////////////////////////////////////////////////////////////////
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

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


int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    int m = N / 2;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    if (N % 2 == 0) {
        int med_a = A[m-1] + A[m];
        int med_b = B[m-1] + B[m];
        cout << med_b - med_a + 1 << endl;
    } else {
        int med_a = A[m];
        int med_b = B[m];
        cout << med_b - med_a + 1 << endl;
    }
    // cout << setprecision(10);
    return 0;
}


Measured memory_bytes: 4764
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;


int main(void)
{
    int n,k;
    cin >>n >>k;

    vector<int> v;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >>tmp;
        v.push_back(tmp);
    }

    set<vector<int> > allPick;
    vector<int> left;
    for(int i = -1; i < n; i++){
        vector<int> right;
        right.clear();
        if(i >= 0){
            left.push_back(v[i]);
        }
        for(int j = n; j > 0; j--){
            if(i+(n-j) >= min(n, k)){
                continue;
            }
            if(j <= n-1){
                right.push_back(v[j]);
            }
            vector<int> tmpv = left;
            tmpv.insert(tmpv.end(), right.begin(), right.end());
            sort(tmpv.begin(), tmpv.end());
            allPick.insert(tmpv);

        }
    }

    int maxScore = 0;
    for(set<vector<int> >::iterator it = allPick.begin(); it != allPick.end(); it++){
        vector<int> tp = *it;
        int ignore = k - tp.size();
        int currentScore = 0;
        for(int i = 0; i < tp.size(); i++){
            //printf("%d ", tp[i]);
            if(tp[i] < 0 && ignore > 0){
                ignore--;
                continue;
            }
            currentScore += tp[i];
        }
        //printf("\n");
        maxScore = max(maxScore, currentScore);
    }

    printf("%d\n", maxScore);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    ll h,w;
    cin >> h >> w;
    if(h==1 || w == 1){
        cout << 1 << endl;
        return 0;
    }
    cout << (h*w+1)/2 << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      m: usize,
      abcs: [(usize, usize, i64); m],
    }
    const INF: i64 = 1 << 62;

    let mut ds = vec![INF; n];
    ds[0] = 0;
    for i in 0..n+1 {
        let mut ok = false;
        for e in 0..m {
            let (a, b, c) = abcs[e];
            if ds[a-1] != INF {
                if ds[a-1] - c < ds[b-1] {
                    ds[b-1] = ds[a-1] - c;
                    ok = true;
                    if i == n && b == n {
                        println!("{}", "inf");
                        return;
                    }
                }
            }
        }
        if !ok {
            break;
        }
    }
    println!("{}", ds[n-1]*-1);
}


Measured memory_bytes: 4352
import std.functional,
       std.algorithm,
       std.container,
       std.typetuple,
       std.typecons,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

void main() {
  int[] HW = readln.chomp.split.to!(int[]);
  int H = HW[0],
      W = HW[1];
  int[] hw = readln.chomp.split.to!(int[]);
  int h = hw[0],
      w = hw[1];

  writeln((H - h) * (W - w));
}

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

int	main(void)
{
  	int	k;
  	char	s[101];
  	int	len;
  	int	i;
  
  	scanf("%d\n", &k);
  	scanf("%s", s);
  
  	len = strlen(s);
  
  	if (k >= len)
    {
      	printf("%s", s);
    }
  	else
    {
      	for(i=0; i<k; i++)
        {
          	printf("%c", s[i]);
        }
      	printf("...");
    }
  	return (0);
}

Measured memory_bytes: 1732
#include <map>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

template<class T>
class IdMaker{
public:
  std::map<T,int> _m;
  int getId(const T &v){
    if(_m.find(v) == _m.end()){
      int next = _m.size();
      return _m[v] = next;
    }
    return _m[v];
  }
};

int V[7];
int P[7];

int L[7];
int X[7];
int Y[7];

int Q[7][7];

int dist(int x1, int y1, int x2, int y2){
  return abs(x1 - x2) + abs(y1 - y2);
}

int main(){
  int n, m, w, t;
  IdMaker<string> idm;

  cin >> n >> m >> w >> t;

  vector<long long> dpa(t + 1);

  REP(i, m){
    string s; cin >> s;
    cin >> V[idm.getId(s)] >> P[idm.getId(s)];
  }

  REP(i, n){
    cin >> L[i] >> X[i] >> Y[i];

    REP(j, L[i]){
      string r; cin >> r;
      cin >> Q[i][idm.getId(r)];
    }
  }

  REP(i, (1 << n)){
    vector<int> v;
    REP(j, n) if(i & (1 << j))
      v.push_back(j);

    int t_memo = INT_MAX;
    long long m_memo = 0;

    do{
      int px = 0;
      int py = 0;

      int tm = 0;

      REP(j, v.size()){
        tm += dist(px, py, X[v[j]], Y[v[j]]);
        px = X[v[j]]; py = Y[v[j]];
      }
      tm += dist(px, py, 0, 0);

      t_memo = min(t_memo, tm);
    }while(next_permutation(v.begin(), v.end()));

    // cout << "i=" << i << " : tm=" << t_memo << endl;

    vector<long long> dp(w + 1);

    REP(i, v.size()){
      REP(j, m) if(Q[v[i]][j]){
        int weight = V[j];
        int earn   = P[j] - Q[v[i]][j];

        if(earn <= 0) continue;

        REP(k, w){
          if(k + weight > w) break;
          dp[k + weight] = max(dp[k + weight], dp[k] + earn);
        }
      }
    }

    REP(k, w + 1)
      m_memo = max(m_memo, dp[k]);

    REP(k, t + 1){
      if(k + t_memo > t) break;
      dpa[k + t_memo] = max(dpa[k + t_memo], dpa[k] + m_memo);
    }
  }

  long long ans = 0;

  REP(i, t + 1){
    // cout << "dpa[" << i << "]: " << dpa[i] << endl;
    ans = max(ans, dpa[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define int long long
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}



signed main(){
    int n;
    cin >> n;
    vector<int>a(n),b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    ll dst[51][51]={};
    Fill(dst,(ll)1<<53);
    rep(i,51)dst[i][i] = 0;
    for(int i=1;i<51;i++){
        for(int j=0;j<51;j++){
            dst[j][j%i] = min(dst[j][j%i],(ll)1<<i);
        }
    }
    for(int k=0;k<51;k++){
        for(int i=0;i<51;i++){
            for(int j=0;j<51;j++){
                dst[i][j] = min(dst[i][j],dst[i][k]+dst[k][j]);
            }
        }
    }
    bool flag =0;
    ll ans = 0;
    while(1){
        ll ma = 0;
        rep(i,n){
            ma = max(dst[a[i]][b[i]],ma);
        }
        if(ma==(ll)1<<53){
            flag = 1;
            break;
        }
        if(ma==0){
            break;
        }
        int k = 0;
        for(int i=0;i<51;i++){
            if(ma&((ll)1<<i)){
                k = i;
            }
        }
        ans += (ll)1<<k;
        for(int i=0;i<51;i++){
            dst[i][i%k] = min(dst[i][i%k],(ll)0);
        }
        for(int k=0;k<51;k++){
            for(int i=0;i<51;i++){
                for(int j=0;j<51;j++){
                    dst[i][j] = min(dst[i][j],dst[i][k]+dst[k][j]);
                }
            }
        }

    }
    if(flag){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

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

int main()
{
	int n,m,sum=0,t=0;
	cin>>n>>m;
	
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	
	for(int i=1;i<=n;i++)
	   {
	     sum+=a[i];
	   }
	   
	  int  digit=ceil(sum*1.0/4/m);
	   
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=digit)
		t++;
	}
	
	if(t>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
	
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	int n, a[100000];
	scanf("%d", &n);
	for(int i = 0, j; i < n; ++i)
	{
		scanf("%d", &j);
		a[j - 1] = i + 1;
	}
	for(int i = 0; i < n; ++i)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
}


Measured memory_bytes: 1152
from collections import defaultdict
from math import gcd
import time
import sys
from collections import Counter
import itertools
import math
# read = sys.stdin.buffer.read
# readline = sys.stdin.buffer.readline
# readlines = sys.stdin.buffer.readlines
input = sys.stdin.readline

start = time.time()
N = int(input())
A = list(map(int, input().split(' ')))
Asum = [i+A[i] for i in range(N)]
Adif = [i-A[i] for i in range(N)]

ans = 0
d = defaultdict(int)
for i in range(N):
    ans += d[Adif[i]]
    d[Asum[i]] += 1

print(ans)


Measured memory_bytes: 155608
N = int(input())
l = list()

for n in range(N):
    a = input()
    l.append(a)

l_uniq = list(set(l))

if len(l) == len(l_uniq):
    for i in range(0, N-1):
        if l[i+1][0] != l[i][-1]:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")
    


Measured memory_bytes: 3060
import math

D,G = map(int,input().split())
pc = [list(map(int,input().split()))for _ in range(D)]

digit = "0"+str(D)+"b"
ans = float("INF")
for i in range(2**D):
  flags = list(str(format(i,digit)))
  points = 0
  problems = 0
  last0 = -1
  #まずは完答組での点数を算出
  for j in range(D):
    if int(flags[j]):
      points += pc[j][0]*100*(j+1)+pc[j][1]
      problems += pc[j][0]
    else:
      last0 = j
  if points >= G:
    ans = min(ans,problems)
    continue
  elif last0 == -1:
    continue
  else:
    r = G-points
    need = math.ceil(r/(100*(last0+1)))
    if need > pc[last0][0]-1:
      continue
    else:
      ans = min(ans,problems+need)
      
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python3

import collections

h,w=map(int,input().split())
sy,sx=map(int,input().split())
gy,gx=map(int,input().split())
board=[['#']*(w+2)]+[list('#'+input()+'#') for _ in range(h)]+[['#']*(w+2)]
checked=[[False]*(w+1) for _ in range(h+1)]
checked[sy][sx]=True
q=collections.deque()
q.append((sy,sx))
ans=0
while 1:
  cur_pos=[]
  while len(q)!=0:
    y,x=q.popleft()
    cur_pos.append((y,x))
    for dy,dx in [[-1,0],[1,0],[0,-1],[0,1]]:
      if 1<=y+dy<=h and 1<=x+dx<=w and board[y+dy][x+dx]=='.' and checked[y+dy][x+dx]==False:
        checked[y+dy][x+dx]=True
        q.append((y+dy,x+dx))
  if checked[gy][gx]==True:
    print(ans)
    exit()
  if len(cur_pos)==0:
    print(-1)
    exit()
  ans+=1
  for y,x in cur_pos:
    for dy in range(-2,3):
      for dx in range(-2,3):
        if dy==0 and dx==0:
          continue
        if 1<=y+dy<=h and 1<=x+dx<=w and board[y+dy][x+dx]=='.' and checked[y+dy][x+dx]==False:
          checked[y+dy][x+dx]=True
          q.append((y+dy,x+dx))

Measured memory_bytes: 130204
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  if(s%10==3)cout<<"bon"<<endl;
  else if(s%10==0||s%10==1||s%10==6||s%10==8) cout<<"pon"<<endl;
  else cout<<"hon"<<endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <set>

using namespace std;
int n,a[100010];
bool solve(int k){
	multiset<int> m;
	for(int i=0;i<k;i++){
		m.insert(-1);
	}
	for(int i=0;i<n;i++){
		int x = *m.begin();
		if(x>=a[i]) return false;
		auto it = m.lower_bound(a[i]);
		it--;
		m.erase(it); m.insert(a[i]);
	}
	return true;
}

int main(){
	int i;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	int l = 0,r = n;
	while(r - l>1){
		int mid = (l + r)/2;
		if(solve(mid)) r = mid;
		else l = mid;
	}
	cout << r << endl;
}

Measured memory_bytes: 7296
#131 C
import sys
import fractions
a,b,c,d = map(int, sys.stdin.readline().split())
#print(a,b,c,d)

dc = b//c - (a-1)//c
dd = b//d - (a-1)//d
lcm = (c*d)//fractions.gcd(c, d)

dcd = b//lcm -(a-1)//lcm
#print(dc, dd, dcd)

ans = b-(a-1) -(dc+dd) + dcd
print(int(ans))

Measured memory_bytes: 5344
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];

  rep(k, n - m + 1) {
    rep(l, n - m + 1) {
      bool flag = true;
      rep(i, m) {
        rep(j, m) {
          if (a[k + i][l + j] != b[i][j]) {
            flag = false;
            break;
          }
        }
      }
      if (flag) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  
  return 0;
}

Measured memory_bytes: 256
K = int(input())
ans = [False for _ in range(K)]
num = 0
p = 7%K
for i in range(K+1):
    num += p
    p = (p*10)%K
    if ans[num%K] == False:
        ans[num%K] = True
    else:
        print("-1")
        break
    if num%K == 0:
        print(i+1)
        break

Measured memory_bytes: 140436
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define ld long double
#define F first
#define S second
int const M=2e5+10,mod=1e9+7,inf=1e9+10;
int n,a[M],ans[M];
pii cur[M];
main()
{
	int n;
	cin>>n;
	int maxx=0,tmp=-1,sv=0;
	for(int i=1;i<=n;i++)cin>>a[i],maxx=max(a[i],maxx);
	for(int i=1;i<=n;i++)
	{
		if(a[i]==maxx)continue;
		int hlp=min(a[i],maxx-a[i]);
		if(hlp>tmp)sv=a[i],tmp=hlp;
	}
	cout<<maxx<<" "<<sv;
}

Measured memory_bytes: 2304
def primeFac(n):
	res = {1}
	for i in range(2, int(n**0.5) + 1):
		while n % i == 0:
			n //= i
			res.add(i)
		if n <= 1:
			break
	if n > 1:
		res.add(n)
	return res

a, b = map(int, input().split())
res = primeFac(a) & primeFac(b)
print(len(res))

Measured memory_bytes: 39024
s = input()
a = ['A','C','G','T']
c = 0
j = 0

for i in range(len(s)):
    if s[i] in a:
        j += 1
    else:
        if j > c:
            c = j
            j = 0

if j > c:
    print(j)
else:
    print(c)

Measured memory_bytes: 9060
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n,m;
    cin >> n >> m;
    cout << n * m << endl;
    return 0;
}


Measured memory_bytes: 3100
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#include <unordered_map>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);

    vector< vector<int> > G(N);
    vector<int> C(N);
    for(int i=0; i<N; i++) scanf("%d", &C[i]), C[i]--;

    for(int i=0; i+1<N; i++) {
        int u, v; scanf("%d%d", &u, &v);
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    vector<ll> ans(N, 1LL*N*(N+1)/2);
    vector<int> sub(N), near(N, -1), newest(N, -1), depth(N);
    vector< unordered_map<int, int> > rec(N);
    auto dfs = [&](auto &&self, int cur, int par) -> void {
        sub[cur] = 1;
        near[cur] = newest[ C[cur] ];
        int v = newest[ C[cur] ];
        newest[ C[cur] ] = cur;
        for(auto to : G[cur]) {
            if(to == par) continue;
            depth[to] = depth[cur] + 1;
            self(self, to, cur);
            if(rec[to].count(C[cur])) {
                ll v = sub[to] - rec[to][ C[cur] ];
                ans[ C[cur] ] -= v*(v+1)/2;                
            }
            else {
                ll v = sub[to];
                ans[ C[cur] ] -= v*(v+1)/2;
            }
            if(rec[cur].size() < rec[to].size()) swap(rec[cur], rec[to]);
            for(auto e : rec[to]) rec[cur][e.first] += e.second;
            sub[cur] += sub[to];
        }
        rec[cur][ C[cur] ] = sub[cur];        
        newest[ C[cur] ] = v;
    };

    dfs(dfs, 0, -1);
    vector<int> vs(N);
    iota(vs.begin(), vs.end(), 0);
    sort(vs.begin(), vs.end(), [&](auto x, auto y) {
            return depth[x] > depth[y];
        });

    {
        vector<ll> sz(N, N);
        for(auto v : vs) {
            if(near[v] == -1) sz[ C[v] ] -= sub[v];
        }
        for(int i=0; i<N; i++) {
            ans[i] -= sz[i]*(sz[i]+1)/2;
        }
    }
    
    for(int i=0; i<N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 70408
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,m,n) for(int i=m;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	ll n;
	cin>>n;
	ll max_d=1;
	for(ll i=1;i<=sqrt(n);i++){
		if(n%i==0){
			max_d = i;
		}
	}
	cout<<max_d+(n/max_d)-2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

/*
 * 問題文
 *
 * すぬけくんとアライグマは N 枚のカードの山を作りました。
 * カードの山の上から i 番目のカードには整数 aiが書かれています。
 * N枚のカードを分け合うことにしました。 
 * すぬけくんがカードの山の上から何枚かのカードを取ったあと、アライグマは残ったカード全てを取ります。 
 * このとき、すぬけくんもアライグマも 1枚以上のカードを取る必要があります。
 * すぬけくんとアライグマが持っているカードに書かれた数の総和をそれぞれ x,yとして、|x - y| を最小化したいです。 
 * |x - y| としてありうる値の最小値を求めなさい。

 *  黒の面に0、白の面に1が書かれた N個のオセロの駒が、どの駒も黒の面が上を向くように一列に並べられています。
 *  その後、ある区間にある駒を全て裏返すという操作が Q 回だけ行なわれました。 
 *  具体的には i 回目の操作においては、左から li 番目の駒から ri番目の駒までの駒全てが裏返されました。
 *  最終的な盤面を求めてください。
 *
 */

long long N;
vector<long long> S;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N ;
	for(int i=0; i<N; i++){
		long long u;
		cin >> u;
		if(i == 0){
			S.push_back(u);
		}
		else{
			S.push_back(S[i - 1] + u); //累積和
		}
	}

	long long ans = (1LL<<61);
	for(int i=0; i<N - 1; i++){
		long long a = S[i];
		long long b = S[N - 1] - S[i];
		long long c = abs(a - b);
		if(ans > c){
			ans = c;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2420
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main()
{
    optimize_cin();
 
    lint N; cin >> N;
    lint x; cin >> x;
    vector<lint> a(N);
    rep (i, N) { cin >> a[i]; }
 
    lint cnt = 0;

    if (a[0] > x)
    {
        cnt += a[0] - x;
        a[0] = x;
    }
    for (lint i = 0; i < N - 1; ++i)
    {
        bool flag = true;
        while (a[i] + a[i+1] > x)
        {
            if (flag)
            {
                cnt += a[i+1] - (x - a[i]);
                a[i+1] = x - a[i];
            }
            else 
            {
                cnt += a[i] - (x - a[i+1]);
                a[i] = x - a[i+1];
            }
            flag = false;
        }
    }
 
    cout << cnt << "\n";
 
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>

using namespace std;

int main(){

  string s;

  while(1){
    getline(cin,s);
  
    for(int i=0;i<s.length();i++){
      if(s[i]=='a' && s.substr(i+1,4)=="pple"){
	s.replace(i,5,"peach");
      }else if(s[i]=='p' && s.substr(i+1,4)=="each"){
	s.replace(i,5,"apple");
      }
    }
    break;
  }
  cout << s << endl;
}



Measured memory_bytes: 3164
import sys
N =int(input())
t = [0]
x = [0]
y = [0]
for i in range(N):
    tmp_t,tmp_x,tmp_y = map(int,input().split())
    t.append(tmp_t)
    x.append(tmp_x)
    y.append(tmp_y)
for i in range(1,N+1):
    distance = abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
    if t[i]-t[i-1] < distance or (distance+(t[i]-t[i-1]))%2 != 0 :
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 11812
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

bool isEven(string s){
  int n = s.size();
  if(n%2) return 0;
  string left = "";
  string right = "";
  rep(i,n/2) left.push_back(s[i]);
  rep(i,n/2) right.push_back(s[i+n/2]);
  return left==right;
}

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for(int i=0;i<n-1;i++){
    string tmp = "";
    for(int j=0;j<=i;j++){
      tmp.push_back(s[j]);
    }
    if(isEven(tmp)) ans = i+1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
    char s[10];
    int n,i,j;
    scanf("%s",s);
    if(s[0]==s[1]&&s[1]==s[2])printf("Yes\n");
    else if(s[1]==s[2]&&s[2]==s[3])printf("Yes\n");
    else printf("No\n");
}


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

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

int gcd(int x, int y, int z)
{
    return gcd(gcd(x, y), z);
}

int main()
{
    int k;
    cin >> k;
    int ans = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += gcd(a, b, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n,m; cin >> n >> m;
    vector<bitset<10>> sw(m,0);
    rep(i,m){
        ll k ; cin >> k; 
        rep(j,k){
            ll s;  cin >> s; s--;
            sw.at(i).set(s,1);
        }
    }
    vector<ll> p(m);
    rep(i,m) cin>>p.at(i);
    ll ans = 0;

    for(int i=0;i<(1<<n);i++){
        bitset<10> a(i);
        bool flag = true;
        rep(j,m){
            bitset<10> x = (sw.at(j) & a);
            //cout << x << endl;
            if((x.count()%2)!=p.at(j)) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
S = input()

s1, s2 = int(S[:2]), int(S[2:])

if 1 <= s1 <= 12:
    if 1 <= s2 <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= s2 <= 12:
        print('YYMM')
    else:
        print('NA')


Measured memory_bytes: 2940