akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mp make_pair
 
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<pii, pii> ii_ii;
typedef pair<int, long> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<string, string> ss;
typedef pair<int, ss> iss;
 
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<pll> vpll;
typedef vector<pli> vpli;
typedef vector<pii> vpii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, pii>> vpiii;
 
typedef map<string, string> mss;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<int, bool> mib;
typedef map<int, ll> mill;
typedef map<int, vpii> mivpii;

const int MAXN = 2e5;
const int MAXM = 3e3;
const int MOD = 1e9 + 7;

int dp[MAXM + 1];
pii a[MAXM + 1];
int fac[MAXN + 1];
int inv[MAXN + 1];

void fast_io() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int modpow(int x, int y, int mod) {
	int ans = 1;
	x %= mod;
	while(y) {
		if(y & 1) ans = (1LL * ans * x) % mod;
		x = (1LL * x * x) % mod;
		y >>= 1;
	}
	return ans;
}

void init() {
	fac[0] = 1, inv[0] = modpow(fac[0], MOD - 2, MOD);
	for(int i = 1; i <= MAXN; i++) {
		fac[i] = (1LL * i * fac[i - 1]) % MOD;
		inv[i] = modpow(fac[i], MOD - 2, MOD);
	}
}

int nCr(int n, int r) {
	return (1LL * fac[n] * inv[r] % MOD * inv[n - r]) % MOD;
}

int sub(int a, int b) {
	a = (a - b) % MOD;
	if(a >= MOD) a %= MOD;
	while(a < 0) a += MOD;
	return a;
}

int main() {
	fast_io();
//	freopen("input/dp_y.txt", "r", stdin);
	
	int h, w, n, mul;
	cin >> h >> w >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i].fi >> a[i].se;
		a[i].fi--, a[i].se--;
	}
	sort(a, a + n);
	
	init();
	for(int i = 0; i < n; i++) {
		dp[i] = nCr(a[i].fi + a[i].se, a[i].fi);
		for(int j = 0; j < i; j++) {
			if(a[i].fi - a[j].fi < 0 or a[i].se - a[j].se < 0) continue;
			mul = (1LL * dp[j] * nCr(a[i].fi - a[j].fi + a[i].se - a[j].se, a[i].se - a[j].se)) % MOD;
			dp[i] = sub(dp[i], mul);
		}
	}
	
	h--, w--;
	ll ans = nCr(h + w, w);
	for(int i = 0; i < n; i++) {
		mul = (1LL * dp[i] * nCr(h - a[i].fi + w - a[i].se, w - a[i].se)) % MOD;
		ans = sub(ans, mul);
	}
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;
 
