akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int main(){
    int a,b,c;
    char A,B;
    cin >> a >> A >> b >> B >> c;
    
    if (a==2019){
        if(b>=5) cout << "TBD";
        else cout << "Heisei";
    }
    else if (a>2019) cout << "TBD";
    else cout << "Heisei";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>

using namespace std;
typedef pair<string, int> process;

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

  queue<process> que;

  for(int i = 0; i < n; i++) {
    string name;
    int time;
    cin >> name >> time;
    que.push(make_pair(name, time));
  }

  int time = 0;
  while(!que.empty()) {
    process p = que.front();
    que.pop();

    if(p.second <= q) {
      time += p.second;
      cout << p.first << " " << time << endl;
    } else {
      time += q;
      que.push(make_pair(p.first, p.second -q));
    }
  }

  return 0;
}



Measured memory_bytes: 6392
a,b = input().split()
a,b = int(a), int(b)
x = max(a,b)
y = min(a,b)
t = 0
if x % y == 0:
    t = y
else:
    while x % y != 0:
        z = x%y
        x = y
        y = z
    t = z

glm = a * b /t
print(round(glm))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define foreach(c,itr) for(__typeof(c)::iterator itr=c.begin();itr!=c.end();itr++)
typedef long long ll;
int i,j;

int main(){
	ios::sync_with_stdio(false);
    cin.tie();
    
	ll d,t,s;
	cin>>d>>t>>s;
	if(d>t*s) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 18;
int n;
int a[maxN];
pair < int, int > f[maxN][2];
int ans[maxN];
int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < (1 << n); i++) cin >> a[i];
    f[0][0] = make_pair(a[0], 0);
    f[0][1] = make_pair(-10000000, -1);
    for (int mask = 1; mask < (1 << n); mask++) {
        pair < int, int > can1 = make_pair(a[mask], mask);
        pair < int, int > can2 = make_pair(-10000, -1);
        for (int j = 0; j < n; j++) {
            if (mask & (1 << j)) {
                int val = mask ^ (1 << j);
                for (int k = 0; k < 2; k++) {
                    if (f[val][k] == can1 || f[val][k] == can2) continue;
                    if (f[val][k] > can1) {
                        can2 = can1;
                        can1 = f[val][k];
                    }
                    else if (f[val][k] > can2) {
                        can2 = f[val][k];
                    }
                }
            }
        }
        f[mask][0] = can1;
        f[mask][1] = can2;
        ans[mask] = f[mask][0].first + f[mask][1].first;
    }
    for (int i = 1; i < (1 << n); i++) {
        ans[i] = max(ans[i - 1], ans[i]);
        cout << ans[i] << '\n';
    }
	return 0;
}


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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int dp[10013][100][2];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    int d;
    cin >> s >> d;
    int n=s.length();
    for(int i=0;i<s[0]-'0';i++)
        dp[0][i%d][0]++;
    dp[0][(s[0]-'0')%d][1]=1;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<10;j++)
        {
            for(int k=0;k<d;k++)
            {
                int h=(j+k)%d;
                dp[i][h][0]=(dp[i][h][0]+dp[i-1][k][0])%mod;
                if(j<s[i]-'0')
                    dp[i][h][0]=(dp[i][h][0]+dp[i-1][k][1])%mod;
                else if(j==s[i]-'0')
                    dp[i][h][1]=dp[i-1][k][1];
            }
        }
    }
    cout << (dp[n-1][0][0]+dp[n-1][0][1]-1+mod)%mod;
    return 0;
}


Measured memory_bytes: 15872
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let iterator = input.split_whitespace();

    let mut stack: Vec<i32> = Vec::new();
    for s in iterator {
        if s == "+" {
            let b = stack.pop().unwrap();
            let a = stack.pop().unwrap();
            stack.push(a + b);
        } else if s == "-" {
            let b = stack.pop().unwrap();
            let a = stack.pop().unwrap();
            stack.push(a - b);
        } else if s == "*" {
            let b = stack.pop().unwrap();
            let a = stack.pop().unwrap();
            stack.push(a * b);
        } else {
            stack.push(s.parse().unwrap());
        }
    }

    return stack.pop().unwrap().to_string();
}



Measured memory_bytes: 5032
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            long k = cin.ReadLong;
            long a = cin.ReadLong;
            long b = cin.ReadLong;

            // 変換効率がダメ
            if (b - a <= 2)
            {
                Console.WriteLine(1 + k);
                return;
            }

            // k-2回でa枚未満
            if (1 + (k - 2) < a)
            {
                Console.WriteLine(1 + k);
                return;
            }

            long ans = 0;
            ans += a;
            k -= a - 1;

            if (k % 2 == 1)
            {
                ans += 1;
                k -= 1;
            }

            ans += (b - a) * (k / 2);

            Console.WriteLine(ans);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


