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

#define MAXN 1005
#define MAXK 1000000
#define int long long
#define LL long long
#define pii pair<long, long>
#define fi first
#define se second
#define fastio ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
using namespace std;

int H, W;
int mod = 1e9+7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

signed main() {
    fastio;
    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) cin >> a[i][j];
    }
    dp[1][1] = 1 % mod;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            if (a[i][j] != '.') continue;
            if (i-1 >= 1) dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
            if (j-1 >= 1) dp[i][j] = (dp[i][j] + dp[i][j-1]) % mod;
        }
    }
    cout << dp[H][W] << endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <unordered_set>
#include <stdio.h>

using namespace std;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define PI 3.141592653589793
#define vi vector<int>
#define vll vector<long long>
#define p pair<int,int>
const int MOD = 1000000007;
inline double degcos(double ang) {return cos(ang*PI/180);}
inline double degsin(double ang) {return sin(ang*PI/180);}
#define rep(i,j,k,in) for (int i = j; i < k; i += in)


/*---END OF TEMPLATE---*/




int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N,K;
    cin >> N >> K;
    int opt[100];
    bool states[100001];
    for (int i = 0; i < N; i++) {
        cin >> opt[i];
    }
    bool flag;
    for (int i = 0; i <= K; i++) {
        flag = false;
        for (int j = 0; j < N; j++) {
            if (opt[j] > i) {
                break;
            }
            flag = (!states[i-opt[j]] || flag);
        }
        states[i] = flag;
    }
    if (states[K]) {
        cout << "First" << endl;
    }
    else {
        cout << "Second" << endl;
    }

    return 0;
}

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

int main()
{ 
 int n;
 cin>>n;
 vector<int> ar(n);
 for(int i=0;i<n;++i)
 {
   cin>>ar[i];
 }
 vector<int> dp(n+1,0);
 dp[1]=0;
 dp[2]=abs(ar[1]-ar[0]);
 for(int i=3;i<=n;++i)
 {
   dp[i]=min(dp[i-1]+abs(ar[i-1]-ar[i-2]),dp[i-2]+abs(ar[i-1]-ar[i-3]));
 }
 cout<<dp[n]<<'\n';
}  

  
 
        
        
  


  


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    int A,B;
    cin >> A >> B;
    if(A >= 13){
        cout << B << endl;
    }
    else if(A>=6 && A <= 12){
        cout << B/2 << endl;
    }
    else{
        cout << "0" << endl;
    }

}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    final long MOD = (long)1e9+7;

    int n = sc.nextInt();
    String s = sc.next();
    char[] arr = new char[s.length()];

    Map<Character, Integer> map = new HashMap<>();

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {
        arr = s.toCharArray();
        Arrays.sort(arr);

        for (int i=0; i<n; i++) {
            if (!map.containsKey(arr[i])) {
                map.put(arr[i], 1);
            } else {
                int tmp = map.get(arr[i]);
                map.put(arr[i], tmp+1);
            }
        }

        List<Integer> list = new ArrayList<>(map.values());

//        out.println(list);

        long ans = 1;

        for (int i=0; i<list.size(); i++) {
            ans *= list.get(i)+1;
            ans %= MOD;
        }

        out.print(ans-1);
        out.flush();
    }
}