public class Main{
	static int ans = 0;
	static long T;
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		T = sc.nextInt();
		dfs(0,0,0,0);
		System.out.println(ans);
	}

	private static void dfs(long x, int x3, int x5, int x7) {
		if(x3>0&&x5>0&&x7>0&&x<=T) ans++;
		if(x*10<T) {
			dfs(x*10+3,x3+1,x5,x7);
			dfs(x*10+5,x3,x5+1,x7);
			dfs(x*10+7,x3,x5,x7+1);
		}
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <numeric>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;

int gcd(int a, int b, int c) {
    int tmp = __gcd(a, b);
    return __gcd(tmp, c);
}

int main() {
    int k;
    cin >> k;
    
    ll r = 0;

    int cur = 1;
    for (int a=1; a<=k; ++a) {
        for (int b=1; b<=k; ++b) {
            for (int c=1; c<=k; ++c) {
                r += gcd(a,b,c);
            }
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3636
def dist(x1, x2):
    d = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return d**0.5

n = int(input())
x = [list(map(int, input().split())) for _ in range(n)]
d = 0
for i in range(n-1):
    for j in range(i+1, n):
        d += dist(x[i], x[j])
print(2*d / n)


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    int n, a[100], i, j, work, cnt=1;

    scanf("%d", &n);

    for(i=0; i<n; i++)
        scanf("%d", &a[i]);

    for(i=0; i<n; i++){
        for(j=i+1; j<n; j++){
            if(a[i] < a[j]){
                work = a[i];
                a[i] = a[j];
                a[j] = work;
            }
        }
    }

    for(i=0; i<n-1; i++){
        if(a[i] > a[i+1])
            cnt++;
    }

    printf("%d\n", cnt);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define N 100

int main()
{
    int num, i, j, temp, count = 0;
    int A[N];

    scanf("%d", &num);
    for (i = 0; i < num; i++)
        scanf("%d", &A[i]);

    for (i = 0; i < num - 1; i++)
    {
        for (j = num - 1; j > i; j--)
        {
            if (A[j] < A[j - 1])
            {
                temp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = temp;
                count++;
            }
        }
    }

    for (i = 0; i < num; i++)
    {
        printf("%d", A[i]);
        if (i != num - 1)
            printf(" ");
    }
    printf("\n");
    printf("%d\n", count);

    return 0;
}



Measured memory_bytes: 2048
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        o: Chars, e: Chars
    }

    solve(&o, &e);
}

fn solve(o: &Vec<char>, e: &Vec<char>) {
    for i in 0..(o.len() - 1) {
        print!("{}{}", o[i], e[i]);
    }
    if o.len() == e.len() {
        print!("{}{}", o[o.len() - 1], e[e.len() - 1]);
    } else {
        println!("{}", o[o.len() - 1]);
    }
    println!("");
}


Measured memory_bytes: 2148
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	string s;
	int i,id,cnt=0;
	cin>>s;
	if(s[0]!='A'){
		cout<<"WA"<<endl;
		return 0;
	}	
	f(i,2,s.length()-1){
		if(s[i]=='C'){
			cnt++;
			id=i;
		}
	}
	if(cnt!=1){
		cout<<"WA"<<endl;
		return 0;
	}
	f(i,1,s.length()){
		if(i!=id){
			if(s[i]-'a'<0){
				cout<<"WA"<<endl;
				return 0;
			}
		}
	}
	cout<<"AC"<<endl;
} 
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<numeric>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rep(i, n) for(int i=0; i<n; i++)
#define COUT(a) cout << a << endl;
#define PB push_back

using namespace std;
using ll = long long;
using P = pair<ll, ll>;


int main() {
    ll X, Y;
    cin >> X >> Y;

    COUT(X+Y/2)

}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
//#pragma GCC target ("avx")
//#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 102
#define M 50
#define M2 100
ll h, w;
string s[N];
ll a, b;

int main(){
	INIT;
	cin>>a>>b;
	a--; b--;
	h = w = M2;
	rep(i, M2) s[i] = string(w, (i<M?'#':'.'));
	for(int i = 0; i < M-1; i+=2) for(int j = 0; j < M2; j+=2) if(a-->=1) s[i][j] = '.';
	for(int i = M+1; i < M2; i+=2) for(int j = 0; j < M2; j+=2) if(b-->=1) s[i][j] = '#';
	cout<<h<<" "<<w<<endl;
	rep(i, h) cout<<s[i]<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
 
using ll = long long;
using ld = long double;
const int root = 0;
 
int main() {
  int n;
  cin >> n;
  vector<vector<int>> inp(n);
  for (int i = 0, a, b; i + 1 < n; ++i) {
    cin >> a >> b;
    inp[a - 1].push_back(b - 1);
    inp[b - 1].push_back(a - 1);
  }
 
  vector<int> c(n);
  for (auto &c_i : c) cin >> c_i;
  sort(c.begin(), c.end(), greater<int>());
 
  int max_sum = 0, idx = 0;
  vector<int> max_w(n, -1);
  queue<int> que;
  que.push(root);
  max_w[root] = c[idx++];
 
  while (!que.empty()) {
    int cur = que.front(); que.pop();
    for (auto u : inp[cur]) {
      if (max_w[u] != -1) continue;
      max_w[u] = c[idx++];
      max_sum += min(max_w[cur], max_w[u]);
      que.push(u);
    }
  }
 
  cout << max_sum << endl;
  for (int v = 0; v < n; ++v) {
    cout << max_w[v] << " \n"[v == n - 1];
  }
  return 0;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    while(1){  
        int h;
        cin>>h;
        if(h==0) return 0;
        
        int table[10][5],table_cp[10][5];
        rep(i,h) rep(j,5) cin>>table[i][j];

        bool flag=true;
        int ans=0;
        while(flag){
            rep(i,h) rep(j,5) table_cp[i][j]=table[i][j];

            flag=false;

            for(int i=h;i>=0;i--){
                for(int j=1;j<4;j++){
                    if(table[i][j] && table[i][j-1]==table[i][j] && table[i][j]==table[i][j+1]){
                        flag=true;
                        table_cp[i][j-1]=0;
                        table_cp[i][j]=0;
                        table_cp[i][j+1]=0;
                    }
                }
            }

            rep(i,h) rep(j,5) ans+=table[i][j]-table_cp[i][j];
            
            int cnt=h;
            while(cnt--){
                for(int i=h-1;i>0;i--){
                    rep(j,5){
                        if(table_cp[i][j]==0){
                            table_cp[i][j]=table_cp[i-1][j];
                            table_cp[i-1][j]=0;
                        }
                    }
                }
            }
            
            rep(i,h){
                rep(j,5){
                    table[i][j]=table_cp[i][j];
                }
            }
        }

        cout<<ans<<endl;
    }
    
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using ll = 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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

bool is_month(ll m){
    if(1<=m && m<=12){
        return true;
    }else{
        return false;
    }
}

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

    // input
    string s;
    cin >> s;

    ll front = stoi(s.substr(0, 2));
    ll back = stoi(s.substr(2, 2));

    bool is_front_month = is_month(front);
    bool is_back_month = is_month(back);

    if(is_front_month && is_back_month){
        p("AMBIGUOUS");
    }
    else if(is_front_month){
        p("MMYY");
    }
    else if(is_back_month){
        p("YYMM");
    }
    else{
        p("NA");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
using namespace std;
 
//  =========     /\       /|    |====/|
//      |        /  \       |    |   / |
//      |       /____\      |    |  /  |
//      |      /      \     |    | /   |
//  ========= /        \  =====  |/====|  
//  code

struct data{
    int w,s,v;
};

bool com(data d1,data d2){
    return (d1.w + d1.s < d2.w + d2.s);
}
int main(){
    init;
    const int SIZE = 2e4 + 5;
    long long int N,i,j,k,l;
    cin>>N;
    long long int dp[SIZE][N+1];
    vector<data> v(N+1);
    memset(dp,0,sizeof(dp));

    for(i=1;i<=N;i++){
        data *d = new data;
        cin>>d->w>>d->s>>d->v;
        v[i] = *d;
    }

    sort(v.begin(),v.end(),com);
    for(i = 1; i <= N; i++){
        for(j = v[i].s + v[i].w;j >= 0; j--){
            if(j >= v[i].w)
                dp[j][i] = max(dp[j][i-1] , dp[j-v[i].w][i-1] + v[i].v);
            else dp[j][i] = max(dp[j][i] , dp[j][i-1]);
        }
    }
    k = -1;
    for(i=0;i <= 2e4+4;i++){
        k = max(k , dp[i][N]);
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 156800
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i, a, n) for (int i = (a); i < (n); i++)
int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n,t;
  cin>>n>>t;
  int a[n];
  rep(i,0,n){cin>>a[i];}
  int sum=n*t;
  rep(i,0,n-1){if(a[i+1]-a[i]<=t){sum-=t-(a[i+1]-a[i]);}}
  cout<<sum<<endl;
}

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

#define N 1000
using namespace std;      
int n, q;
int a[N], b[N], S[N];     
vector<int> v;

int rec(int i, int n){    
  if(i==n) {
    int sum=0;
    for(int i=0;i<n;i++) {
      if(S[i]) sum+=a[i]; 
    }    v.push_back(sum);     
    return 0;
  }
  rec(i+1,n);
  S[i]=1;
  rec(i+1,n);
  S[i]=0;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> a[i];      
  cin >> q;
  for(int i=0;i<q;i++)
    cin >> b[i];      
  bool flag;
  rec(0,n);
  for(int i=0;i<q;i++){
    flag=false;
    for(vector<int>::iterator it=v.begin(); it!=v.end(); it++){
      if(b[i]==*it) flag=true;
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }

}



Measured memory_bytes: 6972
s=input()
k=int(input())
con1=0
ans=0
for c in s:
    if c!='1':
        ans=int(c)
        break
    con1+=1
else:
    ans=1
if k==1:
    ans=int(s[0])
if k<=con1:
    ans=1
print(ans)    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
using namespace std;

int main()
{
    ll n;
    cin>>n;
    
    ll a[n+1] = {0};
    ll b[n+1] = {0};
    ll c[n+1] = {0};
    
    for(ll i=1;i<=n;i++)    cin>>a[i];
    for(ll i=1;i<=n;i++)    cin>>b[i];
    for(ll i=1;i<n;i++)    cin>>c[i];
    
    a[0] = 10000000;
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
        ans += b[a[i]];
        if(a[i] == (1+a[i-1]))  ans += c[a[i-1]];
    }
    
    cout<<ans;
    
    return 0;
}


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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  int ind1 = -1;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    if(A[i] == 1) ind1 = i;
  }
  int ans = 100000;
  for(int offset = 0; offset < K && ind1 - offset >= 0; offset++){
    int tmp = 0;
    tmp += (ind1 + (K - 1) +offset - 1) / (K - 1); //切り上げ割り算 b + a - 1 / a
    tmp += ((N - ind1 - 1) + (K - 1) -offset - 1) / (K - 1);
    ans = min(tmp ,ans);
  }
  if(K >= N) ans = 1;
  
  cout << ans;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

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

	}
}

*/


int main(void) {
	int s; cin >> s;

	int a = s / 100;

	int b = s % 100;

	if (1 <= a && a <= 12 && 1<=b&&b<=12) {
		cout << "AMBIGUOUS" << endl;
	}
	else if (1 <= b && b <= 12) {
		cout << "YYMM" << endl;
	}
	else if (1 <= a && a <= 12) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "NA" << endl;
	}




}


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

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> xs(N + 1);
    vector<int> ys(M + 1);
    for (int i = 0; i < N; i++)
        cin >> xs[i];
    xs[N] = X;
    for (int i = 0; i < M; i++)
        cin >> ys[i];
    ys[M] = Y;
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    if (*max_element(xs.begin(), xs.end()) >= *min_element(ys.begin(), ys.end()))
    {
        cout << "War" << endl;
        return 0;
    }
    cout << "No War" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
