akhauriyash/Code-Regression huggingface dataset:
mod=10**9+7
n,m=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
p=0
q=0
for i in range(n-1):
    p=(p+(X[i+1]-X[i])*(i+1)%mod*(n-i-1))%mod
for i in range(m-1):
    q=(q+(Y[i+1]-Y[i])*(i+1)%mod*(m-i-1))%mod
print(p*q%mod)

Measured memory_bytes: 90708
from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path
import numpy as np

import sys
def input():
	return sys.stdin.readline().strip()

N, M, L = list(map(int, input().split()))

graph = np.full((N, N), np.inf)
for i in range(M):
	A, B, C = list(map(int, input().split()))
	graph[A - 1, B - 1] = C
	graph[B - 1, A - 1] = C


dist = shortest_path(graph, method='FW', directed=False)
graph2 = np.full((N, N), np.inf)
for i in range(N):
	for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1
graph2 = csr_matrix(graph2)
num = shortest_path(graph2, method="FW", directed=False)


Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1)

Measured memory_bytes: 19872
from copy import copy
s = input() + "T"
n=len(s)
x, y = map(int, input().split())

xy=[[],[]]

sgn = 1
now = n
for i in range(n):
    if s[i] == "T":
        x -= i
        now = i + 1
        break
for i in range(now, n):
    if s[i] == "T":
        xy[sgn].append(i - now)
        now = i + 1
        sgn ^= 1


cur = {0}
for i in xy[0]:
    nxt = set()
    for j in cur:
        nxt.add(j + i)
        nxt.add(j - i)
    cur = copy(nxt)

flag = x in cur

cur = {0}
for i in xy[1]:
    nxt = set()
    for j in cur:
        nxt.add(j + i)
        nxt.add(j - i)
    cur = copy(nxt)

print("Yes" if flag and y in cur else "No")

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

namespace AtCoder.Abc171
{
    class A
    {
        public static void Main()
        {
            var a = Console.ReadLine().ToCharArray().First();

            if (a <= 'Z')
                Console.WriteLine('A');
            else
                Console.WriteLine('a');
        }
    }
}


Measured memory_bytes: 26152
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b)
{
    return(*(int *)a-*(int *)b);
}
int main()
{
    int a[101],m,n,b,c,d,sum=0;
    scanf("%d",&m);
    for(n=0;n<m;n++)
        scanf("%d",&a[n]);
    qsort(a,m,sizeof(a[0]),cmp);
    for(b=0;b<m-2;b++)
    {
        for(c=b+1;c<m-1;c++)
        {
            if(a[b]==a[c])
                continue;
            for(d=c+1;d<m;d++)
            {
                if(a[b]==a[d]||a[c]==a[d])
                    continue;
                if(a[b]+a[c]<=a[d])
                    break;
                else
                    sum++;
            }
        }
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 1732
def factorization(n):
    res = set()
    tmp = n
    for i in range(2, int(n ** 0.5) // 1):
        if tmp % i == 0:
            while tmp % i == 0:
                tmp //= i
            res.add(i)
    res.add(tmp)
    return res

a, b = map(int,input().split())
ans = factorization(a) & factorization(b) | {1}
print(len(ans))


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

int main(){
string a;
  cin>>a;
  char b;
  for(int j=0; j<26;j++){
    b='a'+j;
 for(int i=0;i<a.size();i++){
if(a[i]==b){
  break;
}
   if(i==a.size()-1){
     cout<<b<<endl;
     j=30;
   }
 }
   if(j==25){
  cout<<"None"<<endl;   
}
  } 
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char math[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin >> math[i][j];    
        }
    }
    int wid[h][w];
    int hig[h][w];
    queue<int> q_wid[h],q_hig[w];
    for(int i=0; i<h; i++){
        int cnt=0;
        for(int j=0; j<w; j++){
            if(math[i][j]=='.')cnt++;
            else if(math[i][j]=='#'){
                q_wid[i].push(cnt);
                cnt=0;
                //if(j!=0&&j!=w-1)q_wid[i].push(cnt);
            }
            if(j==w-1)q_wid[i].push(cnt);
        }
    }
    for(int i=0; i<w; i++){
        int cnt=0;
        for(int j=0; j<h; j++){
            if(math[j][i]=='.')cnt++;
            else if(math[j][i]=='#'){
                q_hig[i].push(cnt);
                cnt=0;
                //if(j!=0&&j!=h-1)q_hig[i].push(cnt);
            }
            if(j==h-1)q_hig[i].push(cnt);
        }
    }
    /*for(int i=0; i<h; i++){
        while(!q_wid[i].empty()){
            cout << q_wid[i].front() << " ";
            q_wid[i].pop();
        }
        cout << endl;
    }
    cout << endl;
    for(int i=0; i<w; i++){
        while(!q_hig[i].empty()){
            cout << q_hig[i].front() << " ";
            q_hig[i].pop();
        }
        cout << endl;
    }
    cout << endl;*/
    int mx=-1;
    int ans[h][w];
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            ans[i][j]=0;
        }
    }
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(math[i][j]=='.'){
                int tmp=q_wid[i].front();
                ans[i][j]+=tmp;
            }
            else q_wid[i].pop();
        }
    }
    for(int i=0; i<w; i++){
        for(int j=0; j<h; j++){
            if(math[j][i]=='.'){
                int tmp=q_hig[i].front();
                ans[j][i]+=tmp-1;
            }
            else q_hig[i].pop();
            //cout << mx << " ";
            if(mx<ans[j][i])mx=ans[j][i];
        }
    }
    /*for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }*/
    cout << mx << endl;
}

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

