akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i < n; i++)
using P = pair<ll, ll>;

int main()
{
    ll n, x, d = 0, ans = 1;
    cin >> n >> x;
    ll l[n];
    rep(i, n) cin >> l[i];
    rep(i, n)
    {
        d += l[i];
        if (d <= x)
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
# https://atcoder.jp/contests/abc086/submissions/3454297

def main():
    import sys

    input = sys.stdin.readline

    N, K = map(int, input().split())

    grid = [[0] * (K * 2) for _ in range(K * 2)]
    for _ in range(N):
        col, row, color = input().split()
        col = int(col)
        row = int(row)
        if color == 'W':
            row += K
            # Bに統一
        row %= K * 2
        col %= K * 2
        grid[row][col] += 1

    tbl = [[0] * (K * 2 + 1) for _ in range(K * 2 + 1)]
    for row in range(K * 2):
        for col in range(K * 2):
            tbl[row + 1][col + 1] = tbl[row + 1][col] + tbl[row][col + 1] - tbl[row][col] + grid[row][col]

    def count(row, col, row2, col2):
        return tbl[row2][col2] - tbl[row][col2] - tbl[row2][col] + tbl[row][col]

    ret = 0
    for row in range(K):
        for col in range(K):
            tmp = (
                    count(0, 0, row, col)
                    + count(row, col, row + K, col + K)
                    + count(row + K, col + K, K * 2, K * 2)
                    + count(row + K, 0, K * 2, col)
                    + count(0, col + K, row, K * 2)
            )
            ret = max(ret, tmp, N - tmp)
            # xox
            # oxo
            # xox
            # x=tmp
            # o=N-tmp

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 106588
import java.util.Arrays;
import java.util.Scanner;

class Main {
    static int n;
    static int m;
    static Edge[] e;
    static long dis[];
    static final long inf = 1000000000000000l;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        e = new Edge[m];
        dis = new long[n];
        Arrays.fill(dis, inf);
        dis[0] = 0;

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            e[i] = new Edge(a - 1, b - 1, -c);
        }

        sc.close();
        if (bellmanFord()) {
            System.out.print("inf");
        } else {
            System.out.println(-dis[n - 1]);
        }

    }

    public static boolean bellmanFord() {

        for (int i = 0; i < n + 1; i++) {
            for (int j = 0; j < m; j++) {
                if (dis[e[j].from] != inf && dis[e[j].to] > dis[e[j].from] + e[j].cost) {
                    dis[e[j].to] = dis[e[j].from] + e[j].cost;
                    // 2週目でもう一度更新しようとした時 n 週目でも更新することになるのでinf
                    if (i == n && e[j].to == n - 1) {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

class Edge {
    int from;
    int to;
    long cost;

    Edge(int from, int to, long cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }
}

Measured memory_bytes: 29416
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

string s;
string ans = "";

signed main(void){
	cin >> s;
	ans += s[0];
	ans += to_string(s.size()-2);
	ans += s[s.size()-1];
	cout << ans << endl;

	return 0;
}

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

using namespace std;

class Dice{

public:
    unique_ptr<vector<int>> nums;

    Dice(int n){
        nums.reset(new vector<int>(6));
    }

    void rotate(char dir){
        int a, b, c, d;
        switch(dir){
        case 'N':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = b;
            nums->at(1) = c;
            nums->at(5) = d;
            nums->at(4) = a;
            break;
        case 'E':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = d;
            nums->at(2) = a;
            nums->at(5) = b;
            nums->at(3) = c;
            break;
        case 'W':
            a = nums->at(0), b = nums->at(2), c = nums->at(5), d = nums->at(3);
            nums->at(0) = b;
            nums->at(2) = c;
            nums->at(5) = d;
            nums->at(3) = a;
            break;
        case 'S':
            a = nums->at(0), b = nums->at(1), c = nums->at(5), d = nums->at(4);
            nums->at(0) = d;
            nums->at(1) = a;
            nums->at(5) = b;
            nums->at(4) = c;
            break;
        }
    }

};

int main()
{

    Dice d(6);
    for(int i = 0; i < 6; i++){
        cin >> d.nums->at(i);
    }
    string s;
    cin >> s;
    for(char c: s){
        d.rotate(c);
    }
    cout << d.nums->at(0) << endl;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DIM 3007
#define DIMM 100007
#define INF 1000000009.0
#define X 500007
#define epc 0.0000001
#define pi 3.14159265358979323846
#define MAX 25
#define MODULO 10009
const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

typedef tree<
I,
null_type,
less<I>,
rb_tree_tag,
tree_order_statistics_node_update> mset;

ll ns,nt,a[DIM][DIM],i,j,c;
str s,t;
cr res[DIM];

int main()
{
    //freopen("suffarray.in", "r", stdin);
    //freopen("suffarray.out", "w", stdout);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout<<"ops"<<endl;

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //ll x1,y1,xs,ys,y1,y2,x3,x4,y3,y4;

    cin>>s>>t;
    ns=s.length();
    nt=t.length();
    for(int i=1;i<=ns;i++){
     for(int j=1;j<=nt;j++){
        if(s[i-1]==t[j-1])a[i][j]=a[i-1][j-1]+1;
        else a[i][j]=max(a[i-1][j],a[i][j-1]);
     }
    }
    i=ns;j=nt;
     while(i!=0 && j!=0){
        if(s[i-1]==t[j-1]){
         c++;
         res[c]=s[i-1];
         i--;
         j--;
        }
        else{
         if(a[i-1][j]>a[i][j-1])i--;
         else j--;
        }
     }
     for(i=c;i>=1;i--)cout<<res[i];
     cout<<endl;
}


Measured memory_bytes: 70784
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
INF=10**9+7
def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m
ans=0
ans=(ans+pow(2,n,INF)-1)%INF
bunsi=1
bunbo=1
for i in range(a):
    bunsi=(bunsi*(n-i))%INF
    bunbo=(bunbo*(i+1))%INF
x=(bunsi*modinv(bunbo,INF))%INF
bunsi=1
bunbo=1
for i in range(b):
    bunsi=(bunsi*(n-i))%INF
    bunbo=(bunbo*(i+1))%INF
y=(bunsi*modinv(bunbo,INF))%INF
ans=(ans-x-y)%INF
print(ans)





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

#define MAX 100005
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

	int arr[n];
	for(int i = 0; i < n; i++)cin>>arr[i];

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);

	for(int i = 2; i < n; i++){
		int minAns = INT_MAX;
		for(int j = i - 1; j >= i - k && j >= 0; j --){
			minAns = min(minAns, dp[j] + abs(arr[i] - arr[j]));
		}
		dp[i] = minAns;
	}

	cout<<dp[n - 1];
}

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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

/*
int	gcd(int A, int B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}

long	gcd(long A, long B) {
	while (0!=B) {
		A %=B;
		swap(A, B);
	}
	return A;
}

long	lcm(long A, long B) {
	long G=gcd(A, B);
	return A/G*B;
}

long	GCD(vector<long> &A) {
	long B=A.at(0);
	for (long i=1; i<A.size(); i++)
		B =gcd(B, A.at(i));
	return B;
}

long	LCM(vector<long> &A) {
	long B=A.at(0);
	for (long i=1; i<A.size(); i++)
		B =lcm(B, A.at(i));
	return B;
}
*/

int	main() {
	int N;
	cin >>N;
	vector<vector<int>> A(N, vector<int> (2, 0));
	for (int i=0; i<N; i++) {
		int X, L;
		cin >>X >>L;
		A.at(i).at(0)=X-L;
		A.at(i).at(1)=X+L;
	}
	sort(A.begin(), A.end());
	vector<vector<int>> B;
	int ib=0;
	B.push_back(A.at(0));
	for (int i=1; i<A.size();i++) {
		if (B.back().at(0)==A.at(i).at(0))
			continue;
		B.push_back(A.at(i));
	}
	int S=1;
	int r=B.at(0).at(1);
	for (int i=1; i<B.size(); i++) {
		if (B.at(i).at(0)>=r) {
			r=B.at(i).at(1);
			S++;
		} else
			r=min(r, B.at(i).at(1));
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 12212
function Main(input){

input=parseInt(input);
answer = 100000;
a = input - 1;
b = 1

for (; a > 0; a--,b++) {
    sum = 0;
    aa = a.toString(10);
    ak = aa.length - 1;
    bb = b.toString(10);
    bk = bb.length - 1;
    for (; ak >= 0; ak--) {
        sum = sum + parseInt(aa[ak]);
    }
    for (; bk >= 0; bk--) {
        sum = sum + parseInt(bb[bk]);
    }
    if (sum < answer) {
        answer = sum;
    }
}

console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, A;
  cin >> N >> A;

  N %= 500;

  // 解答
  cout << (N <= A ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll n,a,b;
	cin >> n >> a >> b;

	cout << n/(a+b)*a + min(n%(a+b), a)<< '\n';
	return 0;
}



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

int main() {
	int len;
	cin>>len;
	string str;
	cin>>str;
	int x=0;
	int high=0;
	for(int i=0;i<len;i++){
		if(str[i]=='D'){
			x--;
		}
		else{
			x++;
			if(x>high){
				high=x;
			}
		}
	}
	cout<<high<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll, ll> P;

#define rep(i,n) for(int i = 0; i < int(n); i++)
using namespace std;

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

struct BIT {
	typedef ll input_t;

	vector<input_t> bit_;
	const long long n_;

	BIT(long long n) :n_(n) {
		bit_.resize(n + 1LL, 0);
	}

	input_t sum(int i) {
		input_t s = 0;
		while (i > 0) {
			s += bit_[i];
			i -= i & (-i);
		}
		return s;
	}

	void add(int i, input_t x) {
		while (i <= n_) {
			bit_[i] += x;
			i += (i & (-i));
		}
	}
};


struct BSearch {
	static ll solve(ll left, ll right, function<ll(ll)> pred) {
		while (right - left > 1) {
			ll middle = left + right;
			middle /= 2;
			if (pred(middle)) {
				right = middle;
			}
			else {
				left = middle;
			}
		}
		return right;
	}
};

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> as(n);
	rep(i, n)cin >> as[i];
	sort(as.begin(), as.end());
	vector<ll> sums(n+1, 0);
	rep(i, n) {
		sums[i + 1] = sums[i] + as[i];
	}
	ll left = 0, right = 1e6;
	map<ll, ll> memo;
	map<ll, ll> memo2;
	ll b = BSearch::solve(left, right, [&](ll mid) {
		//両手の合計の最低値がmidである
		ll count = 0;
		ll vSum = 0;
		for (int i = 0; i < n; i++) {
			ll r = mid - as[i];
			auto l = lower_bound(as.begin(), as.end(), r);
			ll c = as.end() - l;
			ll index = l - as.begin();
			ll rSum = sums[n] - sums[index];
			vSum += rSum + c * as[i];
			count += c;
		}
		memo[mid] = count;
		memo2[mid] = vSum;
		return count <= m;
	});
	ll pmid = -1;
	for (auto p : memo) {
		auto mid = p.first;
		if (p.second <= m) {
			ll sum = memo2[mid];
			ll r = m - p.second;
			sum += r * pmid;
			cout << sum << endl;
			return 0;
		}
		pmid = mid;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 4848
X, K, D = map(int, input().split())
X = abs(X)

if X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(D)
else:
    if X > K*D:
        print(X - K*D)
    else:
        cnt = X // D
        if (K - cnt) % 2 == 0:
            print(X - cnt*D)
        else:
            print(abs(X - (cnt+1)*D))

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

int main(void){
	int N;
	cin >> N;
	int A[N];
	for(int i=0;i<N;i++)cin >> A[i];
	long long S[N+1];
	S[0] = 0;
	for(int i=0;i<N;i++){
		S[i+1]=S[i]+A[i];
	}
	sort(S,S+(N+1));
	long long ans = 0;
	for(int i=0;i<N+1;i++){
		long long count = 1;
		while(S[i]==S[i+1]){
			i++;
			count++;
		}
		ans += (count)*(count-1)/2;
	}
	cout << ans;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <vector>
using namespace std;



int main(){
    long long int A, B ,C, K;
    cin >> A >> B >> C >> K;
    
    long long int score = 0;
    
    for (int i = 0; i < A && K > 0; i++) {
        K--;
        score++;
    }
    for (int i = 0; i < B && K > 0; i++) K--;
    for (int i = 0; i < C && K > 0; i++){
        score--;
        K--;
    }
    
    cout << score << endl;
    
    
    return 0;
}

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

int main() {
string S;
  cin >> S;
  int count = 0;
  for(int i = 0; i < S.length(); i++){
  	if(S[0] != S[i]){
    	count ++;
    }
  }
  if(count == 0){
  	cout << "No" << endl;
  }
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
    int N;
    if (scanf("%d", &N) == EOF)
        return 0;
    int L[N];
    int max = 0;
    int max_N;

    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &L[i]) == EOF)
            return 0;
        if (L[i] > max)
        {
            max = L[i];
            max_N = i;
        }
    }
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        if (max_N == i)
        {
            continue;
        }
        sum += L[i];
    }
    if (sum > max)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}

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

string S;

int main(){
  cin >> S;
  if(S == "Cloudy"){
    cout << "Rainy";
  }
  if(S == "Rainy"){
    cout << "Sunny";
  }
  if(S == "Sunny"){
    cout << "Cloudy";
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
typedef pair<int,int> pii;
int MOD = 998244353;

signed main(){
    string s;
    cin >> s;

    int cnt1 = 0;
    int cnt2 = 0;
    rep(i,s.size()){
        if(i%2){
            if(s[i] == '0')cnt1++;
            else cnt2++;
        }else{
            if(s[i] == '1')cnt1++;
            else cnt2++;
        }
    }
    cout << min(cnt1,cnt2) << endl;
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc124.contest.atcoder.jp/tasks/abc124_a


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

const int N = 1e5 + 5;
int a[N], dp[N];
int n, k;

int solve(int idx){
    if(idx > n){
        return 1e10;
    }
    if(idx == n){
        return 0;
    }

    int &ans = dp[idx];
    if(ans != -1){
        return ans;
    }

    ans = 1e10;
    for(int i = 1;i <= k and (i + idx) <= n;i ++){
        ans = min(ans, solve(i + idx) + abs(a[idx] - a[i + idx]));
    }
    return ans;
}


int32_t main(){
    memset(dp, -1, sizeof(dp));

    cin >> n >> k;

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

    int ans = solve(1);
    cout << ans << endl;
}


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

int main()
{
   long long A,B,K;
   cin>>A>>B>>K;
   
   if(A<=K)
   {
        K=K-A;
        A=0;
        B=B-K;
     
   		if(B<0)
     	{
       		B=0;
     	}
   }
   
   else
   {
       A=A-K;
   }
   cout<<A<<" "<<B<<endl;
    return 0;
}


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

//Compiler version g++ 6.3.0

int main()
{
  int n, rem, sum,mod;
  cin>>n;
  if(n%1000==0)
  {
    cout<<"0"<<endl;
  }
  else
  {
    rem=n/1000;
    mod=n%1000;
    sum=1000-mod;
    cout<<sum<<endl;
  }
}

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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
    if ( ch == 'A') return 1;
    else if ( ch == 'C') return 2;
    else if ( ch == 'G') return 3;
    else return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return key % (M - 1); }

int find(char str[]) {
    int i = 0;
    int key = getKey(str);
    while (i < M) {
        int j = (h1(key) + i * h2(key)) % M;
        if (!strcmp(H[j], str)) {
            return 1;
        } else if (H[j][0] == '\0') {
            return 0;
        } else {
            i++;
        }
    }
    return 0;
}

void insert(char str[]) {
    int i = 0;
    int key = getKey(str);
    while (i < M) {
        int j = (h1(key) + i * h2(key)) % M;
        if (!strcmp(H[j], str)) {
            break;
        } else if (H[j][0] == '\0') {
            strcpy(H[j], str);
        } else {
            i++;
        }
    }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s %s", com, str);

        if ( com[0] == 'i' ){
            insert(str);
        } else {
            if (find(str)){
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 15460
N, M = map(int, input().split())
root = {i: [] for i in range(N)}
for i in range(M):
  a, b = map(int, input().split())
  root[a-1].append(b-1)
  root[b-1].append(a-1)
fact = 1
for i in range(N-1):
  fact *= (i+1)
realcnt = 0
for i in range(fact):
  p = [i for i in range(1, N)]
  L = []
  for j in range(N-1):
    L.append(i % (j + 1))
    i //= (j + 1)
  LL = [0]
  for j in range(N-1):
    LL.append(p[L[N-2-j]])
    p.remove(p[L[N-2-j]])
  cnt = 1
  for j in range(N-1):
    if LL[j+1] in root[LL[j]]:
      cnt += 1
  if cnt == N:
    realcnt += 1
print(realcnt)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MX=1e18;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    bool f=0;for(ll i=0;i<n;i++)if(a[i]==0)f=1;
    if(f)return cout<<"0" , 0;

    ll ans = 1;
    for(ll i=0,x;i<n;i++){
        x=a[i];
        if(MX/x<ans)return cout<<"-1" , 0;
        ans*=x;
    }
    cout<<ans;
}



Measured memory_bytes: 4436
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

struct Edge {
    int to;
    int cost;
    Edge(int t, int c) : to(t), cost(c) {}
};

constexpr int INF = numeric_limits<int>::max();

int N;
vector<vector<Edge>> G;

/**
 * ???????§???????????????? Bellman-Ford???
 *
 * \return ???????????????????????° true, ????????° false
 */
bool bellmanford(int start, vector<int>& d)
{
    d.resize(N);
    fill(begin(d), end(d), INF);
    d[start] = 0;

    REP(i, N) {
        REP(v, N) {
            if(d[v] == INF) continue;
            for(Edge e : G[v]) {
                int cost_new = d[v] + e.cost;
                if(cost_new < d[e.to]) {
                    d[e.to] = cost_new;
                    if(i == N-1) return false;
                }
            }
        }
    }

    return true;
}

void solve()
{
    vector<int> d;
    bellmanford(0, d);

    REP(i, N) {
        cout << i << " " << d[i] << "\n";
    }
}

int main()
{
    cin >> N;
    G.resize(N);

    REP(_, N) {
        int from, k;
        cin >> from >> k;
        REP(_, k) {
            int to, cost;
            cin >> to >> cost;
            G[from].emplace_back(to, cost);
        }
    }

    solve();

    return 0;
}

Measured memory_bytes: 3136
#!/usr/bin/env python3
n = int(input())
a, b = map(int, input().split())
cnt = [ 0, 0, 0 ]
for p_i in map(int, input().split()):
    if p_i <= a:
        cnt[0] += 1
    elif p_i <= b:
        cnt[1] += 1
    else:
        cnt[2] += 1
print(min(cnt))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<numeric>
#include<utility>
#define ll long long int
#define ss string
#define endl "\n"
using namespace std;
int main()
{
 int n;
 cin>>n;
 vector<string>v(n);
 for(int i=0;i<n;i++)
 {
   cin>>v[i];
 }
 sort(v.begin(),v.end());
 v.erase(unique(v.begin(),v.end()),v.end());
 cout<<v.size();
  return 0;
}


Measured memory_bytes: 9564
S = input()
suuji = int(S)

mae = suuji // 100
ushiro = suuji % 100

if mae == 0 and ushiro == 0:
    print("NA")
else:
    if 1 <= mae <= 12:
        if 1 <= ushiro <= 12:
            print("AMBIGUOUS")
        else:
            print("MMYY")
    else:
        if 1 <= ushiro <= 12:
            print("YYMM")
        else:
            print("NA")


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node
{
    int order;
    int num;
}sz[100005];
bool px(node a,node b)
{
    return a.order<b.order;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>sz[i].order;
        sz[i].num=i;
    }
    sort(sz+1,sz+1+n,px);
    cout<<sz[1].num;
    for(int i=2;i<=n;i++)
    cout<<" "<<sz[i].num;
    cout<<endl;



    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  if(n%2){
    cout << 0 << endl;
    return 0;
  }
  ll ans = 0;
  for(ll f = 10; f<=n; f*=5){
    ans += n/f;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
s=input()
pa,pb=0,0
for i in range(n):
  if s[i]=='a':
    if pa+pb<a+b:
      pa+=1
      print('Yes')
    else:
      print('No')
  elif s[i]=='b':
    if pa+pb<a+b and pb<b:
      pb+=1
      print('Yes')
    else:
      print('No')
  else:
    print('No')


Measured memory_bytes: 4016
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt(),b=sc.nextInt();
		int c=sc.nextInt();
		int[] d=new int[n];
		for(int i=0;i<n;i++){
			d[i]=sc.nextInt();
		}
		for(int i=0;i<d.length-1;i++){
            for(int j=0;j<d.length-i-1;j++){
            	if(d[j]<d[j+1]){
            		int s=d[j];
            		d[j]=d[j+1];
            		d[j+1]=s;
            	}
            }
		}
		int pt=d[0];
		int ans=(c+pt)/(a+b);
		int bp=0;
		for(int i=1;i<n;i++){
			pt+=d[i];
			bp=(c+pt)/(a+(i+1)*b);//1ドルあたりのカロリー数
			if(bp>ans)ans=bp;
		}
		System.out.println(ans);
	}
}

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


const int mod = 1e9+7;
long long A[1001];

int main(){
	long long n,a,sum=1;;
	cin >> n;
	
	for(int i=2;i<=n;i++){
		a=i;
		for(int j=2;a>1;j++){
			while(a%j==0){
				A[j]++;
				a/=j;
			}
		}
	}
	
	for(int i=2;i<=n;i++){
		sum = (sum*(A[i]+1))%mod;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut t: Vec<char> = read::<String>().chars().collect();
    t.pop();
    if s == t {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 2072
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long a[n];
    for(int i=0;i<n;i++)cin >> a[i];
    long const mod = 1e9+7;
    
    long dp[n][3];
    for(int i=0;i<n;i++){
        dp[i][0] = -1<<30;
        dp[i][1] = -1<<30;
        dp[i][2] = -1<<30;
    }
    if(n==2)cout<<max(a[0],a[1])<<endl;
    else if(n==3)cout<<max(a[0],max(a[1],a[2]))<<endl;
    else{
        dp[0][0] = a[0];
        
        dp[1][1] = a[1];
        
        dp[2][0] = a[0]+a[2];
        dp[2][2] = a[2];

        dp[3][1] = max(a[1],a[0])+a[3];

        for(int i=4;i<n;i++){
            dp[i][0] = dp[i-2][0]+a[i];
            dp[i][1] = max(dp[i-2][1],dp[i-3][0]) + a[i];
            dp[i][2] = max(max(dp[i-2][2],dp[i-3][1]),dp[i-4][0]) + a[i];
        }
        if(n%2==1)cout << max(max(dp[n-3][0],dp[n-2][1]),dp[n-1][2])<<endl;
        else cout<< max(dp[n-2][0],dp[n-1][1]) << endl;

        // for(int i=0;i<n;i++){
        //     for(int j=0;j<=2;j++){
        //         printf("%ld %ld %ld\n",i,j,dp[i][j]);
        //     }
        // }
    }
}


Measured memory_bytes: 9880
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s, t;
    cin >> s>> t;
    if(s+t.back() == t) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double lod;
const int N=4e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
struct P{ int x,y; inline bool operator < (const P &b) const { return y<b.y; } }p[N];
int x[N],c[N];
int mn[N];
int main()
{
	int x1=gi(),y1=gi(),x2=gi(),y2=gi(),i;
	int n=gi(),t,k,sum=0,s;
	const lod pi=3.14159265358979323846;
	for (i=1;i<=n;i++)
		p[i].x=gi(),p[i].y=gi();
	if (x1>x2) { x1*=-1; x2*=-1; for (i=1;i<=n;i++) p[i].x*=-1; }
	if (y1>y2) { y1*=-1; y2*=-1; for (i=1;i<=n;i++) p[i].y*=-1; }
	for (i=1;i<=n;i++)
		if (p[i].x<x1||x2<p[i].x||p[i].y<y1||y2<p[i].y) p[i--]=p[n--];

	for (i=1;i<=n;i++) x[i]=p[i].x;
	sort(x+1,x+1+n);
	sort(p+1,p+1+n);
	for (i=1;i<=n;++i) mn[i]=0x7fffffff;
	mn[0]=0x80000000;
	sum=0;
	for (i=1;i<=n;++i) {
		k=lower_bound(mn,mn+n+1,p[i].x)-mn;
		mn[k]=p[i].x;
		sum=max(sum,k);
	}
	/*
	for (i=1;i<=n;i++) {
		k=lower_bound(x+1,x+1+n,p[i].x)-x;
		s=0;
		for (t=k;t;t^=t&-t) s=max(s,c[t]);
		sum=max(sum,++s);
		for (t=k;t<=n;t+=t&-t) c[t]=max(c[t],s);
		}*/
	cout << fixed << setprecision(15);
	double ans=100LL*(abs(x1-x2)+abs(y1-y2));
	ans=ans-20*sum+5*pi*sum;
 	if (sum==abs(x1-x2)+1||sum==abs(y1-y2)+1)
		ans=ans+5*pi;
	cout<<ans<<endl;
	//printf("%.15lf\n",
	//cout<<100LL*(x2-x1+y2-y1)+(sum==min(y2-y1,x2-x1)+1?-(sum-1)*(20*5-pi)+10*pi-20:-sum*(20-5*pi));//);
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x; cin >> x;
  if(x == 0){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,a;
	cin>>h>>a;
	if(a>=h)
		cout<<"1"<<endl;
	else 
	{
		if(h%a==0)
			cout<<h/a<<endl;
		else
			cout<<(h/a)+1<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxn = 212345;

int n, k, a[maxn], cnt[maxn];

int main() {
  scanf("%d%d", &n, &k);
  FOR(i, 1, n) scanf("%d", a + i);
  chkmin(k, 200);
  FOR(i, 1, k) {
    FOR(j, 1, n) cnt[j] = 0;
    FOR(j, 1, n) {
      cnt[max(j - a[j], 1)]++;
      cnt[min(j + a[j] + 1, n + 1)]--;
    }
    int now = 0;
    FOR(j, 1, n) {
      now += cnt[j];
      a[j] = now;
    }
  }
  FOR(i, 1, n) printf("%d ", a[i]);
}


Measured memory_bytes: 5348
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  ll N;
  cin >> N;
  vll W(N);
  rep(i,0,N) cin >> W[i];

  ll Wsum = vec_sum(W);
  ll res = 0;
  ll min = INF;
  rep(i,0,N){
    res += W[i];
    if(min > abs(res - (Wsum - res))) min = abs(res - (Wsum - res));
  }

  print(min);

 return 0;
}


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

int main()
{
	int a = 0, b = 0;
	cin >> a >> b;
	cout << a / b << " " << a % b << " ";
	cout << setiosflags(ios::fixed|ios::showpoint) << setprecision(10) << (double)a / (double)b << endl;

	return 0;
}



Measured memory_bytes: 3264
import java.util.*;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        int[] h = new int[N];
        for(int i = 0; i < N;i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
            h[i] = sc.nextInt();
        }
        int ansx = 0;
        int ansy = 0;
        int ansh = 0;
        boolean bl = false;
        for(int cx = 0; cx <= 100; cx++){
            for(int cy = 0; cy <= 100; cy++){
                bl = true;
                int index = -1;
                for(int i = 0; i < N; i++){
                    if(h[i] > 0){
                        index = i;
                    }
                }
                int H = h[index] + Math.abs(x[index] - cx) + Math.abs(y[index] - cy);
                for(int i = 0; i < N; i++){
                    if(h[i] != Math.max(0,H - Math.abs(x[i] - cx) - Math.abs(y[i] - cy))){
                        bl = false;
                        break;
                    }
                }
                if(bl){
                    ansh = H;
                    ansx = cx;
                    ansy = cy;
                }
            }
        }
        System.out.println(ansx + " " + ansy + " " + ansh);
    }
}


Measured memory_bytes: 22356
N,M,L = (int(i) for i in input().split())
A = [[int(i) for i in input().split()] for i in range(N)]
B = [[int(i)for i in input().split()] for i in range(M)]
C = []
for i in range(N):
    for i2 in range(L):
        ans = 0
        for i3 in range(M):
            ans += A[i][i3]*B[i3][i2]
        if i2 == L-1:
            print(ans)
        else:
            print(ans,end=" ")

Measured memory_bytes: 8700
def print_fig(h, w):
    for _ in range(h):
        print("#" * w)
    print("")

while True:
    x = input().split()
    w, h = int(x[0]), int(x[1])
    if (w, h) == (0, 0): break
    print_fig(int(x[0]), int(x[1]))


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1005]={0};
ll a[4]={10,20,50,100};
int main()
{  ll n,m,k;
    cin>>n>>m>>k;
	swap(n,m);
	swap(n,k);
	cout<<n<<" "<<m<<" "<<k<<endl;
}

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

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<P> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ll tmp = min(m, a[i].second);
        ans += tmp * a[i].first;
        m -= tmp;
    }

    cout << ans << endl;
}



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

int main () {
    int n;
    string s;
    cin >> n >> s;
    
    if (s.substr(0, n/2) ==  s.substr(n/2)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int i=1; i<=n; i+=2){
        int num=0;
        for(int j=1; j<=i; j+=2){
            if(i%j==0) ++num;
        }
        if(num==8) ++ans;

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


Measured memory_bytes: 256
//AOJ0099とほぼ同じ。座標圧縮がいらない。
//1位の見つけ方→1位が得点(順位そのまま),1位以外が得点(1位と得点したチームを比べる),1位以外が減点(順位そのまま),1位が減点(O(N)で1位を探す)
//欠点：最悪計算量O(N^2)
#include<iostream>
#define rep(j,n) for(j = 0;j < n;j++)
using namespace std;

int N,R,L;	//チーム数 <= 10^5,レコード数 <= 10^6,競技時間
int n[1000000],t[1000000],x[1000000];

int score[100000];
int Time[100000];

int main(){
	int i,j;
	int num = 0;	//今最高得点の奴の番号
	cin >> N >> R >> L;
	rep(i,R){
		cin >> n[i] >> t[i] >> x[i];
		n[i]--;
	}
	Time[0] = t[0];

	rep(i,R){
		//cout << "num = " << num << endl;
		score[ n[i] ] += x[i];
		//1位がそのまま
		if( (n[i] == num && x[i] >= 0) || (n[i] != num && x[i] <= 0) ){
			if(i < R-1)
				Time[ num ] += t[i+1] - t[i];
			else
				Time[ num ] += L - t[i];
			continue;
		}
		//1位と今のチームを比べる
		if( n[i] != num && x[i] >= 0 ){
			if( ( score[ num ] > score[ n[i] ] ) || ( score[ num ] == score[ n[i] ] && num < n[i] ) ){
			}
			else{
				num = n[i];
			}
			if(i < R-1)
				Time[ num ] += t[i+1] - t[i];
			else
				Time[ num ] += L - t[i];
			continue;
		}
		//1位を調べなおす
		for( j = 0; j < N; j++){
			if( ( score[ num ] > score[ j ] ) || ( score[ num ] == score[ j ] && num < j ) ){
			}
			else{
				num = j;
			}
		}
		if(i < R-1)
			Time[ num ] += t[i+1] - t[i];
		else
			Time[ num ] += L - t[i];
	}
	int MAX = 0,ANS = 0;
	for(j = 0;j < N;j++){
		if(MAX < Time[j]){
			MAX = Time[j];
			ANS = j;
		}
	}
	ANS++;
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 13180
local read = io.read
local concat = table.concat
local char = string.char

local h, w = read("n", "n", "l")
local black = string.byte("#")

local a_t = {}
for i = 1, h do
	a_t[i] = read()
end

local del_i_t = {}
for i = 1, h do
	local is_breaked = false
	for j = 1, w do
		if a_t[i]:byte(j) == black then
			is_breaked = true
			break
		end
	end
	if not is_breaked then
		del_i_t[i] = true
	end
end

local del_j_t = {}
for j = 1, w do
	local is_breaked = false
	for i = 1, h do
		if a_t[i]:byte(j) == black then
			is_breaked = true
			break
		end
	end
	if not is_breaked then
		del_j_t[j] = true
	end
end

local copy_a_t = {}
local last_i = 0
for i = 1, h do
	if not del_i_t[i] then
		last_i = last_i + 1
		local last_j = 0
		copy_a_t[last_i] = {}
		for j = 1, w do
			if not del_j_t[j] then
				last_j = last_j + 1
				copy_a_t[last_i][last_j] = char(a_t[i]:byte(j))
			end
		end
	end
end

local out_t = {}
for i = 1, #copy_a_t do
	out_t[i] = concat(copy_a_t[i], "")
end

print(concat(out_t, "\n"))


Measured memory_bytes: 2856
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S,T;
  cin>>S>>T;
  if(S==T.substr(0,S.size())){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3576
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    int n;
    cin >> n;
    if (n & 1) {
        cout << 0;
        return 0;
    }
    int p = 0;
    while (n) {
        p += n / 10;
        n /= 5;
    }
    cout << p;
}
/*

*/


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

const int MAX_N = 100001;

int par[MAX_N];
int rank[MAX_N];
int nele[MAX_N];

void init(){
   for(int i=0; i<MAX_N; ++i){
      par[i] = i;
      rank[i] = 0;
      nele[i] = 1;
   }   
}

int root(int x){ 
   if(par[x]==x) return x;
   else return par[x] = root(par[x]);
}

void unite(int x, int y){ 
   x = root(x);
   y = root(y);
   if(x==y) return;

   nele[x] += nele[y];
   nele[y] = nele[x];

   if(rank[x]<rank[y]){
      par[x] = y;
   }else{
      par[y] = x;
      if(rank[x]==rank[y]) ++rank[x];
   }   
   return;
}

bool same(int x, int y){ 
   return root(x)==root(y);
}

int main(){
   init();

   int N, M, K;
   std::cin >> N >> M >> K;
   int A, B;
   int old_friend[N];
   std::fill(old_friend, old_friend+N, 0);
   for(int i=0; i<M; ++i){
      std::cin >> A >> B;
      --A; --B;
      unite(A, B);
      ++old_friend[A]; ++old_friend[B];
   }
   std::vector<int> blocked[N];
   int C, D;
   for(int i=0; i<K; ++i){
      std::cin >> C >> D;
      --C; --D;
      blocked[C].push_back(D);
      blocked[D].push_back(C);
   }
   
   for(int i=0; i<N; ++i){
      int count = nele[root(i)];
      for(int j=0; j<blocked[i].size(); ++j){
	 if(same(i,blocked[i][j])) --count;
      }
      count -= old_friend[i] + 1;
      std::cout << count << ' ';
   }
   std::cout << std::endl;
   return 0;
}


Measured memory_bytes: 7552
#include <iostream>
using namespace std;
int main() {
    double w;
    while (cin >> w) {
        if (w <= 48) {
            cout << "light fly" << "\n";
        } else if (w <= 51) {
            cout << "fly" << "\n";
        } else if (w <= 54) {
            cout << "bantam" << "\n";
        } else if (w <= 57) {
            cout << "feather" << "\n";
        } else if (w <= 60) {
            cout << "light" << "\n";
        } else if (w <= 64) {
            cout << "light welter" << "\n";
        } else if (w <= 69) {
            cout << "welter" << "\n";
        } else if (w <= 75) {
            cout << "light middle" << "\n";
        } else if (w <= 81) {
            cout << "middle" << "\n";
        } else if (w <= 91) {
            cout << "light heavy" << "\n";
        } else {
            cout << "heavy" << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 1192
#include <functional>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main() {
    int n; cin >> n;
    vector<vector<int> > adj(n);
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    function<void(int, int, int, int*)> calc_depth = [&](int i, int p, int d, int *tbl) {
        tbl[i] = d;
        for (int j : adj[i]) {
            if (j != p) calc_depth(j, i, d+1, tbl);
        }
    };
    const int diam = [&]() {
        int depth[n];
        calc_depth(0, -1, 0, depth);
        int v = max_element(depth, depth+n) - depth;
        calc_depth(v, -1, 0, depth);
        return *max_element(depth, depth+n);
    }();
    const int mincol = diam / 2 + 1;
    long long ans = LONG_MAX;
    function<void(int, int, int, int*)> dfs = [&](int i, int p, int h, int *g) {
        int deg = p == -1 ? adj[i].size() : adj[i].size() - 1;
        g[h] = max(g[h], deg);
        for (int j : adj[i]) if (j != p) dfs(j, i, h+1, g);
    };
    for (int u = 0; u < n; u++) {
        // center = u
        int g[n], depth[n];
        fill(g, g+n, 0);
        calc_depth(u, -1, 0, depth);
        int maxd = *max_element(depth, depth+n);
        if (mincol == maxd + 1) {
            dfs(u, -1, 0, g);
            long long temp = 1;
            for (int i = 0; g[i] > 0; i++) temp *= g[i];
            ans = min(ans, temp);
            // cerr << u << ' ' << temp << endl;
        }
        for (int v : adj[u]) {
            // center u-v
            calc_depth(u, v, 0, depth);
            calc_depth(v, u, 0, depth);
            int maxd = *max_element(depth, depth+n);
            if (mincol == maxd + 1) {
                fill(g, g+n, 0);
                dfs(u, v, 0, g);
                dfs(v, u, 0, g);
                long long temp = 2;
                for (int i = 0; g[i] > 0; i++) temp *= g[i];
                ans = min(ans, temp);
                //cerr << u << ' ' << v << ' ' << temp << endl;
            }
        }
    }
    cout << mincol << ' ' << ans << endl;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    string w;
    cin >> w;
    int a[26];
    fill(a, a + 26, 0);
    rep(i, w.size()){
        a[w[i]-'a']++;
    }
    rep(i, 26){
        if(a[i] % 2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256