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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

ll mod_inv(ll m){
  return mpow(m, MOD-2);
}

struct COM{
  vll fact, fact_inv;
  COM(ll n): fact(n+1,1), fact_inv(n+1,1){
    for(ll i=1; i<=n; i++)
      fact[i] = fact[i-1]*i%MOD;

    fact_inv[n] = mod_inv(fact[n]);
    for(ll i=n; i>=1; i--)
      fact_inv[i-1] = fact_inv[i]*i%MOD;
  }

  ll calc(ll n, ll k){
    if(k<0 || n<k)
      return 0;
    ll res = fact[n]*fact_inv[n-k]%MOD*fact_inv[k]%MOD;
    return res;
  }
};



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll x(n);
  REP(i,n)cin>>x[i];

  vll remind(n+3);
  for(ll i=1; i<=n; i++){
    remind[i+1]=(remind[i]+mod_inv(i))%MOD;
  }


  COM com(n);
  ll ans=0;
  REP(i,n-1){
    ll dist=x[i+1]-x[i];
    ll l=1;
    ll r=i+2;
    ll plus=dist*((remind[r]-remind[l]+MOD)%MOD)%MOD;
    ans=(ans+plus)%MOD;
  }

  ans=ans*com.fact[n-1]%MOD;

  cout<<ans<<endl;
}



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

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

int Q;

int main(){

    set<pii> st;
    ll sumb = 0;
    ll funa = 0;
    pii cent = pii(0, 0);
    cin >> Q;
    for(int q = 0; q < Q; q++){
        int num, a, b;
        cin >> num;
        if(num == 1){
            cin >> a >> b;
            sumb += b;
            st.insert(pii(a, q));
            if((int)st.size() == 1){
                cent = pii(a, q);
            }
            // 前が奇数、今偶数
            else if(st.size() % 2 == 0){
                if(cent <= pii(a, q)){
                    funa += abs(cent.first - a);
                }
                else{
                    funa += abs(cent.first - a);
                    auto it = --st.find(cent);
                    // funa -=  abs(it->first - cent.first);
                    cent = *it;
                }
            }
            // 前が偶数、今奇数
            else{
                if(cent >= pii(a, q)){
                    funa += abs(cent.first - a);
                }
                else{
                    funa += abs(cent.first - a);
                    auto it = ++st.find(cent);
                    funa -=  abs(it->first - cent.first);
                    cent = *it;
                }
            }
        }
        else{
            cout << cent.first << " " << funa + sumb  << endl;
        }
    }
    


    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}


int main()
{
    std::string word = "aa";
    int64_t a,b,c,d,e,f;
 
    std::vector< std::pair< int64_t, int64_t > > list;
    std::cin>> word;

    std::string aa = "No";

if( word.size() != 1 )
    {
        for( int i = 1; i < word.size(); i++ )
        {
            if( word[0] != word[i] )
            {
                aa = "Yes";
            }
        }
    }
    
 std::cout<< aa;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x-I .)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int H, W;
vector<vector<char>> nap(10, vector<char>(10));

bool exist(int i, int j, vector<vector<char>> now){
    if(i == H && j == W){
        bool ok = true;
        REP(i,H)REP(j,W){
            if(nap[i][j] == '#')if(now[i][j] != '#')ok = false;
        }
        return ok;
    }
    bool res = false;
    vector<vector<char>> rgo = now;
    vector<vector<char>> dgo = now;
    rgo[i][j+1] = '#';
    dgo[i+1][j] = '#';
    if(j < W)if(exist(i, j+1, rgo))res = true;
    if(i < H)if(exist(i+1, j, dgo))res = true;
    return res;
}

int main(){
    cin >> H >> W;
    REP(i,H)REP(j,W)cin >> nap[i][j];
    vector<vector<char>> so(10, vector<char>(10));
    so[1][1] = '#';
    cout << (exist(1,1,so) ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    
		int n = sc.nextInt();
		
		for (int i = 1; i <= n; i++){
			if ((i % 3 == 0) || (i % 10 == 3) || include3(i / 10)){
					System.out.print(" "+ i);
			}
		}
		System.out.println("");
	}
	
	public static boolean include3(int num){
		boolean flg = false;
		String s = Integer.toString(num);
		for (int i = 0; i < s.length(); i++){
			if (s.charAt(i) == '3'){
				flg = true;
			}
		}
		return flg;
	}
}

