akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define maxn 100
#define int long long int
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

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

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x)
{ //bit計算
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num)
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
signed main()
{
    int H, W, N;
    cin >> H >> W >> N;
    int a[N];
    rep(i, N)
    {
        cin >> a[i];
    }
    int ans[H][W];
    int place = 0;
    rep(i, H)
    {
        int j;
        for (j = 0; j < W; j++)
        {
            for (place = 0; place < N; place++)
            {
                if (a[place] > 0)
                {
                    break;
                }
            }
            ans[i][j] = place + 1;
            a[place]--;
        }
    }
    rep(i, H)
    {
        if (i % 2 == 0)
        {
            rep(j, W)
            {
                cout << ans[i][j] << " ";
            }
        }
        else
        {
            for (int j = W - 1; j >= 0; j--)
            {
                cout << ans[i][j] << " ";
            }
        }
        cout << endl;
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

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<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

inline int topbit(unsigned long long x){
    return x?63-__builtin_clzll(x):-1;
}

inline int popcount(unsigned long long x){
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x){
    return __builtin_parity(x);
}

signed main(){
    char c;cin>>c;
    c++;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  int s[5], sum = 0;
  for(int i = 0; i < 5; ++i) {
	cin >> s[i];
	if(s[i] < 40) s[i] = 40;
	sum += s[i];
  }
  cout << sum / 5 << endl;
  return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#define AC ios_base::sync_with_stdio(0),cin.tie(0)
#define ll unsigned long long 
using namespace std;
int main(){
	AC;
	ll n,m;
	cin>>m>>n;
	if(m==1 || n==1){
		cout<<1<<"\n";
		return 0;
	}
	ll ans=0;
	ans=((m+1)/2)*((n+1)/2)+((m/2)*(n/2));
	cout<<ans<<"\n";
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define maxn 200100
int cnt[maxn];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		if(u==1) cnt[v]+=1;
		if(v==n) cnt[u]+=2;
	}
	for(int i=1;i<=n;++i)
	{
		if(cnt[i]==3)
		{
			puts("POSSIBLE");
			exit(0);
		}
	}
	puts("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long moder = 1000000007;
long long fac[100005];
int main(){
	long long n,m;
	cin>>n>>m;
	if(n<m) swap(n,m);
	if(n-m>=2){
		cout<<0;
		return 0;
	}
	fac[0] = 1;
	for(int i=1; i<=n+1; i++){
		fac[i]=fac[i-1]*i;
		fac[i]%=moder;
	}
	long long ret = fac[n]*fac[m];
	if(n==m){
		ret%=moder;
		ret*=2;
		cout<<ret%moder;
	}
	else{
		cout<<ret%moder;
	}
}

Measured memory_bytes: 4332
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,d,i;
set<string>st;
string s;
cin>>a;
for(i=1;i<=a;i++)
{cin>>s;st.insert(s);
}
cout<<st.size()<<endl;
}

Measured memory_bytes: 19160
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	S = input()
	if N % 2 != 0:
		print("No")
	else:
		M = N // 2
		judge = "Yes"
		for i in range(M):
			if S[i] != S[i + M]:
				judge = "No"
		print(judge)
	

if __name__ == '__main__':
	main()

Measured memory_bytes: 3444
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        if((N & 1) == 0){
            double p = N*1.0/(2*N);
            println(p);
        }
        else{
            double p = (N+1)*1.0/(2*N);
            println(p);
        }
        
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 23252
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        int X = N;
        for(int i=0;i<N;i++){
            A[i] = int.Parse(str[i]);
            X = Math.Min(X,A[i]);
        }
        int S = 0;
        int L = 0;
        for(int i=0;i<N;i++){
            if(A[i] == X){
                S++;
            }
            else if(A[i] == X+1){
                L++;
            }
            else{
                sb.Append("No\n");
                return;
            }
        }
        if(L == 0){
            if(X == N-1 || X*2 <= N){
                sb.Append("Yes\n");
            }
            else{
                sb.Append("No\n");
            }
        }
        else{
            X++;
            if(S+1 <= X && X <= S+L/2){
                sb.Append("Yes\n");   
            }
            else{
                sb.Append("No\n");
            }
        }
    }
}

Measured memory_bytes: 18912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
const ll INF = (1ll << 60);
const ll MOD = 1000000007;
int main() {
  string s; cin>>s;
  ll x,y; cin>>x>>y;
  ll N=s.length();
  vi v; v.PB(-1); REP(i,N) if(s[i]=='T') v.PB(i); v.PB(N);
  vi a;
  for(ll i=0;i<v.size()-1;i++) {
    a.PB(v[i+1]-v[i]-1);
  }

  vi b,c;
  for(ll i=0;i<a.size();i++) if(i%2) b.PB(a[i]);
  for(ll i=0;i<a.size();i++) if(i%2==0) c.PB(a[i]);

  vector<US<ll>> st(b.size()+1);
  st[0].insert(0);
  for(ll i=0;i<b.size();i++) {
    for(ll j:st[i]) {
      st[i+1].insert(j+b[i]);
      st[i+1].insert(j-b[i]);
    }
  }

  vector<US<ll>> st2(c.size()+1);
  st2[0].insert(0);
  if(c.size()) st2[1].insert(c[0]);
  for(ll i=1;i<c.size();i++) {
    for(ll j:st2[i]) {
      st2[i+1].insert(j+c[i]);
      st2[i+1].insert(j-c[i]);
    }
  }


  if (st[b.size()].find(y)==st[b.size()].end()||st2[c.size()].find(x)==st[c.size()].end()) {
    cout<<"No"<<endl;
    return 0;
  }

  cout<<"Yes"<<endl;
}


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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans2 = 0;
    if (x * 2 == w && y * 2 == h)
        ans2 = 1;
    cout << w * h / 2.0 << " " << ans2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int S[MAX], n;
int binarySearch(int, int);

int main(){
  int i, q, count = 0, T[MAX];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
    if(binarySearch(n, T[i]) == 1) count++;
  }
  printf("%d\n",count);

  return 0;
}