int main(){
	int A,B;
	cin>>A>>B;

	if(A%3==0 || B%3==0 || (A+B)%3==0) puts("Possible");
	else puts("Impossible");
	return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "string"
using namespace std;

string s;
bool flag=true;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	if(s[0]=='A'){
		int cnt=0;
		int pos;
		for(int i=2;i<=s.size()-2;i++){
			if(s[i]=='C'){
				pos=i;
				cnt++;
			}
		}
		if(cnt!=1)
			flag=false;
		if(flag){
			for(int i=1;i<s.size();i++){
				if(pos==i){
					continue;
				}
				else if(int(s[i]) < 97){
					flag=false;
					break;
				}
			}
		}

		if(flag){
			cout<<"AC";
		}
		else
			cout<<"WA";
	}
	else{
		cout<<"WA";
	}
	return 0;
}

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

char s[3];

int main(){
  
  scanf("%s", s);
  
  if (!strcmp (s, "RRR")){
    printf("%d", 3);
  }else if(!strcmp(s, "RRS")){
    printf("%d", 2);
  }else if(!strcmp(s, "SRR")){
    printf("%d", 2);
  }else if(!strcmp(s, "SSS")){
    printf("%d", 0);
  }else{
    printf("%d", 1);
    
  }
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define int long long
using namespace std;

int k,x;
signed main() {
	cin>>k>>x;
	for(int i=k-1; i>=1; i--) {
		cout<<x-i<<" ";
	}
	cout<<x<<' ';
	for(int i=1; i<=k-1; i++) {
		cout<<x+i<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		
		int ans = 10000;
		
		for (int i=0; i<N; i++){
			int c = sc.nextInt();
			int t = sc.nextInt();
			
			if (t<=T){
				ans = Math.min(c, ans);
			}
		}
		if (ans == 10000){
			System.out.println("TLE");
			
		}
		else
			System.out.println(ans);
		
		sc.close();
		
	}

}


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

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> work;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        work.push_back({a, b});
    }
    sort(work.begin(), work.end());
    priority_queue<int> q;
    int pos = 0;
    int ans = 0;
    for (int i = 1; i <= M; i++) {
        while(work[pos].first <= i && pos < N) {
            q.push(work[pos].second);
            pos++;
        }
        if (q.empty()) continue;
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 1908
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    h, w, k = nm()
    ans = 0
    C = [ns() for _ in range(h)]

    def calc(bi, bj):
        res = 0
        for i in range(h):
            for j in range(w):
                if bi & (1 << i) and bj & (1 << j) and C[i][j] == '#':
                    res += 1
        return res


    for bi in range(1 << h):
        for bj in range(1 << w):
            ans += (calc(bi, bj) == k)
    print(ans)
    return

solve()


Measured memory_bytes: 9216
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = list(input())

if S[0] == "A" and "C" in S[2:-1]:
	S.remove("A")
	S.remove("C")
else:
	print("WA")
	exit()

for x in S:
	if not x in ascii_lowercase:
		print("WA")
		exit()
else:
	print("AC")

Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };
#define all(u) begin(u),end(u)
#define mp make_pair
#define pb push_back
#define MAX 20
int H, W;
char C[MAX][MAX];
int B[MAX][MAX];
int D[MAX][MAX];
vector<pi> G;
int sy, sx;

int ans;
void dfs(int now, int check, int dis)
{
  if(check==(1<<G.size())-1)
    {
      ans=min(ans,dis);
    }

  rep(i,G.size())
    {
      if((check>>i) & 1)continue;
      dfs(i,check|(1<<i),dis+D[now][i]);
    }
}