Measured memory_bytes: 24164
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	int n;
	std::cin >> n;
	int a = n / 1000, b = n % 1000 / 100, c = n % 1000 % 100 / 10, d = n % 1000 % 100 % 10;
	if (a + b + c + d == 7) {
		std::cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << std::endl;
	}
	 else if (a + b + c - d == 7) {
		std::cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << std::endl;
	}
	else if (a + b - c - d == 7) {
		std::cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << std::endl;
	}
	else if (a - b - c - d == 7) {
		std::cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << std::endl;
	}
	else if (a - b + c - d == 7) {
		std::cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << std::endl;
	}
	else if (a - b - c + d == 7) {
		std::cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << std::endl;
	}
	else if (a - b + c + d == 7) {
		std::cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << std::endl;
	}
	else if (a + b - c + d == 7) {
		std::cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << std::endl;
	}
	return 0;
}

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

int main() {
  char a, b;
  cin >> a >> b;
  if ((a=='H'&&b=='H')||(a=='D'&&b=='D')) {
    cout << 'H' << endl;
  }
  else {
    cout << 'D' << endl;
  }
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
#define vii vector <pair <int, int> >
using namespace std;

const ll INF = 1e15;

const ll MAXN = 1e5 + 100;
ll n, a[MAXN];

int check(ll val) {

    for(int i = 1; i <= n; ++i) {

        val -= (val % a[i]);

    }

    if(val == 2) {return 0;}
    else if(val > 2) {return 1;}
    else {return 2;}

}

void bin_search() {


    ll l = 2;
    ll r = INF;
    ll mx = -1;
    ll mn = INF;

    while(l <= r) {

        ll mid = (l + r) / 2ll;

        if(check(mid) == 0) {r = mid - 1; mx = max(mx, mid); mn = min(mn, mid);}
        else if (check(mid) == 1) {r = mid - 1;}
        else {l = mid + 1;}

    }

    l = 2;
    r = INF;

    while(l <= r) {

        ll mid = (l + r) / 2ll;

        if(check(mid) == 0) {l = mid + 1; mx = max(mx, mid); mn = min(mn, mid);}
        else if (check(mid) == 1) {r = mid - 1;}
        else {l = mid + 1;}

    }

    if(mn == INF && mx == -1) {cout << -1;return;}

    cout << mn << ' ' << mx;


}

void solve() {

    cin >> n;

    for(int i = 1; i <= n; ++i) {

        cin >> a[i];

    }

    bin_search();

}

int main(){

mal
//freopen("ladder.in", "r", stdin);
//freopen("ladder.out", "w", stdout);

ll tt = 1;


while(tt--) {

    solve();

}

return 0;
}



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


int main(){
int A,B;
cin>>A>>B;
int all_tap = A;
int howmany = 1;
if(B==1){
    cout<<0<<endl;
    return 0;
}
while(all_tap < B){
    howmany++;
    all_tap--;
    all_tap +=A;
}
cout<<howmany<<endl;
}

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

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
long long A[100000];
vector<int> G[100000];

long long f(int x, int p) {
  if (G[x].size() <= 1) return A[x];
  long long c = 0, m = 0;
  for (int t : G[x]) {
    if (t == p) continue;
    long long e = f(t, x);
    m = max(e, m);
    c += e;
  }
  long long b = c - A[x];
  long long a = A[x] - b;
  if (a < 0 || b < 0 || m > (c-m)+a) {
    puts("NO");
    exit(0);
  }
  return a;
}

signed main() {
  scanf("%d", &N);
  rep(i, N) scanf("%d", &A[i]);
  rep(i, N-1) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int r = -1;
  rep(i, N) {
    if (G[i].size() > 1) {
      r = i;
      break;
    }
  }
  if (r == -1) {
    int x = A[0];
    rep(i, N) {
      if (A[i] != x) {
        puts("NO");
        return 0;
      }
    }
    puts("YES");
  }
  else {
    if (f(r, -1) == 0) puts("YES");
    else puts("NO");
  }
  return 0;
}


Measured memory_bytes: 13184
def main():
    a,b,c = map(int,input().split())
    s =[list(map(str,input()))for i in range(a)]
    cnt =0
    count=0
    for i in range(2**a):
        for j in range(2**b):
            cnt=0
            for ia in range(a):
                for ib in range(b):
                    if not i &(1<<ia) and not j&(1<<ib):
                            if s[ia][ib] =='#':
                                cnt+=1
            if cnt ==c:
                count+=1
    print(count)
if __name__ =='__main__':
    main()



Measured memory_bytes: 9048
// Problem Link: 
    // Tutorial Link: 
     
    #include<bits/stdc++.h>
     
    using namespace std;
     
    #define LL long long
    #define pb push_back
    #define pLL pair<LL,LL>
    #define ff first
    #define ss second
    #define rep(i,a,b) for(LL i=a;i<=b;++i)
    #define repb(i,a,b) for(LL i=a;i>=b;--i)
    #define ld double
    #define mp make_pair
    #define vLL vector<LL>
    #define vpLL vector<pLL>
    #define vld vector<ld>
    #define pld pair<ld,ld>
    #define vpld vector<pld>
    #define SLL set<LL>
    #define SpLL set<pLL>
    #define FIO ios::sync_with_stdio(false)
    #define mod 1000000007
     
    LL n,k,a[200005];
    vLL pos, neg;
     
    int main()
    {
    	FIO;
    	cin >> n >> k;
    	rep(i,1,n) cin >> a[i];
    	LL pc = 0, nc = 0;
    	rep(i,1,n) {
    		if(a[i] > 0) {
    			pos.pb(a[i]);
    			pc++;
    		}
    		else if(a[i] < 0) {
    			neg.pb(a[i]);
    			nc++;
    		}
    	}
    	if(pc+nc < k) {
    		cout << 0 << endl;
    		return 0;
    	}
    	sort(pos.begin(), pos.end());
    	reverse(pos.begin(), pos.end());
    	sort(neg.begin(), neg.end());

		if(pc == 0) {
			if(nc < n && k%2) {
				cout << 0 << endl;
				return 0;
			}
			if(k%2) reverse(neg.begin(), neg.end());
			LL ans = 1;
			rep(i,0,k-1) ans = (ans*neg[i]) % mod;
			cout << (ans+mod) % mod << endl;
			return 0; 
		}
		else if (pc+nc == k) {
			LL ans = 1;
			for(auto c: pos) ans = (ans*c) % mod;
			for(auto c: neg) ans = (ans*c) % mod;
			cout << (ans+mod) % mod << endl;
			return 0;
		}
     
    	LL ans = 1, cp = 0, cn = 0, tot = 0;
    	while(tot < k) {
			if(cp == pc-1 && (k-tot)%2 == 0) {
				cp = pc;
			}
    		if(cp == pc) {
    			tot++;
    			cn++;
    			ans = (ans*neg[cn-1]) % mod;
    		}
    		else if(cn == nc || tot == k-1) {
    			tot++;
    			cp++;
    			ans = (ans*pos[cp-1]) % mod;
    		}
    		else {
    			if(cn < nc-1 && (cp == pc-1 || (pos[cp]*pos[cp+1] < neg[cn]*neg[cn+1]))) {
					tot += 2;
    				cn++;
    				ans = (ans*neg[cn-1]) % mod;
    				cn++;
    				ans = (ans*neg[cn-1]) % mod;
				}
    			else {
					tot++;
					cp++;
					ans = (ans*pos[cp-1]) % mod;
				}
    		}
    	} 
    	cout << (ans+mod)%mod << endl;
    }

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vec P(A), Q(B), R(C);
    REP(i,0,A) cin >> P[i];
    REP(i,0,B) cin >> Q[i];
    REP(i,0,C) cin >> R[i];

    DESC(P); DESC(Q); ASC(R);
    while(SZ(P) > X) P.pop_back();
    while(SZ(Q) > Y) Q.pop_back();
    REV(P); REV(Q);

    ll x = 0, y = 0;
    while(SZ(R) > 0) {
        x = MIN(x,X-1);
        y = MIN(y,Y-1);
        ll p = P[x], q = Q[y];
        ll r = R.back(); R.pop_back();
        if(p <= q && q <= r) {
            P[x] = r;
            ++x;
        }
        else if(p <= r && r <= q) {
            P[x] = r;
            ++x;
        }
        else if(q <= p && p <= r) {
            Q[y] = r;
            ++y;
        }
        else if(q <= r && r <= p) {
            Q[y] = r;
            ++y;
        }
    }
    
    ll sum = 0;
    REP(i,0,X) sum += P[i];
    REP(i,0,Y) sum += Q[i];
    PR(sum);

    return 0;
}