Measured memory_bytes: 26060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main()
{
    int TC; cin >> TC;
    int count = TC; int ans = 1;
    while (count % 360 > 0)
    {
        count += TC;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3620
A, B, K = map(int, input().split())
set1 = set([i for i in range(A, A+K)])
set2 = set([i for i in range(B+1-K, B+1)])
set3 = sorted((set1|set2))
for i in set3:
    if A<=i<=B:
        print(i)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define pii pair<int,int>
#define ff first
#define ss second
#define mod 1000000007


int main() {
flash;

    int n; cin>>n;
    vector<int>v[n+1];
    int x,y,max_size=0;
    int b[n-1];
    
    for(int i=0;i<n-1;i++){
        cin>>x>>y;
        v[x].pb(y);
        b[i] = y;
    }
    
    max_size = v[1].size();
    for(int i=2;i<=n;i++){
        max_size = max(max_size,1+(int)v[i].size());
    }
    cout<<max_size<<endl;
    
    int c[n+1] = {0}, color=0 ;
    //c[1] = 1;
    
    for(int i=1;i<n;i++){
        color = 1;
        for(int j=0;j<v[i].size();j++){
            
            if( color != c[i] ){
                c[v[i][j]] = color;
            }
            else{
                c[v[i][j]] = ++color;
            }
            color++;
        }
    }
    
    for(int i=0;i<n-1;i++){
        cout<<c[b[i]]<<endl;
    }
    
    
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    string s,t;
    cin>>s>>t;
    s = s+s;
    int l=t.length();
    rep(i,l){//i個ずらす
        bool ans = true;
        rep(j,l){
            if(s[j+i]!=t[j]){
                ans = false;
            }
        }
        if(ans){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace template
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // ここに処理を書く
            string s = cin.Read;
            string t = cin.Read;

            Console.WriteLine(t+s);
        }
    }

    public 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: 11220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

bool same(char x, char y){
  return (x==y || x=='?' || y=='?');
}

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int asz = a.size();
  int bsz = b.size();
  int csz = c.size();
  
  vector<bool> ab(mx,true),bc(mx,true),ac(mx,true);
  rep(i,asz)rep(j,bsz)if(!same(a[i],b[j])){
    ab[50000+i-j] = false;
  }
  rep(i,asz)rep(j,csz)if(!same(a[i],c[j])){
    ac[50000+i-j] = false;
  }
  rep(i,bsz)rep(j,csz)if(!same(b[i],c[j])){
    bc[50000+i-j] = false;
  }
  int ans = inf;
  for(int i=-4000; i<4001; i++)for(int j=-4000; j<4001; j++){
    if(ab[50000+i] && ac[50000+j] && bc[50000+j-i]){
      int tmp = max(asz,max(bsz+i,csz+j)) - min(0,min(i,j));
      ans = min(ans, tmp);
    }
  }
  cout << ans << ln;
  return 0;
}

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

using namespace std;

int main(){
	int a, b, c, d, e;
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
	if(c + e > a || c - e < 0 || d + e > b  || d - e < 0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1172
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans = "Yes";

    Set<String> set = new HashSet<>();
    String w = sc.next();
    set.add(w);
    char siri = w.charAt(w.length()-1);
    

    for(int i = 0 ; i < n-1 ; ++i){
      w = sc.next();
      if(set.add(w) && siri==w.charAt(0)){
        siri = w.charAt(w.length()-1);
        set.add(w);
      }else{
        ans = "No";
      }
    }
    
    System.out.println(ans);

  }
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int a, b;
    cin >> a >> b;

    int vis[4] = {};
    vis[a] = 1;
    vis[b] = 1;
    for (int i = 1; i <= 3; i++) {
        if(vis[i] == 0) {
            return cout << i, 0;
        }
    }

    return 0;
}



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

int main(){
	int n;
	std::cin >> n;
	std::vector<int> x(n),y(n),h(n);
	rep(i,n){
		std::cin >> x[i]>>y[i]>>h[i];
	}

	int dum;
	rep(j,101){
		rep(k,101){
			bool han=1;
			dum=0;
			rep(i,n){
				if(dum==0 && h[i]!=0)dum=abs(x[i]-j)+abs(y[i]-k)+h[i];
				if(h[i]==0 || abs(x[i]-j)+abs(y[i]-k)+h[i]==dum)int aaa=2;
				else han=0;
				if(!han)break;
			}
			rep(i,n){
				if(dum==0 && h[i]!=0)dum=abs(x[i]-j)+abs(y[i]-k)+h[i];
				if((h[i]==0 && dum-abs(x[i]-j)-abs(y[i]-k)<0)|| abs(x[i]-j)+abs(y[i]-k)+h[i]==dum)int aaa=2;
				else han=0;
				if(!han)break;
			}
			
			if(han)std::cout << j<<" "<<k<< " "<<dum << std::endl;
		}
		
	}

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define max(a,b) (a>b?a:b)
#define abs(a) (a>0?(a):-(a))
#define lowbit(a) (a&-a)
const long double pi=acos(-1);
const long double cp=5*pi-20;
using namespace std;

//bit
int c[301000],maxi=0;
int que(int val){
    int r=0;
    for(;val;val-=lowbit(val))
        r=max(c[val],r);
    return r;
}
void add(int val,int r){
    for(;val<=maxi;val+=lowbit(val))
        c[val]=max(c[val],r);
    return ;
}

//point
struct pnt{
    int x;
    int y;
    friend bool operator <(pnt a,pnt b){
        return a.x<b.x;
    }
}point[301001];

//lisan
int rak[301001],irak[301001];
bool cmp(int a,int b){
    return point[a].y<point[b].y;
}

//main

int sx,sy,tx,ty;
int jsx,jtx;
int n,cnt=0;
int x,y;
int a,b,q,maxs=0;
bool op;
long double ans;
int main(){
    scanf("%d%d%d%d%d",&sx,&sy,&tx,&ty,&n);
    if(sy>ty) swap(sy,ty),swap(sx,tx);
    jsx=sx,jtx=tx;
    if(jsx>jtx) swap(jsx,jtx),op=true;
    ans=(long double) ((jtx-jsx)*100.+(ty-sy)*100.);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a,&b);
        if(a<jsx||a>jtx) continue;
        if(b<sy||b>ty) continue;
        point[++cnt]=(pnt) {a,b};
        irak[cnt]=cnt;
    }
    n=cnt;
    maxi=cnt;
    sort(point+1,point+n+1);
    sort(irak+1,irak+n+1,cmp);
    for(int i=1;i<=n;i++){
        rak[irak[i]]=i;
    }
    //for(int i=1;i<=n;i++)
    //    printf("%d\n",rak[i]);
    if(op){
        //printf("\n\n\n\n");
        for(int i=n;i>=1;i--){
            q=que(rak[i])+1;
            add(rak[i],q);
            maxs=max(maxs,q);
        }
    }
    else{
        for(int i=1;i<=n;i++){
            q=que(rak[i])+1;
            //printf("%d:\t%d\n",rak[i],q);
            add(rak[i],q);
            maxs=max(maxs,q);
        }
    }
    x=jtx-jsx;
    y=ty-sy;
    //printf("%d\n",maxs);
    if(min(x,y)==maxs-1)
        ans+=maxs*cp+5*pi;
    else
        ans+=maxs*cp;
    //cout<<ans<<endl;
    printf("%.15Lf\n",ans);
    return 0;
}

Measured memory_bytes: 4608
/**
	Language: C++
	Author  : 21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
	FastIO();
	int n, m;
	cin >> n >> m;
	vi h(n);
	for (int &hi: h) cin >> hi;
	vector<vi> ed(n);
	int a, b;
	for (int  i = 0 ;i < m; ++i) {
		cin >> a >> b;
		--a;--b;
		ed[a].push_back(b);
		ed[b].push_back(a);
	}
	vector<bool> ans(n, true);
	for (int i = 0; i < n; ++i) {
		for (int ad: ed[i]) {
			if (h[ad] >= h[i]) {
				ans[i] = false;
				break;
			}
		}
	}
	int c = count(ans.begin(), ans.end(), true);
	cout << c << '\n';
	return 0;
}


Measured memory_bytes: 8744
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

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

int find(vi& map, int mask)
{
	for(int i=map.size()-1; i>=0; --i){
		if(map[i] & mask)
			return i;
	}
	return -1;
}

bool add(vi& map, int y, int mask)
{
	if(y == map.size())
		map.push_back(mask);
	else
		map[y] |= mask;
	
	if(map[y] == 31){
		map.erase(map.begin()+y);
		return true;
	}
	else
		return false;
}

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi map;
		rep(i, n){
			int d, p, q;
			scanf("%d%d%d", &d, &p, &q);
			--q;
			if(d == 1){
				int mask = ((1<<p)-1) << q;
				add(map, find(map, mask) + 1, mask);
			}
			else{
				int mask = 1 << q;
				int y = find(map, mask) + 1;
				rep(j, p){
					if(add(map, y+j, mask))
						--y;
				}
			}
		}
		
		int ans = 0;
		rep(i, map.size())
			ans += __builtin_popcount(map[i]);
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 1268
#include <cmath>
#include <iostream>
#include <iomanip>

#define M_PI 3.14159265358979323846

int main(void){
	double a, b, x;
  	std::cin >> a >> b >> x;
    
    if(2 * x >= (a * a) * b) {
        std::cout << std::setprecision(10) 
        << std::atan((2*b - 2*x/(a*a))/a) * 180.0 / M_PI
        << std::endl;
    }
    else {
        // a * t * b / 2 = x
        std::cout << std::setprecision(10) 
        << std::atan(b / (2*x/(a*b))) * (180.0) / M_PI
        << std::endl;
    }
    
	return 0;  
}

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

int A,B,C,D,E,F;

double calc(int a,int b)
{
	if(a==0 && b==0)return 0;
	if(a+b>F)return 0;
	return (double)(100*b)/(a+b);
}

int main()
{
	vector<int> w,s;
	int tmp,ansi=0,ansj=0;
	double dtmp,ans=0;
	
	cin >> A >> B >> C >> D >> E >> F;
	
	for(int i=0;100*A*i<=F;i++)
	{
		for(int j=0;100*B*j<=F;j++)
		{
			tmp=100*A*i+100*B*j;
			if(tmp>F)break;
			w.push_back(tmp);
		}
	}
	for(int i=0;C*i<=F;i++)
	{
		for(int j=0;D*j<=F;j++)
		{
			tmp=C*i+D*j;
			if(tmp>F)break;
			s.push_back(tmp);
		}
	}
	
	for(int i:w)
	{
		for(int j:s)
		{
			dtmp=calc(i,j);
			if(dtmp<=calc(100,E) && dtmp>ans)
			{
				ans=dtmp;
				ansi=i;
				ansj=j;
			}
		}
	}
	
	if(ans==0)ansi=100*A;
	cout << ansi+ansj << " " << ansj << endl;
	return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll N;
    cin >> N;
    ll A[N];
    for(int i = 0; i < N; i++) cin >> A[i];
    ll count = 0;
    count += A[0]/2;
    A[0] %= 2;
    for(int i = 1; i < N; i++){
        if(A[i] > 0){
            count += A[i-1];
            A[i] -= A[i-1];
        }
        count += A[i]/2;
        A[i] %= 2;
    }
    cout << count << "\n";
    return 0;
}


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


#define M_MAX 20
#define N_MAX 50000
#define INFTY 1 << 29

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

long long int point[n];
for(int i=0;i<n;i++){
point[i]=k-q;
}

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

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


}
for(int j=0;j<n;j++){
if(point[j]>0)cout << "Yes\n";
else cout << "No\n";
}
//cout << count;

}


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

using namespace std;

int main() {
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int cnt = 0;
    for (int i = n / r; i >= 0; i--) {
        int n2 = n - r * i;
        if (n2 == 0) {
            cnt++;
            continue;
        }
        for (int j = n2 / g; j >= 0; j--) {
            int n3 = n2 - g * j;
            if (n3 >= 0 && n3 % b == 0) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;
struct heap{
	int h,t;
	heap(int h=0,int t=0):h(h),t(t){}
	inline bool operator>(const heap&a)const{
		return t>a.t;
	}
};
priority_queue<heap,vector<heap>,greater<heap> >w,a[100005];
int n,m,f[100005],v[100005],sum,num[100005],p,s;
char b[100005];
unsigned long long ans;
inline char tc(void){
	static char fl[10000],*A=fl,*B=fl;
	return A==B&&(B=(A=fl)+fread(fl,1,10000,stdin),A==B)?EOF:*A++;
}
inline int read(void){
	int a=0;char c;
	while((c=tc())<'0'||c>'9');
	while(c>='0'&&c<='9')a=a*10+c-'0',c=tc();
	return a;
}
int gf(int x){
	return x==f[x]?x:f[x]=gf(f[x]);
}
int main(void){
	register int i,x,y;
	n=read(),m=read();
	for(i=1;i<=n;++i)f[i]=i;
	for(i=1;i<=n;++i)v[i]=read();
	for(i=1;i<=m;++i)
		x=1+read(),y=1+read(),f[gf(x)]=gf(y);
	for(i=1;i<=n;++i)a[gf(i)].push(heap(gf(i),v[i]));
	for(i=1;i<=n;++i)
		if(gf(i)==i)
			++sum;
	s=sum,sum=sum*2-2;
	if(sum==0){
		puts("0");
		return 0;
	}
	for(i=1;i<=n;++i)
		if(gf(i)==i){
			--sum,ans+=a[i].top().t,a[i].pop(),num[i]=1;
			if(!a[i].empty())w.push(a[i].top()),a[i].pop();
		}
	if(sum<0){
		puts("Impossible");
		return 0;
	}
	while(sum--){
		while(!w.empty()){
			x=w.top().h;
			if(num[x]+1==s)w.pop();
			else break;
		}
		if(w.empty()){
			puts("Impossible");
			return 0;
		}
		ans+=w.top().t,++num[w.top().h];
		int y=w.top().h;
		w.pop();
		if(!a[y].empty()){
			w.push(a[y].top()),a[y].pop();
		}
	}
	printf("%llu\n",ans);
	return 0;
}

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n >> m;
    if (n == 0) {
        if (m == 100) {
            cout << 101 << endl;
        } else {
            cout << m << endl;
        }
    } else if (n == 1) {
        if (m == 100) {
            cout << 10100 << Endl;
        } else {
            cout << m * 100 << endl;
        }
    } else {
        if (m == 100) {
            cout << 1010000 << endl;
        } else {
            cout << m * 10000 << endl;
        }
    }
}

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

int main()
{
    int n,d;
    cin >> n >> d;
    vector<vector<int>> a(n,vector<int> (d));
    for(int i = 0 ;i < n;i++){
        for(int j = 0;j < d;j++ ){
            cin >> a[i][j];
        }
    }
    int count = 0;
    for(int i = 0;i < n-1;i++){
        for(int j = i+1;j < n;j++){
            int s = 0;
            for(int k = 0;k < d;k++){
                s += abs(a[i][k] - a[j][k])*abs(a[i][k] - a[j][k]);
            }
            int temp  = (int)pow(s,0.5);
            if(temp*temp == s)
                count++;
        }
    }
    cout << count;

    return 0;
}

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


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

	for (int i = n - 1; i >= 0; i--)
	{
		if (i != 0)cout << a[i] << " ";
		else if (i == 0)cout << a[i] << endl;
	}
}


Measured memory_bytes: 3116
import itertools
n,m,q = map(int,input().split())
target = [list(map(int,input().split())) for _ in range(q)]
ans = 0

for A in itertools.combinations_with_replacement(range(1,m+1),n):
  count = 0
  for abcd in target:
    if A[abcd[1]-1] - A[abcd[0]-1] == abcd[2]:
      count += abcd[3]
  
  ans = max(ans,count)

print(ans)

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

int main()
{
  vector<int> bingo(100, -1);
  int N, d, n;
  vector<bool> opened(9, false);

  for (int i = 0; i < 9; i++)
  {
    cin >> n;
    bingo[n - 1] = i;
  }
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> d;
    if (bingo[d - 1] != -1)
    {
      opened[bingo[d - 1]] = true;
    }
  }
  if (
      (opened[0] && opened[1] && opened[2]) ||
      (opened[3] && opened[4] && opened[5]) ||
      (opened[6] && opened[7] && opened[8]) ||
      (opened[0] && opened[3] && opened[6]) ||
      (opened[1] && opened[4] && opened[7]) ||
      (opened[2] && opened[5] && opened[8]) ||
      (opened[0] && opened[4] && opened[8]) ||
      (opened[2] && opened[4] && opened[6]))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

signed main() {
  int N, D;
  cin >> N >> D;
  
  vector<vector<int>> X(N, vector<int>(D));
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < D; j++ ){
      cin >> X.at(i).at(j);
    }
  }
  
  int ans = 0;
  double kazu = 0;
  for( int i = 0; i < N-1; i++ ){
    for( int j = i+1; j < N; j++ ){
      kazu = 0;
      for( int k = 0; k < D; k++ ){
        kazu += pow((X.at(i).at(k) - X.at(j).at(k)), 2.0);
      }
      for( int k = 1; k <= kazu; k++ ){
        if( k*k == kazu ) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
l = [i+1 for i in range(n)]
cnt = 0
for i in range(n):
    if p[i] != l[i]:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;


int main(){
    string S;
    cin >> S;
    if(S.at(0)==S.at(1) || S.at(1)==S.at(2) || S.at(2) == S.at(3)){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }
}

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

int main(){
    int N;
    cin>>N;
    vector<string> W(N);
    for(int i=0; i<N; i++){
        cin>>W[i];}
  
bool ans = true;
 for(int i = 0; i < N - 1; ++i){
  if(W[i].back() != W[i+1].front()){
   ans = false;}
 }
 for(int i=0; i<N; i++){
  for(int j=i+1; j<N; j++){
   if(W[i] == W[j]){
    ans = false;}  //同じ単語が出てきてはいけないルール
  }
 }

if(ans){cout<<"Yes"<<endl;}
else{cout<<"No"<<endl;}
}


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

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

    if (A == B && B != C)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (B == C && C != A)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (C == A && A != B)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string str;
	cin >> str;
	for (int i = 0;i < str.length();++i) {
		cout << 'x';
	}
	return 0;
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define _ << ' ' <<
using namespace std;
using ll = long long;

string s[20];
int d[20][20];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

int main()
{
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i)
        cin >> s[i];

    int sol = 0;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (s[i][j] == '#') continue;
            queue<pair<int, int>> q;
            q.emplace(i, j);
            memset(d, -1, sizeof d);
            d[i][j] = 0;
            while (!q.empty())
            {
                int x, y;
                tie(x, y) = q.front();
                q.pop();
                for (int k = 0; k < 4; ++k)
                {
                    int xx = x + dx[k];
                    int yy = y + dy[k];
                    if (xx < 0 || xx == h || yy < 0 || yy == w) continue;
                    if (d[xx][yy] != -1) continue;
                    if (s[xx][yy] == '#') continue;
                    d[xx][yy] = d[x][y] + 1;
                    q.emplace(xx, yy);
                }
            }
            for (int x = 0; x < h; ++x)
                for (int y = 0; y < w; ++y)
                    sol = max(sol, d[x][y]);
        }
    }
    cout << sol;
}


Measured memory_bytes: 256
while(1):
    m,f,r=map(int,input().split())
    rank = ""
    if (m == -1) and (f == -1) and (r == -1):
        break
    if (m == -1) or (f == -1):
        rank = "F"
    elif m+f >= 80:
        rank = 'A'
    elif 80 > m+f >= 65:
        rank = 'B'
    elif 65 > m+f >= 50:
        rank = 'C'
    elif 50 > m+f >= 30:
        if r >= 50:
            rank = 'C'
        else:
            rank = 'D'
    elif 30 > m+f :
        rank = 'F'

    print(rank)
        

Measured memory_bytes: 7676
import java.util.*;

public class Main {

    static int MOD = 1000000007;
    public static void main(String[] args) {

        int ans=0;
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt(),b=sc.nextInt();
        //int n=sc.nextInt(),m=sc.nextInt();
      //  String s=sc.next();
        ans=Math.min(a,b);
        String s="";
        for(int i=0;i<Math.max(a,b);i++)s+=ans;


        System.out.println(s);

    }

}


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

int main() {
  int N, A, B, ans=0;
  cin >> N >> A >> B;

  for(int i=1; i<=N; ++i) {
    string S = to_string(i);
    int tmp = 0;
    for(char c:S) { tmp += c-'0'; }
    if(A <= tmp && tmp <= B) ans += i;
  }

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	N := getStdinInt()
	A := getStdinIntArr()
	Amap := make([]int, N)

	for i := 0; i < N; i++ {
		idx := A[i]
		Amap[idx-1] = i
	}
	for i := 0; i < N; i++ {
		fmt.Printf("%d ", Amap[i]+1)
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 7996
// https://atcoder.jp/contests/ddcc2020-qual/tasks/ddcc2020_qual_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define FORR(i, s, n) for (int i = (n - 1); i >= s; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    int M;
    cin >> M;
    int num = 0, sum = 0;
    while (M--) {
        int d, c;
        cin >> d >> c;
        sum += d * c;
        num += c;
    }
    cout << num - 1 + (sum - 1) / 9 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

struct process {
    string name;
    int time;
};

class Queue {
    private:
        int head_;
        int tail_;

    public:
        process queue[100001];
        
        void initialize() {
            head_ = 0;
            tail_ = 0;    
        }

        bool isEmpty() {
            return head_ == tail_;
        }

        bool isFull() {
            return head_ == (tail_ + 1) % 100001;
        }

        void enqueue(struct process ps) {
            if (isFull()) {
                cout << "Warning, queue is full" << endl;
            }
            queue[tail_] = ps;
            if (tail_ + 1 == 100001) {
                tail_ = 0;
            }
            else {
                tail_++;
            }
        }

        process dequeue() {
            if (isEmpty()) {
                cout << "Warning, queue is empty" << endl;
            }
            process ps = queue[head_];
            if (head_ + 1 == 100001) {
                head_ = 0;
            }
            else {
                head_++;
            }
            return ps;
        }
};

void test(void) {
    process a = {"ABC", 123};
    Queue q;
    q.initialize();
    q.enqueue(a);
    q.enqueue({"BCD", 345});
    process y = q.dequeue();
    cout << y.name << endl;
    process z = q.dequeue();
    cout << z.name << endl;
}

int main(void) {
    int processNum, quantum;
    string processName;
    int processTime;
    int processTotalTime = 0;

    cin >> processNum >> quantum;
    Queue processQ;

    processQ.initialize();

    // すべてのプロセスをキューに登録
    for (int i=0; i < processNum; i++) {
        cin >> processName >> processTime;
        processQ.enqueue( {processName, processTime} );
    }

    // シミュレーション
    while (processQ.isEmpty() == false) {
        process target = processQ.dequeue();
        
        if (target.time <= quantum) {
            processTotalTime += target.time;
            target.time = 0;
            cout << target.name << " "<< processTotalTime << endl;
        }
        else {
            processTotalTime += quantum;
            target.time -= quantum;
            processQ.enqueue(target);
        }

    }

    return 0;
}


Measured memory_bytes: 7124
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//1000000000

typedef struct {
    long long int A;
    long long int B;
} Array;
int main(int argc, const char * argv[]) {
    long long int N;
    scanf("%lld\n", &N);
    Array *array = malloc(sizeof(Array) * N);
    memset(array, 0, sizeof(array) * N);
    for(int i = 0; i < N; i++) {
        Array *a = array + i;
        scanf("%lld %lld", &(a->A), &(a->B));
    }
    
    long long int total = 0;
    long long int increase = 0;
    for (long long int i = N - 1; i >= 0; i--) {
        Array *a = array + i;
        long long int v = a->A + increase;
        long long int tmp = (v  + a->B - 1) / a->B;
    
        tmp = tmp * a->B - v;
        total += tmp;
        increase += tmp;
    }
    
    free(array);
    
    printf("%lld\n", total);
    return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  long ans = 0;
  rep (i, N) {
    long a;
    cin >> a;
    ans += a - 1;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#import sys

#input = sys.stdin.readline
import math
#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True


def main():
#    h,w,a,b = map(int, input().split())
    a,b,x=map(int,input().split())


    t1=math.atan(2*(a*a*b-x)/a/a/a)
    t2=math.atan(b/a)
    t3=math.atan(a*b*b/2/x)

    if x>=a*a*b/2:
        print(math.degrees(t1))
    else:
        print(math.degrees(t3))




if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds           #-}
{-# LANGUAGE KindSignatures      #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE Strict              #-}
{-# LANGUAGE TypeApplications    #-}
import           Data.Proxy   (Proxy (..))
import           Data.Ratio   ((%))
import           GHC.TypeLits (KnownNat, Nat, natVal)

main :: IO ()
main = do
  [x, y] <- map read . words <$> getLine
  print $ solve x y

solve :: Int -> Int -> MInt
solve x y
  | (x + y) `mod` 3 /= 0 = 0
  | otherwise            = comb (n + m) n
  where n = (-x + y * 2) `div` 3
        m = (x * 2 - y) `div` 3

comb :: Int -> Int -> MInt
comb n k
  | n < k || n < 0 || k < 0 = 0
  | otherwise = perm n k `div` product [1 .. k']
  where k' = modulo k :: MInt

perm :: Int -> Int -> MInt
perm _ 0 = 1
perm n k = product [n'-k'+1 .. n']
  where n' = modulo n :: MInt
        k' = modulo k :: MInt

-- Modulo Library
newtype Mod a (n :: Nat) = Mod { unMod :: a }
  deriving (Eq, Ord)

modulo :: forall n a. (Integral a, KnownNat n) => a -> Mod a n
modulo a = Mod . mod a $ modulus @n

modulus :: forall n a. (Integral a, KnownNat n) => a
modulus = fromInteger $ natVal (Proxy @n)

instance Show a => Show (Mod a n) where
  show (Mod a) = show a

instance (Integral a, KnownNat n) => Num (Mod a n) where
  fromInteger = modulo . fromInteger

  Mod a + Mod b = modulo $ a + b
  Mod a * Mod b = modulo $ a * b

  abs    (Mod a) = modulo $ abs a
  signum (Mod a) = modulo $ signum a
  negate (Mod a) = modulo $ negate a

instance (Integral a, KnownNat n) => Enum (Mod a n) where
  succ (Mod x)
    | x == unMod (maxBound :: Mod a n) =
        errorWithoutStackTrace "Prelude.Enum.succ{Mod}: tried to take `succ' of maxBound"
    | otherwise           = Mod $ x + 1

  pred (Mod x)
    | x == unMod (minBound :: Mod a n) =
        errorWithoutStackTrace "Prelude.Enum.pred{Mod}: tried to take `pred' of minBound"
    | otherwise            = Mod $ x - 1

  toEnum = fromIntegral
  fromEnum = fromIntegral . unMod

  enumFrom     x   = enumFromTo     x maxBound
  enumFromThen x y = enumFromThenTo x y bound
    where
      bound | fromEnum y >= fromEnum x = maxBound
            | otherwise                = minBound

instance (Integral a, KnownNat n) => Bounded (Mod a n) where
  maxBound = Mod $ pred (modulus @n)
  minBound = 0

instance (Integral a, KnownNat n) => Real (Mod a n) where
  toRational (Mod a) = toInteger a % 1

instance (Integral a, KnownNat n) => Integral (Mod a n) where
  toInteger (Mod a) = toInteger a
  quotRem a b = (a * inv b, 0)

inv :: forall n a. (Integral a, KnownNat n) => Mod a n -> Mod a n
inv x = go (unMod x) (modulus @n) 1 0
  where go _ 0 u _ = modulo u
        go a b u v = go b (a - t * b) v (u - t * v)
          where t = a `div` b

type MInt = Mod Int 1000000007


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
typedef long long ll;
// 1 = R 2 = B 3 = G 4 = RG 5 = RB 6 = GB

int main()
{
	ll n,ans = 1;
	ll a[7] = {0};
	string s;
	cin >> n >> s;
	a[0] = n;
	
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'R'){
			if(a[5]) {ans = ans*a[5]%MOD;a[5]--;}
			else if(a[2]) {ans = ans*a[2]%MOD;a[2]--;a[4]++;}
			else if(a[3]) {ans = ans*a[3]%MOD;a[3]--;a[6]++;}
			else {ans = ans*a[0]%MOD;a[0]--;a[1]++;}
		}
		else if(s[i] == 'B'){
			if(a[6]) {ans = ans*a[6]%MOD;a[6]--;}
			else if(a[1]) {ans = ans*a[1]%MOD;a[1]--;a[4]++;}
			else if(a[3]) {ans = ans*a[3]%MOD;a[3]--;a[5]++;}
			else {ans = ans*a[0]%MOD;a[0]--;a[2]++;}
		}
		else{
			if(a[4]) {ans = ans*a[4]%MOD;a[4]--;}
			else if(a[1]) {ans = ans*a[1]%MOD;a[1]--;a[6]++;}
			else if(a[2]) {ans = ans*a[2]%MOD;a[2]--;a[5]++;}
			else {ans = ans*a[0]%MOD;a[0]--;a[3]++;}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 900
import * as fs from 'fs';

namespace AtCoder.abc138 {
    /**
     * 2
     * 10 30
     */
    class ProgramB {
        main(inp: string) {
            const aList: number[] = inp.split('\n')[1].split(' ').map(x => parseInt(x));

            let denominator: number =
                aList.reduce((accum, current) => accum += 1 / current, 0);

            console.log(1 / denominator);
        }
    }

    const func = new ProgramB();
    func.main(fs.readFileSync('/dev/stdin', 'utf8').trim())
}