int binarySearch(int n, int key){
  int left, right, mid;
  left = 0;
  right = n;
  while(left < right){
    mid = (left + right) / 2;
    if(key == S[mid]) return 1;
    if(key > S[mid]) left = mid + 1;
    else if(key < S[mid]) right = mid;
  }
  return 0;
}

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

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

int main(void) {
  int N, K;
  scanf("%d %d", &N, &K);

  int XY[N][2];
  int Xs[N], Ys[N];
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &XY[i][0], &XY[i][1]);
    Xs[i] = XY[i][0];
    Ys[i] = XY[i][1];
  }
  qsort(Xs, N, sizeof(int), cmp);
  qsort(Ys, N, sizeof(int), cmp);

  unsigned long long ans = -1;

  for (int l = 0; l < N-1; ++l) {
    for (int r = l + 1; r < N; ++r) {
      for (int d = 0; d < N-1; ++d) {
        for (int u = d + 1; u < N; ++u) {
          int ll = Xs[l], rr = Xs[r];
          int dd = Ys[d], uu = Ys[u];
          unsigned long long area = (unsigned long long)(rr - ll) * (uu - dd);
          // printf("ll:%d, rr:%d, dd:%d, uu:%d, area:%llu\n", ll, rr, dd, uu, area);
          if (area >= ans)
            continue;

          int sum = 0;
          for (int i = 0; i < N; ++i) {
            int x = XY[i][0];
            int y = XY[i][1];
            if (ll <= x && x <= rr && dd <= y && y <= uu)
              ++sum;
            if (sum >= K) {
              ans = area;
              break;
            }
          }
        }
      }
    }
  }

  printf("%llu\n", ans);
}


Measured memory_bytes: 128
/* ex 7_1
   offNaria */

#include <stdio.h>

typedef struct point
{
    int x_elem;
    int y_elem;
} point;

//b-aベクトルをaを中心として反時計まわりに90度回転し，始点をbにしたものの終点を計算する関数
point shift_point(point a, point b);

int main(void)
{
    point p_1, p_2, p_3, p_4;
    scanf("%d %d %d %d", &p_1.x_elem, &p_1.y_elem, &p_2.x_elem, &p_2.y_elem);
    p_3 = shift_point(p_1, p_2); //p_2-p_1ベクトルをp_1を中心として反時計回りに90度回転し，始点をp_2としたベクトルの終点がp_3
    p_4 = shift_point(p_2, p_3); //p_3-p_2ベクトルをp_2を中心として反時計回りに90度回転し，始点をp_3としたベクトルの終点がp_4
    printf("%d %d %d %d\n", p_3.x_elem, p_3.y_elem, p_4.x_elem, p_4.y_elem);
    return 0;
}