int main()
{
  while(true)
    {
      cin >> W >> H;
      if(H==0&&W==0)return 0;
      G.clear();
      rep(i,H)
	{
	  rep(j,W)
	    {
	      cin >> C[i][j];
	      if(C[i][j]=='*')G.pb(pi(i,j));
	      else if(C[i][j]=='o')
		{
		  sy=i;
		  sx=j;
		}
	    }
	}

      G.pb(pi(sy,sx));

      bool ok=true;
      //point to point
      rep(i,G.size())
	{
	  repi(j,i+1,G.size())
	    {
	      queue<pi> Q;
	      Q.push(G[i]);
	      memset(B,-1,sizeof(B));
	      B[G[i].first][G[i].second]=0;
	      bool flag=false;
	      while(!Q.empty())
		{
		  int ty = Q.front().first;
		  int tx = Q.front().second;
		  Q.pop();
		  if(ty==G[j].first && tx==G[j].second)
		    {
		      flag=true;
		    }
		  rep(r,4)
		    {
		      int y = ty + dd[r];
		      int x = tx + dd[r+1];
		      if(y<0||y>=H||x<0||x>=W)continue;
		      if(C[y][x]=='x')continue;
		      if(B[y][x]==-1 || B[ty][tx]+1<B[y][x])
			{
			  B[y][x]=B[ty][tx]+1;
			  Q.push(pi(y,x));
			}
		    }
		}
	      if(flag)
		{
		  D[i][j]=B[G[j].first][G[j].second];
		  D[j][i]=D[i][j];
		}
	      else
		{
		  ok=false;
		}
	    }
	  
	}
      if(!ok)
	{
	  cout << "-1" << endl;
	  continue;
	}
      /*rep(i,G.size())
	{
	  rep(j,G.size())
	    {
	      printf("%d ",D[i][j]);
	    }
	  printf("\n");
	  }*/
      ans=114154;
      dfs(G.size()-1, 1<<(G.size()-1), 0);

      cout << ans << endl;
    }
  
}

Measured memory_bytes: 3028
#include "cmath"
#include "iostream"

using namespace std;

long long a, b, n;
long long fuuu(long long x) { return floorl(a * x / b) - (a * floorl(x / b)); }

int main() {
  
    cin >> a >> b >> n;
    cout << max(fuuu(min(b - 1, n)), fuuu(0));
    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
int main()
{
  int a,b,c,d,low,hig;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(a>c) low=a;
   else   low=c;
  if(b>d) hig=d;
   else   hig=b;
   if(low<hig) printf("%d\n",hig-low);
    else        printf("0\n");
 
   return 0;
}

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

int main(){
    ll n,d,x,y;
    cin>>n>>d;
    ll count=0;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)
        count++;
    }
    cout<<count<<endl;
	return 0;
}

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

int c[100010];
int up[100010];
void solve(long long N, long long M, vector<long long> X){
	map<int,int> v;
	map<int,map<int,int> > v2;
	
	for(int i : X){
		v2[i%M][i]++;
		c[i%M]++;
	}
	for( auto &i : v2){
		int val = 0;
		for( auto &j : i.second ){
			val += j.second / 2;
		}
		up[i.first] = val;
	}

	long long ans = 0;
	//for(int i = 0 ; i < M ; i++) cout << i << " " << c[i] << endl;

	for(int i = 0 ; i <= M / 2 ; i++){
		if( i == 0 ){
			ans += c[i] / 2;
		}else if( i == M - i ){
			ans += c[i] / 2;
		}else{
			int u = min(c[i],c[M-i]);
			int p1 = min(up[i],(c[i]-u) / 2) + min((c[M-i]-u) / 2,up[M-i]) + u;

			int p2 = 0;
			if( u > 0 ){
				u--;
				p2 = min(up[i],(c[i]-u) / 2) + min((c[M-i]-u) / 2,up[M-i]) + u;
			}
			int p3 = up[M-i] + up[i];
			ans += max(p1,max(p2,p3));
			//cout << i << " " << p1 << " " << p2 << " " << p3 << endl;
		}
	}
	cout << ans << endl;
}



int main(){	
	ios::sync_with_stdio(false);
	long long M;
	long long N;
	cin >> N;
	vector<long long> X(N-1+1);
	cin >> M;
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> X[i];
	}
	solve(N, M, X);
	return 0;
}


Measured memory_bytes: 16640
n, m = map(int, input().split())
c = list(map(int, input().split()))

dp = [float('inf') for _ in range(n + 10001)]
dp[0] = 0

for i in range(n):
    for j in c:
        dp[i + j] = min(dp[i + j], dp[i] + 1)

print(dp[n])


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

int n,k,lcm,num,ans=0;
int a[100005];

int getlcm(int a,int b)
{
	return (a*b)/(__gcd(a,b));
}

int with(int a,int b)
{
	if (a%b==(b/2))  return true;
	else return false;
}