Measured memory_bytes: 7500
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] p = new int[n];
		for(int i = 0;i < n;i++){
			p[i] = saori.saori_hayami();
		}
		Arrays.sort(p);
		int ans = 0;
		p[n-1] = p[n-1]/2;
		for(int i = 0;i < n;i++){
			ans += p[i];
		}
		System.out.println(ans);

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

long gcd(long a, long b)
{
	if (a % b == 0)
		return b;
	else
		return (gcd(b, a % b));
}

long  lcm(long a, long b)
{
	return (a * b / gcd(a,b));
}

int  main()
{
	long a,b; cin >> a >> b;
	long c,d; cin >> c >> d;
	long total = b - a + 1;

	long b_div_c = b / c; long a_div_c = (a-1) / c;
	long b_div_d = b / d; long a_div_d = (a-1) / d;
	long cnum = b_div_c - a_div_c; //cで割り切れる個数
	long dnum = b_div_d - a_div_d; //dで割り切れる個数
	long cdnum = (b / lcm(c,d)) - ((a-1) / lcm(c,d));
	cout << total - (cnum+dnum-cdnum) << endl;
	return (0);
}

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

bool checkPalindrome(string str) {
    for(int i=0;i<str.length();i++) {
        if(str[i] != str[str.length()-i-1])
            return false;
    }
    return true;
}