/*

p q r -> p = r
p r q -> p = r
q p r -> q = r
q r p -> q = r
r p q -> x
r q p -> x

*/

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

int main()
{
    char c;
    cin >> c;
    if( c >= 'a' && c <= 'z' ) cout << 'a';
    if( c >= 'A' && c <= 'Z' ) cout << 'A';

    return 0;    
}

Measured memory_bytes: 3676
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int N;
  int M;
  int kei=0;

  cin >> N;
  cin >> M;
  vector<int> homework(M);

  for(int i = 0;i < M;i++){
    cin >> homework.at(i);
    kei += homework.at(i);
  }
  if(N >= kei){
    cout << N-kei << endl;
  }else{
    cout << "-1" << endl;
  }
}


Measured memory_bytes: 3664
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int M;
  cin>>M;
  ll sum = 0, ans = -1;
  ll d, c;
  for(int i=0;i<M;++i) {
    cin>>d>>c;
    sum += d*c;
    ans += c;
  }
  if(sum%9==0) ans += sum/9-1;
  else ans += sum/9;
  cout<<ans<<endl;
}



Measured memory_bytes: 3520
#include <iostream>
using namespace std;
int main(){
    int x,y;
    while(true){
        cin>>x>>y;
        if(x==0&&y==0){
            break;
        }
        if(x<y){
            cout<<x<<" "<<y<<endl;
        }else{
            cout<<y<<" "<<x<<endl;
        }
    }
}