point shift_point(point a, point b)
{
    point rotatedVec = {b.x_elem + (a.y_elem - b.y_elem), b.y_elem + (b.x_elem - a.x_elem)};
    return rotatedVec;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int n;
string w;
set<string>ss;
int main(){
	cin>>n;
	char c;
	for(int i=0;i<n;i++){
		cin>>w;
		if(ss.count(w)==0){
			if(i!=0&&c!=w[0]){
				cout<<"No";
				return 0;
			}
			c=w[w.size()-1];
			ss.insert(w);
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

/*
sからtへの3の倍数の経路のうち最小のものを出力する

1 -> 2 を
1 -> 5
2 -> 6
3 -> 4

深さ優先探索
進められる辺がなくなるまで、以下を繰り返す
1. スタート地点から伸びる辺を選択し、sを訪問済みにセットして、辺の先の頂点をスタックに追加
2. 以後、スタックの上にある頂点が未到達なら到達済みに変更した上で辺の先の頂点をスタックに追加
なお、未到達の管理は配列に整数値を格納することで行う. デフォルトでは-1、到達したら最短距離を格納
*/

void solve(){
    ll n,m;
    cin >> n >> m;
    vector<ll> g[n*3+10];
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        g[3*a-2].emplace_back(3*b-1);
        g[3*a-1].emplace_back(3*b);
        g[3*a].emplace_back(3*b-2);
    }
    ll s,t;
    cin >> s >> t;

    ll visited[3*n+10];
    rep(i,3*n+1){
        visited[i]=-1;
    }
    /*
    stack<ll> st;
    st.push(s*3-2);
    visited[s*3-2]=0;
    while(!st.empty()){
        ll tmp = st.top();
        st.pop();
        for(auto i:g[tmp]){
            if(visited[i]==-1){
                visited[i]=visited[tmp]+1;
                st.push(i);
            }
        }
    }
    */
    queue<ll> st;
    st.push(s*3-2);
    visited[s*3-2]=0;
    while(!st.empty()){
        ll tmp = st.front();
        st.pop();
        for(auto i:g[tmp]){
            if(visited[i]==-1){
                visited[i]=visited[tmp]+1;
                st.push(i);
            }
        }
    }
    
    if(visited[t*3-2]!=-1) cout << visited[t*3-2]/3 << endl;
    else cout << -1 << endl;

}

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

Measured memory_bytes: 19072
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>

/* template start */
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, unsigned long long b) {
  if(b==0)return 1;
  if (a==0)return 0;
  Num x = 1;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

using ll = long long;

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

  ll x,n;
  std::cin>>x>>n;

  std::set<ll> p;
  rep(i,0,n){
    ll e;
    std::cin>>e;
    p.insert(e);
  }

  rep(i,0,100){
    if(p.find(x-i)==p.end()){
      std::cout<<x-i<<"\n";
      return 0;
    }
    if(p.find(x+i)==p.end()){
      std::cout<<x+i<<"\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<int> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    int n;
    int x[102], y[102];
    int xx, yy, hh;
    ll h[102];
    cin >> n;
    REP(i, n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] == 0)continue;
        xx = x[i];
        yy = y[i];
        hh = h[i];
    }
    REP(px, 101)REP(py, 101){
        int ah;
        ah = abs(px - xx) + abs(py - yy) + hh;
        bool flag = true;
        REP(i, n){
            ll ch;
            ch = ah - abs(px - x[i]) - abs(py - y[i]);
            if(ch > 0){
                if(ch != h[i]){
                    flag = false;
                    break;
                }
            }else{
                if(h[i]!=0){
                    flag = false;
                    break;
                }
            }
        }
        if(flag){
            cout << px << " " << py << " " << ah << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1000000007;
const ll INF=1e15;
const int BIG=1e7;


int m[100001];
vector<pair<int,int>> d[100001];

void dfs(int x){
    int N=d[x].size();
    for(int i=0;i<N;i++){
        int a=d[x].at(i).first;
        if(m[a]==BIG) {
            m[a]=(m[x]+d[x].at(i).second)%2;
            dfs(a);
        }
    }
    return;
}
int main(){
    int N;
    cin>>N;
    for(int i=2;i<100001;i++) m[i]=BIG;
    for(int i=0;i<N-1;i++){
        int a,b,w;
        cin>>a>>b>>w;
        d[a].push_back(make_pair(b,w%2));
        d[b].push_back(make_pair(a,w%2));
    }
    dfs(1);
    for(int i=1;i<=N;i++) cout<<m[i]<<endl;

}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=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 {
        mint res(*this);
        return res/=a;
    }
};

//n -> big, a -> small
mint choose(int n,int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}
int main(){
    cout << fixed << setprecision(10);
       int x,y;
    cin >> x >> y;
    if((x+y)%3!=0) cout<<0<<endl;
    else{
        int n1 = (2*x-y)/3;
        int n2 = (2*y-x)/3;
        if(n1<0 || n2<0){
            cout<<0<<endl;
            return 0;
        }else{
            cout<<choose(n1+n2,n1).x<<endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 256
package main

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

var scanner *bufio.Scanner

func printIt() {
	for {
		word := nextString()
		if word == "-" {
			break
		}
		wordByte := []byte(word)
		n := nextInt()
		for i := 0; i < n; i++ {
			idx := nextInt()
			wordByte = append(wordByte[idx:], wordByte[:idx]...)
		}
		fmt.Println(string(wordByte))
	}
}

func nextInt() int {
	scanner.Scan()
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(1)
	}
	return num
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	printIt()
}



Measured memory_bytes: 1096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double pi = Math.PI;
        double r = sc.nextDouble();
        double area = r * r * pi;
        double length = 2 * r * pi;
        System.out.printf ("%f %f\n", area, length);
        sc.close();
    }
}


Measured memory_bytes: 28088
n = int(input())

p = list(map(int,input().split()))

c = 0
for i in range(n-1):
    if(p[i] == i+1 and p[i+1] == i+2):
        p[i],p[i+1] = p[i+1],p[i]
        c += 1
for i in range(n):
    if(p[i] == i+1):c += 1
print(c)


Measured memory_bytes: 14004
N = int(input())
A = [[x - 1 for x in list(map(int, input().split()))] for i in range(N)]

days = 0
cand = set(range(N))

while True:
    games = set() # その日に試合ができるプレイヤーの集合
    
    for p in cand:
        if A[p] != []:
            if A[ A[p][0] ][0] == p:
                games.add(p)
                games.add(A[p][0])
            
    # print(A)
    
    if not games: # その日の試合が開催されない
        if any(A): # 未だ組み合わせ希望が残っている
            print(-1) # 大会の組み合わせ希望は不可能
            break
        else: # 大会が終了
            print(days)
            break
    else:
        for i in games:
            A[i].pop(0)

    days += 1
    cand = games # 前日試合をした選手の中から、その日試合する選手を選択

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

using namespace std;

typedef pair<int, int> P;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<P> pt(m);
  for(int i = 0; i < m; i++) cin >> pt[i].first >> pt[i].second;
  sort(pt.begin(), pt.end());
  int up[n], lw[n];
  for(int i = 0; i < n; i++) up[i] = lw[i] = i;
  for(int i = 0; i < m; i++) {
    P p = pt[i];
    up[p.second] = up[p.second - 1];
    lw[p.second - 1] = lw[p.second];
  }
  for(int i = 0; i < n; i++) cout << lw[i] -up[i] + 1 << (i==n-1 ? '\n':' ');

  return 0;
}

Measured memory_bytes: 5132
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009 /// I wanna be the wind
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    ll cont=0;
    ll maior=0;
    rep(i,0,sz(s)){
        if(s[i]=='R')cont++;
        else cont=0;
        maior=max(cont,maior);
    }
    cout<<maior<<'\n';
    return 0;  
}   

Measured memory_bytes: 3612
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	string S, T;
	cin>>S>>T;
	int n = S.length();
	int m = T.length();
	int ans = 10000;
	for (int i=0; i<=n-m; i++){
		int count = 0;
		for (int j=0; j<m; j++){
			if(S[j + i]  != T[j])	count++;
		}
		ans = min(ans, count);
	}
	cout<<ans;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll N;
    cin>>N;
    long double nn=sqrt(N);
    ll ans=1e18;
    for(int i=1; i<=nn; ++i){
        if(N%i==0){
            ans=min(ans,i+(N/i)-2);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;

namespace PrintTestCases
{

	class PrintTestCases
	{
		static void Main()
		{
            int tmp;
            int i = 0;
            ArrayList data = new ArrayList();

            while (true)
            {
                tmp = int.Parse(Console.ReadLine());
                if (tmp == 0) break;
                data.Add(tmp);
            }

            for(i = 0; i < data.Count; i++)
            {
                Console.WriteLine("Case " + (i+1) + ": " + data[i]);
            }
			
		}
	}

}

Measured memory_bytes: 9944
#include <bits/stdc++.h>
 
using namespace std;
 
#define boost                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long int
// #define int ll
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for (auto &z : v)
#define sp << ' ' <<
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353
#define PI_2 1.57079632679489661923

#define N 1000005

int main() {
    ll tt = 1, n, m, l, r, c, i, j, k, w, x, y;
    boost;
    
    // cin >> tt;
    ll ans = 1001;
    vi spf(N, 0);

    spf[1] = 1;
    for(i = 2; i < N; i++){
        if(spf[i]) continue;
        spf[i] = i;

        for(j = i*i; j < N; j += i){
            if(spf[j] != 0) continue;
            spf[j] = i;
        }
    }

    for(int _ = 1; _ <= tt; _++) {
        // cout << "Case #" << _ << ": ";
        cin >> n;
        vi arr(n);
        loop(z, arr) cin >> z;
        bool poss = 1;

        unordered_set<int> primes;
        for(i = n - 1; i >= 0 and poss; i--){
            r = arr[i];

            while(r > 1){
                l = spf[r];

                if(primes.find(l) != primes.end()){
                    poss = 0;
                    break;
                }
                primes.insert(l);
                c = l;
                while(r > 1 and l == c) r = r/l, l = spf[r];
            }
        }

        if(poss) cout << "pairwise coprime" << nl;
        else{
            ll gcd = arr[0];
            for(auto &z: arr) gcd = __gcd(gcd, z);

            if(gcd == 1) cout << "setwise coprime" << nl;
            else cout << "not coprime" << nl;
        }

    }
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    forn(i, 0, n) cin >> a[i];
    ll x = 0, y = 0;
    forn(i, 0, n) y += a[i];
    ll ans = LINF;
    forn(i, 0, n) {
        x += a[i];
        y -= a[i];
        if (i != n - 1)
            setmin(ans, abs(x - y));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

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

	int br = 0;
	int par = 0;
	while ( n-- ){
		int a;
		cin>>a;

		if ( a % 2 == 0 ){
			par++;
			if ( a % 3 == 0 || a % 5 == 0 ){
				br++;
			}
		}
	}

	if ( br == par ){
		cout<<"APPROVED"<<endl;
	}else{
		cout<<"DENIED"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
 
  int n;
  cin>>n;
  int a[n];
  rep(i,0,n) cin>>a[i];
  int x=0;
  rep(i,0,n) if(a[i]!=i+1)x++;
  if(x<=2) cout<<"YES";
  else cout<<"NO";


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
using Graph = vector<vector<int>>;

int main() {
  //入力
  int N,M;
  cin >> N >> M;
  vector<int> vec[M];
  FOR(i,0,M) {
    int k; cin >> k;
    vec[i].resize(k); //resizeは便利
    FOR(j,0,k) {
      cin >> vec[i][j];
      vec[i][j]--;
    }
  }
  int p[M];
  FOR(i,0,M) cin >> p[i];
  
  //bit探索
  int ans = 0;
  
  for(int bit=0; bit<(1<<N); bit++) {
    bool ok = true; //デフォはtrue(一度でも条件を満たさなかったときにfalseに切り替わる)
    FOR(j,0,M) {
      int c=0;
      for(int id: vec[j]) { //こうすればループ回数を知らなくて良い
        if((bit >> id) & 1) c++; //そのスイッチがオンかどうか
      }
      c %= 2;
      if(c != p[j]) ok = false;
    }
    if(ok) ans++;
  }
  
  cout << ans << endl;
        
  
  
  
  return 0;
}

Measured memory_bytes: 3632
// AOJ 3101 Shortest Crypt
// 2019.9.23 bal4u

#include <stdio.h>
#include <string.h>
#include <ctype.h>

//// 入出力関係
#if 1
#define gc() getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#else
#define gc() getchar()
#define pc(x) putchar(x)
#endif

int in() {  // 整数の入力
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力　スペース以下の文字で入力終了
	do *s = gc();
	while (*s++ > ' ');
	*(s-1) = 0;
}

void out(int n) { // 非負整数の表示（出力）
	int i; char b[30];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

#define ABS(a)  ((a)>=0?(a):-(a))
char S[100005];
signed char c[128];

int main()
{
	int i, e, n, N;

	memset(c, 1, sizeof(c));
	for (i = 'N'; i <= 'Z'; i++) c[i] = -1;
	for (i = 'n'; i <= 'z'; i++) c[i] = -1;
	N = in(), ins(S);
	e = n = 0;
	for (i = 0; i < N; i++) {
		if (isupper(S[i])) n += c[S[i]];
		else               e += c[S[i]];
	}
	out(i = ABS(n)+ABS(e));
	if (i > 0) {
		if (n > 0) while (n--) pc('A');
		else if (n < 0) { n = -n; while (n--) pc('Z'); }
		if (e > 0) while (e--) pc('a');
		else if (e < 0) { e = -e; while (e--) pc('z'); }
		pc('\n');
	}
	return 0;
}



Measured memory_bytes: 2100
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
	int v;
	color[u] = GRAY;
	d[u] = ++tt;
	for(v = 0;v < n;v++){
		if(M[u][v]==0) continue;
		if(color[v]==WHITE){
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++tt;
}

void dfs(){
	int u;
	for(u=0;u<n;u++) color[u] = WHITE;
	tt = 0;

	for(u=0;u<n;u++){
		if(color[u]==WHITE) dfs_visit(u);
	}
	for(u=0;u<n;u++){
		printf("%d %d %d\n",u+1,d[u],f[u]);
	}
}

int main(){
	int u,v,k,i,j;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++) M[i][j] = 0;
	}

	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
	getchar();getchar();
}

Measured memory_bytes: 636
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, B, C):
    ans = 0
    pa = -2
    for a in A:
        ans += B[a-1]
        if pa == a-1:
            ans += C[a-2]
        pa = a
    return ans


def main():
    N = read_int()
    A = read_int_n()
    B = read_int_n()
    C = read_int_n()
    print(slv(N, A, B, C))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6732
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var inputs = Console.ReadLine().Split(' ');
        var A = new List<long>(inputs.Length);
        int minusCount = 0;
        long min = long.MaxValue;
        long sum = 0;
        for (int i = 0; i < inputs.Length; i++)
        {
            A.Add(long.Parse(inputs[i]));
            if (A[i] < 0) minusCount++;
            min = Math.Min(Math.Abs(A[i]), min);
            sum += Math.Abs(A[i]);
        }

        if (minusCount % 2 != 0)
        {
            sum -= 2 * min;
        }

        Console.WriteLine(sum);
    }

}



Measured memory_bytes: 27740
#include <stdio.h>

int main( void ) {
	int i, e, ee, x, y, z, min;

	while ( scanf( "%d", &e ), e ) {
		min = e;
		for ( z = 0; z * z * z <= e; z++ ) {
			ee = e - z * z * z;
			for ( y = 0; y * y <= ee; y++ ) {
				x = ee - y * y;

				if ( x + y + z < min )
					min = x + y + z;
			}
		}

		printf( "%d\n", min );
	}

	return 0;
}

Measured memory_bytes: 600
"""

https://atcoder.jp/contests/agc013/tasks/agc013_c

蟻がカードを持っていて、すれ違う際にカードを交換すると考える
T秒後にどの蟻がどのカードを持っているか考えればいい

Tが大きいため、良い感じに処理する必要がある
→1周をシミュレートする？
→1周した際の変化を累積させ、最後の余分な時間分を計算すればいい

1週分のシミュレーションには、最悪(N/2)**2 = 2500000000
がかかるので、もっと高速化を考える必要がある

実は1周するにあたり、カードは以下のように動く
>>>> <<<<
7531 2468

>> <<<<
31 24
75   68

つまり、2回かけて1つ後ろに移動する

あとは計算しやすいような工夫を考える
普通に移動経路を時間とともに列挙しようとするとO(LCM(右向き,左向き))かかる

=====答えを見た=====

あまりにシンプルで驚愕
流石AGC…
困った時はいい性質がないか観察することが大事…

カードは必ず昇順に並ぶ？
最初は昇順
→昇順でぶつかったとする
→カードは交換されるので、順序は変わらない！！(すごい)

あとはT秒後の0のカードの位置さえ分かればいい
愚直にやってもできるが…
ぶつかる際、AとA+1が交換される
時計回りのやつは+1される。反時計回りのやつは-1される
→あるアリが持ってる数字はすれ違う回数がわかれば求められる
一周にかかる時間は L//2
残りを良い感じに計算する (二分探索すればO(logN))


WA→LLが奇数なのに/2してるのがまずかったので全部2倍する
"""

from sys import stdin
import bisect
import sys
N,LL,T = map(int,stdin.readline().split())
LL *= 2
T *= 2

R = []
L = []
R2 = []
L2 = []

for i in range(N):
    x,w = map(int,stdin.readline().split())
    x *= 2
    if w == 1:
        R.append((x,i))
        R2.append(x)
        R2.append(x-LL)
    else:
        L.append((x,i))
        L2.append(x)
        L2.append(x+LL)

R2 += [float("-inf"),float("inf")]
L2 += [float("-inf"),float("inf")]
R2.sort()
L2.sort()

ans = [None] * N
for rx,ind in R:

    last = (rx + T) % LL
    plus = ind + (T // (LL//2)) * len(L)
    rem  = T % (LL//2)

    #print (plus,rem,file=sys.stderr)
    #rx以上 re+2*rem未満の数を数えればいい
    #l <= x < rを求めるには r以上最小のind-l以上最小のind
    plus += bisect.bisect_left(L2,rx+2*rem) - bisect.bisect_left(L2,rx)
    ans[plus % N] = last
    #print (plus,last,file=sys.stderr)

for lx,ind in L:

    last = (lx - T) % LL
    plus = ind - (T // (LL//2)) * len(R)
    rem = T % (LL//2)

    #lx以下、le-2*rem超過の数を数えればいい
    #l < x <= r -> l+1 <= x < r+1
    plus -= bisect.bisect_left(R2,lx+1) - bisect.bisect_left(R2,lx-2*rem+1)
    ans[plus % N] = last

if None in ans:
    print (sasasas)

for i in ans:
    print (i//2)

    





Measured memory_bytes: 88448
N = int(input())
Xlist = list(map(int,input().split()))
Xlist.sort()
wat = 2**100
for p in range(Xlist[0],Xlist[-1]+1):
  nwat = 0
  for x in Xlist:
    nwat += (x-p)**2
  if nwat < wat:
    wat = nwat
print(wat)

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

int main(){
    int X;
    int Y;
    cin >> X >> Y;
    int i,j;
    
    if(Y % 2 == 1|| 2 * X > Y){
        cout << "No" << endl;
        return 0;
    }

    for(i = X;i >= 0;i--){
        if(2 * i > Y){
            continue;
        }else{
            if((Y - 2 * i) % 4 == 0 && (Y - 2 * i) / 4 + i == X){
                cout << "Yes" << endl;
                return 0;
            }else{
                continue;
            }
        }
    }
	cout << "No" << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,ans = 0;
	cin >> N;
	while(N > 0){
		ans += 800;
		if (N % 15 == 0){
			ans -= 200;
		}
		N--;
	}
	cout << ans <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <string>
#define int long long
#define pii pair<int, int>
using namespace std;

void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}

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

signed main() {
	fast();
	int n;
	cin >> n;
	int g = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		g = gcd(g, x);
	}
	cout << g;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
K, N = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
B = A + K

A = np.concatenate((A, B)).tolist()
ans = 10 ** 18
for i in range(N):
    d = A[i + N - 1] - A[i]
    ans = min(d, ans)

print(ans)

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

using namespace std;

int const S = 444444;
int const N = 123456;

vector<int> s[N];
vector<int> vs[N];
int len[N];
int p[42];
int fr;
int link[26][S];
int insub[S], term[S], dep[S];


int newnode() {
  for (int i = 0; i < 26; i++) link[i][fr] = -1;
  return fr++;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int c = getchar();
    while (c <= 32) c = getchar();
    while (c > 32) {
      s[i].push_back(c - 'a');
      c = getchar();
    }
    len[i] = (int) s[i].size();
  }
  fr = 0;
  newnode();
  for (int i = 0; i < n; i++) {
    int v = 0;
    vs[i] = vector<int>(len[i]);
    for (int j = 0; j < len[i]; j++) {
      int letter = s[i][j];
      if (link[letter][v] < 0) {
        link[letter][v] = newnode();
      }
      v = link[letter][v];
      insub[v]++;
      if (j + 1 != len[i])
        vs[i][j + 1] = v;
      dep[v] = j + 1;
    }
    term[v] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    std::reverse(vs[i].begin(), vs[i].end());
    vs[i].erase(std::unique(vs[i].begin(), vs[i].end(), [](int i, int j) {
      return insub[i] == insub[j];
    }), vs[i].end());
  }
  int q;
  scanf("%d", &q);
  for (int cq = 0; cq < q; cq++) {
    int k;
    scanf("%d", &k);
    int c = getchar();
    while (c <= 32) c = getchar();
    for (int j = 0; j < 26; j++) {
      p[j] = c - 'a';
      c = getchar();
    }
    k--;
    int ans = 0;
    for (int v : vs[k]) {
      if (term[v] > 0) {
        ++ans;
      }
      for (int i = 0; i < 26; i++) {
        if (p[i] == s[k][dep[v]]) {
          break;
        }
        int to = link[p[i]][v];
        if (to < 0) continue;
        ans += insub[to];
      }
    }
    printf("%d\n", ans + 1);
  }
}


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

template<typename T>
inline int chkmax(T &x, T y) {
	return x < y ? x = y, 1 : 0;
}

const int MAXN = 1e6 + 9;

char s[MAXN];
int n, a[MAXN];

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1) + 1;

	int res = 0;
	for (int i = 1; i <= n; ++i) {
		a[i] = res;
		s[i] == '<' ? ++res : res = 0;
	}
	res = 0;
	for (int i = n; i; --i) {
		chkmax(a[i], res);
		s[i - 1] == '>' ? ++res : res = 0;
	}

	printf("%lld\n", std::accumulate(a + 1, a + n + 1, 0LL));

	return 0;
}

Measured memory_bytes: 4608
def insert_sort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt

def shellSort(A, n):
    cnt = 0
    G = []; h = 0
    while h <= n:
        if 3 * h + 1 <= n:
            h = 3 * h + 1
            G.append(h)
        else: break
    G = sorted(G, reverse=True)
    m = len(G)
    for i in range(m):
        cnt = insert_sort(A, n, G[i], cnt)
    return m, cnt, G

A = []
n = int(input())
for i in range(n):
    A.append(int(input()))

m, cnt, G = shellSort(A, n)
print(m)
for i in range(m):
    if i == m - 1:
        print(G[i])
    else:
        print(G[i], end=" ")
print(cnt)
for i in A:
    print(i)



Measured memory_bytes: 45524
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <tuple>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

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

    auto orders = VI();
    REP(i, n)
    {
        int order;
        cin >> order;
        orders.push_back(order);
    }

    int answer = 0;
    REP(i, n)
    {
        int manzoku;
        cin >> manzoku;
        answer += manzoku;
    }

    auto mariajus = VI();
    REP(i, n - 1)
    {
        int mariaju;
        cin >> mariaju;
        mariajus.push_back(mariaju);
    }

    FOR(i, 0, n - 1)
    {
        if (orders[i] + 1 == orders[i + 1])
        {
            answer += mariajus[orders[i] - 1];
        }
        else
        {
        }
    }

    cout << answer << endl;
}



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

unsigned long long factorial(int x) {

  if(x != 1)
    return x * factorial(x-1);
  else if(x == 1)
    return 1;
}

int main() {
  int a;
  cin >> a;
  cout << factorial(a) << endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back
#define fi first
#define be begin()
#define en end()
#define se second

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

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; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if ((abs(a-b) <= d && abs(b - c) <= d) || abs(a-c) <= d){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 256