int main(){
    ll n;
    cin>>n;
    vector<string> data;
    for (ll i=0; i<n; i++){
        vector<char> b;
        for (int j=0; j<10; j++){
            char a;
            cin>>a;
            b.push_back(a);
            sort(b.begin(), b.end());
        }
        string c;
        for (int j=0; j<10; j++) c+=b[j];
        data.push_back(c);
    }
    sort(data.begin(),data.end());
    
    map <string,ll> pp;
    ll sum=0;
    
    for (ll i=0; i<n; i++){
        pp[data[i]]+=1;
    }

    for (const auto& x:pp){
        ll v=x.second;
        sum+=v*(v-1)/2;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 13556
#include <stdio.h>

int main(void)
{
	int sta[10];
	int v1,v2;
	float lon;
	int i,n,comp;
	
	while(1){
		
		lon = comp = 0;
		
		for(i = 0; i < 10; i++){
			scanf("%d,", &sta[i]);
			lon += sta[i];
		}
		if(scanf("%d,%d", &v1, &v2) == EOF) break;
		
		lon = lon * 1.0 * v1 / (v1 + v2);
		
		for(i = 0; i < 10; i++){
			comp += sta[i];
			
			if(lon <= comp){
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	return(0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define preturn(X) cout<<X<<endl; return 0
typedef long long ll;

int n;
vector<int> edges[100000+1];
int degree[100000+1];
bool visited[100000+1];
queue<int> q;

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    cin>>n;
    int x,y;
    rep(i,0,n-1){
    	cin>>x>>y;
    	edges[x].pb(y);
    	edges[y].pb(x);
    	degree[x]++;
    	degree[y]++;
    }
    rep(i,1,n+1){
    	if(degree[i]==1){
    		q.push(i);
    	}
    }
    while(!q.empty()){
    	int x = q.front();
    	visited[x] = 1;
    	q.pop();
    	iter(it,edges[x]){
    		if(!visited[(*it)]){
    			visited[(*it)] =1;
    			iter(it1,edges[(*it)]){
	    			if(!visited[(*it1)]){
	    				degree[(*it1)]--;
	    				if(degree[(*it1)]==0){
	    					preturn("First");
	    				}
	    				else if(degree[(*it1)]==1){
	    					q.push((*it1));
	    				}
	    			}	
    			}
    			break;
    		}
    	}
    }
    preturn("Second");
}

Measured memory_bytes: 6528
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int h = in.nextInt();
		int w = in.nextInt();
		int counter = 0;
		for(int i =0;i<n;i++) {
			int a = in.nextInt();
			int b = in.nextInt();
			if(a>=h&&b>=w) {
				counter++;
			}			
		}
		System.out.println(counter);
	}
}


Measured memory_bytes: 25584
#include <stdio.h>

int main() {
  int number_of_snack, number_of_member;
  scanf("%d %d", &number_of_snack, &number_of_member);
  if(number_of_snack % number_of_member == 0) {
    printf("0\n");
  } else {
    printf("1\n");
  }
  return 0;
}


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

int main() {
 string S,T,U;
 int A,B;

 cin >> S >> T ;
 cin >> A >> B;
 cin >> U;

 if(S.find(U) == string::npos){

 }
 else{
     A = A - 1;
 }
 if(T.find(U) == string::npos){

 }
 else{
     B = B - 1;
 }

cout << A <<" "<< B<< endl;



}


Measured memory_bytes: 256
//By : BebekJK
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//Declare -> ordered_set NAMA;
//Nth smallest integer -> find_by_order(N-1)
//Number of elements less than N -> order_of_key(N)
//Delete N from the set -> erase(N)

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

typedef long long ll;
typedef long long ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int main(){
//	BOOST();
	string s , t;
	cin>>s>>t;
	for(int i=0;i<s.length();i++){
		if(s[i]!=t[i]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}







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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define INT(n) int n;assert(0<scanf("%d",&n))
#define VI(v,n) vector<int> v(n);REP(i,n){assert(0<scanf("%d",&v[i]));}

int main(){
  int ans = 0;
  INT(n); VI(as, n);
  unordered_map<int, int> mp;
  for(int a: as){mp[a] += 1;}
  if (mp[1] == 1){ans++;}
  for(int a: as){
    if (0 < mp[1]){continue;}
    if (1 < mp[a]){continue;}
    bool ok = true;
    REP(i, 2, a){
      if (a < i*i){break;}
      if (a % i == 0 && 0 < mp[i]){ok = false; break;}
      if (a % i == 0 && 0 < mp[a / i]){ok = false; break;}
    }
    if (ok){ans++;}
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 32528
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
using namespace std;
// using namespace atcoder;



vector<ll> fact;

void calcFact(ll n, ll mod) {
    fact.assign(n+1, 1);
    repi(i, n+1) {
        fact[i] = fact[i-1] * i % mod;
    }
}

ll mpow(ll x, ll n, ll mod){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}

ll combination(ll n, ll a, ll mod) {
    if (n < a) {
        return 0;
    }

    ll X = fact[n];
    ll Y = fact[a];
    ll Z = fact[n-a];
    ll iY = mpow(Y, mod - 2, mod);
    ll iZ = mpow(Z, mod - 2, mod);

    ll res = X * iY % mod;
    res = res * iZ % mod;

    return res;
}

void Main()
{
    ll K;
    string S;
    cin >> K >> S;

    ll n = K + S.size();

    ll mod = 7+1e9;

    vector<ll> pow25(n+1, 1);
    vector<ll> pow26(n+1, 1);
    repi(i, n+1) pow25[i] = pow25[i-1] * 25 % mod;
    repi(i, n+1) pow26[i] = pow26[i-1] * 26 % mod;

    calcFact(n, mod);

    ll res = 0;
    rep(i, S.size() + K) {
        if (1+i - (int)S.size() < 0) {
            continue;
        }
        ll v = 1;
        v = v * combination(i, S.size() - 1, mod) % mod;
        v = v * pow25[1+i - S.size()] % mod;
        v = v * pow26[S.size() + K - i - 1] % mod;

        res += v;
        res %= mod;
    }

    put(res);
}
signed main(){ Main();return 0;}

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

using namespace std;

#define ll long long int

int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll i,sum=0;
              string s;
              cin>>s;
              for(i=0;i<s.length();i++)
              {
                  sum+=(s[i]-48);
              }
              if(sum%9==0)
                cout<<"Yes\n";
              else
                cout<<"No\n";
              return(0);
}


Measured memory_bytes: 3740
#include <stdio.h>
int main(void){
    int a;
    int i;
   
    scanf("%d",&a);
    
    if(100<=a && a<=111){
        printf("111");
    }
    for(i=1;i<9;i++){
   if(i*100+i*10+i+1<=a && a<=(i+1)*100+(i+1)*10+i+1){
        printf("%d",(i+1)*100+(i+1)*10+i+1);
    }
    }
    return 0;
}

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

int main(){
	string s;
	cin >> s;
	if(s[5] ==  '1'){
		cout << "TBD" << endl;
	}else{
		if(s[6] <= '4'){
			cout << "Heisei" << endl;
		}else{
			cout << "TBD" << endl;
		}
	}
	return 0;
}




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

typedef pair<string, int> P;

int bfs(string worm){
	queue<P> que;
	que.push(P(worm, 0));

	map<string, int> d;
	
	while(!que.empty()){
		P p = que.front();
		que.pop();

		if(d[p.first]) continue;

		string str = p.first;

		bool flag = false;
		for(int i=0;i<str.size()-1;i++){
			if(str[i] != str[i+1]){
				flag = true;
				break;
			}
		}

		if(!flag) return p.second;

		d[p.first] = p.second;

		for(int i=0;i<str.size()-1;i++){
			if(str[i] != str[i+1]){
				char temp;
				string next;

				if(str[i] != 'b' && str[i+1] != 'b'){
					temp = 'b';
				}else if(str[i] != 'g' && str[i+1] != 'g'){
					temp = 'g';
				}else{
					temp = 'r';
				}

				next = str;
				next[i] = next[i+1] = temp;

				que.push(P(next, p.second+1));
			}
		}
	}
	return -1;
}

int main(){
	string worm;
	while(cin >> worm && worm != "0"){
		int ret = bfs(worm);
		if(ret>=0) cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
       if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
    int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
    ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
    freopen((name+".in").c_str(),"r",stdin);
    freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
          dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define MAXN 200010
ll n;char a[MAXN];
int main(){
    cin>>n;
    cin>>(a+1);
    ll r=0,w=0;
    for(int i=1;i<=n;i++){
        if(a[i]=='R')r++;
        else w++;
    }
    ll ans=0;
    for(int i=1;i<=r;i++){
        if(a[i]=='W')ans++;
    }cout<<ans<<endl;
}
/* stuff to remember
    * int overflow, array bounds
    * special cases (n=1? n=0?)
    * do something instead of nothing and stay organized
    * USE STATIC ARRAYS
    * DEFINING ARRAYS BEFORE main()
    * DO NOT DEFINE ARRAYS IN main()
    * USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 3916
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      int i=0;
      for (String var : br.readLine().split(" "))
        seq[i++] = Integer.parseInt(var);

      int q = partition(seq, 0, n-1);
      dispIntArrayPartition(seq, q);
    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }

  public int partition(int[] seq, int p, int r) {

    int x = seq[r];
    int i = p-1;
    int t;

    for(int j=p; j<r; j++) {
      if(seq[j] <= x) {
        t = seq[++i]; seq[i] = seq[j]; seq[j] = t;
      }
    }
    t = seq[i+1]; seq[i+1] = seq[r]; seq[r] = t;

    return i+1;
  }

public void dispIntArrayPartition(int[] target, int q) {
  StringBuilder s = new StringBuilder();
  int l=target.length-1;

  for (int i=0; i<q; i++) { s.append(target[i]).append(" "); }
  s.append("[").append(target[q]).append("] ");
  for (int i=q+1; i<l; i++) { s.append(target[i]).append(" "); }
  s.append(target[l]);

  System.out.println(s);
  }
}


Measured memory_bytes: 40128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int cell[9],targets[10];
int n;

const int pattern[8][3]={
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,3,6},
    {1,4,7},
    {2,5,8},
    {0,4,8},
    {2,4,6}
};

void solve(){
    REP(i,n){
        REP(j,9){
            if(targets[i]==cell[j]){
                cell[j]=0;
                break;
            }
        }
    }
    REP(i,8){
        if (!(cell[pattern[i][0]] || cell[pattern[i][1]] || cell[pattern[i][2]])){
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
}

int main()
{
    REP(i,9){
        cin >> cell[i];
    }
    cin >> n;
    REP(i,n){
        cin >> targets[i];
    }
    solve();
}

Measured memory_bytes: 256
object Main {
  
  def main(args: Array[String]) {
     val list = readLine().split(" ").map(_.toInt)
     val (a, b) = (list(0), list(1))
     
     val d = a / b
     val r = a % b
     val f = a.asInstanceOf[Double] / b.asInstanceOf[Double]
     println(f"$d $r $f%.5f")
  }
}


Measured memory_bytes: 44024
n = int(input())
h = list(map(int, input().split()))

maxh = h[0]

for i in range(1, n):
    if h[i] < maxh and h[i] < maxh - 1:
        print("No")
        exit(0)
    if h[i] > maxh:
        maxh = h[i]

print("Yes")

Measured memory_bytes: 14396
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<numeric>

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

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

int main() {
	ll a, b;
	cin >> a >> b;
	ll c;
	c = lcm(a, b);
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import deque
import bisect

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	N = NI()
	R = [NLI() for _ in range(N)]
	B = [NLI() for _ in range(N)]
	R.sort(key= lambda x: x[1], reverse=True)
	B.sort(key= lambda x: x[0])
	ans = 0

	for b in B:
		for r in R:
			if r[0] < b[0] and r[1] < b[1]:
				ans += 1
				R.remove(r)
				break
	
	print(ans)





if __name__ == "__main__":
	main()

Measured memory_bytes: 3316
n = int(input())
t =list(map(int, input().split()))
m = int(input())
p, x = [0]*m, [0]*m
for i in range(m):
    p[i], x[i] = map(int, input().split())

for j in range(m):
    prev = t[p[j]-1]
    t[p[j]-1] = x[j]
    print(sum(t))
    t[p[j]-1] = prev

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int a,b,n;
  cin>>a>>b;
  n=(a+b)/2;
  if(abs(a-n)==abs(b-n))
  {
      cout<<n;
  }
  else
  {
      cout<<"IMPOSSIBLE";
  }
 
 
 
 
 
    return 0;
}

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

#define MOD 1000000007;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> like(m);
	for(int i=0; i<n; i++){
		int k;
		cin >> k;
		for(int j=0; j<k; j++){
			int a;
			cin >> a;
			like[a-1]++;
		}
	}
	int ans=0;
	for(auto e: like){
		if(e==n)
			ans++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int a, b;
	bool flug = false;
	while (cin >> a >> b , a || b) {
		if (flug) cout << "\n";
		int count = 0;
		for (int i = a; i <= b; i++) {
			if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
				cout << i << "\n";
				count++;
			}
		}
		if (count == 0) cout << "NA\n";
		flug = true;
	}
	return 0;
}

Measured memory_bytes: 1164
ANS = 0

n, m, q = (int(i) for i in input().split())
t = []
for i in range(q):
	t.append([int(i) for i in input().split()])

def sml(lst):
	# ~ print("lst=",lst)
	ret = 0
	for x in t:
		# ~ print("x = ",x)
		if lst[x[1]-1] - lst[x[0]-1] == x[2]:
			ret+= x[3]
	return ret

def f(k, n, m, lst):
	if k==n:
		ans = sml(lst)
		# ~ print(lst,"->", ans)
		global ANS
		ANS = max(ans, ANS)
	elif k==0:
		for i in range(1,m+1):
			lst+=[i]
			f(k+1, n, m, lst)
			lst.pop()
	else:
		for i in range(lst[-1], m+1):
			lst+=[i]
			f(k+1, n, m, lst)
			lst.pop()
			
f(0,n,m,[])
	
print(ANS)


Measured memory_bytes: 9140
#include <stdio.h>
#include <math.h>
 
struct Point {
    double x,y;
};
 
void makeKochCurve (Point * p1, Point * p2, int n, int maxDepth) {
    if (n > maxDepth) return;
    Point s = { p1->x + (p2->x - p1->x) / 3, p1->y + (p2->y - p1->y) / 3};
    Point t = { p1->x + (p2->x - p1->x) * 2 / 3, p1->y + (p2->y - p1->y) * 2 / 3};
 
    double th = M_PI * 60 / 180;
    Point u = { (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x , (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) +s.y};
 
    makeKochCurve(p1, &s, n + 1, maxDepth);
    printf("%.8f %.8f\n", s.x, s.y);
    makeKochCurve(&s, &u, n + 1, maxDepth);
    printf("%.8f %.8f\n", u.x, u.y);
    makeKochCurve(&u, &t, n + 1, maxDepth);
    printf("%.8f %.8f\n", t.x, t.y);
    makeKochCurve(&t, p2, n + 1, maxDepth);
 
}
 
int main() {
    Point s = {0,0};
    Point e = {100,0};
 
    int n;
    scanf("%d", &n);
 
    printf("%.8f %.8f\n", s.x, s.y);
    makeKochCurve(&s, &e, 1, n);
    printf("%.8f %.8f\n", e.x, e.y);
 
    return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;

int main(){
  ll n; cin>>n;
  vector<pair<pair<string,ll>,ll>>v;
  
  for(ll i=1;i<=n;i++){
  string s; cin>>s; ll t; cin>>t; t*=-1;
  //v.push_back(pair<pair<string,ll>,ll>((s,t),i));はダメ
  v.push_back(make_pair(make_pair(s,t),i));
  }
  
  sort(v.begin(),v.end());
  
  for(pair<pair<string,ll>,ll>t:v){
   cout<<t.second<<endl;
  }
  
}

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

using namespace std;

/*const int maxn=1e6;
int dp[maxn];
int h[maxn];

int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=1;i<n;i++)
    {
        dp[i]=1e9;
        for(int j=1;j<=min(i,k);j++)
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
    }
    cout<<dp[n-1];

    return 0;
}*/
/*const int maxn=1e5;
int a[maxn][3];
int dp[maxn][3];
int main()
{
    int n;
    cin>>n;
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i-1][j];
        }
        dp[i][0]=a[i-1][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i-1][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i-1][2]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return 0;
}*/

const int maxn=110;
long long a[maxn][2];
const int maxx=1e5+10;
long long dp[maxn][maxx];

int main()
{
    long long n,w;
    cin>>n>>w;
    for(long long i=1;i<=n;i++)
    {
        for(long long j=0;j<2;j++)
        {
            cin>>a[i-1][j];
        }
        for(int j=0;j<1e5+10;j++)
        {
            if(j-a[i-1][0]>=0)
                dp[i][j]=max(dp[i-1][j],(a[i-1][1]+dp[i-1][j-a[i-1][0]]));
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
    return 0;
}





















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

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

using ll = long long;

int main() {
  string S;
  ll Q;
  cin >> S >> Q;
  string f, e;
  int test = 1;
  for(ll i = 0LL; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) test *= -1;
    else if(t==2){
      int x;
      string y;
      cin >> x >> y;
      if((test == 1&&x==1) || (test==-1&&x==2)){
        y+=f;
        f=y;
      }
      else if((test == 1&&x==2) || (test==-1 && x==1)){
        e+=y;
      }
    }
  }
  f+=S;
  f+=e;
  if(test == -1) reverse(f.begin(), f.end());
  cout << f << endl;
}

Measured memory_bytes: 1340
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(b >= a*c){
        cout << c << endl;
    }else{
        cout << b/a << endl;
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    long long A[N];
    long long minus = 0;
    long long ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(A[i] < 0) minus++;
        A[i] = abs(A[i]);
        ans += A[i];
    }
    if(minus % 2 == 1) cout << ans - *min_element(A, A + N) * 2 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			int e = sc.nextInt();
			list.add(a);
			list.add(b);
			list.add(c);
			list.add(d);
			list.add(e);
			Collections.sort(list);
			for(int x = 4; x >= 0  ; x--){
				System.out.print(list.get(x));
				if (x != 0) System.out.print(" ");
			}
			System.out.println();
		sc.close();
	}

}

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

int main() {
  ll a,b,c,ans=0;
  cin>>a>>b>>c;
  if(a%2==1 || b%2==1 || c%2==1){
    cout<<0<<endl;
    return 0;
  }
  if(a==b&&b==c){
    cout<<-1<<endl;
    return 0;
  }
  while(true){
    ans++;
    ll x,y,z;
    x=b/2+c/2;
    y=a/2+c/2;
    z=a/2+b/2;
    a=x;b=y;c=z;
    if(a%2==1 || b%2==1 || c%2==1){
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String X = sc.next();
		String Y = sc.next();
		String answer;

		if(0>X.compareTo(Y)){
			answer = "<";
		}
		else if (0<X.compareTo(Y)){
			answer = ">";
		}
		else {
			answer = "=";
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 21840
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner a = new Scanner(System.in);
		int b = a.nextInt();
		int c = a.nextInt();
		int d,r;
		double f;
		d = b/c;
		r = b - (c * d);
		f = (double)b/(double)c;
		//BigDecimal x = new BigDecimal(f);
		//x = x.setScale(13, BigDecimal.ROUND_HALF_UP);
		//System.out.print(d+" "+r+" "+x);
		System.out.print(d+" "+r+" ");
		System.out.printf("%.8f\n",f);
	}

}

Measured memory_bytes: 17360
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

//Cooley-Tukey FFT algorithm
vector<complex<double>> fft(vector<complex<double>>a,bool inverse=false){
    int n=a.size();
    int h=0;        //h=log_2(n)
    for(int i=0;1<<i<n;i++)h++;
    //バタフライ演算用の配置入れ替え
    for(int i=0;i<n;i++){
        int j=0;
        for(int k=0;k<h;k++) j|=(i>>k&1)<<(h-1-k);
        if(i<j)swap(a[i],a[j]);
    }
    
    //バタフライ演算
    for(int b=1;b<n;b*=2){
        //第 log_2(b)+1段
        //ブロックサイズ=b*2
        
        for(int j=0;j<b;j++){
            //ブロック内j個目
            //重み　w=(1の原始 2b 乗根　のj乗)
        complex<double> w=polar(1.0,-(2*M_PI)/(2*b)*j*(inverse ? 1:-1));

        for(int k=0;k<n;k+=b*2){
            //kを先頭とするブロック
            complex<double> s=a[j+k];       //前
            complex<double> t=a[j+k+b]*w;   //後
            a[j+k]=s+t;
            a[j+k+b]=s-t;
            }
        }
    }
    if(inverse){
        for(int i=0;i<n;i++)a[i]/=n;
    }
    
    return a;
}

//関数のオーバーロード
vector<complex<double>> fft(vector<double> a,bool inverse=false){
    vector<complex<double>> a_complex(a.size());
    rep(i,a.size())a_complex[i]=complex<double>(a[i],0);
    return fft(a_complex,inverse);
}

vector<double> convolve(vector<double> a,vector<double> b){
    int s=a.size()+b.size()-1;  //畳み込み結果のサイズ
    int t=1;                    //FFTに使う配列のサイズ
    while(t<s)t*=2;
    a.resize(t);                //FFTするためにリサイズ
    b.resize(t);                //FFTするためにリサイズ
    vector<complex<double>> A=fft(a);
    vector<complex<double>> B=fft(b);

    for(int i=0;i<t;i++){
        A[i]*=B[i];             //畳み込み結果のFFT結果を得る
    }
    A=fft(A,true);              //IFFTで畳み込み結果を得る
    a.resize(s);
    for(int i=0;i<s;i++)a[i]=A[i].real();   //実部が答え
    
    return a;
}

int main(){

long long  N,M;
cin>>N>>M;

vector<int>A(N);

rep(i,N)cin>>A[i];

vector<double> num(200001,0);
rep(i,N)num[A[i]]+=1;

vector<double>ans=convolve(num,num);

vector<long long > B(200001);

rep(i,200001)B[i]=(long long) (0.5+ans[i]);

long long Answer=0;
for(int i=200000;i>0;i--){
    Answer+=i*min(B[i],M);
    M=max((M-B[i]),(long long )0);
    if(M==0)break;
}

cout<<Answer<<endl;

return 0;

}
/*
5 3
10 14 19 34 33

202

9 14
1 3 5 110 24 21 34 5 3

1837

9 73
67597 52981 5828 66249 75177 64141 40773 79105 16076

8128170



7




56 


715
*/


Measured memory_bytes: 39232
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    for(i in 0 until n){
        val s = readLine()!!.split(" ")[0]
        if (s == "AC") ac++
        else if(s == "WA") wa++
        else if (s == "TLE") tle++
        else re++
    }
    println("AC x ${ac}")
    println("WA x ${wa}")
    println("TLE x ${tle}")
    println("RE x ${re}")
}

Measured memory_bytes: 59796
"""
def LinearSearch1(S, n, t):
    for i in range(n):
        if S[i] == t:
            return i
            break
    else:
        return -1
"""

def LinearSearch2(S, n, t):
    S.append(t)
    i = 0

    while S[i] != t:
        i += 1

    S.pop()
    if i == n:
        return -1
    else:
        return i


n = int(input())
S = [int(s) for s in input().split()]

q = int(input())
T = {int(t) for t in input().split()}

# ans = sum(LinearSearch1(S, n, t) >= 0 for t in T)
ans = sum(LinearSearch2(S, n, t) >= 0 for t in T)

print(ans)

Measured memory_bytes: 8444
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n - 1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - 1;
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < n - 1; i++) {
            c[i] = sc.nextInt();
        }
        int levelOfSaticfaction_b = 0;
        int levelOfSaticfaction_c = 0;
        for (int i = 0; i < a.length; i++) {
            levelOfSaticfaction_b += b[a[i]];
            if (i >= 1) {
                if (a[i] - a[i - 1] == 1) {
                    levelOfSaticfaction_c += c[a[i - 1]];
                }
            }
        }
        System.out.println(levelOfSaticfaction_b + levelOfSaticfaction_c);
        sc.close();
    }
}

Measured memory_bytes: 21972
h, w, k = map(int, input().split())

buf = []
total = 0
for row in range(h):
    row = list(input())

    buf.append(row)

    total += row.count('#')

colors = list(zip(*buf))

if k > total:
    print(0)
    exit()

# diff個減らせればOK
diff = total - k

candH = 2 ** h
candW = 2 ** w


def counting(text):
    res = []
    for i, c in enumerate(text):
        if c == '#':
            res.append(i)
    return res

ans = 0
for a in range(candH):
    for b in range(candW):
        hBit = a
        wBit = b
        currentCount = 0

        hIndexList = []
        for r in range(h):
            shouldAgg = hBit % 2 == 1
            hBit = hBit >> 1

            l = []
            if shouldAgg:
                l = counting(buf[r])
            hIndexList.append(l)
            currentCount += len(l)

        for c in range(w):
            shouldAgg = wBit % 2 == 1
            wBit = wBit >> 1

            if shouldAgg:
                cIndex = counting(colors[c])
                currentCount += len(cIndex)

                for ci in cIndex:
                    if c in hIndexList[ci]:
                        currentCount -= 1

        if currentCount == diff:
            ans += 1


print(ans)

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

typedef long long ll;
const ll INF = 1e18;

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i < b;++i) cout << ary[i] << (b-1 == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

int n;
vector<int> sz(5010,1);
vector<ll> a(5010);
vector<vector<int>> edges(5010);
vector<vector<ll>> dp0(5010,vector<ll>(5010,INF)),dp1(5010,vector<ll>(5010,INF));

void dfs(int u,int par = -1) {
    (a[u] > 0 ? dp0 : dp1)[u][0] = a[u];
    for (int& v : edges[u]) if (v != par) {
        dfs(v,u);
        vector<ll> temp0(5010,INF),temp1(5010,INF);
        sz[u] += sz[v];
        for (int i = 0;i < sz[u];++i) {
            if (dp0[u][i] == INF) continue;
            for (int j = 0;j < sz[v];++j) {
                if (dp0[v][j] == INF) continue;
                temp0[i+j] = min(temp0[i+j],dp0[u][i]+dp0[v][j]);
                temp0[i+j+1] = min(temp0[i+j+1],dp0[u][i]);
            }
            for (int j = 0;j < sz[v];++j) {
                if (dp1[v][j] == INF) continue;
                temp1[i+j] = min(temp1[i+j],dp0[u][i]+dp1[v][j]);
                if (dp1[v][j] < 0) temp0[i+j+1] = min(temp0[i+j+1],dp0[u][i]);

            }
        }
        for (int i = 0;i < sz[u];++i) {
            if (dp1[u][i] == INF) continue;
            for (int j = 0;j < sz[v];++j) {
                if (dp0[v][j] == INF) continue;
                temp1[i+j] = min(temp1[i+j],dp1[u][i]+dp0[v][j]);
                temp1[i+j+1] = min(temp1[i+j+1],dp1[u][i]);
            }
            for (int j = 0;j < sz[v];++j) {
                if (dp1[v][j] == INF) continue;
                temp1[i+j] = min(temp1[i+j],dp1[u][i]+dp1[v][j]);
                if (dp1[v][j] < 0) temp1[i+j+1] = min(temp1[i+j+1],dp1[u][i]);
            }
        }
        dp0[u] = temp0;
        dp1[u] = temp1;
    }
}

int main() {
    cin >> n;
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    dfs(0);
    int ans = n;
    for (int i = 0;i < n;++i) if (dp0[0][i] < INF) {
        ans = i;
        break;
    }
    for (int i = 0;i < n;++i) if (dp1[0][i] < INF && dp1[0][i] < 0) {
        ans = min(ans,i);
        break;
    }
    cout << ans << endl;
    // for (int i = 0;i < n;++i) p_ary(dp0[i],0,n,j);
    // cout << endl;
    // for (int i = 0;i < n;++i) p_ary(dp1[i],0,n,j);
    // cout << endl;
    // p_ary(sz,0,n,i);
    return 0;
}

Measured memory_bytes: 395904
use std::io::stdin;
use std::str::FromStr;
use std::hash::Hash;
use std::collections::HashMap;

fn main(){
    let _: usize = get_one();
    let xs: Vec<i64> = get_vec();
    let cnts = count(&xs);
    let mut ans = 0;
    for (&x, cnt) in cnts.iter() {
        if x <= cnt {
            ans += cnt - x;
        } else {
            ans += *cnt;
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

fn count<'a, T>(v: &'a Vec<T>) -> HashMap<&'a T, i64>
    where T: Eq + Hash
{
    let mut outcome = HashMap::new();
    for elm in v {
        *outcome.entry(elm).or_insert(0) += 1;
    }
    return outcome;
}


Measured memory_bytes: 13560
n,m = gets.chomp.split.map(&:to_i)
num = Array.new(n,0)
m.times do |i|
  a,b = gets.chomp.split.map(&:to_i)
  num[a - 1] += 1
  num[b - 1] += 1
end
n.times do |i|
  puts num[i]
end

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

int main()
{
	string S;
	cin >> S;
	int a, b, c, d;
	a = S[0] - '0';
	b = S[1] - '0';
	c = S[2] - '0';
	d = S[3] - '0';

	for(int i=0; i<2; i++){
		for(int j=0; j<2; j++){
			for(int k=0; k<2; k++){
				int result=a;
				if(i==0){
					result -= b;
				} else {
					result += b;
				}
				if(j==0){
					result -= c;
				} else {
					result += c;
				}
				if(k==0){
					result -= d;
				} else {
					result += d;
				}
				if(result == 7){
					cout << a << (i!=0 ? "+" : "-")
						<< b << (j!=0 ? "+" : "-")
						<< c << (k!=0 ? "+" : "-")
						<< d << "=7" << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}


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

using namespace std;
int main()
{
	long long a;
	cin >> a;
	long long limit = sqrt(a);
	long long res = a - 1;;
	for (long long i = 1; i <= limit; i++) {
		if (a % i == 0) {
			res = min(res, a / i + i - 2);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# 練習
import math
h,w,a,b = list(map(int, input().split()))
p = 10**9+7
# 方針
# (0,0)    ~ (0,w-1)
# (h-1,0 )~ (h-1,w-1)で考える
# 通れないのは(h-a) ~ (h-1)行かつ(0) ~ (b-1) 列のところ
# b <= i <= w-1 のiについて1,2,3の組み合わせはそれぞれ以下の通り 
# 1, (0,0) ~ (h-a-1,i)      (h-a-1+i)! /(h-a-1)! * i!
# 2, (h-a-1,i )~(h-a,i)　  1
# 3, (h-a,i) ~ (h-1,w-1)   (a-1+w-1-i)! /(a-1)! * (w-1-i)!
def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)

    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac

fac, ifac = make_tables(p, h+w-2)
total = 0
for i in range(b, w):
    r1 = cmb(h-a-1+i,i,p,fac, ifac)
    r3 = cmb(a-1+w-1-i, a-1,p,fac, ifac)
    
    total = total +( r1*r3)
print(total%p)   

Measured memory_bytes: 26864
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

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

int main() {
    // input, ready
    int N,M;
    cin >> N >> M;
    vector<ll> hList(N+1,0);
    vector<vector<int>> road(N+1);
    for (int i=0; i<=N; i++) {
        vector<int> tmp;
        road[i] = tmp;
    }
    for (int i=1; i<=N; i++) cin >> hList[i];
    for (int i=0; i<M; i++) {
        int A,B;
        cin >> A >> B;
        road[A].push_back(B);
        road[B].push_back(A);
    }
    bool check_list[N+1];
    memset(check_list,0,sizeof(check_list));

    // resolve
    int ans=0;
    for (int i=1; i<=N; i++) {
        if (check_list[i]) continue;
        check_list[i] = true;
        bool isHighest = true;
        for (auto obs: road[i]) {
            if (hList[i] > hList[obs]) check_list[obs] = true;
            else isHighest = false;
        }
        if (isHighest) ans++;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9276
h,w = map(int, input().split())
a = []
for i in range(h):
    a.append(list(map(int,input().split())))
now="R"
x,y=0,0
carry=False
ans=[]
while True:
    if carry:
        if a[y][x]%2==1: # drop
            carry=False
    else:
        if a[y][x]%2==1: # grab
            carry=True

    if now=="R":
        nxtx=x+1
        nxty=y
        if nxtx==w:
            nxtx=x
            nxty+=1
            now="L"
            if nxty==h:
                break
    else:
        nxtx=x-1
        nxty=y
        if nxtx==-1:
            nxtx=0
            nxty+=1
            now="R"
            if nxty==h:
                break
    if carry:
        ans.append([y+1,x+1,nxty+1,nxtx+1])
    x=nxtx
    y=nxty


print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 96912
#include <stdio.h>
#include <stdlib.h>

typedef struct{
  int A;
  int B;
}Store;

Store S[100000];

int Cmp(const void *a, const void *b){
  return ((Store *)a)->A - ((Store *)b)->A;
}

void Do(int N, int M){
  int i, m;
  long long n;
  for(i = 0;i < N;i++) scanf("%d %d", &S[i].A, &S[i].B);
  qsort(S, N, sizeof(Store), Cmp);
  m = 0;
  n = 0;
  for(i = 0;i < N;i++){
    if(m + S[i].B < M){
      n += (long long) S[i].A * S[i].B;
      m += S[i].B;
    }else{
      n += (long long) S[i].A * (M - m);
      break;
    }
  }
  printf("%lld\n", n);
}

int main(void){
  int N, M;
  scanf("%d %d", &N, &M);
  Do(N, M);
  return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>



using namespace std;


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

	vector<int> vec(N, 0);
	for (int i=0; i < N; i++) {
		cin >> vec[i];
	}

	string ans="Yes";
	int res = 0;

	for (int j = N - 1; j >= 1; j--) {

		if (vec[j] < vec[j - 1]) {
			if (vec[j - 1] - vec[j] == 1) {
				vec[j - 1] -= 1;
			}
			else {
				res++;
			}
		}


	}

	if (res > 0) {
		ans = "No";
	}

	cout << ans << endl;
}


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

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

    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    vector<ll> dp(100001, 1LL << 60);

    dp[0] = 0;

    REP(i, N)
        for (int j = 100000; j >= v[i]; j--)
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);

    int ans = 0;
    REP(i, 100001)
        if (dp[i] <= W)
            ans = i;

    cout << ans << '\n';
    return 0;
}

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

int main() {
  vector<int>a(5);
  for(int i=0; i < 5; i++){
    cin >> a[i];
    }
  int k;
  cin >> k;
  
  for(int i=0;i<4; i++){
    for(int j=i+1; j<5; j++){
      if ((a[j]-a[i]) > k){
        cout <<":(" << endl;
        return 0;
        }
      }
    }
  cout << "Yay!" << endl;
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ZERO(a) memset(a,0,sizeof(a))
#define FILL(a,b) memset(a,b,sizeof(a))
#define SORT(v) sort((v).begin(),(v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define FOR(i,a,b)  for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
int A, B;

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

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

int main(void) {
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
k = int(input())
d = deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
    x = d.popleft()
    mod = x % 10
    if mod != 0:
        d.append(x*10+mod-1)
    d.append(x*10+mod)
    if mod != 9:
        d.append(x*10+mod+1)
print(x)

Measured memory_bytes: 11956
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[][] = new int[N][2];
		for(int i = 0; i < N; i++) {
			A[i][0] = i;
			A[i][1] = sc.nextInt();
		}
		Arrays.sort(A, Comparator.comparingInt(o -> o[1]));
		
		for(int i = 0; i < N; i++) {
			System.out.print(A[i][0] + 1);
			if(i == N - 1) {
				System.out.println();
			} else {
				System.out.print(" ");
			}
		}
	}
}


Measured memory_bytes: 66844
h,w = map(int,input().split())
l = [list(input()) for i in range(h)]
dp = [[0 for i in range(w)] for i in range(h)]
dp[0][0] = 1
mod = 10**9+7

for i in range(h):
    for j in range(w):
        if i+1<h and l[i+1][j] != "#":
            dp[i+1][j] = (dp[i][j]+dp[i+1][j])%mod
        if j+1 < w and l[i][j+1] != "#":
            dp[i][j+1] = (dp[i][j]+dp[i][j+1])%mod
print(dp[-1][-1]%mod)

Measured memory_bytes: 52396