Measured memory_bytes: 3076
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    String str=s.next();
	char[] c=str.toCharArray();
    if(Character.isUpperCase(c[0])) System.out.println("A");
    else System.out.println("a");

  }  
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

const ll mod = static_cast<int>(1e9 + 7);

ll dp[4][4][4][110];

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

	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				if (i == 0 && j == 2 && k == 1) {
					dp[i][j][k][3] = 0;
				}
				else if (i == 0 && j == 1 && k == 2) {
					dp[i][j][k][3] = 0;
				}
				else if (i == 2 && j == 0 && k == 1) {
					dp[i][j][k][3] = 0;
				}
				else {
					dp[i][j][k][3] = 1;
				}
			}
		}
	}

	for (int m = 4; m <= N; ++m) {
		for (int i = 0; i < 4; ++i) {
			for (int j = 0; j < 4; ++j) {
				for (int k = 0; k < 4; ++k) {
					for (int l = 0; l < 4; ++l) {
						if (j == 0 && k == 2 && l == 1) {
							dp[j][k][l][m] += 0;
						}
						else if (j == 0 && k == 1 && l == 2) {
							dp[j][k][l][m] += 0;
						}
						else if (j == 2 && k == 0 && l == 1) {
							dp[j][k][l][m] += 0;
						}
						else if (i == 0 && k == 2 && l == 1) {
							dp[j][k][l][m] += 0;
						}
						else if (i == 0 && j == 2 && l == 1) {
							dp[j][k][l][m] += 0;
						}
						else {
							dp[j][k][l][m] += dp[i][j][k][m - 1];
							dp[j][k][l][m] %= mod;
						}
					}
				}
			}
		}
	}

	ll ans = 0;
	for (int i = 0; i < 4; ++i) {
		for (int j = 0; j < 4; ++j) {
			for (int k = 0; k < 4; ++k) {
				ans += dp[i][j][k][N];
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353


def get_factorials(max, mod=None):
    """
    階乗 0!, 1!, 2!, ..., max!
    :param int max:
    :param int mod:
    :return:
    """
    ret = [1]
    n = 1
    if mod:
        for i in range(1, max + 1):
            n *= i
            n %= mod
            ret.append(n)
    else:
        for i in range(1, max + 1):
            n *= i
            ret.append(n)
    return ret


def mod_invs(max, mod):
    """
    逆元のリスト 0 から max まで
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


def factorial_invs(max, mod):
    """
    階乗 0!, 1!, 2!, ..., max! の逆元
    :param int max:
    :param int mod:
    """
    ret = []
    r = 1
    for inv in mod_invs(max, mod):
        r = r * inv % mod
        ret.append(r)
    return ret


class Combination:
    def __init__(self, max, mod):
        """
        :param int max:
        :param int mod: 3 以上の素数であること
        """
        self._factorials = get_factorials(max, mod)
        self._finvs = factorial_invs(max, mod)
        self._mod = mod

    def ncr(self, n, r):
        """
        :param int n:
        :param int r:
        :rtype: int
        """
        if n < r:
            return 0
        return self._factorials[n] * self._finvs[r] % self._mod * self._finvs[n - r] % self._mod


N, A, B, K = list(map(int, sys.stdin.readline().split()))
comb = Combination(max=N, mod=MOD)
# ans = 0
# # A の数が決まれば B の数も決まる
# for a in range(N + 1):
#     if (K - a * A) % B != 0:
#         continue
#     b = int((K - a * A) // B)
#     if not (0 <= a <= N and 0 <= b <= N):
#         continue
#
#     s = 0
#     # 緑
#     c = min(a, b)
#     # A
#     a -= c
#     # B
#     b -= c
#     # 無色
#     d = N - a - b - c
#     # ここ高速化したい
#     while c >= 0 and d >= 0:
#         s += comb.ncr(N, a) * comb.ncr(N - a, b) * comb.ncr(N - a - b, c)
#         a += 1
#         b += 1
#         c -= 1
#         d -= 1
#
#     ans += s
#     ans %= MOD
# print(ans)


# # dp[i, a, b]: i番目までで、残り使うべき A が a 個、B が b 個残ってるパターン数
# dp = np.zeros((N + 1, N + 1, N + 1), dtype=int)
#
# # A の数が決まれば B の数も決まる
# for a in range(N + 1):
#     if (K - a * A) % B != 0:
#         continue
#     b = int((K - a * A) // B)
#     if not (0 <= a <= N and 0 <= b <= N):
#         continue
#     dp[0][a][b] += 1
#
# for i in range(1, N + 1):
#     dp[i] += dp[i - 1]
#     dp[i, :-1] += dp[i - 1, 1:]
#     dp[i, :, :-1] += dp[i - 1, :, 1:]
#     dp[i, :-1, :-1] += dp[i - 1, 1:, 1:]
# print(dp)
# print(dp[-1][0][0])


# 未証明、DP テーブル見た
ans = 0
for a in range(N + 1):
    if (K - a * A) % B != 0:
        continue
    b = int((K - a * A) // B)
    if not (0 <= a <= N and 0 <= b <= N):
        continue
    ans += comb.ncr(N, a) * comb.ncr(N, b)
    ans %= MOD
print(ans)


Measured memory_bytes: 38704
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, core.stdc.string;

immutable long INF = 1L<<59;

void main() {
    auto N = readln.chomp.to!int;
    auto X = readln.split.map!(to!long).array;
    auto G = new Tuple!(int, long)[][](2*N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, s[2].to!long);
        G[s[1]-1] ~= tuple(s[0]-1, s[2].to!long);
    }
    foreach (i; 0..N) {
        G[i] ~= tuple(i+N, X[i]);
        G[i+N] ~= tuple(i, X[i]);
    }

    auto dist = new long[](2*N);
    auto color = new int[](2*N);
    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, long)), "a[2] > b[2]");
    foreach (i; N..2*N) pq.insert(tuple(i, i, 0L));
    dist[] = 1L << 59;


    while (!pq.empty) {
        auto n = pq.front[0];
        auto c = pq.front[1];
        auto d = pq.front[2];
        pq.removeFront;
        if (dist[n] <= d) continue;
        dist[n] = d;
        color[n] = c;
        foreach (e; G[n]) {
            auto m = e[0];
            auto nd = d + e[1];
            if (dist[m] <= nd) continue;
            pq.insert(tuple(m, c, nd));
        }
    }


    long ans = 0;

    foreach (i; 0..2*N) {
        foreach (e; G[i]) {
            int j = e[0];
            long c = e[1];
            if (j > i || color[i] == color[j]) continue;
            ans += dist[i] + dist[j] + c;
        }
    }

    ans.writeln;
}


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

int main(void){
  int x,y,z;
  cin >> x >> y >> z;
  if((x==5 && y== 5 && z==7) || (x==5 && y== 7 && z==5) || (x==7 && y== 5 && z==5)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct unionfind{
  vector<int> p;
  unionfind(int n){
    p = vector<int>(n, -1);
  }
  int root(int x){
    if (p[x] == -1){
      return x;
    } else {
      p[x] = root(p[x]);
      return p[x];
    }
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    p[x] = y;
  }
};
int main(){
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> E(M);
  for (int i = 0; i < M; i++){
    int S, D, C;
    cin >> S >> D >> C;
    S--;
    D--;
    E[i] = make_tuple(C, S, D);
  }
  sort(E.begin(), E.end());
  unionfind UF(N);
  vector<bool> used(M, false);
  int sum = 0;
  for (int i = 0; i < M; i++){
    int C = get<0>(E[i]);
    int S = get<1>(E[i]);
    int D = get<2>(E[i]);
    if (!UF.same(S, D)){
      used[i] = true;
      UF.unite(S, D);
      sum += C;
    }
  }
  int ans1 = 0;
  int ans2 = 0;
  for (int i = 0; i < M; i++){
    if (used[i]){
      int sum2 = 0;
      unionfind UF2(N);
      int cnt = 0;
      for (int j = 0; j < M; j++){
        if (i != j){
          int C = get<0>(E[j]);
          int S = get<1>(E[j]);
          int D = get<2>(E[j]);
          if (!UF2.same(S, D)){
            UF2.unite(S, D);
            cnt++;
            sum2 += C;
          }
        }
      }
      if (sum2 > sum || cnt < N - 1){
        ans1++;
        ans2 += get<0>(E[i]);
      }
    }
  }
  cout << ans1 << ' ' << ans2 << endl;
}


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


ll f(ll x) {
    x++;
    ll res = 0;
    // 1の位
    if ((x/2) % 2 != 0) res += 1;

    // それより上の位
    ll order = 1;
    while (true) {
        
        order++;
        ll y = ((1ULL)<<order);
        ll r = x%y;
        y/=2;
        if (x < y) break;
        if (r < y) continue;
        else {
            if((r-y)%2 != 0) res += y;
        }
    }

    return res;
}


int main() 
{
    ll a, b;
    cin >> a >> b;
    ll ans = f(b) ^ f(a-1);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	double kkt; cin >> kkt;

	double res = kkt * sqrt(2);
	for (int i = 0; i <= (int)kkt; i++) {
		double tmp = 0.0;
		int d = i;
		tmp = sqrt(kkt * kkt - d * d);
		chmax(res, (double)i + chmax(tmp, 1.0));

	}
	cout << fixed << setprecision(12) << res << endl;
	return 0;

}


Measured memory_bytes: 3296
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-03 11:02:19
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

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

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

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

  int n, m, q; cin >> n >> m >> q;
  vector<int> a(q), b(q), c(q), d(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i]; --b[i];
  }

  vector<int> v(n, -1);

  int ans = 0;

  auto dfs = [&](auto&& rec, int p) -> void {
    if (p == n) {
      debug(v);
      int t = 0;
      for (int i = 0; i < q; ++i) {
        if (v[b[i]] - v[a[i]] == c[i]) t += d[i];
      }
      ans = max(ans, t);
    } else {
      for (int i = (p == 0 ? 1 : v[p - 1]); i <= m; ++i) {
        v[p] = i;
        rec(rec, p + 1);
      }
    }
  };

  dfs(dfs, 0);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.L;
		long p=26,g=26;
		int d=1;
		const string c="abcdefghijklmnopqrstuvwxyz";
		for(;p<n;d++) {
			n-=p;
			p*=26;
			g*=26;
		}
		var ans="";
		for(int i = d-1;i>=0;i--) {
			int k=0;
			long j=g/26;
			for(;j<n;j+=g/26,k++) {
			}
			ans+=c[k];
			n-=j-g/26;
			g/=26;
		}
		Console.WriteLine(ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27536
from collections import defaultdict


def solve():
    n, *v = map(int, open(0).read().split())
    
    dict1 = defaultdict(int)
    for i in range(0, n, 2):
        dict1[v[i]] += 1
    
    dict2 = defaultdict(int)
    for i in range(1, n, 2):
        dict2[v[i]] += 1
    
    sorted1 = sorted(dict1.items(), key=lambda x: x[1], reverse=True) + [(-1, 0)]
    sorted2 = sorted(dict2.items(), key=lambda x: x[1], reverse=True) + [(-2, 0)]
    
    ans = n
    for i in range(2):
        for j in range(2):
            if sorted1[i][0] == sorted2[j][0]:
                continue
            ans = min(ans, n - sorted1[i][1] - sorted2[j][1])
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 20952
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

int main() {
  string s;
  cin >> s;
  int n = s.size() / 2;
  for (int i = n - 1; i > 0; i--) {
    string t = s.substr(0, i);
    string u = s.substr(i, i);
    if (t == u) {
      cout << t.size() * 2 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args ){
	    Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();
	    int b = sc.nextInt();
	    if( (a*b) % 2 == 0 ) System.out.println("Even");
	    else System.out.println("Odd");
    }
}

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

#define mi           map<int,int>
#define pii          pair<int,int>
#define mpi          map<pii,int>
#define vi           vector<int>
#define vpi          vector<pii>
#define pb           push_back
#define mp           make_pair
#define x            first
#define y            second
#define all(a)       (a).begin(),(a).end()
#define fo(i,k,n)    for(int i=k;i<n;i++)
#define fod(i,k,n)   for(int i=k;i>=n;i--)
#define sz(x)        (int)x.size()

#define PI 3.141592653

typedef long long ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll> > vpl;
typedef pair<ll,ll> pll;

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int arr[n];
    fo(i,0,n) cin>>arr[i];
    int cnt=0;
    fo(i,0,n){
        if(arr[i]!=i+1) cnt++;
    }
    if(cnt<=2) cout<<"YES";
    else cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
k, n = gets.strip.split.map(&:to_i)
ary = gets.strip.split.map(&:to_i)
leng = []
ary.each_with_index do |a, b|
  if b == 0
    leng << k-ary[-1]+a
  else
    leng << a-ary[b-1]
  end
end
puts k - leng.max

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    string T = "ABC";
    string::size_type pos = 0;
    int num = 0;
    while ((pos = S.find(T, pos)) != string::npos)
    {
        ++num;
        pos += T.length();
    }
    
    //The count function for string can only be used to find one char (or num)
    cout << num << "\n";
    return 0;
    
}

Measured memory_bytes: 256
while True:
    h, w = map(int, input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if (i+j)%2==0:
                print("#", end="")
            else:
                print(".", end="")
        print()        
    print()




Measured memory_bytes: 7000
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
N = rs()
print('hon' if N[-1] in ['2', '4', '5', '7', '9'] else 'pon' if N[-1] in ['0', '1', '6', '8'] else 'bon')

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

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    int mn_a = 1e5;
    rep(i, 0, A){
        cin >> a[i];
        mn_a = min(mn_a, a[i]);
    }
    int mn_b = 1e5;
    rep(i, 0, B){
        cin >> b[i];
        mn_b = min(mn_b, b[i]);
    }
    int ans = mn_a + mn_b;
    rep(i, 0, M){
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, a[x-1]+b[y-1]-c);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n; cin>>n;
    vector<pp> a(n);
    rep(i,n){
        int A; cin>>A;
        a[i]=mk(A,i);
    }
    sort(al(a)); reverse(al(a));
    rep(i,n){
        cout<<(a[0].second==i ? a[1].first : a[0].first)<<endl;
    }
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;


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

	vector<long long> a(n + 1);

	for (long long i = 1; i <= n; i++) cin >> a[i];

	vector<long long> came;
	set<long long> mark;

	came.push_back(1);
	mark.insert(1);

	long long loop_start = 0;
	long long loop_num = 0;

  	if (k < n) {
		long long now = 1;
		for (int i = 0; i < k; i++) {
			now = a[now];
		}

		cout << now << endl;
		return 0;
	}
  
	for (long long i = 0; i < n + 2; i++) {
		if (mark.count(a[came[i]]) > 0) {
			//見つけた!!
			for (long long j = 0; j <= i; j++) {
				if (came[j] == a[came[i]]) {
					loop_start = j;
					loop_num = i - j + 1;
					break;
				}
			}
			break;
			
		}
		else {
			came.push_back(a[came[i]]);
			mark.insert(a[came[i]]);
		}
	}


	cout << came[(k - loop_start) % loop_num + loop_start] << endl;
}

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

int main()
{
    int A,B,i,x,p=0;

    cin>>A>>B;

    if(B==1){
        cout<<"0";
    }

    else{

        for(i=1 ; ; i++){
            x = i;
            p = A+p;

            if(p>=B){
                x = i;
                break;
            }
            else{
                p = p-1;
            }
        }

        cout<<x;
    }
}


Measured memory_bytes: 256
//
//  main.cpp
//  ALDS1_3_D
//
//  Created by ptyuan on 2018/10/21.
//  Copyright © 2018 Sy. All rights reserved.
//

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    stack <int> s1;
    stack <pair<int, int> > s2;
    char c;
    int sum = 0;
    for (int i = 0; cin >> c; i++) {
        if ('\\' == c) {
            s1.push(i);
        } else if ('/' == c && s1.size() > 0) {
            int j = s1.top();
            s1.pop();
            sum += i - j;
            int a = i - j;
            
            while (s2.size() > 0 && s2.top().first > j) {
                a += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, a));
        }
    }
    
    vector<int> vec;
    while (s2.size() > 0) {
        vec.push_back(s2.top().second);
        s2.pop();
    }
    
    reverse(vec.begin(), vec.end());
    
    cout << sum << endl;
    cout << vec.size();
    for (int i = 0; i < vec.size(); i++) {
        cout << " " << vec[i];
    }
    
    cout << endl;
    
    
    return 0;
}



Measured memory_bytes: 3268
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  unordered_map<ll, int> dmp;
  unordered_map<ll, int> tmp;
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    dmp[x]++;
  }
  int m;
  cin >> m;
  for(int i = 0; i < m; i++){
    ll x;
    cin >> x;
    tmp[x]++;
  }
  for(auto itr = tmp.begin(); itr != tmp.end(); ++itr){
    ll val = itr->first;
    int count = itr->second;
    if(dmp[val] < count){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
	return 0;
}


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

/*int Digits_count(int number){
  int count = 0;
  while(number != 0){
    number /= 10;
    count++;
  }
  return count;
}*/

int main(void){
  int n;
  int Dig;
  int x = 0;
  cin >> n;
  int number = n;
  //int count = Digits_count(n);
  while(n != 0){
    Dig = n % 10;
    x += Dig;
    n /= 10;
  }
  if(number%x == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
const int maxN = (int)1e5 + 100;
int a[maxN], b[maxN];
int p[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    vector < pair < int, int > > c1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        c1.emplace_back(a[i], i);
    }
    vector < pair < int, int > > c2;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        c2.emplace_back(b[i], i);
    }
    sort(c1.begin(), c1.end());
    sort(c2.begin(), c2.end());
    for (int i = 0; i < n; i++) {
        if (c1[i].first > c2[i].first) {
            cout << "No";
            return 0;
        }
    }
    for (int i = 0; i + 1 < n; i++) {
        if (c1[i + 1].first <= c2[i].first) {
            cout << "Yes";
            return 0;
        }
    }
    for (int i = 0; i < c1.size(); i++) {
        p[c1[i].second] = c2[i].second;
    }
    int it = 0;
    int v = 1;
    while (p[v] != 1) {
        v = p[v];
        it++;
    }
    it++;
    if (it == n) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 3188
#pragma warning(disable: 4996)
#include<stdio.h>
 int main() {
	 int x;
	 scanf("%d", &x);
	 int c500 = x / 500; // 500 円硬貨の数
	 int r500 = x % 500; // 端数
	 int c5 = r500 / 5; // 5 円硬貨の数
	 printf("%d\n", c500 * 1000 + c5 * 5);
	
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (n, d) = readLine()!!.split(' ').map { it.toInt() }

    val arr = Array(n) {IntArray(d)}
    repeat(n) { i->
        arr[i] = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    }

    fun chk (y: IntArray, z: IntArray): Boolean {
        var tmp = 0
        repeat(d) {
            val a = y[it] - z[it]
            tmp += a*a
        }
        var dist = Math.sqrt(tmp.toDouble())
        return dist == Math.floor(dist)
    }

    var ans = 0
    for ( i in 0 until n-1) {
        for (j in i+1 until n) {
            if(chk(arr[i],arr[j])) ans++
        }
    }

    println(ans)
}


Measured memory_bytes: 36416
import math
def calc(h, w):
    case1 = (0 if h % 3 == 0 else h)
    mid = math.floor(w/2)
    case2 = float("inf")
    for i in range(1, h):
        Smin = min(i*w, mid*(h-i), (w-mid)*(h-i))
        Smax = max(i*w, mid*(h-i), (w-mid)*(h-i))
        case2 = min(Smax-Smin, case2)
    return min(case1, case2)
H, W = map(int, input().split())
print(min(calc(H,W), calc(W,H)))

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

int main() {
  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  ll g = gcd(n, m);

  ll ng = n / g;
  ll mg = m / g;

  bool ok = true;
  for (ll i = 0; i < g; i++) {
    if (s[ng * i] != t[mg * i]) {
      ok = false;
      break;
    }
  }

  if (ok) {
    cout << lcm(n, m) << endl;
  } else {
    puts("-1");
  }

  return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,count=0;
  cin >> n;
  string s,t;
  cin >> s >> t;
  for (int i=0;i<=n;i++){
    bool hantei=true;
  	for(int j=0;j<n-i;j++){
      if (s[i+j]!=t[j]) hantei=false;
    }
    if(hantei)break;
    count++;
  }
  cout << n+count <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
ll mob=1000000007;
using namespace std;
int main()
{ 
int a,b,m;
  cin>>a>>b>>m;int q=1000001,w=1000001,e=1000001;int d[m];
  int a1[a];
 
  FOR(a) {cin>>a1[i];if(q>a1[i]) q=a1[i];}
  int b1[b];
  FOR(b) {cin>>b1[i];if(w>b1[i]) w=b1[i];}
  int m1[m][3];
  FOR(m)
  { For(j,0,3)
   {
     cin>>m1[i][j];
   }
   if(a1[m1[i][0]-1]+b1[m1[i][1]-1]-m1[i][2]<e)
     e=a1[m1[i][0]-1]+b1[m1[i][1]-1]-m1[i][2];
  }

if(e<q+w)
  cout<<e;
 else
   cout<<q+w;


return 0;
}


Measured memory_bytes: 2176
n,a,b = map(int,input().split())
ans = 0
for i in range(2):
  for j in range(10):
    for k in range(10):
      for l in range(10):
        for m in range(10):
          if i*10000+j*1000+k*100+l*10+m <= n and a <= i+j+k+l+m <= b:
            ans += i*10000+j*1000+k*100+l*10+m
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
 vector<string> a={"Sunny","Cloudy","Rainy","Sunny"};
  
  for(int i=0; i<3; i++){
  if(s==a[i]){
    cout << a[i+1] << endl;
  }
  }
  
  
  
}


Measured memory_bytes: 256