signed main()
{
	cin>>n>>k;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		if (a[i]%2==1)  return cout<<0<<endl,0;
	}
	num=a[1]/2,lcm=a[1];
	for (int i=2;i<=n;i++)  num=getlcm(a[i]/2,num);
	for (int i=1;i<=n;i++)  lcm=getlcm(a[i],lcm);
	
	for (int i=1;i<=n;i++)
	{
		if (!with(num,a[i]))  return cout<<0<<endl,0;
	}
	while (1)
	{
		if (num>k)  break;
		else
		{
			ans++;
			num+=lcm;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;
vector<map<ll,ll>>dp;
ll n,m;
vector<vector<ll>> edge;
ll dfs0(ll par,ll node)
{
  if(dp[node].count(par))return dp[node][par];
  ll res=1;
  for(auto nn:edge[node])
  {
    if(nn==par)continue;
    res=(ll)res*(dfs0(node,nn)+1)%m;
  }
  dp[node][par]=res;
  return res;
}
ll dfs(ll par,ll node)
{
  //cout<<par<<" "<<node<<endl;
  if(dp[node].count(par))return dp[node][par];
  if(edge[node].size()==1&&par!=-1)return 1;
  ll mul=1;
  vector<ll>lmul(edge[node].size()),rmul(edge[node].size());
  unordered_map<ll,int>ma;
  int cnt=0;
  for(auto itr=edge[node].begin();itr!=edge[node].end();itr++)
  {
    ma[*itr]=cnt++;
    lmul[ma[*itr]]=mul;
    mul=mul*(dfs(node,*itr)+1)%m;
  }
  mul=1;
  for(auto itr=edge[node].rbegin();itr!=edge[node].rend();itr++)
  {
    rmul[ma[*itr]]=mul;
    mul=mul*(dfs(node,*itr)+1)%m;
  }
  for(ll nn:edge[node])
  {
    dp[node][nn]=lmul[ma[nn]]*rmul[ma[nn]]%m;
  }
  dp[node][-1]=mul;
  return dp[node][par];
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>m;
  edge.resize(n);
  dp.resize(n);
  rep(i,n-1)
  {
    ll a,b;
    cin>>a>>b;
    a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs0(-1,0);
  rep(i,n)
  {
    cout<<dfs(-1,i)<<"\n";
  }
  cout<<flush;
  return 0;

}


Measured memory_bytes: 39296
#include <bits/stdc++.h>//coded by Nurstan ^_^

#define ll long long
#define pb push_back
#define mp make_pair

#define all(x) x.begin(), x.end()

#define F first
#define S second

// fixed << setprecision
// next_permutation(a, a + n)
// set <int> :: iterator it = x.begin(); it != x.end(); it ++

using namespace std;

const ll INF = int(1e9) + 123;
const int UNF = int(1e5) * 2;

inline void boost(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main(){
	boost();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int mini = 10000;
	for(int i = 1; i <= n / 2; i ++) {
		int f = i, sum = 0, sum2 = 0;
		int s = n - i;
		while(f != 0) {
			sum += (f % 10);
			f /= 10;
		}
		while(s != 0) {
			sum2 += (s % 10);
			s /= 10;
		}
		mini = min(mini, sum2 + sum);
	}	
	cout << mini;
	exit(0); 
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) (x.begin(),x.end())
#include<math.h>
#include<vector>
#include<iostream>
#include<istream>
#include<string.h>
using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[100000];
    vector<ll> k;

    cin>>a[0];
    ll m=a[0];

    ll counter=0;
    for(int i=1;i<n;i++)
    {
        cin>>a[i];
        //printf("%lld ",a[i]);
        if(a[i]<=m)
        {
            //printf("duhfiuoahf\n");
            m=a[i];
            counter++;
        }
        else
        {
            //printf("duhfiuoahf\n");
            k.push_back(counter);
            counter=0;
            m=a[i];
        }
    }
    k.push_back(counter);
    ll maximum=k[0];
    //printf("%d\n",k.size());
    for(int i=1;i<k.size();i++)
    {
        if(k[i]>maximum)
        {
            maximum=k[i];
        }
    }
    printf("%lld\n",maximum);
    return 0;
}


Measured memory_bytes: 1912
fun main(args: Array<String>) {
	val n = readLine()!!.toInt()
  	val a = readLine()!!.split(" ").map{ it.toLong() }
  	var result: Long = a[0]
  	val max = 1_000_000_000_000_000_000L
  	
  	if (a.contains(0)) {
     	println("0")
      	return
    }

  	for (i in 1..n-1) {
    	result *= a[i]	
      	if (result > max) {
  			println("-1")
          	return;
  		}
      
      	if (result < a[i]) {
        	println("-1")
          	return
        }
    }
    
 	println(result)  
}

Measured memory_bytes: 62940
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
  string S;
  cin>>S;
  if(S=="SAT") cout<<"1"<<endl;
  else if(S=="FRI") cout<<"2"<<endl;
  else if(S=="THU") cout<<"3"<<endl;
  else if(S=="WED") cout<<"4"<<endl;
  else if(S=="TUE") cout<<"5"<<endl;
  else if(S=="MON") cout<<"6"<<endl;
  else cout<<"7"<<endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

long s(long n) {
    long res = 0;
    for ( ; n > 0; n /= 10) res += n % 10;
    return res;
}

int main() {
    int k;
    cin >> k;
    long n = 0, r = 1;
    for (int i=0; i<k; i++) {
        if ((n + r) >  s(n + r) * r) r *= 10;
        n += r;
        cout << n << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string s;
  cin >> s;
  if (s[0] > s[1]) {
    cout << s[0] << s[0] << s[0] << endl;
  } else if (s[0] < s[1]) {
    cout << s[0] - '0' + 1 << s[0] - '0' + 1 << s[0] - '0' + 1 << endl;
  } else if (s[0] > s[2]) {
    cout << s[0] << s[0] << s[0] << endl;
  } else if (s[0] < s[2]) {
    cout << s[0] - '0' + 1 << s[0] - '0' + 1 << s[0] - '0' + 1 << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()

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

    ll n,k,x,y;
    Cin4(n,k,x,y);
    if(n<k) Cout(x*n);
    else Cout(x*k+y*(n-k));
    return 0;
}

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

int main() {
  int sum = 0;
  int h, n;
  cin >> h >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum + a[i];
  }
  //cout << sum;
  if (h <= sum) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 640
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

# 必ず勝率が上がる勝ち方がある
def main():
    """ main """
    N,K = map(int, input().split())
    HS = list(map(int, input().split()))
    ans = 0
    for h in HS:
        if h >= K: ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 12648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static int[] A;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        A = sc.nextIntArray(N);

        System.out.println(solve());
    }

    static int solve() {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            map.put(A[i], i);
        }

        int[] B = Arrays.copyOf(A, N);
        Arrays.sort(B);

        int odd = 0;
        for (int bi = 0; bi < N; bi++) {
            int ai = map.get(B[bi]);
            if( (Math.abs(ai - bi)) % 2 == 1 ) odd++;
        }
        return (odd+1) / 2;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 46172
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin >> a;
	int arr[a][3];
	for(int i=0; i<a; i++)
	{
		int b, c, d;
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
	}
	int dp[a][3], ans = 0;
	memset(dp, 0, sizeof(dp));
	dp[0][0] = arr[0][0];
	dp[0][1] = arr[0][1];
	dp[0][2] = arr[0][2];
	for(int i=0; i<a; i++)
	{
		if(i > 0)
		{
			dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0];
			dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + arr[i][1];
			dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[i][2];
		}
		ans = max(ans, dp[i][0]);
		ans = max(ans, dp[i][1]);
		ans = max(ans, dp[i][2]);
	}
	printf("%d\n",ans);
	return 0;
} 

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


int main(){
  ll n;
  ll  ans = 10;
  cin >> n;
  for(ll i = 1;i <=sqrt(n)+1; i++){
      if(n%i==0){
        ll cnta = 0, cntb = 0;
        ll a, b, f;
        a = i;
        b = n/i;
        while(a){
          a /= 10;
          cnta++;
        }
        while(b){
          b /= 10;
          cntb++;
        }
        f = max(cnta, cntb);
        ans = min(ans, f);
      }
  }
  cout << ans << endl;
  return 0;
        
        

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<math.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
#define N (1000000000+7)
#define INF (ll)1e16
typedef long long ll;

ll dp[100010]={0};

int main(void){
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i>=a[j]&&dp[i-a[j]]==0)dp[i]=1;
        }
    }
    if(dp[k])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import math

[N, K] = [int(i) for i in input().split()]

sum = 0
list = []
for n in range(1,N+1):
    if n < K:
        x = abs(math.log2(K/n))
        x_ceil = math.ceil(x)
        sum += pow(0.5, x_ceil)/N
    else:
        sum += 1/N

print(sum)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    int A,B,C,D ,i;

    scanf("%d%d%d%d" ,&A ,&B ,&C ,&D);

    for(i=0 ; i<1000 ; i++){
        C=C-B;
        if(C<=0){
            printf("Yes");
            break;
        };
        
        A=A-D;
        if(A<=0){
            printf("No");
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 1732
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <map>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){if(a < b) {a = b; return true;} return false;}
template<class T> inline bool chMin(T& a, T b){if(a > b) {a = b; return true;} return false;}

int main(){
    ll N;
    vector<ll> idou;
    cin >> N;
    rep(i, 0, 5){
        ll temp;
        cin >> temp;
        idou.push_back(temp);
    }
    sort(begin(idou), end(idou));
    ll ans = N / idou[0];
    if (idou[0] == 1) ans--;
    ans += 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<functional>
#include<queue>
#include<algorithm>

using namespace std;

int main(void){

    int n;
    cin >> n;

    
    int a = n % 100;

    int b = a/5;
    int c = a % 5;

    //cout << a << " " << b << " " << c << endl;

    n -= b*105;
    n -= (c > 0? c+100 : 0);

    //cout << n << endl;

    if(n < 0) cout << "0" << endl;
    else cout << "1" << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int> a(n),b(n);
	for(int &x:a) cin >> x;
	for(int &y:b) cin >> y;
	if(a > b)
		swap(a,b);
	int cnt = 0;
	while(a < b && ++cnt ) next_permutation(a.begin(),a.end());
	cout << cnt << endl;
    return 0;
}

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

int main(){
  ll a,b,c,k;
  cin >>a >>b >>c >>k;
  if(k%2==0) cout << a-b << endl;
  else cout << b-a << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    constexpr int mod = 1000000007;
    
    string L;
    cin >> L;
    
    vector<vector<long long>> dp(L.size() + 1, vector<long long>(2, 0));
    dp[0][0] = 1;
    rep(i, L.size()) rep(j, 2) {
        for (int x = 0; x <= (j ? 1 : L[i] - '0'); ++x) {
            if (x == 0) dp[i + 1][j || x < L[i] - '0'] += dp[i][j];
            else dp[i + 1][j || x < L[i] - '0'] += 2 * dp[i][j];
            dp[i][j] %= mod;
        }
    }
    cout << (dp[L.size()][0] + dp[L.size()][1]) % mod << endl;
    return 0;
}


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

#define HEAP priority_queue
#define rep(i, n) for(int i = 0, _end_ = (n); i < _end_; ++i)
#define per(i, n) for(int i = (n) - 1; i >= 0 ; --i)
#define forn(i, l, r) for(int i = (l), _end_ = (r); i <= _end_; ++i)
#define nrof(i, r, l) for(int i = (r), _end_ = (l); i >= _end_; --i)
#define FOR(a, b) for(auto (a): (b))
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define X first
#define Y second
#define eps 1e-6
#define pi 3.1415926535897932384626433832795
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define FILL(a, b) memset((a), (b), sizeof((a)))
#define MCPY(a, b) memcpy((a), (b), sizeof((b)))

using namespace std;

typedef long long LL;
typedef double flt;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef pair<int,int> pii;
typedef pair<int,LL> pil;
typedef pair<LL,int> pli;
typedef pair<LL,LL> pll;
typedef vector<pil> vil;
typedef vector<pii> vii;
typedef vector<pli> vli;
typedef vector<pll> vll;

const int iinf = 1e9 + 7;
const int oo = 0x3f3f3f3f;
const LL linf = 1ll << 60;
const flt dinf = 1e60;

template <typename T>
inline void scf(T &x)
{
	bool f = 0; x = 0; char c = getchar();
	while((c < '0' || c > '9') && c != '-') c = getchar();
	if(c == '-') { f = 1; c = getchar(); }
	while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
	if(f) x = -x; return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) { scf(x); return scf(y); }
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) { scf(x); scf(y); return scf(z); }
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) { scf(x); scf(y); scf(z); return scf(w); }

inline char mygetchar(){ char c = getchar(); while(c == ' ' || c == '\n') c = getchar(); return c; }

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

#ifdef ONLINE_JUDGE
#define debug(...) ;
#else
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define DEBUG
#endif

//---------------------------------------------------------head----------------------------------------------------

const LL mod = 1e9 + 7;

int n, m;

int main()
{
	scf(n, m);
	if(n > m) swap(n, m);
	if(m - n > 1){ puts("0"); return 0; }
	LL ans = 1ll;
	if(n == m) ans *= 2ll;
	forn(i, 1, n) ans = ans * (LL)i % mod;
	forn(i, 1, m) ans = ans * (LL)i % mod;
	printf("%d\n", (int)ans);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	int a,b,c;scanf("%d%d%d",&a,&b,&c);
	if(a+b>=c-1)printf("%d\n",b+c);
	else printf("%d\n",b+a+b+1);
	return 0;
}


Measured memory_bytes: 128
N = int(input())
HS = [int(i) for i in input().split()]

max = 0
result = 'Yes'
tmpmax = 0

for i in HS:
    if max > i:
        max = max - 1
        if max > i:
            result = 'No'
            break
    else:
        max = i
    if (max > tmpmax or tmpmax==0):
        tmpmax = max
    elif (tmpmax > max + 1):
        result = 'No'
        break

print(result)


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

int main(){
  int n;
  double pre;
  cin >> n;
  long long x[n];
  for(int i = 0; i<n; i++){
    cin >>x[i];
    pre += log10(x[i]);
  }
  if(pre>18){
    cout << -1 << endl;
    return 0;
  }
  long long ans = 1;
  for(int i =  0; i<n;i++){
    ans *= x[i];
  }
  if(ans >1000000000000000000){
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}

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

int n, x;
ll ans;
vector<int> a;

void eat_candy(int i) {
  ll tmp, d;

  d = a[i] + a[i + 1];

  if (d > x) {
    ans += d - x;

    if (a[i + 1] < d - x) {
      tmp = (d - x) - a[i + 1];
      a[i + 1] = 0;
      a[i] -= tmp;
    } else {
      a[i + 1] -= d - x;
    }
  }

  return;
}

void solve() {
  int i;

  ans = 0;

  for (i = 0; i <= n; i++) {
    eat_candy(i);
  }

  cout << ans << "\n";

  return;
}

int main() {
  int i;

  cin >> n >> x;

  a.resize(n + 2);

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

  solve();

  return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;
using System.Text;


public struct Card
{
	public char suits;
	public int number;
	
	public Card( string s )
	{
		suits = s[0];
		number = int.Parse( s[1].ToString() );
	}
}
public class Test
{
	public static void Main( )
	{
		StringBuilder output = new StringBuilder();

		var n = int.Parse( Console.ReadLine() );
		var O = Console.ReadLine().Trim().Split().Select( x => new Card( x ) ).ToArray();
		
		Card[] A = new Card[n];
		Card[] B = new Card[n];
		Array.Copy( O, A, n );
		Array.Copy( O, B, n );

		BubbleSort( A, n );
		for( var i=0; i<n-1; i++ ) {
			output.Append( string.Format( "{0}{1} ", A[i].suits, A[i].number ) );
		}
		output.Append( string.Format( "{0}{1}\n", A[n-1].suits, A[n-1].number ) );
		output.Append( IsStable( O, A, n ) );

		SelectionSort( B, n );
		for( var i=0; i<n-1; i++ ) {
			output.Append( string.Format( "{0}{1} ", B[i].suits, B[i].number ) );
		}
		output.Append( string.Format( "{0}{1}\n", B[n-1].suits, B[n-1].number ) );
		output.Append( IsStable( O, B, n ) );
		Console.Write( output);
		
		return;
	}
	public static string IsStable( Card[] A, Card[] B, int n )
	{
		bool res = true;
		bool[] check = new bool[36];
		for( var i=0; i<n; i++ ) {
			for( var j=0; j<n; j++ ) {
				if( A[i].number == B[j].number ) {
					if( A[i].suits == B[j].suits ) {
						check[j] = true;
						break;
					} else if( !check[j] ){
						res = false;
						goto END;
					}
				}
			}
		}
		END:
		

		return res? "Stable\n":"Not stable\n";
	}


	public static void BubbleSort( Card[] A, int n )
	{
		for( var i=0; i < n; i++ ) {
			for( var j=n-1; i+1 <= j; j-- ) {
				if( A[j].number < A[j-1].number ) {
					swap<Card>( ref A[j], ref A[j-1] );
				}
			}
		}

		return;
	}
	public static void SelectionSort( Card[] A, int n )
	{
		for( var i=0; i < n; i++ ) {
			var mini = i;
			for( var j=i; j < n; j++ ) {
				if( A[j].number < A[mini].number ) {
					mini = j;
				}
			}
			if( i != mini ) {
				swap<Card>( ref A[i], ref A[mini] );
			}
		}
		return;
	}
	public static void swap<T>( ref T a, ref T b )
	{
		var t = a;
		a = b;
		b = t;
		return;
	}
}



Measured memory_bytes: 20224
from itertools import product


def solve(string):
    n = string
    ans = 0
    for i in range(3, len(n) + 1):
        tmp = ("".join(x) for x in product("753", repeat=i) if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if len(x) < len(n) or x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 48476
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    //ll P , Q , R;
    //cin >> P >> Q  >> R;

    ll N, D;
    cin >> N >> D;
    
    ll ans = N / ((D + D) + 1);


    if(N % ((D + D) + 1) > 0){
        ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
s = input()
count = 1
answer = 0
for i in s:
    if count % 2 == 1:
        if i == 'R' or i == 'U' or i == 'D':
            answer += 0
        else:
            answer += 1
    elif count % 2 == 0:
        if i == 'L' or i == 'U' or i == 'D':
            answer += 0
        else:
            answer += 1
    count += 1
if answer == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
using namespace std;

void proc(string& str) {
	string ret;
	char buf[128];
	int size = str.size();
	int s = 0;
	char c1, c2 = -1;
	for(int i=0; i<size; i++) {
		char c1 = str[i];
		if(c1 != c2) {
			if(i-s > 0) { sprintf(buf, "%d%c", i-s, c2); ret += string(buf); }
			c2 = c1;
			s = i;
		}
	}
	if(size-s > 0) { sprintf(buf, "%d%c", size-s, c2); ret += string(buf); }
	
	str = ret;
}

int main() {
	int n;
	string str;
	
	while( 1 ) {
		cin >> n;
		if(n == 0) break;
		cin >> str;
		for(int i=0; i<n; i++) {
			proc(str);
		}
		cout << str << endl;
	}
}

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

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

bool seen[100010]={false};
ll p=1000000007;

ll mb[100010]={};
ll mw[100010]={};

ll dp(ll k,vector<vector<ll>> &a,bool b){
    if(mb[k]!=0){
        if(b)return mb[k];
        return mw[k];
    }
    ll db,dw;
    db=1;
    dw=1;
    seen[k]=true;
    for(ll j=0;j<a[k].size();j++){
        if(seen[a[k][j]]==false){
            db=(db*dp(a[k][j],a,false))%p;
            dw=(dw*(dp(a[k][j],a,true)+dp(a[k][j],a,false)))%p;
        }
    }
    mb[k]=db;
    mw[k]=dw;
    if(b) return db;
    return dw;
}

int main() {
    ll n;cin>>n;
    ll x[n],y[n];
    ll i;
    vector<vector<ll>> a(n+1);
    for(i=1;i<n;i++){
        cin>>x[i]>>y[i];
        a[x[i]].push_back(y[i]);
        a[y[i]].push_back(x[i]);
    }
    cout<<(dp(1,a,true)+dp(1,a,false))%p<<endl;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#include <tuple>
#include <string>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
#define FORk(N) for(int k=0;k<N;++k)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
void swap(ll &a,ll &b){
  ll tmp=a;
  a=b;
  b=tmp;
}
int main(){
  ll N;
  cin>>N;
  vector<ll> W(N),_sum(N),sum_(N);
  FORi(N){
    cin>>W[i];
  }
  _sum[0]=W[0];
  sum_[N-1]=W[N-1];
  FORi(N-1){
    _sum[i+1]=_sum[i]+W[i+1];
    sum_[N-1-i-1]=sum_[N-1-i]+W[N-1-i-1];
  }
  ll min_=LLONG_MAX;
  FORi(N-1){ 
    //cout<<abs(sum_[i+1])<<endl;
    min_=min(min_,abs(_sum[i]-sum_[i+1]));
    
  }
  cout<<min_<<endl;
                     
  return 0;
}


Measured memory_bytes: 256
while line = gets
  m, f, r = line.chomp.split(' ').map(&:to_i)
  break if m == -1 && f == -1 && r == -1
  if m == -1 || f == -1
    puts 'F'
  elsif m + f >= 80
    puts 'A'
  elsif m + f >= 65
    puts 'B'
  elsif m + f >= 50
    puts 'C'
  elsif m + f >= 30
    if r >= 50
      puts 'C'
    else
      puts 'D'
    end
  else
    puts 'F'
  end
end

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int64 fact[1010], inv[1010];

int64 mpow(int64 a, int64 b){
	if(b == 0) return 1;
	if(b%2) return a*mpow(a, b-1)%mod;
	int64 ret = mpow(a, b/2);
	return ret*ret%mod;
}

void init(){
	fact[0] = 1; inv[0] = 1;
	REP(i, 1009) fact[i+1] = fact[i]*(i+1)%mod;
	REP(i, 1010) inv[i] = mpow(fact[i], mod-2);
}

int64 comb(int64 a, int64 b){
	if(a < b) return 0;
	return fact[a]*inv[b]%mod*inv[a-b]%mod;
}

int64 dp[1010][1010] = {};

int main(void){
	int32 N;
	int32 A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	dp[0][0] = 1;
	init();
	FOR(i, 1, N+1){
		REP(j, N+1){
			dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
			if(!(A <= i && i <= B)) continue;
			int64 now = 1;
			if(i*C > j) continue;

			FOR(k, C, D+1){
				if(i*k > j) break;
				dp[i][j] = (dp[i][j]+dp[i-1][j-i*k]*fact[N-j+i*k]%mod*inv[N-j]%mod*mpow(inv[i], k)%mod*inv[k])%mod;
			}
		}
	}
	cout << dp[N][N] << endl;
}


Measured memory_bytes: 8192