list1 = []
for i in range(N):
  a = int(input())
  list1.append(a-1)

count =0
x = 0
while x != 1 and count < 100000:
  count +=1
  x = list1[x]
  
if count < 100000:
  print(count)
else:
  print(-1)


Measured memory_bytes: 13036
N,M=map(int,input().split())
ab=[[0,0] for i in range(M)]
for i in range(M):
    ab[i][0],ab[i][1]=map(int,input().split())
r=0
ans=0
ab.sort()
for i in range(M):
    a=ab[i][0]
    b=ab[i][1]
    if a>=r:
        ans+=1
        r=b
    else:
        if b<r:
            r=b
print(ans)



Measured memory_bytes: 20016
t;main(a,b,c){
    long int k;
    scanf("%d%d%d%ld",&a,&b,&c,&k);
    
    if(k%2==0){
        t=a-b;
    }else{
        t=b-a;
    }
    
    if(abs(a-b)>pow(10,18)){
        printf("Unfair");
    }else{
        printf("%d",t);
    }
    
}

Measured memory_bytes: 1680
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	int ans=0;
	for(int i=1;i<s.length();i++){
		if(s[i]!=s[i-1])ans++; 
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define int 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 rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int a, b, c;
    cin >> a >> b >> c;
    cout << (a <= c && c <= b ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();
		long min=N;
		for(int i=1;i<=Math.pow(N, 0.5);i++) {
			long A=0;
			long B=0;
			if(N%i!=0) {
				continue;
			}else {
				A=N/i;
				B=N/A;
				String a=String.valueOf(A);
				String b=String.valueOf(B);
				long len=Math.max(a.length(),b.length());
				if(len<min) {
					min=len;
				}
				
				
			}
			
		}
		System.out.println(min);

	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
using namespace std;

int main() {
    long long A,B,C;
    long long X,Y;
    cin >> A>>B>>C>>X>>Y;
    
    long long ans=0;
    if (A>2*C && B>2*C) {
        if (X>Y) {
            ans=(2*X)*C;
        }
        else{
            ans=(2*Y)*C;
        }
    }
    else if ((A+B)>2*C) {
        if (X>Y) {
            if (A>2*C) {
                ans=(2*X)*C;
            }
            else{
                ans+=(2*Y)*C;
                ans+=(X-Y)*A;
            }
        }
        else{
            if (B>2*C) {
                ans=(2*Y)*C;
            }
            else{
                ans+=(2*X)*C;
                ans+=(Y-X)*B;
            }
        }
    }
    else{
        ans+=(X*A)+(Y*B);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int ansN,N,SN;
    cin >> ansN;
    N = ansN;
    while(N){
        SN += N % 10;
        N /= 10;
    }
    if (ansN % SN == 0) {
        cout << "Yes";
    }else {
        cout << "No";
    }
}

Measured memory_bytes: 256
#!.//usr/bin/env python3
import sys


def solve(N: int, K: int):
    print(N-(K-1))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# coding: utf-8
# Your code here!
import sys

class Node:
    def __init__(self, id):
        self.id = id
        self.label = None
        self.friends = []
        self.blocks = []

sys.setrecursionlimit(10**9)
N,M,K = [int(i) for i in input().split()]

nodes = [Node(i) for i in range(N)]

for _ in range(M):
    a,b = [int(i) for i in input().split()]
    nodes[a-1].friends.append(b-1)
    nodes[b-1].friends.append(a-1)

for _ in range(K):
    c,d = [int(i) for i in input().split()]
    nodes[c-1].blocks.append(d-1)
    nodes[d-1].blocks.append(c-1)

def dfs(nodes, i, label):
    if nodes[i].label is None:
        nodes[i].label = label
        for j in nodes[i].friends:
            dfs(nodes, j, label)
        
        #for j in nodes[i].blocks:
        #    dfs(nodes, j, label)

label = 0
for i in range(len(nodes)):
    dfs(nodes, i, label)
    label+=1

node_cnts = [0] * (label+1)
for i in range(len(nodes)):
    node_cnts[nodes[i].label] += 1
            
#print(*node_cnts)
result = [0] * len(nodes)
for node in nodes:
    #print(node.id, node.label, node.friends, node.blocks)
    b_cnt = 0
    for b in node.blocks:
        if nodes[b].label == node.label:
            b_cnt += 1
            
    result[node.id] = node_cnts[node.label] - len(node.friends) - b_cnt - 1

print(*result)


Measured memory_bytes: 90224
p = lambda  x: x#print(x)

# スペース区切りの整数の入力
N = int(input())

l = [int(i) for i in input().split()]

# X = sum(l)
# x = 0
# ans = 1000000000000000000
# 
# for i in range(N-1):
# 	x += l[i]
# 	ans = min(ans, abs(X-2*x))
# 
# print(ans)

p(N)
p(l)

s = 0
a = sum(l)
ans = float('inf') 

p("s=" + str(s))
p("ans=" + str(ans))
p("a=" + str(a))
p("abs(s - a)=" + str(abs(s - a)))


for i in range(0, N-1):
	s += l[i]
	a -= l[i]
	ans = min(ans, abs(s-a))

print(ans)


Measured memory_bytes: 24668
#include <iostream>

using namespace std;

int main(void){
	int a, b;
	char op;

	for(;;){
		cin >> a >> op >> b;
		if(op == '?')
			break;

		cout << (op^'+' ? op^'-' ? op^'*' ? a/b : a*b : a-b : a+b) << endl;
	}

	return 0;
}



Measured memory_bytes: 3112
input1 = int(input())
input2 = int(input())
 
if input1 == 1:
  print(3) if input2 == 2 else print(2)
elif input1 == 2:
  print(3) if input2 == 1 else print(1)
else:
  print(1) if input2 == 2 else print(2)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
ll cnt[1000009];
int main()
{
   long long int a[100000],p=0,i,j;

   int n;
   ll ans=0;
   cin>>n;
   long long int b[n+9];
   for( i=0;i<n;i++){
        cin>>p;
        cnt[p]++;
        ans=gcd(ans,p);
   }
 if(ans>1) cout<<"not coprime"<<endl;

 else{  ll x=0;
       for(i=2;i<=1000000;i++){
          x=0;
        for(j=i;j<=1000000;j+=i){
              x+=cnt[j];

        }
        if(x>1) break;

       }


   if(x>1)cout<<"setwise coprime"<<endl;
   else cout<<"pairwise coprime"<<endl;
 }
}






Measured memory_bytes: 11408
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2010;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
ll num[N];

int main() 
{
	ll res = 0;
	ll a,b,c,d,e,n;
	cin>>n>>a>>b>>c>>d>>e;
	num[1] = n;
	/*while(1) {
		res++;
		if(num[5] != 0) {
			if(num[5] >= e) {
				num[5] -= e;
				num[6] += e;
			}
			else {
				num[6] += num[5];
				num[5] = 0;
			}
		}
		if(num[4] != 0) {
			if(num[4] >= d) {
				num[4] -= d;
				num[5] += d;
			}
			else {
				num[5] += num[4];
				num[4] = 0;
			}
		}
		if(num[3] != 0) {
			if(num[3] >= c) {
				num[3] -= c;
				num[4] += c;
			}
			else {
				num[4] += num[3];
				num[3] = 0;
			}
		}
		if(num[2] != 0) {
			if(num[2] >= b) {
				num[2] -= b;
				num[3] += b;
			}
			else {
				num[3] += num[2];
				num[2] = 0;
			}
		}
		if(num[1] != 0) {
			if(num[1] >= a) {
				num[1] -= a;
				num[2] += a;
			}
			else {
				num[2] += num[1];
				num[1] = 0;
			}
		}
		//cout<<num[1]<<" "<<num[2]<<" "<<num[3]<<" "<<num[4]<<" "<<num[5]<<" "<<num[6]<<endl;
		if(num[6] == n) break;
	}*/
	ll t = min(a,b);
	ll o = min(c,d);
	ll ans = min(min(t,o),e);
	if(n%ans == 0) res = n/ans;
	else res = n/ans + 1;
	res += 4;	
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
# SS, SW, WS, WWのときについてそれぞれ調べればよい

N=int(input())
s=input()
A=["SS","SW","WS","WW"]
for i,c in enumerate(s):
    for j in range(4):
        if A[j][-2:]=="SS":
            if c=="o":A[j]+="S"
            else:A[j]+="W"
        elif A[j][-2:]=="SW":
            if c=="o":A[j]+="W"
            else:A[j]+="S"
        elif A[j][-2:]=="WS":
            if c=="o":A[j]+="W"
            else:A[j]+="S"
        else:
            if c=="o":A[j]+="S"
            else:A[j]+="W"
A=[t[1:-1]for t in A if t[:2]==t[-2:]]
print(A[0]if A else-1)

Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

void NO() {
  cout << "-1\n";
  exit(0);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  
  int n; cin >> n;
  vector<int> leaves(n + 1);
  for (int &x : leaves) {
    cin >> x;
  }

  if (n == 0) {
    cout << (leaves[0] == 1 ? "1" : "-1") << endl;
    return 0;
  }

  if (leaves[0] != 0) NO(); 
  
  vector<int64_t> suff(n + 1);
  for (int i = n - 1; i >= 0; --i) {
    suff[i] = suff[i + 1] + leaves[i + 1];
  }

  vector<int64_t> internal(n + 1);
  internal[0] = 1;
  for (int d = 1; d <= n; ++d) {
    internal[d] = min(2 * internal[d - 1] - leaves[d], suff[d]);
    if (internal[d] < 0) NO();
  }

  int64_t ans = 0;
  for (int i = 0; i <= n; ++i) {
    ans += internal[i] + leaves[i];
  }

  cout << ans << endl;
}


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

int div(int n,int m,int &cnt){
    cnt+=n/m;
    return n%m;
}

int main(){
    int n;
    cin>>n;
    int cnt=0;
    n=div(n,25,cnt);
    n=div(n,10,cnt);
    n=div(n,5,cnt);
    n=div(n,1,cnt);
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v) memset(x,v,sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j,k;
void solve()
{
  ll n; cin>>n;
  string s; cin>>s;
  bool flag=false;
  ll ans=1;
  for(i=1;i<n;i++){
     if(s[i]!=s[i-1]) ans++;
  }
  cout<<ans<<endl;
}
signed main(){
   
     solve();

  return 0;
}



Measured memory_bytes: 512
import java.util.*;

public class Main {

    private static final int MOD = 1_000_000_007;

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

        System.out.println((H+A-1)/A);
    }
}


Measured memory_bytes: 22996
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> P(N); rep(i, 0, N) {
		cin >> P[i];
	}
	vector<pair<int, int>> v;
	rep(i, 0, N)v.emplace_back(P[i], i);
	sort(all(v));
	reverse(all(v));

	set<pair<int, int>> st;

	st.emplace(v.front().second, v.front().first);
	int ans = 0;
	rep(i, 1, N) {
		auto p = make_pair(v[i].second, v[i].first);
		st.insert(p);
		int x = v[i].first;
		int id = v[i].second;
		auto it = st.find(p);
		int l1 = it != st.begin() ? prev(it)->first : -1;
		int l2 = l1 != -1 && prev(it) != st.begin() ? prev(prev(it))->first : -1;
		int r1 = next(it) != st.end() ? next(it)->first : -1;
		int r2 = r1 != -1 && next(next(it)) != st.end() ? next(next(it))->first : -1;

		int l, r; l = r = id;

		if (r1 == -1) r1 = N;
		if (r2 == -1) r2 = N;
		dump(l2, l1, id, r1, r2);
		ans += x * (id - l1) * (r2 - r1);
		dump(ans);
		ans += x * (l1 - l2) * (r1 - id);
		dump(ans);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8816
import java.util.Scanner;

public class Main {
    public static int number;
    public static int res;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()){
            number = sc.nextInt();
            res = 0;
            for (int i = 0; i < 10; i++) {
                calc(i, 0, 1);
            }
            System.out.println(res);
        }
    }
    public static void calc(int index, int sum, int rep) {
        sum += index;
        if (rep == 4) {
            if (sum == number) {
                res++;
            }
            return;
        }
        
        for (int i = 0; i < 10; i++) {
            calc(i, sum, rep + 1);
        }
    }
}

Measured memory_bytes: 26300
line = input().split(" ")
N = int(line[0])
M = int(line[1])

g = {}
E = []
for _ in range(M):
    line = input().split(" ")
    a = line[0]
    b = line[1]
    E.append((a,b))
    if not a in g:
        g[a] = []
    g[a].append(b)

    if not b in g:
        g[b] = []
    g[b].append(a)

def judge(a, b):
    flags = {}
    for v in g:
        flags[v] = False
    q = [a]
    flags[a] = True
    while len(q)>0:
        v = q.pop(0)
        for u in g[v]:
            if (v==a and u==b) or (v==b and u==a):
                continue
            elif not flags[u]:
                flags[u] = True
                q.append(u)
    ret = True
    for v in flags:
        ret = ret and flags[v]

    return not ret

cnt = 0
for e in E:
    if judge(e[0],e[1]):
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include<iostream>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[160000],n;
int main(){
  r(j,1e9){
    int t=j*j*j;
    if(t>=160000)break;
    a[t]++;
    r(i,1e9){
      int p=i*(i+1)*(i+2)/6;
      if(p<160000)a[p]++;
      else break;
      if(p+t<160000)a[p+t]++;
    }
  }
  r(i,160000){
    if(a[i])a[i]=i;
    else a[i]=a[i-1];
  }
  while(cin>>n,n) cout<<a[n]<<endl;
}

Measured memory_bytes: 3716
// Shik and Travel
// * frank_c1
// * 2017 / 12 / 18
 
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = (1 << 17) + 5;
int wi[maxn], ai[maxn], bi[maxn];
int st[maxn], su[maxn];
pii ci[maxn * 17], ta[maxn], tb[maxn];
int n, idx;

bool chk(int x) {
	idx = 0;
	for (int i = n; i >= 1; --i) {
		st[i] = idx + 1;
		if (!ai[i]) ci[++idx] = make_pair(0, 0);
		else {
			int u = ai[i], v = bi[i];
			if (su[u] > su[v]) swap(u, v);
			int mx = x - wi[u] - wi[v];
			int ca = 0, cb = 0, ww = (int)(1e9), ps = 1;
			for (int j = st[u]; j < st[u] + su[u]; ++j) ta[++ca] = make_pair(ci[j].first, ci[j].second);
			for (int j = st[v]; j < st[v] + su[v]; ++j) tb[++cb] = make_pair(ci[j].second, ci[j].first);
			sort(ta + 1, ta + ca + 1); sort(tb + 1, tb + cb + 1);
			for (int j = ca; j >= 1; --j) {
				while (ps <= cb && ta[j].first + tb[ps].first <= mx) ww = min(ww, tb[ps++].second);	
				if (ps > 1) ci[++idx] = make_pair(ww + wi[v], ta[j].second + wi[u]);
			}
			ca = cb = 0; ww = (int)(1e9); ps = 1;
			for (int j = st[u]; j < st[u] + su[u]; ++j) ta[++ca] = make_pair(ci[j].second, ci[j].first);
			for (int j = st[v]; j < st[v] + su[v]; ++j) tb[++cb] = make_pair(ci[j].first, ci[j].second);
			sort(ta + 1, ta + ca + 1); sort(tb + 1, tb + cb + 1);
			for (int j = ca; j >= 1; --j) {
				while (ps <= cb && ta[j].first + tb[ps].first <= mx) ww = min(ww, tb[ps++].second);
				if (ps > 1) ci[++idx] = make_pair(ta[j].second + wi[u], ww + wi[v]);
			}
		}
		su[i] = idx - st[i] + 1;
	}
	return su[1] > 0;
}

int main() {
	scanf("%d", &n);
	for (int i = 2; i <= n; ++i) {
		int f; scanf("%d%d", &f, &wi[i]);
		if (!ai[f]) ai[f] = i; else bi[f] = i;
	}
	int l = 0, r = 34 * (1 << 17);
	while (l < r) {
		int mid = (l + r) >> 1;
		if (chk(mid)) r = mid; else l = mid + 1;
	}
	return printf("%d\n", l), 0;
}

Measured memory_bytes: 14720
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define readf(a) scanf("%lf", &a)
#define readc(a) scanf("%c", &a)
#define debug(a, b) printf("%s = %d\n", a, b)
#define debug1(a, i, b) printf("%s[%d] = %d", a, i, b)
#define show(a) putchar(a)
#define pb emplace_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
typedef long long LL;
typedef int Int;
typedef double db;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
char s[N];
ll dp[N];
signed main()
{
    int n, p;
    read(n); read(p);
    reads(s + 1);

    ll ans = 0;
    if(p == 2 || p == 5)
    {
        for(int i = n; i; i--)
            if((s[i]-'0') % p == 0)
                ans += 1ll*i;
    }
    else
    {
        ll d = 1, x = 0;
        for(int i = n; i; i--)
        {
            x += (s[i]-'0') * d;
            x %= p;

            d *= 10;
            d %= p;

            ans += dp[x];
            dp[x]++;
            if(x == 0) ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}
/**

**/



Measured memory_bytes: 4100
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using ll = long long;

template <typename T>
T min(T a, T b){
  return (a < b) ? a : b;
}

template <typename T>
class SegTree{
  static const int MAXN = 100010;
  T INF;
  int n;
  T A[MAXN*4];
  T lazy[MAXN*4];
  public:
  SegTree(int size, T INF): INF(INF){
    n = 1;
    while(n < size){
      n *= 2;
    }
    // n *= 2;
    for(int i = 0; i < MAXN*4; i++) A[i] = INF;
    for(int i = 0; i < MAXN*4; i++) lazy[i] = INF;
  }

  T query(int a, int b){
    return _query(a, b, 0, 0, n);
  }

  T _query(int a, int b, int k, int l, int r){
    lazy_evaluate(k);
    if(a >= r || b <= l){
      return INF;
    }
    if(l >= a && r <= b){
      return A[k];
    }
    lazy_evaluate(k);
    T v1 = _query(a, b, 2*k + 1, l, (l+r)/2);
    T v2 = _query(a, b, 2*k + 2, (l+r)/2, r);
    return min(v1, v2);
  }

  void update(int a, int b, T v){
    _update(a, b, 0, 0, n, v);
  }

  T _update(int a, int b, int k, int l, int r, T v){
    lazy_evaluate(k);
    if(a >= r || b <= l){
      return A[k];
    }
    if(l >= a && r <= b){
      lazy[k] = v;
      lazy_evaluate(k);
      return A[k];
    }
    T v1 = _update(a, b, 2*k + 1, l, (l+r)/2, v);
    T v2 = _update(a, b, 2*k + 2, (l+r)/2, r, v);
    return A[k] = min(v1, v2);
  }

  void lazy_evaluate(int k){
    if(lazy[k] == INF) return;
    A[k] = lazy[k];
    if(k < n-1){
      lazy[2*k+1] = lazy[k];
      lazy[2*k+2] = lazy[k];
    }
    lazy[k] = INF;
  }
};

int main(void){
  int n, q; cin >> n >> q;
  SegTree<int> rmq(n, 0x7FFFFFFF);
  for(int loop = 0; loop < q; loop++){
    int com;
    cin >> com;
    if(com == 0){
      int l, r, v; cin >> l >> r >> v;
      rmq.update(l, r+1, v);
    }else{
      int x, y; cin >> x >> y;
      cout << rmq.query(x, y+1) << endl;
      // cout << rmq._query(x, y+1, 0, 0, n) << endl;
    }
  }
}



Measured memory_bytes: 6260
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }

signed main()
{
	int W, H, x, y;
	cin >> W >> H >> x >> y;
	cout << (double)W * (double)H / 2 << " ";
	if (2 * x == W && 2 * y == H)cout << 1;
	else cout << 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = N.iota.map!(_ => readln.split.map!(to!int).array).array;
    A.sort();
    long ans = N + A.front[0] - 1 + A.back[1];

    foreach (i; 0..N-1) {
        ans += min(A[i+1][0] - A[i][0] - 1, A[i][1] - A[i+1][1] - 1);
    }

    ans.writeln;
}


Measured memory_bytes: 12156
class Room {
    var numOfPeople: Int = 0

    override fun toString(): String {
        return " %d".format(numOfPeople)
    }
}

class Floor {
    val rooms = (1..10).map { _ -> Room() }.toList()
    override fun toString(): String {
        return rooms.joinToString("")
    }
}

class Building {
    val floors = (1..3).map { _ -> Floor() }.toList()
    override fun toString(): String {
        return floors.joinToString("\n")
    }
}

fun main(args: Array<String>) {
    val ownedBuildings = (1..4).map { _ -> Building() }.toList()

    val n = readLine()?.toInt() ?: return

    for (i in 1..n) {
        val inStr = readLine() ?: return

        val (b, f, r, v) = inStr.split(' ').map(String::toInt).toList()

        ownedBuildings[b - 1].floors[f - 1].rooms[r - 1].numOfPeople += v
    }
    val sepLine = "\n%s\n".format((1..20).map { _ -> "#" }.joinToString(""))
    println(ownedBuildings.joinToString(sepLine))
}



Measured memory_bytes: 32712
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, a, b;
    ll mod = 1e9 + 7;
    cin >> n;

    unordered_map<int, vector<int>> e;
    vector<vector<int>> dp(n+1, vector<int>(2, -1));
    auto dfs = [&] (auto& self, int cur, int par, int color) -> ll {
        if (dp[cur][color] != -1)
            return dp[cur][color];
        ll res = 1;
        if (color == 0) { //
            for(int neibor: e[cur]) {
                if (neibor == par) continue;
                ll tmp = self(self, neibor, cur, 0);
                tmp += self(self, neibor, cur, 1);
                tmp %= mod;
                res *= tmp;
                res %= mod;
            }
        } else { // no adjency 1
            for(int neibor: e[cur]) {
                if (neibor == par) continue;
                ll tmp = self(self, neibor, cur, 0);
                res *= tmp;
                res %= mod;
            }
        }
        dp[cur][color] = res;
        return dp[cur][color];
    };
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    ll ans = dfs(dfs, 1, -1, 0) + dfs(dfs, 1, -1, 1);
    cout << (ans % mod) << endl;
    return 0;
}



Measured memory_bytes: 20516
#include<iostream>

using namespace std;
bool flag[60000];
int main()
{
	flag[0]=flag[1]=true;

	for(int i=2;i<60000;i++)
	{
		if(!flag[i])
		{
			for(int j=i*2;j<60000;j+=i) flag[j]=true;
		}
	}

	int n,low,up;
	while(cin>>n)
	{
		for(int i=n-1;;i--)
		{
			if(!flag[i]) {low=i; break;}
		}
		for(int i=n+1;;i++)
		{
			if(!flag[i]) {up=i; break;}
		}
	
		cout<<low<<" "<<up<<endl;
	}
	return 0;
}
			

Measured memory_bytes: 0
n,k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]
loop = []
seen = [0]*n
num = 0
flag = 0
while k>0:
    if seen[num]==1:
        flag = 1
        break
    seen[num]=1
    loop.append(num)
    num = a[num]
    k-=1
if flag:
    index = loop.index(num)
    loop = loop[index:]
    print(loop[(k%len(loop))]+1)
else:
    print(num+1)

Measured memory_bytes: 94704
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var ab = Input3();
            var ans = -1;

            for(int i = 0; i < 15000; i++)
            {
                double c = i * 0.08;
                double d = i * 0.1;

                if ((int)c == ab[0] && (int)d == ab[1])
                {
                    ans = i;
                    break;
                } 
            }

            Console.WriteLine(ans);



        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 13140
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long K = sc.nextLong();
		int Q = sc.nextInt();
		int a[] = new int[Q];

		TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();

		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();

			if (map.containsKey(a[i])) {
				map.put(a[i], map.get(a[i])+1);
			} else {
				map.put(a[i], 1);
			}
		}

		if (K>Q) {
			for (int i = 0; i < N; i++) {
				System.out.println("Yes");
			}
			return;
		}

		long req = Q-K + 1;

		Map<Integer, Integer> yes = new HashMap<>();

		for(Map.Entry<Integer, Integer> e : map.entrySet()) {
			if (e.getValue() >= req) {
				yes.put(e.getKey(), 1);
			}
		}

		for (int i = 1; i < N + 1; i++) {
			if (yes.containsKey(i)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}



Measured memory_bytes: 64188