akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
  static void Main(string[] args)
  {
        string a = Console.ReadLine();
        int ans = int.Parse(a.Substring(a.Length-1 ,1));
        if(ans == 3)
        {
            Console.WriteLine("bon");
        } else if(ans ==0 || ans == 1 || ans == 6 || ans == 8)
        {
            Console.WriteLine("pon");
        }
        else
        {
            Console.WriteLine("hon");
        }




  }

   

}



Measured memory_bytes: 17636
#!/usr/bin/env python3

T = list(input())

ans = ''
for i in range(len(T)) :
    if i+1 == len(T) :
        if T[i] != '?' :
            ans += T[i]
        else :
            ans += 'D'
        continue

    if i == 0 :
        if T[i] != '?' :
            ans += T[i]
        else :
            if T[i+1] == 'P' :
                ans += 'D'
            else :
                ans += 'P'
        continue
    
    if T[i] != '?' :
        ans += T[i]
        continue

    if ans[i-1] == 'P' :
        ans += 'D'
    elif ans[i-1] == 'D' :
        if T[i+1] == 'P' :
            ans += 'D'
        else :
            ans += 'P'

print(ans)

Measured memory_bytes: 10936
from collections import defaultdict


def mapt(fn, *args):
    return tuple(map(fn, *args))

  
def main():
    n, m = mapt(int, input().split(" "))
    # if m == 0: print(0, 0); exit()
    ac = defaultdict(int)
    pena = defaultdict(int)
    for _ in range(m):
        index, symbol = input().split(" ")
        index = int(index)
        index -= 1
        if ac[index]: continue

        if symbol == "AC": ac[index] = 1
        elif symbol == "WA": pena[index] += 1
    # print(ac, pena)
    AC = PENA = 0
    for i in range(n):
        AC += ac[i]
        if ac[i]: PENA += pena[i]
    print(AC, PENA)

main()