int main(int argc, char const *argv[])
{
    string str;
    cin >> str;
    if(checkPalindrome(str) && checkPalindrome(str.substr(0,(str.length()-1)/2)) && checkPalindrome(str.substr((str.length()+3)/2-1,str.length()-((str.length()+3)/2)+1))) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k; cin >> n >> k;
	int64_t h[n]; rep(i,n) cin >> h[i];
	sort(h, h + n);
	int64_t ans = 0;
	for(int i = 0; i < n - k; ++i) {
		ans += h[i];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1792
using static System.Math;
using System;

class M
{
    private const int MOD = 1000000007;
    private readonly int[] _f;
    public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD);
    public M(int n)
    {
        _f = new int[n + 1];
        _f[0] = 1;
        for (int i = 1; i <= n; ++i)
            _f[i] = Mul(_f[i - 1], i);
    }
    public int Fac(int n) => _f[n];
    public int Pow(int a, int m)
    {
        if (m == 0) return 1;
        else if (m == 1) return a;
        var p1 = Pow(a, m / 2);
        var p2 = Mul(p1, p1);
        return ((m % 2) == 0) ? p2 : Mul(p2, a);
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        var res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var md = new M(n + k);
        if (n > k) { Console.WriteLine(0); goto exit; }
        var ans = md.Ncr(k, n);
        Console.WriteLine(ans);
        exit:;
    }
}


Measured memory_bytes: 18012
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        
        int ans=(N*(N-1))/2+(M*(M-1))/2;
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 22612