akhauriyash/Code-Regression huggingface dataset:
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
 
const long long MOD = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
/////////////////////////
//素因数分解 O(√n)
map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(ll i = 2;i * i <= n;i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1LL;
    return res;
}

int main(void){
   
   ll n,p;cin >> n >> p;
   map<ll,ll> mp = prime_factor(p);
   ll ans = 1LL;
   for(auto i : mp){
      if(i.second < n) continue;
      ans *= qp(i.first,i.second/n);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	long long  x;
	cin >> x;
	int cnt=0;
	long long  n = 100;
	while (n < x)
	{
		n = n * 1.01;
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int a[20];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);
	unordered_set<int>se;
	rep(i, 1 << n) {
		int sum = 0;
		rep(j, n) {
			if (i >> j & 1)sum += a[j];
		}
		se.insert(sum);
	}
	int q; scanf("%d", &q);
	rep(i, q) {
		int m; scanf("%d", &m);
		puts(se.find(m) != se.end() ? "yes" : "no");
	}
}

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

int main(){
    int N; cin >> N;
    int res = N;
    for(int i = 0; i <= N; i++){
        int cc = 0;
        int t = i;
        while(t > 0){
            cc += t % 6;
            t /= 6;
        }
        t = N - i;
        while(t > 0){
            cc += t % 9;
            t /= 9;
        }
        if(res > cc) res = cc;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	
	int n,i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]-a[0]<<endl;
	
	return 0;
}

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

int main() {
	int a,b,c,d,e;
	
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	cin>>e;
	
	if(e>c){
		if(a*e>=b+(e-c)*d){
			cout<<b+(e-c)*d<<endl;
		} else {
			cout<<a*e<<endl;
		}
	} else {
	    if(a*e>=b){
			cout<<b<<endl;
		} else {
			cout<<a*e<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3080
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll n , k ;
ll solve(string str , ll n , char ch){
	ll cnt=0 , ss=1;
	for(ll i=0;i<n ;i++){
		if(str[i]!=ch){
			if(ss){
				ss=0;
				cnt++;
			}
			str[i]= ch=='L' ? 'L' : 'R';
			continue;
		}
		else{
			ss=1;
		}
		if(cnt>=k)break;
	}
	cnt=0;
	// cerr<<str<<endl;
	for(ll i=0;i<n-1;i++){
		if(str[i]==str[i+1])cnt++;
	}
	return cnt;
}

int main(){
	//mahakal(),fast;
	cin>> n >> k ;
	string str ;
	cin>> str ;
	ll ans1 = solve(str , n , 'L');
	ll ans2 = solve(str , n , 'R');
	ll ans = max(ans1,ans2);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n,m;
int p;
string s;
bool solve[100100];
int pen[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>p>>s;
		if(s=="AC"){
			solve[p]=true;
		}
		else{
			if(!solve[p])
				pen[p]++;
		}
	}
	int tr=0;
	int ac=0;
	for(int i=1;i<=n;i++){
		if(solve[i]){
			ac++;
			tr+=pen[i];
		}
	}
	cout<<ac<<' '<<tr<<endl;
	return 0;
}


Measured memory_bytes: 768
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int x[100];
int y[100];
int h[100];

int f(int a, int b, int c)
{
  return c + abs(a) + abs(b);
}

int main(){
  int N;
  cin >> N;
  rep(i, N){
    cin >> x[i] >> y[i] >> h[i];
  }

  if(h[0] == 0){
    int id;
    rep(i, N){
      if(h[i]){
        swap(h[i], h[0]);
        swap(x[i], x[0]);
        swap(y[i], y[0]);
        break;
      }
    }
  }

  rep(cx, 101){
    rep(cy, 101){
      int H = f(x[0] - cx, y[0] - cy, h[0]);
      rep(i, 1, N){
        if(f(x[i] - cx, y[i] - cy, h[i]) == H) continue;
        if(h[i] == 0 && f(x[i] - cx, y[i] - cy, h[i]) >= H) continue;
        goto F;
      }
      printf("%d %d %d\n", cx, cy, H);
      return 0;
F:;
    }
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX(a,b) ((a) > (b) ? a : b)
int main(void){
    // Your code here!
    int N;
    int a[100001],b[100001],c[100001];
    int dp[200001][4];
    int i,j,k;
    int ans;
    
    scanf("%d",&N);
    for(i=1;N>=i;i++){
            scanf("%d %d %d\n",&a[i],&b[i],&c[i]);
    }
    
    dp[0][1] = 0; dp[0][2] = 0; dp[0][3] = 0;
    
    for(i=1;N>=i;i++){
        if(i==1){
            dp[i][1] = a[1]; dp[i][2] = b[1]; dp[i][3] = c[1];
        }
        else{
            dp[i][1] = MAX(dp[i-1][2]+a[i],dp[i-1][3]+a[i]);
            dp[i][2] = MAX(dp[i-1][1]+b[i],dp[i-1][3]+b[i]);
            dp[i][3] = MAX(dp[i-1][1]+c[i],dp[i-1][2]+c[i]);
        }
    }
    
    
    ans = MAX(MAX(dp[N][1],dp[N][2]),dp[N][3]);
    
    printf("%d\n",ans);
    
    return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;

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

signed main(){
    int A,B,C,D; cin>>A>>B>>C>>D;
    A --;
    int ans = B-B/C-B/D+B/(C*D/GCD(C,D));
    ans -= A-A/C-A/D+A/(C*D/GCD(C,D));
  Out(ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
	int a[1000];
	int b[1000];
	int n;
	long long s;
	long long t;
	long long x;
	long long y;
		scanf("%d ", &n);

	for (int i = 0; i < n; i++){
		scanf("%d %d", &a[i], &b[i]);
	}
	x = a[0]-1;
	y = b[0]-1;
	for (int i = 1; i < n; i++){
		s = x / a[i];
		t = y / b[i];
		if (s > t){
			s++;
			x = (a[i] * s) - 1;
			y = (b[i] * s )- 1;
		}
		else{
			t++;
			x = (a[i] * t )- 1;
			y = (b[i] * t) - 1;
		}
	}
	printf("%lld", x + y + 2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){

  int N, a[1000000], f_max = 0;

  cin >> N;

  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  for(int i = 0; i < N; i++){
    f_max += a[i] - 1;
  }

  cout << f_max << endl;

  return 0;

}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;
typedef pair<char, char> PCC;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
LL MOD = 1e9+7;
int INF = (1e9) *2+1;
double EPS=1.0e-9;
double PI=atan2(0,-1);


int main()
{
    int n,k;
    cin>>n>>k;
    int p[26];
    CLR(p);
    string s;
    REP(i,n)
    {
        cin>>s;
        p[s[0]-'A']++;
    }
    //sort(p,p+26,greater<int>());
    int cnt=0;
    bool flag=0;
    while(1)
    {
    sort(p,p+26,greater<int>());
        REP(i,k)
        {
            p[i]--;
            if(p[i]<0)
            {
                flag=1;
                 break;
            }
        }
        if(flag) break;
        cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int i,j;
        
        Scanner sc=new Scanner(System.in);
        
        int n,m,l;
        n=sc.nextInt();
        m=sc.nextInt();
        l=sc.nextInt();
 
        Matrix A=new Matrix(n,m);
        for(i=0;i<n;i++){
            for(j=0;j<m;j++)A.setElement(i,j,sc.nextInt());
        }
        
        Matrix B=new Matrix(m,l);
        for(i=0;i<m;i++){
            for(j=0;j<l;j++)B.setElement(i,j,sc.nextInt());
        }
        
        Matrix C=new Matrix(n,l);
        C.getProduct(A,B);
        C.printElement();
    }
}

class Matrix{
    int row;
    int col;
    long elm[][];
    Matrix(int a,int b){
        this.row=a;
        this.col=b;
        elm=new long[a][b];
        this.initialize();
    }
    void initialize(){
        for(int i=0;i<this.row;i++){
            for(int j=0;j<this.col;j++)this.elm[i][j]=0;
        }
    }
    void setElement(int a,int b,int x){
        this.elm[a][b]=x;
    }
    void printElement(){
        for(int i=0;i<this.row;i++){
            for(int j=0;j<this.col;j++){
                if(j==0)System.out.printf("%d",this.elm[i][j]);
                else System.out.printf(" %d",this.elm[i][j]);
            }
            System.out.printf("\n");
        }
    }
    void getProduct(Matrix a,Matrix b){
        for(int i=0;i<a.row;i++){
            for(int k=0;k<b.col;k++){
                for(int j=0;j<b.row;j++){
                    this.elm[i][k]+=a.elm[i][j]*b.elm[j][k];
                }
            }
        }
    }
}


Measured memory_bytes: 73964
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll a,b; char s;
    cin>>a>>s>>b;
    if(s=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;
}




























































































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

S=list(input().rstrip('\n'))
res = 0
if S[0]=='R':
  res += 1
if S[1]=='S':
  if res == 0 and S[2]=='S':
    print(0)
  else:
    print(1)
else:
  res += 1
  if S[2]=='R':
    res += 1
    print(res)
  else:
    print(res)

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())

int main() {
    ll n, m, k, tmp, ans = 0;
    cin >> n >> m >> k;
    vector<ll> a(n+1,0), b(m+1,0);
    rep(i,n) {
        cin >> tmp;
        if(i == 0) a[i+1] = tmp;
        else a[i+1] = a[i] + tmp;
    }
    rep(i,m) {
        cin >> tmp;
        if(i == 0) b[i+1] = tmp;
        else b[i+1] = b[i] + tmp;
    }
    int j = m;
    rep(i,n+1) {
        if(a[i] > k) break;
        while(b[j] > k - a[i]) j--;
        ans = max(ans, (ll)(i + j));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6352
import sys
import numpy as np


def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    exps = np.ceil(np.log2(np.ceil(K / np.arange(1, N+1))))
    ans = 1. / N * np.sum(0.5 ** exps)
    print(ans)


if __name__ == '__main__':
    main()


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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    int sum = 0;
    rep(i,m) sum+=a[i];

    int ans = n-sum;
    if(ans<0) ans = -1;   

    print(ans);

    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod=1e9+7,dp[200001][2];
vec G[200001];
void dfs(int x,int p=-1){
    if(p!=-1&&G[x].size()==1){
        dp[x][0]=1,dp[x][1]=1;
        return;
    }
    ll ans0=1,ans1=1;
    for(auto i:G[x]){
        if(i==p) continue;
        dfs(i,x);
        (ans0*=dp[i][0]+dp[i][1])%=mod;
        (ans1*=dp[i][0])%=mod;
    }
    dp[x][0]=ans0;
    dp[x][1]=ans1;
}
int main(){
    int n,u,v;
    cin>>n;
    rep(i,n-1) cin>>u>>v,G[u].push_back(v),G[v].push_back(u);
    dfs(1);
    if(n==1) cout<<2<<"\n";
    else cout<<(dp[1][0]+dp[1][1])%mod<<"\n";
}

Measured memory_bytes: 16512
#include <iostream>
#include <cmath>

#define LL long long

using namespace std;

int main()
{
    LL N, P;
    cin >> N >> P;
    if(1 == N)
    {
        cout << P << endl;
        return 0;
    }

    // double转化为long long有可能会少1，先加回来
    LL ans = pow(P, 1.0/N) + 1;
    for(; ans >= 1; ans--)
    {
        if((P % (LL)pow(ans, N)) == 0)
        {
            break;
        }
    }

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


Measured memory_bytes: 256
#coding: utf-8

while True:
    m, f, r = (int(i) for i in input().split())

    if m == f == r == -1:
        break
    
    if m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif m + f >= 65 and m + f < 80:
        print("B")
    elif (m + f >= 50 and m + f < 65) or r >= 50:
        print("C")
    elif m + f >= 30 and m + f < 50:
        print("D")
    elif m + f < 30:
        print("F")



Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
cin >> N >> K;
int s[N];
int sum = 0;
for(int i=0; i<N;i++){
	cin >> s[i];
}
sort(s,s+N);
for(int i=0;i<K;i++){
	sum+=s[i];
}
cout << sum << endl;
return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h" // {{{
using namespace std; typedef long long ll; typedef pair<int,int> pii;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define repr(i,h,l) for(int i=(h); i >= (int)(l); --i)
#define reps(i,s,t) for(int i=(s); i <= (int)(t); ++i)
#define ALL(x)      begin(x), end(x)
#define UNQ(x)      (x).erase(std::unique(ALL(x)), end(x))
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#define YDK(f,a,b)  ((f)? (a):(b))
#ifdef  DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t\t= " << (x) << '\n'
#define show2(x,y)  clog << '(' << #x << ',' << #y << ")\t\t= " << '(' << (x) << "\t, " << (y) << ")\n"
#define LN()        fputs("\n--------------------------------\n", stderr)
struct NullPointer{};
#else
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
struct NullPointer{ NullPointer(){cin.tie(0);ios::sync_with_stdio(false);} };
#endif
#define def(op) inline bool operator op (const T &that) const { return comp(that) op 0; }
template<class T> struct Ordered
{ virtual int comp(const T &that) const = 0; def(==); def(!=); def(<); def(<=); def(>); def(>=); };
#undef def
namespace {
  constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; ostringstream _oss;
  TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
  { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
  TMPLT(T,U) inline bool chmax(T &a, const U &b){return b>a ? a=b,1 : 0;}
  TMPLT(T,U) inline bool chmin(T &a, const U &b){return b<a ? a=b,1 : 0;}
  TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
  template<class T>   string toString(const T &x){ _oss.str(""); _oss << x; return _oss.str(); }
  template<class Itr> string mkString(Itr begin, Itr end, const char *sp = " ") {
    _oss.str(""); for(Itr i=begin; i != end; ++i) { if(i != begin)_oss << sp; _oss << *i; }
    return _oss.str();
  }
  // }}}

constexpr int MX = ten(5) + 10;

void Xx_main_xX(const vector<char*> &args)
{
  string s; cin >> s;
  int x[5];
  rep(i, 4) x[i] = s[i] - '0';

  rep(i,2) rep(j,2) rep(k,2) {
    val a = x[0];
    val b = i? x[1] : -x[1];
    val c = j? x[2] : -x[2];
    val d = k? x[3] : -x[3];

    if (a + b + c + d == 7) {
      printf("%d%+d%+d%+d=7\n", a,b,c,d);
      return ;
    }
  }
}

} // {{{
signed main(signed argc, char *argv[]) {
  NullPointer Exception;
  cout << fixed << setprecision(9); Xx_main_xX(vector<char*>(argv, argv+argc)); return 0;
} // }}}



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

int main() {
  int a,b,ans;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(i/10000 == i%10 && i%10000/1000 == i%100/10){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/**
 *    author        : Sudipta Banik Trisha 
 *    created       : August 02, 2020 6:00 PM
 *    Problem Name  : A - Air Conditioner
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc174/tasks/abc174_a
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;

    if(n<30){
        cout << "No" << endl;
    }

    else cout << "Yes" << endl;

    return 0 ;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio

    lli num1 , num2 ;
    cin >> num1 >> num2 ;

    num1 -- , num2 -- ;

    cout << num1 * num2 ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
from collections import deque


def bfs(adj_list, n):
    color = [None] * n
    color_count = 0
    searching = deque()
    for i in range(n):
        if color[i] is None:
            color_count += 1
            color[i] = color_count
            searching.append(i)
            while len(searching) > 0:
                start = searching.popleft()
                for end in adj_list[start]:
                    if color[end] is None:
                        color[end] = color_count
                        searching.append(end)
    return color


def dfs(adj_list, n):
    color = [None] * n
    color_count = 0
    searching = deque()
    for i in range(n):
        if color[i] is None:
            color_count += 1
            color[i] = color_count
            searching.append(i)
            while len(searching) > 0:
                start = searching.pop()
                for end in adj_list[start]:
                    if color[end] is None:
                        color[end] = color_count
                        searching.append(end)
    return color


def main():
    nm = input().split()
    n, m = list(map(int, nm))
    adj_list = [[] for _ in range(n)]
    for _ in range(m):
        st = input().split()
        s, t = list(map(int, st))
        adj_list[s].append(t)
        adj_list[t].append(s)
    color = dfs(adj_list, n)
    q = int(input())
    for _ in range(q):
        st = input().split()
        s, t = list(map(int, st))
        if color[s] == color[t]:
            print("yes")
        else:
            print("no")


if __name__ == "__main__":
    main()



Measured memory_bytes: 23556
// 2013/11/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	int N, R, L;
	cin >> N >> R >> L;

	long long P[100001] = {0};
	int W = 1;

	int T[100001] = {0};
	int tp = 0;

	for(int i=0; i<R; i++){
		int d, t, x;
		cin >> d >> t >> x;

		T[W] += t-tp;
		tp = t;

		P[d] += x;

		if(x>=0){
			if(P[W]<P[d] || (P[W]==P[d] && W>d)){
				W = d;
			}
		}
		else{
			if(W==d){
				W = 1;
				for(int j=2; j<=N; j++){
					if(P[W]<P[j]){
						W = j;
					}
				}
			}
		}
//		cout << W << ' ' << P[W] << endl;
	}

	T[W] += L-tp;

	int C = 1;
	for(int i=2; i<=N; i++){
		if(T[C]<T[i]){
			C = i;
		}
	}
	cout << C << endl;

	return 0;
}

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


using namespace std;
string S;


int main() {
	int cnt = 0;
	string strf, strl;
	cin >> S;

	S[S.length() - 1] = '\0';
	strf = S.substr(0, S.length() / 2);
	strl = S.substr(S.length() / 2);
	cnt++;


	while (strf != strl) {
		
		S[S.length() - (cnt + 1)] = '\0';
		cnt++;
		strf = S.substr(0, (S.length() - cnt) / 2);
		strl = S.substr((S.length() -cnt)/ 2, (S.length() - (cnt))-((S.length() - cnt) / 2));
	}

	cout << S.length() - cnt << endl;


	return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<f64> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut s = vec![0.0; n + 1];
    for i in 0..n {
        s[i + 1] = (a[i] + 1.0) * a[i] / 2.0 / a[i];
    }
    for i in 0..n {
        s[i + 1] += s[i];
    }

    let mut ans = 0.0;
    for i in 0..n - k + 1 {
        let t = s[i + k] - s[i];
        if ans < t {
            ans = t;
        }
    }
    println!("{:.10}", ans);
}


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

def slove():
    n, k = map(int,input().split())
    building = list(map(int,input().split()))
    # print(building)
    
    ans = 10 ** 15
    for i in range(1 << n):
        if i & 1 == 1 or bin(i >> 1).count("1") != k-1:
            continue

        # 2020/06/09 first idea
        # this is not completed answer
        """ 
        p_b = [building[0],]
        for j in range(1,n):
            if i >> j & 1 == 1:
                p_b.append(building[j])
        #print(bin(i),p_b) 
        tmp_ans = 0
        max_h = p_b[0]
        for j in range(1,n):
            if max_h < p_b[j]:
                max_h = p_b[j]
                continue
            else:
                tmp_ans += 1 + max_h - p_b[j]
                max_h += 1
        #print(tmp_ans)
        else:
            ans = min(ans,tmp_ans)
        """
        tmp_ans = 0
        highest = 0
        for j in range(n):
            if i >> j & 1 and highest < building[j]:
                highest = building[j]
            elif i >> j & 1 and highest >= building[j]:
                highest += 1
                tmp_ans += highest - building[j]
            else:
                if highest < building[j]:
                    highest = building[j]
        ans = min(ans,tmp_ans)
    print(ans)

if __name__ == "__main__":
    slove()

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

int main() {
    string s,x;
    cin>>s;

    rep(i,0,s.size()){
        if(s[i]=='1'||s[i]=='0'){
            x+=s[i];
        }
        if(s[i]=='B'){
            if(x.size()!=0){
                x.pop_back();
            }
        }
    }
    cout<<x<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;


struct SegmentTree{
    using F = function<long long(long long,long long)>;
    F f;
    const long long unit;
    int n;
    vector<long long> node;
    

    SegmentTree(F f,long long unit,vector<long long> v):f(f),unit(unit){
            int sz = v.size();
            n = 1;
            while(n < sz) n *= 2;
            node.resize(2*n-1,unit);
            for(int i=0;i<sz;i++) node[i+n-1] = v[i];
            for(int i=n-2;i>=0;i--) node[i] = f(node[2*i+1],node[2*i+2]);
    }
    
    //iをxに更新する。
    void update(int i,long long x){
            i += n-1;
            node[i] = x;
            while(i > 0){
                    i = (i-1)/2;
                    node[i] = f(node[2*i+1],node[2*i+2]);
            }
    }
    
    long long query(int a,int b,int k=0,int l=0,int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return unit;
        if(a <= l && r <= b) return node[k];
        long long vl = query(a,b,2*k+1,l,(l+r)/2);
        long long vr = query(a,b,2*k+2,(l+r)/2,r);
        return f(vl,vr);
    }
};

int main(){
    auto f = [](ll a,ll b){ return min(a,b);};
    auto g = [](ll a,ll b){ return max(a,b);};
    const ll unitf = INF;
    const ll unitg = -1;
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    SegmentTree getmin(f,unitf,a);
    SegmentTree getmax(g,unitg,a);
    vector<int> mx(n);
    mx[0] = 1;
    for(int i=1;i<n;i++){
        if(a[i] > a[i-1]) mx[i] = mx[i-1] + 1;
        else mx[i] = 1;
    }
    int ans = 1;
    bool same = (mx[k-1] >= k);
    for(int i=0;i<=n-k-1;i++){
        if(getmin.query(i,i+k+1)==a[i] && getmax.query(i,i+k+1)==a[i+k]) continue;
        if(mx[i+k] >= k && same) continue;
        if(mx[i+k] >= k) same = true;
        ++ ans;
    }
    /*
    rep(i,n) cout << mx[i] << " " ;
    cout << endl;
    */
    cout << ans << endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	char a,b;
	cin >> a >> b;
	if(a == 'H')
		if(b == 'H')
			cout << a << "\n";
		else cout << "D\n";
	else if(b == 'H')
		cout << "D\n";
	else cout << "H\n";	
	return 0;
}

Measured memory_bytes: 256
import math
from collections import deque
def main():
    t = [int(t)for t in input().split()]
    x,y = t[0],t[1]

    earned = 0

    if x == 1:
        earned += 300000
    elif x == 2:
        earned += 200000
    elif x == 3:
        earned += 100000
    if y == 1:
        earned += 300000
    elif y == 2:
        earned += 200000
    elif y == 3:
        earned += 100000

    if x == y and x == 1:
        earned += 400000

    print(earned)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(string, s);
    s.pop_back();
    while (s.size()) {
        if (s.length() % 2 == 0) {
            const string t = s.substr(0, s.length() / 2);
            if (t + t == s) {
                print(s.length());
                return 0;
            }
        }
        s.pop_back();
    }


    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var t string
var alphabet = []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}

func main() {

	fmt.Scan(&t)
	m := make(map[string]int, len(t))

	for i := 0; i < len(alphabet); i++ {
		m[alphabet[i]]++
	}

	for i := 0; i < len(t); i++ {
		delete(m, string(t[i]))
	}

	for i := 0; i < len(alphabet); i++ {
		if m[alphabet[i]] != 0 {
			fmt.Println(alphabet[i])
			return
		}
	}
	fmt.Println("None")
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

struct DOT{
    int x;
    int y;
    int idx;
};

int uf_find(vector<int>& v, int a)
{
    if(v[a]==a) return a;
    return v[a]=uf_find(v,v[a]);
}

void uf_union(vector<int>& v, int a, int b)
{
    int ap=uf_find(v,a),bp=uf_find(v,b);
    if(ap==bp) return;
    v[max(ap,bp)]=min(ap,bp);
}

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

    int n;
    cin>>n;
    vector<int> group(n);
    vector<pair<set<int>,set<int>>> xy(n);
    for(int i=0; i<n; i++) group[i]=i;

    vector<DOT> dot(n);
    for(int i=0; i<n; i++){
        int x,y;
        cin>>x>>y;
        dot[i]={x,y,i};
    }
    sort(dot.begin(),dot.end(),[](const DOT& d1, const DOT& d2)->bool{
        return d1.x<d2.x;
    });
    for(int i=1; i<n; i++){
        if(dot[i-1].x==dot[i].x){
            uf_union(group,dot[i-1].idx,dot[i].idx);
        }
    }

    sort(dot.begin(),dot.end(),[](const DOT& d1, const DOT& d2)->bool{
        return d1.y<d2.y;
    });
    for(int i=1; i<n; i++){
        if(dot[i-1].y==dot[i].y){
            uf_union(group,dot[i-1].idx,dot[i].idx);
        }
    }

    for(int i=0; i<n; i++){
        int g=uf_find(group,dot[i].idx);
        xy[g].first.insert(dot[i].x);
        xy[g].second.insert(dot[i].y);
    }

    ll answer=0;
    for(int i=0; i<n; i++){
        answer+=(ll)xy[i].first.size()*(ll)xy[i].second.size();
    }

    cout<<answer-(ll)n;

    return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

using namespace std;

int main(){
  int K, S;
  cin >> K >> S;
  int X, Y, Z;
  int ans = 0;
  for(X = 0; X <= K; X++){
    for(int Y = 0; Y <= K; Y++){
      Z = S - X - Y;
      if(Z < 0 || Z > K) continue;
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    int n;
    cin >> n;
    vi a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    si s;
    s.insert(-1);
    s.insert(n);
    vi idx(n+1);
    rep(i,0,n) {
        idx[a[i]] = i;
    }
    ll ret = 0;
    rep(i,1,n+1) {
        int j = idx[i];
        s.insert(j);
        auto it = s.lower_bound(j);
        --it;
        auto jt = s.upper_bound(j);
        int left = j - *it;
        int right = *jt - j;
        ret += (ll)left * right * i;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int n,m,x,y; cin >> n >> m >> x >> y;
  int x_max = -1000;
  rep(i,n){int in; cin >> in; x_max=max(x_max, in);}
  int y_min = 1000;
  rep(i,m){int in; cin >> in; y_min=min(y_min, in);}
  for(int i = x+1; i <= y; ++i){
    if(x_max < i && y_min >= i){
      cout << "No War" <<endl;
      return 0;
    }
  }
  cout << "War" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <complex>

using namespace std;

#define all(c) ((c).begin()),((c).end())
#define debug(c) cerr<<"> "<<#c<<" = "<<(c)<<endl;
#define iter(c) __typeof((c).begin())
#define tr(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

#define EPS 1.0e-6

//ツ点
typedef complex<double> P;

struct C{
	P p;
	double r;
};

vector<P> isCC(const C &c1, const C &c2) {
	double d = abs(c1.p - c2.p);
	if (c1.r + c2.r - d < -EPS || fabs(c1.r - c2.r) - d > EPS) return vector<P>();
	double x = (d*d + c1.r * c1.r - c2.r * c2.r) / 2 / d;
	double y = sqrt(c1.r * c1.r - x * x);
	P diff = (c2.p - c1.p) / d;
	vector<P> res;
	res.pb(c1.p + diff * P(x, y));
	if (y != 0) res.pb(c1.p + diff * P(x, -y));
	return res;
}


int main() {
	for (int N; cin >> N, N != 0; ) {
		vector<P> ps;
		rep (i, N) {
			double x, y; char c; cin >> x >> c >> y;
			ps.pb(P(x, y));
		}
		int res = 0;
		rep (i, N) REP (j, i + 1, N-1) {
			vector<P> isp = isCC((C){ps[i],1},(C){ps[j],1});
			rep (k, isp.size()) {
				int cnt = 0;
				rep (l, N) if (abs(isp[k] - ps[l]) <= 1 + EPS) cnt++;
				res = max(res, cnt);
			}
		}
		if (res == 0) res++;
		cout << res <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#!/mnt/c/Users/moiki/bash/env/bin/python
N,C = map(int, input().split())
D = [ [int(j) for j in input().split()] for _ in range(C)]
colorInit = [ [int(j) for j in input().split()] for _ in range(N)]

from collections import Counter

cset = [ [], [], [] ]

for i in range(1,N+1):
    for j in range(1,N+1):
        cset[(i+j)%3].append(  colorInit[i-1][j-1] ) 

# print("----")
# for i in range(1,N+1):
#     for j in range(1,N+1):
#         print("{:2d} ".format((i+j)%3), end = " ")
#     print("")


cs1 = Counter(cset[1])
cs2 = Counter(cset[2])
cs3 = Counter(cset[0])
        
# print(colorInit)
# print(cs1,cs2,cs3)
# for k in cs1.keys():
#     print("k: ", k  ) 

# exit(0)

ans = float("inf")
for c1 in range(1,C+1):
    for c2 in range(1,C+1):
        if c1 == c2: continue
        for c3 in range(1,C+1):
            if c1 == c3 or c2 == c3: continue
            tmp = 0
            for k in cs1.keys():
                tmp += cs1[k]* D[k-1][c1-1]
            for k in cs2.keys():
                tmp += cs2[k]* D[k-1][c2-1]
            for k in cs3.keys():
                tmp += cs3[k]* D[k-1][c3-1]
            # print("tmp: ", tmp)
            ans = min(ans, tmp)
            # exit(0)
print(ans)



Measured memory_bytes: 57052
N = int(input())
A = list(map(int,input().split()))

for i in range(N-1):
#  print(i)
#  print(A[i+1] - A[i])
  if A[i+1] - A[i] <= -2:
    print('No')
    exit()
  elif A[i+1] - A[i] == -1:
    A[i+1] += 1
print('Yes')

Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forN(i, n) for(int i = 0; i <n ; ++i)
#define endl "\n"
#define noob (main)
typedef long long ll;
using namespace  std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const int N = 2e5 +5 ;
ll n,m,A[N];

int noob(){
    fastIO;
    cin>>n;
    cout<<pow(n,3);
}



Measured memory_bytes: 4204
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = n;
		for (int i = 0; i < n - 1; i++) {
		    ans += (long)(i + 1) * (n - i);
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    long left = Math.min(a, b);
		    int right = Math.max(a, b);
		    ans -= (left + 1) * (n - right);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 58992
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int n;
	cin >> n;

	cout << n / 3 << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace oasobi
{
    static class MainClass
    {
        public static void Main()
        {
            int x = int.Parse(Console.ReadLine());
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int s = x;
            s = s - a;
            while( s >= b)
            {
                s = s - b;
            }
            Console.WriteLine(s);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());
  queue<int> q;
  ll ans=0;
  for(ll i=0;i<N;i++){
    if(i==0) q.push(A[i]);
    else{
      ans += q.front();
      q.pop();
      q.push(A[i]);
      q.push(A[i]);
    }
  }
  cout << ans;
}



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

using ll=long long; 

void solve(){
	map<char, int> dict;
	dict['a']=0;dict['b']=1;dict['c']=2;
	string s[3];
	for(auto& e:s){
		cin>>e;
		reverse(e.begin(), e.end());
	}
	int cur=0;
	while(1){
		if(!s[cur].empty()){
			char next=*(s[cur].end()-1);
			s[cur].pop_back();
			cur=dict[next];
			//cout<<cur<<endl;
		}else{
			cout<<char('A'+cur)<<endl;
			break;
		}
	}
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 100005
vector<int> G[N];
int _dp[N];
int dp(int v) {
	if (~_dp[v]) return _dp[v];
	int rt = 0;
	for (int u : G[v]) {
		rt = max(rt, dp(u) + 1);
	}
	return (_dp[v] = rt);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m;
	cin >> n >> m;
	while (m--) {
		int u, v;
		cin >> u >> v;
		G[v].push_back(u);
	}
	for (int i = 1 ; i <= n ; ++i) {
		G[0].push_back(i);
		_dp[i] = -1;
	}
	_dp[0] = -1;
	cout << dp(0) - 1 << '\n';
}

Measured memory_bytes: 14076