Measured memory_bytes: 30844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    string s;
    cin>>s;
    int ans=700;
    rep(i,s.size()){
        if(s.at(i)=='o'){
            ans+=100;
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3612
N = int(input())
L = []
for i in range(N) :
    s,p = input().split()
    p = int(p)
    L.append([s,p,i+1])

L = sorted(L, key=lambda x: x[1], reverse=True)
L = sorted(L, key=lambda x: x[0], reverse=False)

ans = [L[i][2] for i in range(N)]

print(*ans, sep="\n")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  int i,N,L;
  cin >> N >> L;
  string S[101];
  for(i=0;i<N;i++) 
  {
    cin >> S[i];
  }
  sort(S, S+N);
  for(i=0; i<N; i++) 
  {
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


int main(){
  int n, cnt=0;
  while(cin >> n){
    cnt = 0;
    REP(i, 10) REP(j, 10) REP(k, 10) REP(l, 10) if(i + j + k + l == n) cnt++;
    cout << cnt << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
/*
[tenka1-2019] D - Three Colors
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 300;
const int MAX_A = 300;
const int MAX_S = MAX_N * MAX_A;
const ll MOD = 998244353;

int N;
int a[MAX_N];
ll dp0[MAX_N + 1][MAX_S + 1];
ll dp1[MAX_N + 1][MAX_S + 1];

ll solve() {
    int S = accumulate(a, a + N, 0);
    ll pow3 = 1;
    for (int i = 0; i < N; i++) {
        (pow3 *= 3) %= MOD;
    }

    dp0[0][0] = 1;
    dp1[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= MAX_S; j++) {
            (dp0[i + 1][j] += dp0[i][j] * 2) %= MOD;
            (dp1[i + 1][j] += dp1[i][j]) %= MOD;
            if (j + a[i] <= MAX_S) {
                (dp0[i + 1][j + a[i]] += dp0[i][j]) %= MOD;
                (dp1[i + 1][j + a[i]] += dp1[i][j]) %= MOD;
            }
        }
    }

    ll c0 = 0;
    for (int j = (S + 1) / 2; j <= MAX_S; j++) {
        (c0 += dp0[N][j]) %= MOD;
    }
    ll c1 = (S % 2 == 0) ? dp1[N][S / 2] : 0;

    ll ans = (pow3 - 3 * c0 + 3 * c1 + 3 * MOD) % MOD;

    return ans;
}

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

    cout << solve() << endl;

    return 0;
}


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

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

    int n;
    cin >> n;
    int arr[n];
    long long sum = 0, cur = 0, ans = 2e18;

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

    for (int i = 0; i < n - 1; i++)
        cur += arr[i], ans = min(ans, abs(cur - (sum - cur)));
    cout << ans << '\n';
}

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

const int MAXN = 200005;

int n, pi, v[MAXN];
vector <int> g[MAXN];

struct block{
	int a, b;
	block(int a, int b): a(a), b(b){}
	bool operator <(const block& x) const{
		return (1LL * b * x.a < 1LL * x.b * a);
	}
};

int sz[MAXN], heavy[MAXN];
void prep(int u){
	sz[u] = 1;
	heavy[u] = -1;
	
	for(int v : g[u]){
		prep(v);
		
		sz[u] += sz[v];
		if(heavy[u] == -1 || sz[v] > sz[heavy[u]]){
			heavy[u] = v;
		}
	}
}

long long total;
void combine(multiset <block>& a, multiset <block>& b){
	while(!b.empty()){
		a.insert(*b.begin());
		b.erase(b.begin());
	}
}

multiset <block> M[MAXN];
multiset <block>& solve(int u){
	if(g[u].empty()){
		M[u].insert(block(v[u] == 0, v[u] == 1));
		return M[u];
	}
	
	multiset <block>& r = solve(heavy[u]);
	for(int v : g[u]){
		if(v == heavy[u])continue;
		combine(r, solve(v));
	}
	
	if(v[u] == 0){
		r.insert(block(1, 0));
	}else{
		block t = block(0, 1);
		
		while(!r.empty() && (*r.begin()) < t){
			total += 1LL * t.b * (r.begin()->a);
			t.a += r.begin()->a;
			t.b += r.begin()->b;
			
			r.erase(r.begin());
		}
		r.insert(t);
	}
	return r;
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i < n; i++){
		scanf("%d", &pi);
		g[pi - 1].push_back(i);
	}
	for(int i = 0; i < n; i++)
		scanf("%d", &v[i]);
	
	prep(0);
	multiset <block>& r = solve(0);
	
	long long sum = 0;
	for(block d : r){
		total += 1LL * sum * d.a;
		sum += d.b;
	}
	
	printf("%lld\n", total);
	
    return 0;
}


Measured memory_bytes: 40064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s, n) for(int i = s; i < (int)(n); i++)
#define co(x) cout<<x<<endl
#define SQvec(i,j) vector<vector<int>> data(i, vector<int>(j))
#define mod 1000000000+7
typedef long long int lint;

int main() {
  int a,b;
  cin >> a >> b;
  if(a + b == 15){co("+");}
  else if(a * b == 15){co("*");}
  else{co("x");}
}

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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
	int x=(a+d-1)/d; //a=9	d=4 经过变化后正好3次 
	int y=(c+b-1)/b;
	cout<<(x>=y?"Yes":"No")<<"\n";
 } 

Measured memory_bytes: 3680
/*
Competitive programming template
Author: Aswin Sampath

*/


#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef priority_queue<ll,vl,greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max; 
typedef stack<ll> s;
typedef queue<ll> q;


#define pi 3.141592653589793
#define PI  acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define testcase ll t;cin>>t;while(t--)
#define dbxstl(x){for(auto ele:x)cout<<ele<<space; cout<<endl;}
#define dbxval(x){cout<<x<<endl;}

const ll INF = 1e18+7;
const ll MOD=1e9+7;

void solve(){
    printf("Hello\n");
}

int main(int argc, char const *argv[])
{
    int n,k;
    scanf("%d %d",&n,&k);
    vector<int>h(n);
    for(int &x:h){
        scanf("%d",&x);
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
namespace AtCoder
{
    class Program
    {

        static void Main(string[] args)
        {
            Console.ReadLine();
            var num = Console.ReadLine()
                      .Split()
                      .Select(int.Parse)
                      .Aggregate(0, (p, n) => p | n, p => Convert.ToString((p & -p), 2))
                      .Count() - 1;

            Console.WriteLine(num);

        }
    }
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int H,W;
const int MAX_H=100,MAX_W=100;
char a[MAX_H][MAX_W+1];
const int ALP='z'-'a'+1;
int cnt[ALP];
int main(){
	cin>>H>>W;
	REP(i,H){
		cin>>a[i];
	}
	int olim=0,tlim=0;
	if(W%2){
		tlim+=H/2;
	}
	if(H%2){
		tlim+=W/2;
	}
	if(W%2&&H%2){
		olim=1;
	}
	REP(i,H)REP(j,W)cnt[a[i][j]-'a']++;
	REP(c,ALP){
		if(cnt[c]%2){
			olim--;
		}else if(cnt[c]%4==2){
			tlim--;
		}
	}
	cout<<(olim>=0 && tlim>=0 ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
import sys

def solve(r, g):
    ans = g * 2 - r
    print(ans)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    r = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    g = int(ws[0])
    return (r, g,)

def main():
    solve(*readQuestion())

main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORX(i, a, b, x) for (int i = (a); i <= (b); i+=x)
#define debug(x) cerr << #x << " is= " << x << endl; //use for debugging
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 5] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
 
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
 
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vov        vector<vector<int>> 
#define pr         pair<ll,ll>
#define vpll       vector<pair<ll,ll>>
#define all(v)     v.begin(),v.end()
#define rall(v)    v.rbegin(),v.rend()  //reverse of above;
#define sz(container) int((container).sz())
#define cut(x) {cout<<x<<"\n"; return 0;}
#define setprec(x) cout << fixed << showpoint << setprecision(8)<<x<<endl;
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/__gcd(a,b)
#define time cout << clock() / double(CLOCKS_PER_SEC) << endl;
#define endl "\n"
//#define mod 1000000007
using namespace std;
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//*s.find_by_order(1);
//s.order_of_key() ->number of elements strictly smaller then our item;
//st.rbegin()->second; last element in set
//st.erase(prev(st.end())); delete last element in set;
const int N=1e5+5;
ll mod=1000000007;
int countWays(int arr[], int m, int N) 
{ 
  int count[N + 1]; 
  memset(count, 0, sizeof(count)); 
  count[0] = 1; 
  for (int i = 1; i <= N; i++) 
    for (int j = 0; j < m; j++) 
      if (i >= arr[j]) 
       {
          count[i] += count[i - arr[j]]; 
          count[i]%=mod;
       }
  
 
  return count[N]%mod; 
  
} 
int main()
{
  fast_io;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  int N;
  cin>>N;
  int arr[N-2];
  FOR(i,0,N-3) arr[i]=i+3;
  cout<<countWays(arr, N-2, N); 
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; map<int, int> m;
    cin>>n;
    for(int i =0; i<n; i++){
        int a; cin>>a;
        if(n%2==1){
            if(a%2!=0){
                cout<<0; return 0;
            }
            else{
                m[a]++;
                if(m[a]>2){
                    cout<<0; return 0;
                }
            }
        }
        else{
            if(a%2!=1){
                cout<<0; return 0;
            }
            else{
                m[a]++;
                if(m[a]>2){
                    cout<<0; return 0;
                }
            }
        }   
    }
    if(n%2==0&&m[0]!=0){
        cout<<0; return 0;
    }
    if(n%2==1&&m[0]!=1){
        cout<<0; return 0;
    }

    long long answer=1;
    for(int i=0; i<n/2; i++){
        answer*=2;
        answer%=1000000007;
    }
    cout<<answer;
    return 0;
}

Measured memory_bytes: 2560
from sys import stdin


def main():
    def iterate_tokens():
        for line in stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    Q = int(next(tokens))
    S = next(tokens)
    L = [int()] * Q
    R = [int()] * Q
    for i in range(Q):
        L[i] = int(next(tokens)) - 1
        R[i] = int(next(tokens)) - 1
    AC = [int()] * N
    pre = None
    cnt = 0
    for i, c in enumerate(S):
        if c == "A":
            pre = "A"
        elif pre == "A" and c == "C":
            cnt += 1
            pre = None
        elif pre == "A":
            pre = None
        AC[i] = cnt
    for i in range(Q):
        print(AC[R[i]] - AC[L[i]])
    return


main()


Measured memory_bytes: 14188
#include <stdio.h>

int main() {
  int color_a, color_b, color_c;
  scanf("%d %d %d", &color_a, &color_b, &color_c);
  if(color_a == color_b && color_a == color_c) {
    printf("1\n");
  } else if(color_a == color_b || color_b == color_c || color_c == color_a) {
    printf("2\n");
  } else {
    printf("3\n");
  }
  return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    string s;
    deque<char>ans;
    int f=0;
    cin>>s;
    int n=s.length(),q;
    f(i,0,n)
        ans.push_back(s[i]);
    cin>>q;
    while(q--){
        cin>>n;
        if(n==1){
            f=1-f;
        }
        else{
            char c;
            cin>>n>>c;
            if(f==0){
                if(n==1)
                    ans.push_front(c);
                else
                    ans.push_back(c);
            }
            else{
                if(n==2)
                    ans.push_front(c);
                else
                    ans.push_back(c);
            }
        }
    }
    while(!ans.empty()){
        if(f==0){
            cout<<ans.front();
            ans.pop_front();
        }
        else{
            cout<<ans.back();
            ans.pop_back();
        }
    }
    cout<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 101, W = 1e5 + 1;
ll dp[2][W];
int n, w;

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.precision(10);
   cout << fixed;
   cin >> n >> w;
   bool at = 0;
   for (int i = 0; i < n; ++i){
      at ^= 1;
      int weight, value;
      cin >> weight >> value;
      for (int j = 1; j <= w; ++j){
         dp[at][j] = max(dp[at ^ 1][j], dp[at][j - 1]);
         if (j - weight >= 0)
            dp[at][j] = max(dp[at][j], dp[at ^ 1][j - weight] + value);
      }
   }
   cout << dp[at][w] << '\n';
   return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[2010];

signed main(){
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
	}
	int ans=0;
	if(K==1){
		REP(i,N){
			for(int j=i+1;j<N;j++){
				if(A[i]>A[j]){
					ans++;
					ans%=MOD;
				}
			}
		}
		cout<<ans<<endl;
	}
	else{
		REP(i,N){
			for(int j=i+1;j<N;j++){
				if(A[i]>A[j]){
					ans+=K*(K+1)/2;
					ans%=MOD;
				}
				else if(A[i]<A[j]){
					ans+=K*(K-1)/2;
					ans%=MOD;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int a,b;
	cin >> a >> b;
	string s1,s2;
	for (int i = 0; i < b; ++i) s1 += a+'0';
	for (int i = 0; i < a; ++i) s2 += b+'0';
	if (s1<s2) cout << s1;
	else cout << s2;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define N 10001
int a[N], d;
ll f[N][101];
ll dfs(int len, int pre, int top) {
    if (!len) return pre == 0;
    if (!top && f[len][pre] != -1) return f[len][pre];
    int up = top ? a[len] : 9;
    ll num = 0;
    for (int i = 0; i <= up; i++)
        num = (num + dfs(len - 1, (pre + i) % d, top && (i == up))) % mod;
    if (!top) f[len][pre] = num;
    return num;
}
char c[N];
int main() {
    memset(f, -1, sizeof(f));
    scanf("%s%d", c + 1, &d);
    int n = strlen(c + 1);
    for (int i = n, j = 1; i; i--, j++) a[j] = c[i] - '0';
    cout << (dfs(n, 0, 1) - 1 + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 8960
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    
    vector<P> p(n);
    rep(i, n) {
        p[i] = make_pair(abs(sum - n*a[i]), i);
    }
    sort(all(p));

    out(p[0].second);
    re0;
}

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

using namespace std;

typedef long long int ll;

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

  ll n, k;
  cin >> n >> k;
  vector < ll > a(n + 1);
  for(int i = 1; i <= n; i++) cin >> a[i];

  vector < vector < ll > > dp(64, vector < ll > (n + 1));
  for(int i = 1; i <= n; i++) dp[0][i] = a[i];
  for(int bt = 1; bt < 64; bt++){
    for(int i = 1; i <= n; i++){
      dp[bt][i] = dp[bt - 1][dp[bt - 1][i]];
    }
  }

  ll pos = 1;
  for(int bt = 0; bt < 64; bt++){
    if((k >> bt) & 1){
      pos = dp[bt][pos];
    }
  }

  cout << pos << '\n';
}


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

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

	vector<int> p(N);

	for (int i = 0; i < N; i++) {
		cin >> p.at(i);
	}

	sort(p.begin(), p.end());

	int sum = 0;

	for (int i = 0; i < K; i++) {
		sum += p.at(i);
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3204
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Set;
import java.util.StringTokenizer;


public class Main {
	 static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 
 
	public static void main(String[] args)throws IOException  {
		FastReader s=new FastReader();		
		int n =  s.nextInt();
		double[] ar = new double[n];
	
		for(int i=0;i<n;i++) {
			ar[i]=s.nextInt();
		}
		Arrays.sort(ar);
		for(int i=0;i<n-1;i++) {
			ar[i+1]=(double)(ar[i]+ar[i+1])/2;
		}
		System.out.println(ar[n-1]);
		
		
	}
	
}


Measured memory_bytes: 33204
#include<stdio.h>
int main(){
	int n,m,i;
	scanf("%d%d",&n,&m);
	int road[n];
	for(i=0;i<n;i++)	road[i] = 0;
	for(i=0;i<m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		road[a-1]++;
		road[b-1]++;
	}
	for(i=0;i<n;i++)	printf("%d\n",road[i]);
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, r;
	cin >> n >> r;
	if (n >= 10)
		cout << r << endl;
	else
	{
		r = r + (100 * (10 - n));
		cout << r << endl;
	}

}

Measured memory_bytes: 3604
#include<cstdio>
#include<cmath>
int main()
{
	double a,b,h,m,p,pi=3.141592653589793238462643383279;
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
	if(30*h+m/2>=6*m) p=30*h+m/2-6*m;
	else p=6*m-30*h-m/2;
	printf("%.20lf",sqrt(a*a+b*b-2*a*b*cos(p*pi/180.0)));
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if (((int)log10(i) + 1) % 2)
            ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
n = int(input())
h = list(map(int,input().split()))
b = str()
for i in range(n-1):
    if h[i] >= h[i+1]:
        b+=str(1)
    else:
        b+=str(0)
c = b.split('0')
ans = [len(c[i]) for i in range(len(c))]
print(max(ans))

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

const int INF = (1<<31)-1;
const int MAX = (1<<17)-1;
int n, D[1000000], lazy[1000000];
bool flag[1000000];
void init(int n_ ){
    n = 1;
    while(n<n_) n *= 2;
    for(int i=0; i < 2*n-1; i++){
        D[i] = ((int)1<<31)-1;
        flag[i] = false;
    }
}
void eval(int k, int l, int r){
    if(flag[k]){
      D[k] = lazy[k];
        if(l+1 < r){
          lazy[2*k+1] = lazy[k];
          lazy[2*k+2] = lazy[k];
          flag[2*k+1] = true;
          flag[2*k+2] = true;
        }
        flag[k] = false;
    }
}
void update(int a,int b,int x,int k,int l,int r){
    eval(k, l, r);
    if(r <= a || b <= l)return;
    if(a <= l && r <= b){
        flag[k] = true;
        lazy[k] = x;
        eval(k, l, r);
    }
    else{
        update(a, b, x, 2*k+1, l, (l+r)/2);
        update(a, b, x, 2*k+2, (l+r)/2, r);
        D[k]=min(D[2*k+1],D[2*k+2]);
    }
}
void update(int a, int b, int x) { update(a, b, x, 0, 0, n);}

int query(int a, int b, int k, int l, int r){
    eval(k, l, r);
    if(r <= a|| b <= l) return INF;
    if(a <= l && r <= b) return D[k];
    int vl=query(a, b, 2*k+1, l, (l+r)/2);
    int vr=query(a, b, 2*k+2, (l+r)/2 ,r);
    return min(vl,vr);
}
int findmin(int a, int b) { return query(a, b, 0, 0, n); }


int main(void){
    int p, q;

    cin >> p >> q;
    init(p);

    for(int i=0; i<q; i++){
        int com, x, y, z, m;
        cin >> com;

        if(com == 0){
           cin >> x >> y >> z;
            update(x, y+1, z);
        }else{
          cin >> x >> y;
            cout << findmin(x, y+1) << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 5216
#include<iostream>
using namespace std;
#define maxn 105
int a[maxn];
int n;
int k=0;
void selectionSort()
{
    for(int i=0;i<n;i++)
    {
        int minindex=i;
        for(int j=i;j<n;j++)
        {
            if(a[j]<a[minindex])
                minindex=j;
        }
        if(i!=minindex)
        {


        swap(a[i],a[minindex]);
        k++;

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

        for(int i=0;i<n;i++)
            cin>>a[i];
        selectionSort();
    }
    return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

const int size=100;
int N,M;
int G[size][size];
bool vis[size];

void dfs(int v){
    vis[v]=1;
    REP(u,N){
        if(G[v][u] and !vis[u]) dfs(u);
    }
}

signed main()
{   
    cin>>N>>M;
    vint a(M),b(M);
    REP(i,M){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
        G[a[i]][b[i]]=1;
        G[b[i]][a[i]]=1;
    }

    int ans=0;
    REP(i,M){
        G[a[i]][b[i]]=G[b[i]][a[i]]=0;
        REP(j,N) vis[j]=0;
        dfs(0);
        REP(j,N){
            if(!vis[j]){
                ans++;
                break;
            }
        }
        G[a[i]][b[i]]=G[b[i]][a[i]]=1;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		
		if(a%3==0)
			System.out.println("Possible");
		else if(b%3==0)
			System.out.println("Possible");
		else if((a+b)%3==0)
				System.out.println("Possible");
		else
			System.out.println("Impossible");
}
}

Measured memory_bytes: 21460
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    r,D,x = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    for i in range(10):
        x=r*x-D
        print(x)




if __name__ == "__main__":
    main()

Measured memory_bytes: 77360
#include <iostream>

using namespace std;

int selectionSort(int A[], int N)
{
	int k = 0;

	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (A[j] < A[minj])
				minj = j;
		}
		int t = A[i];
		A[i] = A[minj];
		A[minj] = t;
		if (i != minj) k++;
	}

	return k;
}

int main()
{
	const int MAX = 100;
	int A[MAX], N, k;

	cin >> N;

	for (int i = 0; i < N; i++)
		cin >> A[i];

	k = selectionSort(A, N);

	for (int i = 0; i < N; i++) {
		if (i) cout << ' ';
		cout << A[i];
	}
	cout << '\n';

	cout << k << endl;
}

Measured memory_bytes: 1164
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <vector>

using namespace std;

void b_golden_coins(void) {
	int x;

	int max = 0;

	cin >> x;

	max += (int)(x / 500)*1000;

	int remain = x % 500;

	max += (int)(remain / 5) * 5;

	cout << max << endl;
}

int main()
{
    b_golden_coins();

    return 0;
}

Measured memory_bytes: 3588
using System;
using static System.Console;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
         int employee = int.Parse(ReadLine());
         int[] boss = ReadLine().Split(' ').Select(int.Parse).ToArray();
         int[] bossOfEmployee = new int[employee];

        for (int i = 0; i < boss.Count(); i++)
        {
            bossOfEmployee[boss[i] - 1] += 1;
        }

        for (int i = 0; i < bossOfEmployee.Count(); i++)
        {
            WriteLine(bossOfEmployee[i]);
        }
      }
   }
}

Measured memory_bytes: 43596
s=str(input())
count=0
if s[0]=='A':
  count+=1
for i in range(2,len(s)-1):
  if s[i].count('C')==1:
    count+=1
s=s.replace('A','').replace('C','')
if s.islower()==True:
  count+=1
if count==3:
  print('AC')
else:
  print('WA')
  

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

using namespace std;

const int N = 1e5 + 100;

int n, m, a[N];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= m; ++i)
		scanf("%d", &a[i]);
	int cnt = 0;
	for(int i = 1;i <= m; ++i) 
		if(a[i] & 1)
			cnt++;
	if(cnt > 2) return 0 * puts("Impossible");
	cnt = 0;
	for(int i = 1;i <= m; ++i) {
		if(a[i] & 1) {
			cnt++;
			if(cnt == 1) swap(a[1], a[i]);
			if(cnt == 2) {
				swap(a[m], a[i]);
				break;
			}
		}
	}
	for(int i = 1;i <= m; ++i)
		printf("%d ", a[i]);
	puts("");
	if(m == 1 && a[1] > 1) m = 2, a[2] = 1, a[1]--;
	else if(m == 1 && a[1] == 1) m = 1;
	else if(a[m] == 1) m--, a[1]++;
	else a[m]--, a[1]++;
	printf("%d\n", m);
	for(int i = 1;i <= m; ++i)
		printf("%d ", a[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

#define ll long long

class Solver
{
public:
	ll n;
	vector<ll> a;
	map<ll, ll>hash;
	Solver();
	~Solver();
	void exec();
};

Solver::Solver(){
	cin >> n;
	for (int i = 0; i < 3*n; ++i)
	{
		ll tmp;
		cin >> tmp;
		a.push_back(tmp);
		hash[tmp]++;
	}
}

Solver::~Solver(){}

void Solver::exec(){
	ll sum = 0;
	sort(a.begin(), a.end(), greater<ll>());
	for (int i = 0; i < n; ++i)
	{
		sum += a[2*i+1];
	}
	cout << sum << endl;
}

int main(){
	Solver solution = Solver();
	solution.exec();
}


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

using namespace std;

typedef long long ll;

int main () {
	double R;
	ll n, m; 
	ll i, j;
	ll ret;
	
	cin >> R;
	
	cout << R *2*M_PI << endl;

	return 0;
}

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

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

	string str;
	int cnt = 0;
	int BA = 0;
	int CA = 0;
	int BC = 0;

	for(int i=0;i<n;i++){
		cin >> str;
		for(int j=0;j<str.size()-1;j++){
			if(str[j] == 'A' && str[j+1] == 'B')
				cnt++;
		}
		if(str[0] == 'B' && str[str.size()-1] == 'A'){
			BA++;
		}else if(str[str.size()-1] == 'A'){
			CA++;
		}else if(str[0] == 'B'){
			BC++;
		}
	}

	if(CA > 0){
		if(BA > 0){
			cnt+=BA;
			BA = 0;
		}
		if(BC > 0){
			cnt += min(CA, BC);
		}
	}else if(BA > 1){
		cnt+=(BA-1);
		BA = 1;
		if(BC > 0){
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
bool seen[505][505];

//dpTable
//bool dp[100050];

int main(){
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (i > 0 && i < 10) ans++;
        else if (i > 99 && i < 1000) ans++;
        else if (i > 9999 && i < 100000) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

// 素因数分解; 返り値は(素数, 乗数)のvector配列
vector<pair<ll, int>> factorize(ll n) {
	vector<pair<ll, int>> res;
	for (ll i = 2; i * i <= n; ++i) {
		if (n % i) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────

struct Edge {
	int to, id;
};

vector<vector<Edge>> g;
vi ans;

void dfs(int v, int c = -1, int p = -1) {
	int k = 1;
	for (auto nx : g[v]) {
		int a = nx.to, b = nx.id;
		if (a == p) continue;
		if (k == c) k++;
		ans[b] = k;
		k++;
		dfs(a, ans[b], v);
	}
}

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

	g.resize(n);
	ans.resize(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;

		Edge tmp1 = { b, i }, tmp2 = { a, i };
		g[a].push_back(tmp1);
		g[b].push_back(tmp2);
	}

	dfs(0);

	int mx = 0;
	rep(i, n - 1) {
		mx = max(mx, ans[i]);
	}
	cout << mx << endl;
	rep(i, n - 1) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 8320
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = myconv(next(),4);
  var N = one[0];
  var M = one[1];
  var kyori = new Array(N);
  kyori[0] = 0;
  var max = Math.pow(10,14);
  for(var i = 1; i < N; i++){
    kyori[i] = max;
  }
  var alist = new Array(M);
  var blist = new Array(M);
  var clist = new Array(M);
  for(var i = 0; i < M; i++){
    var tmp = myconv(next(),4);
    alist[i] = tmp[0] - 1;
    blist[i] = tmp[1] - 1;
    clist[i] = tmp[2] * (-1);
  }
  for(var i = 0; i < N - 1; i++){
    for(var j = 0; j < M; j++){
      if(kyori[alist[j]] == max){
         continue;
      }
      //a→bに向かうとき、すでに分かってる距離(∞含む)よりも短いなら更新
      if(kyori[blist[j]] > kyori[alist[j]] + clist[j]){
         kyori[blist[j]] = kyori[alist[j]] + clist[j];
      }
    }
  }
  //負閉路(無限に距離を減らせるような場所)があるか
  var negative = new Array(N).fill(false);
  for(var i = 0; i < N; i++){
    for(var j = 0; j < M; j++){
      if(kyori[alist[j]] == max){
         continue;
      }
      //最初の経路探索が終わった後に、さらに短いところが見つかれば負経路
      if(kyori[blist[j]] > kyori[alist[j]] + clist[j]){
         kyori[blist[j]] = kyori[alist[j]] + clist[j];
         negative[blist[j]] = true;
      }
      if(negative[alist[j]]){
         negative[blist[j]] = true;
      }
    }
  }
  if(negative[N - 1]){
     myout("inf");
  }else{
     myout(kyori[N - 1] * (-1));
  }
}

Measured memory_bytes: 12348
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	Int N; std::cin >> N;
	for (Int h = 1; h <= 3500; ++h)for (Int n = 1; n <= 3500; ++n) {
		Int w = N * h * n;
		Int tmp = 4 * h * n - N * n - N * h;
		if (tmp > 0 && w % tmp == 0) {
			std::cout << h << " " << n << " " << w / tmp;
			return;
		}
	}

}


int main() {

	init();
	calc();

	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int main() {
	string s, t;
	cin >> s;
	int now = 0;
	rep(i, 4) {
		t.pb(s[now++]);
	}
	t.pb(' ');
	rep(i, 8) {
		t.pb(s[now++]);
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 384
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
typedef long long ll;
const ll MAX_N = 300+5;
const ll MOD = 1e9+7;
using namespace std;

long double dp[MAX_N][MAX_N][MAX_N];
int t[4];
double n;

int main()
{
    cin >> n;
    for(int i = 0;i<n;++i)
    {
        int c;
        cin >> c;
        t[c]++;
    }
    for(int i = 0;i<=n;++i)
    {
        for(int j = 0;j<=n;++j)
        {
            for(int k = 0;k<=n;++k)
            {
                if (!(i+j+k))
                    continue;
                long double f = n;
                if (i)
                    f += i*dp[i-1][j+1][k];
                if (j)
                    f += j*dp[i][j-1][k+1];
                if (k)
                    f += k*dp[i][j][k-1];
                dp[i][j][k] = f/(double)(i+j+k);
            }
        }
    }
    cout << fixed << setprecision(15);
    cout << dp[t[3]][t[2]][t[1]];
    return 0;
}


Measured memory_bytes: 436736
#include <bits/stdc++.h>
#define rep(i, s, e) for(int i = s; i < e; i++)
#define rrep(i, s, e) for(int i = s; i > (s)-(e); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int a, b;
  cin >> a >> b;

  if (a+b >= 10) pr("error");
  else pr(a+b);


  return 0;
}


Measured memory_bytes: 256
def factor(n, d):
    if n == 1:
        return d
    else:
        l = [i+1 for i in range(n) if i != 0]
        l.append(n)
        for x in l:
            if n % x == 0:
                if x in d:
                    d[x] += 1
                else:
                    d[x] = 1
                return factor(n/x, d)

n = int(raw_input())
d = {}
for i in range(n):
    d = factor(i+1, d)

ans = 1
for i in d.values():
    ans *= i+1
print ans % 1000000007


Measured memory_bytes: 2692
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var S string
	r := bufio.NewScanner(os.Stdin)
	b := make([]byte, 10000000)
	r.Buffer(b, 10000000)
	r.Scan()
	S = r.Text()

	a := -1
	z := -1
	for i := 0; i < len(S); i++ {
		if S[i:i+1] == "A" && a < 0 {
			a = i
		}
		if S[len(S)-1-i:len(S)-i] == "Z" && z < 0 {
			z = len(S) - 1 - i
		}
	}
	fmt.Println(z - a + 1)
}

Measured memory_bytes: 5120
require 'set'

def bfs(start_node, extra = nil)
    return 0 if start_node.is_goal?(extra)
    reached = Set[start_node]
    dist = 1
    queue = [start_node]
    until queue.empty?
        next_queue = []
        until queue.empty?
            node = queue.shift
            node.each_next_node(extra) do |next_node|
                return dist if next_node.is_goal?(extra)
                next if reached.include?(next_node)
                reached << next_node
                next_queue << next_node
            end
        end
        dist += 1
        queue = next_queue
    end
    return nil
end

n, m, k = gets.split.map(&:to_i)

dark_rooms = 0
gets.split.map(&:to_i).each do |i|
    dark_rooms |= (1 << i)
end

neighbour = Hash.new(0)
(1..n).each do |i|
    neighbour[i] = [0] + gets.split.map(&:to_i)
    neighbour[i].map! {|x| 1 << x}
end

class Integer
    def is_goal?(extra)
        self == 0
    end

    def each_next_node(extra)
        n = extra[:n]
        k = extra[:k]
        dark_rooms = extra[:dark_rooms]
        neighbour = extra[:neighbour]

        a = Array.new(k + 1, 0)
        (1..n).each do |j|
            next if self[j] == 0
            (1..k).each do |i|
                a[i] |= neighbour[j][i]
            end
        end
        a[1..-1].each do |y|
            yield y & dark_rooms
        end
    end
end

extra = {
    :k => k,
    :n => n,
    :dark_rooms => dark_rooms,
    :neighbour => neighbour,
}
p bfs(dark_rooms, extra)



Measured memory_bytes: 13832
S = int(input())
mod = 10**9 + 7
MN = 3

N = S//3 + S % 3


dp = [0] * (S+1)
dp[0] = 1
for i in range(1, S+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= mod

print(dp[S])

Measured memory_bytes: 9148
#include <stdio.h>

int main()
{
	int h, m, s, a;

	scanf("%d", &a);

	h = a / (60 * 60);
	m = (a - (h * 60 * 60)) / 60;
	s = a - (h * 60 * 60) - (m * 60);

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}


Measured memory_bytes: 2056