akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int inf=1e18;
int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("in","r", stdin);
		freopen("out","w",stdout);
	#endif

	int h,n;
	cin>>h>>n;
	vector<int> dp(h+1, inf);
	dp[h]=0;int a,b;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;

		for(int j=h;j>=0;j--)
		{
			int x=min(a,j);
			dp[j-x]=min(dp[j]+b,dp[j-x]);
		}
	}
	
	cout<<dp[0];


}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000000000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N (1<<19)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;

ll n, a, b;
ll x[100000];

int main(){
    ll ans = 0;
    ll now;
    cin >> n >> a >> b;
    rep(i,n) cin >> x[i];
    rep(i,n){
        if(i == 0){
            now = x[i];
            continue;
        }
        if((x[i]-now)*a <= b){
            ans += (x[i]-now)*a;
        } else ans += b;
        now = x[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
//const int mod = (int) 1e9+7;
const int MAXN = (int) 1e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n, mod;
vector<int> adj[MAXN];
ll d[MAXN], ans[MAXN];
vector<int> pre[MAXN], suf[MAXN];
vector<int> ad[MAXN];
map<int, int> mp[MAXN];



ll bp(ll a, ll b){
    ll res = 1;
    while(b){
        if(b % 2) res = (res * a) % mod;
        a = (a * a) %mod;
        b = b / 2;
    }
    return res;
}

void calc(){
    for(int i = 1; i <= n; i++){
        ll mul = 1;
        for(int j = 0; j < ad[i].size(); j++){
            mp[i][ad[i][j]] = j;
            mul = mul*(d[ad[i][j]] + 1);
            mul %= mod;
            pre[i].push_back(mul);
        }
        mul = 1;
        for(int j = ad[i].size() - 1;j >= 0; j--){
            mul = mul*(d[ad[i][j]] + 1);
            mul %= mod;
            suf[i].push_back(mul);
        }
    }
}

ll pr(int a, int ind){
    if(ind < 0){
        return 1;
    }else{
        return pre[a][ind];
    }
}

ll sf(int a, int ind){
    ind = suf[a].size() - ind - 1;
    if(ind < 0){
        return 1;
    }else{
        return suf[a][ind];
    }
}



void dfs1(int a, int par){
    d[a] = 1;
    if(adj[a].size() == 1 && par != -1){
        return;
    }
    for(int i: adj[a]){
        if(i != par){
            ad[a].push_back(i);
            dfs1(i, a);
            d[a] *= (d[i] + 1);
            d[a] %= mod;
        }
    }
}

void dfs2(int a, int par, ll pard){
    ans[a] = 1;
    for(int i: adj[a]){
        if(i != par)
            ans[a] *= (d[i] + 1);
        ans[a] %= mod;
    }
    ans[a] *= (pard + 1);
    ans[a] %= mod;
    for(int i: adj[a]){
        if(i == par) continue;
        ll pardi = 1;
        pardi *= pr(a, mp[a][i] - 1);
        pardi %= mod;
        pardi *= sf(a, mp[a][i] + 1);
        pardi %= mod;
        pardi *= pard + 1;
        pardi %= mod;
        dfs2(i, a, pardi);
    }
}

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

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n>>mod;

    for(int i = 0; i < n - 1; i++){
        int a, b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    dfs1(1, -1);
    calc();
    ans[1] = d[1];

    for(int i: adj[1]){
        ll pardi = 1;
        pardi *= pr(1, mp[1][i] - 1);
        pardi %= mod;
        pardi *= sf(1, mp[1][i] + 1);
        pardi %= mod;
        dfs2(i, 1, pardi);
    }
    for(int i = 1; i <= n; i++){
        cout<<ans[i]<<endl;
    }
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 41856
import java.util.Scanner;
public class Main
{
 	public static void main(String[] args)
    {
     	 Scanner sc = new Scanner(System.in);
      	String[] num = sc.nextLine().split(" ");
      	if(Integer.parseInt(num[0]) > Integer.parseInt(num[1]))
        {
         	System.out.println("safe"); 
        }else{
          	System.out.println("unsafe"); 
        }
    }
}

Measured memory_bytes: 35768
# _*_ coding:utf-8 _*_
#  CADDi2018 for Beginners C
#  https://atcoder.jp/contests/caddi2018b/tasks/caddi2018_a

def getMaxGCD(count,product):
	# getPrimeFunction
	primeSet = []  # リストの初期化
	maxCheckNumber = round(product ** (1 / 2))
	checkRange = range(2, maxCheckNumber + 1, 1)
	for i in checkRange:
		baseCount = 0
		while product % i == 0:
			baseCount = baseCount + 1
			product = product // i
		if  0 < baseCount:
			primeSet.append((i, baseCount))
# 二つを引数にしそれぞれ出力する
	if 1 < product:
		primeSet.append((product, 1))

	gcdNumber = 1
	for baseCount,powNumber in  primeSet:
		gcdNumber = gcdNumber * (baseCount ** ( powNumber // count))
	return gcdNumber

if __name__ == '__main__':
	n , p  = map(int,input().strip().split(' '))
	if n == 1:
		print(p)
		exit(0)
	if p == 1:
		print(1)
		exit(0)
	solution=getMaxGCD(n,p)
	print('{}'.format(solution))

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

using namespace std;
int N;
int main() {
    cin >> N;
    vector <int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];  
    sort(A.begin(), A.end());
    int sol = 0;
    for (int i = 0; i < N; ++i)
        for (int j = i + 1; j < N; ++j) {
            sol = sol + (lower_bound(A.begin(), A.end(), A[i] + A[j]) - A.begin() - j - 1);
        }
    cout << sol << '\n';
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		
		int[] c = new int[n];
		int[][] a = new int[n][m];
		
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			for(int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		
		// 用意
		int cost = 0;
		int[] aTemp = new int[m];
		boolean mastered = true;
		List<Integer> list = new ArrayList<>();
		
		// bit全探索
		for(int i = 0; i < 1 << n; i++) {
			
			// n冊それぞれ探索
			for(int j = 0; j < n; j++) {
				
				// check
				if((i >> j & 1) == 1) {
					
					for(int k = 0; k < m; k++) {
						aTemp[k] += a[j][k];
					}
					
					cost += c[j];
				}
				
			}
			
			// アルゴリズム理解度満たしているかチェック
			for(int j = 0; j < m; j++) {
				if(aTemp[j] < x) {
					mastered =false;
					break;
				}
			}
			
			
			// マスターしてればコストを一時格納
			if(mastered) {
				list.add(cost);
			}
			
			// 後始末
			for(int j = 0; j < m; j++) {
				aTemp[j] = 0;
			}
			cost = 0;
			mastered = true;
			
		}
		
		Collections.sort(list);
		
		if(list.size() == 0) System.out.println(-1);
		else System.out.println(list.get(0));
		
	}

}


Measured memory_bytes: 38112
#include <stdio.h>
#include<math.h>
int main()
{
 long int x,y,z,sum,i=0,k;
 
 scanf("%ld",&z);
 sum=0;
while(z--)
{
  scanf("%ld%ld",&x,&y);
  sum+=(x==y)?1:((y-x)+1);
}
printf("%ld",(sum));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int inf = 1e15;

int a,b,c,d,n;

map<int,int> mp;

int solve(int n)
{
    if(n == 0) return inf;
    if(n == 1) return 0;
    
    if(mp.find(n) != mp.end()) return mp[n];
    
    int res = inf;
    
    if(d < 10000 && n < 1e12) res = min(res,(n-1)*d);
    
    if(n%2 == 0) res = min(res,solve(n/2) + a);
    else res = min(res,  min( solve((n-1)/2) + a + d, solve((n+1)/2)+ a + d ));
    
    if(n%3 == 0) res = min(res,solve(n/3) + b);
    else if(n%3 == 1) res = min(res,solve((n-1)/3) + d + b);
    else res = min(res,solve((n+1)/3) + d + b);
        
    if(n%5 == 0) res = min(res,solve(n/5) + c);
    else if(n%5 == 1) res = min(res,solve(n/5) + c + d);
    else if(n%5 == 4) res = min(res,solve((n+1)/5) + c + d);
    else if(n%5 == 3) res = min(res,solve((n+2)/5) + c + d + d);
    else res = min(res, solve(n/5) + c + d + d);
    
    mp[n] = res;
        
    return res;
}

signed main()
{
    fast;
    
    int t = 1;
    
    cin >> t;
    
    while(t--)
    {
        mp.clear();
        
        cin >> n >> a >> b >> c >> d;
        cout << solve(n) + d<< '\n';
    }
}

Measured memory_bytes: 4292
#include<stdio.h>
#define N 2000
#define Q 2000
int i,n,q,key[N],A[N],M[Q];
void solve(int,int);

int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&M[i]);
  
  for(i=0;i<q;i++){
    key[i]=0;
    solve(0,M[i]);
    if(key[i]==1)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

void solve(int c,int sum){
  if(sum==0) key[i]=1; 
  if(sum>0&&c<n){
    solve(c+1,sum-A[c]);
    solve(c+1,sum);
  }
}

Measured memory_bytes: 592
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n;
int p[101];
const int INF=100000000;
long long dp[101][101];

void f(){
  for(int i=1;i<=n;i++)dp[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      dp[i][j]=INF;
      for(int k=i;k<=j-1;k++)dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }
}
int main(){
  scanf("%d",&n);
  
  for(int i=1;i<=n;i++)scanf("%d %d",&p[i-1],&p[i]);
  f();
  printf("%d\n",dp[1][n]);
  return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, m;
priority_queue<ll> q;
int main() {
	cin >> n >> m;
	REP(i, n) {
		ll a;
		cin >> a;
		q.push(a);
	}
	REP(i, m) {
		ll tp = q.top();
		q.pop();
		q.push(tp / 2);
	}
	ll ans = 0;
	REP(i, n) {
		ans += q.top();
		q.pop();
	}
	cout << ans << endl;
}




Measured memory_bytes: 1400
#include<stdio.h>
#define MAX 100005
 
typedef struct{
  int parent, left, right, depth;
}Node;
 
Node tree[MAX];
 
void print(int);
void getDepth(void);

int n,i;

int main(void){
  int k,j,rank,c,d,pre;
 
  scanf("%d",&n);
 
  for(i = 0; i < n; i++){
    tree[i].parent = tree[i].left = tree[i].right = -1;
  }
 
  for(i = 0; i < n; i++){
    scanf("%d%d",&rank ,&k);
    for(j = 0; j < k; j++){
      scanf("%d", &c);
       
      if(j == 0){
    tree[rank].left = c;
    tree[c].parent = rank;
    pre = c;
      }else{
    tree[pre].right = c;
    tree[c].parent = rank;
    pre = c;
      }
    }
  }

  getDepth();

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

  return 0;
}

void print(int i){
  int left;

  printf("node %d: parent = %d, depth = %d, ",i,tree[i].parent,tree[i].depth);
  if(tree[i].parent == -1){
    if(tree[i].left == -1){
      printf("root, []\n");
    }else{   
      left = tree[i].left;
      printf("root, [");
      printf("%d",left);
      while(1){
	if(tree[left].right == -1){
	  break;
	}
	printf(", %d",tree[left].right);
	left = tree[left].right;
      }
      printf("]\n");
    }
  }else if(tree[i].parent != -1 && tree[i].left != -1){
    left = tree[i].left;
    printf("internal node, [");
    printf("%d",left);
    while(1){
      if(tree[left].right == -1){
	break;
      }
      printf(", %d",tree[left].right);
      left = tree[left].right;
    }
    printf("]\n");
  }else{
    printf("leaf, []\n");
  }
}

void getDepth(){
  int i,p;

  for(i = 0; i < n; i++){
    p = tree[i].parent;
    while(1){
      if(p == -1){
	break;
      }
      p = tree[p].parent;
      tree[i].depth++;
    }
  }
}

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

int main(){
	int n;
	string m;
	string word[] = { ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz" };
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> m;
		int btn = 0;
		int cnt = 0;
		for (int j = 0; j < m.length(); j++){
			if (m[j] != '0'){
				btn = (int)(m[j] - '0');
				cnt++;
				switch (btn){
					case 1:
						if (cnt > 5){
							cnt = 1;
						}
						break;
					case 7:
					case 9:
						if (cnt > 4){
							cnt = 1;
						}
						break;
					case 2:
					case 3:
					case 4:
					case 5:
					case 6:
					case 8:
						if (cnt > 3){
							cnt = 1;
						}
						break;
				}
			}
			else{
				if (cnt > 0){
					cout << word[btn - 1][cnt-1];
					cnt = 0;
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define int long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define db(i) cout<<i<<" ";
#define db1(i) cout<<"("<<i<<")";
#define db2(i) cout<<"["<<i<<"]";
#define db3(i) cout<<"{"<<i<<"}";
#define ff first 
#define ss second
#define vv vector
#define pp pair
#define pi acos(-1);
#define printarr(a,n) cout<<"[";for(int i=0;i<n;i++){db1(a[i]);}cout<<"]";

using namespace std;

bool isprime(int n)
{
    for(int i=2;i<=sqrt(n);i++)
        if(n%i==0)
        return false;
    return true;
}
int maxarr(int *a,int n)
{
    int val=a[0];
    for(int i=1;i<n;i++)
    {
        if(val<a[i])
        {
            val=a[i];
        }
    }
    return val;
}

int minarr(int *a,int n)
{
    int val=a[0];
    for(int i=1;i<n;i++)
    {
        if(val>a[i])
        {
            val=a[i];
        }
    }
    return val;
}


int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
} 
int power(int x, int y, unsigned int p=ULLONG_MAX)  
{  
    int res = 1;     
    x = x % p; 
    if (x == 0) 
      return 0; 
    while (y > 0)  
    {    
        if (y & 1)  
           res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
bool cmp(const pair<int,int> &a,const pair<int,int> &b)
{
    if(a.ss<b.ss)
        return true;
    else if(a.ss>b.ss)
        return false;
    else
    {
        if(a.ff<b.ff)
            return true;
        else
            return false;
    }
    
}
bool cmp1(const pair<int,int> &a,const pair<int,int> &b)
{
    return (a.ss<b.ss);
}


//if no test cases add coments for reading




signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        n=5;
        int a[n],v;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]==0)
            {
                v=i+1;
            }
        }
        cout<<v;
     
      
    }
   
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5005;
ll c[maxn], p[maxn], b[maxn], n, k, ans = -999999999999, t, cnt, vis[maxn], inf = 0;
int main()
{
    //freopen("input.in", "r", stdin);
    // cin >> n >> k;
    // for (int i = 1; i <= n; i++)
    //     cin >> p[i];
    // for (int i = 1; i <= n; i++)
    //     cin >> c[i];
    // ll temp;
    // for (int i = 1; i <= n; i++)
    // {
    //     memset(b, 0, sizeof(b));
    //     memset(vis, 0, sizeof(vis));
    //     cnt = 0, temp = 0, t = i, inf = 0;
    //     while (vis[p[t]] == 0)
    //         b[cnt + 1] = c[p[t]], inf += c[p[t]], cnt++, vis[p[t]] = 1, t = p[t];
    //     if (k <= cnt)
    //     {
    //         ll ab = 0;
    //         for (int j = 1; j <= k; j++)
    //         {
    //             ab += b[j];
    //             ans = max(ans, ab);
    //         }
    //         continue;
    //     }
    //     if (inf <= 0)
    //     {
    //         ll ab = 0;
    //         for (int j = 1; j <= cnt; j++)
    //         {
    //             ab += b[j];
    //             ans = max(ans, ab);
    //         }
    //     }
    //     {
    //         int kk = k / cnt;
    //         kk--;
    //         temp = (kk * inf);
    //         ans = max(temp, ans);
    //         for (int j = 1; j <= cnt; j++)
    //         {
    //             temp = temp + b[j];
    //             ans = max(temp, ans);
    //         }
    //         kk++;
    //         for (int j = 1; j <= k - kk * cnt; j++)
    //         {
    //             temp = temp + b[j];
    //             ans = max(temp, ans);
    //         }
    //     }
    // }
    // cout << ans << endl;
    int as;
    cin>>as;
    if(as>=30) puts("Yes");
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int sum=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    if(sum==1){
      if(s[i]=='F'){
	cout<<"Yes"<<'\n';
	return 0;
      }
    }
    else{
      if(s[i]=='C'){
	sum++;
      }
    }
  }
  cout<<"No"<<'\n';
  return 0;
}


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

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> v) { for(ll i=0, N=v.size()-1; i<=N; i++) if(i!=N) cout << v[i] << ' '; else cout << v[i] << endl; }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

signed main() {
	ll N;
	string S;
	cin>>N>>S;
	ll ans=0;
	for(ll i=1;i<N-1;i++){
		ll len=0;
		for(ll j=0;j<N;j++){
			if(S[j]==S[i+j]){
				len++;
			}else{
				len=0;
			}
			ll t=len<i ? len : i;
			chmax(ans,t);
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
ll mod;
vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

int main(){
    int n;
    cin>>n;
    mod = n;
    mod_build(n);
    vector<ll> ans(n);
    ll x;
    cin>>x;
    ans[n-1]+=n-x;
    ans[0]+=x;
    REP(i,1,n){
        int x;
        cin>>x;
        ll res=inv[i];
        REP(j,1,n){
            if(i==j)continue;
            else res*=inv[(i-j+n)%n];
            res%=n;
        }
        ll p = 1;
        rep(j,n-1){
            ans[n-1-j]+=p*res*x%mod;
            p = p*i%mod;
        }
    }
    rep(i,n)ans[i]%=mod;
    rep(i,n)cout<<ans[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
using namespace std;


int main(void){
    int Q[1000000];
    int tail = 0, head = 0;

    pair<string, int> p[100001];
    int n, q, su=0;
    cin >> n >> q;
    for(int i=0; i<n; i++){
        cin >> p[i].first >> p[i].second;
        Q[tail] = i;
        tail++;
        su+=p[i].second;
    }
    int sum=0, k;
    while(su != sum){
    int d=Q[head];
    head++;
    if(p[d].second>q){
        p[d].second=p[d].second-q;
        Q[tail] = d;
        tail++;
        sum+=q;
    }
    else{
        sum+=p[d].second;
        cout << p[d].first << " " <<sum << endl;
    }
    }
    return 0;
    
}


Measured memory_bytes: 7784
using System;
namespace AtCorder_0519
{
    class Program
    {
        static void Main(string[] args)
        { 
            var str = Console.ReadLine();
            int i = 0;
            int[] arr = new int[4];
            foreach (char item in str)
            {
                arr[i] = int.Parse(item.ToString());
                i++;
            }

            bool flg = false;
            for (int k = 1; k < arr.Length; k++)
            {
                var b = arr[k - 1];
                var c = arr[k];

                if (b == c)
                {
                    flg = true;
                    break;
                }
            }

            if (flg)
            {
                Console.WriteLine("Bad");
            }
            else
            {
                Console.WriteLine("Good");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a), __##i = (b); i < __##i; i += (s))
#define down(i, a, b, s) for (int i = (a), __##i = (b); _##i < i; i -= (s))

const int maxn = 2002;

int n, m;
char a[maxn][maxn];
int r[maxn][maxn], d[maxn][maxn];

int go_right(int i, int j, int cnt) {
  if (j >= m || a[i][j] == '#')
    return cnt;
  else
    return r[i][j] = go_right(i, j + 1, cnt + 1);
}

int go_down(int i, int j, int cnt) {
  if (i >= n || a[i][j] == '#')
    return cnt;
  else
    return d[i][j] = go_down(i + 1, j, cnt + 1);
}

int main(int argc, char const *argv[]) {
  // freopen("D.txt", "r", stdin);

  while (cin >> n >> m) {
    memset(r, 0, sizeof(r));
    memset(d, 0, sizeof(d));

    range(i, 0, n, 1) { cin >> a[i]; }

    int ans = 0;
    range(i, 0, n, 1) {
      range(j, 0, m, 1) {
        if (a[i][j] != '#') {
          if (r[i][j] == 0) {
            go_right(i, j, 0);
          }
          if (d[i][j] == 0) {
            go_down(i, j, 0);
          }
          ans = max(ans, r[i][j] + d[i][j] - 1);
        }
      }
    }

    // range(i, 0, n, 1) {
    //   range(j, 0, m, 1) { cout << r[i][j] << " "; }
    //   cout << endl;
    // }

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

Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    vector<int> a(3);
    for (int i = 0; i < 3; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int sum = 0;
    for (int i = 1; i < 3; i++) {
        sum += a[i] - a[i - 1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine() ?: return
    var r = s.drop(1)
    while (r.isNotEmpty()) {
        r = if (r.length % 2 == 1) {
            r.drop(1)
        } else {
            if (s.substring(0, r.length / 2) == s.substring(r.length / 2, r.length)
            ) {
                println(r.length.toString())
                return
            } else {
                r.drop(1)
            }
        }
    }
}

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

int n, i, j, jwb;

int main (){
    jwb=0;
    cin>>j;
    for (int n=1; n<=9; n++){
        for (int i=1; i<=9; i++){
            if (n*i==j){
               jwb++;
            }
        }
    }if (jwb>0){
        cout<<"Yes"<<endl;
    }else {
        cout<<"No"<<endl;
    }
}

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

class Main{

	static char[][] map;
	static int H;
	static int W;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N =sc.nextInt();
		int K =sc.nextInt();
		int[] a = new int[N];
		for(int i =0 ;i< N;i++){
			a[i] = sc.nextInt();
		}
		int[] sub = a.clone();
		Arrays.sort(sub);
		int min = sub[0];
		int right = 0;
		for(int i = 0;i < N;i++){
			if(min == a[i]){
				right = i;
				break;
			}
		}

		int ans = 0;
		for(int i = 0;i < N;i++){
			if(a[i] != min){
				int c = 0;
				for(int j = i;j < i+K;j++){
					if(j >= N){
						break;
					}
					if(c >= K-1){
						break;
					}
					if(a[j] != min){
						c++;
					}
					a[j] = min;
					
				}
				ans++;
			}
		}
		
		
		System.out.println(ans);


	}
}




class Pair implements Comparable{
	String from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}





Measured memory_bytes: 50052
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>



ll n, dp[110000], sz[110000], mod = 1e6;
vector<ll> in(110000);
vector<ll> g[110000];
ll com[2100][2100];

void cominit(){
    
    REP(i, 2010){
        com[i][0] = 1;
        REPO(j, i){
            com[i][j] = com[i - 1][j - 1] + com[i - 1][j];
            com[i][j] %= mod;
        }
    }
}
void dfs(ll v, ll p){
    ll now = 1;
    vector<ll> l;
    REP(i, g[v].size()){
        ll w = g[v][i];
        if(w == p)continue;
        dfs(w, v);
        now *= dp[w];
        now %= mod;
        sz[v] += sz[w];
        l.push_back(sz[w]);
    }
    ll t = sz[v];
    REP(i, l.size()){
        now *= com[t][l[i]];
        now %= mod;
        t -= l[i];
    }
    sz[v] += 1;
    dp[v] = now;
}

int main() {
    cominit();
    cin >> n;
    REP(i, n - 1){
        ll a, b;
        cin >>a >> b;
        a--;
        b--;
        g[a].push_back(b);
        in[b]++;
    }
    REP(i, n){
        if(in[i] == 0){
            dfs(i, -1);
            cout << dp[i] << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 29340
import scala.io.StdIn._
object Main {
  def main(args:Array[String]) {
    var read = readLine().split(' ').map(_.toInt)

    if(read(3) <= read(0)) println(read(3))
    else if(read(3) <= (read(0) + read(1))) println(read(0))
    else println(2 * read(0) + read(1) - read(3))
  }
}


Measured memory_bytes: 54544
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        String Str = input.nextLine();
          
        System.out.println(insertX(Str));
    }
    
    private static int insertX(String string){
        int start = 0;
        int end = string.length() - 1;
        int countx = 0;
        while(start < end){
            if(string.charAt(start) != string.charAt(end) && string.charAt(start) != 'x' && string.charAt(end) != 'x'){
                countx = -1;
                return countx;
            }
            else if(string.charAt(start) != string.charAt(end)){
                countx ++;
                if(string.charAt(start) == 'x') end ++;
                else start --;
            }
            start ++;
            end --;
        }
        return countx;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
	char s[100001];
    scanf("%s",s);
    ll l=strlen(s);
    sort(s,s+l);
    char f='a';
    ll i=0;
    while(i<l){
        if(s[i]==f){
            f++;
        }
        i++;
    }
    if(f=='a'+26) cout<<"None"<<endl;
    else cout<<f<<endl;
}

Measured memory_bytes: 384
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int c,n,m;
	int map[][];
	int s, e;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			c = sc.nextInt();
			n = sc.nextInt();
			m = sc.nextInt();
			map = new int[n][n];
			for(int[] a: map) fill(a, INF);
			s = sc.nextInt()-1;
			e = sc.nextInt()-1;
			if( (c|n|m|(s+1)|(e+1)) == 0 ) break;
			for(int i=0;i<m;i++) {
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				int f = sc.nextInt();
				map[a][b] = map[b][a] = f;
			}
			System.out.println(dijkstra());
		}
	}
	
	int dijkstra() {
		int[][] chiket = new int[n][c+1];
		boolean visited[][] = new boolean[n][c+1];
		for(int[] a: chiket) fill(a, INF);
		chiket[s][0] = 0;
		for(;;) {
			int u=-1;
			int cc = -1;
			int max = INF;
			for(int i=0;i<n;i++) for(int j=0;j<=c;j++) {
				if( chiket[i][j] < max && !visited[i][j]) {
					u = i;
					cc = j;
					max = chiket[i][j];
				}
			}
//			System.out.println(u);
			if(u == -1) break;
			for(int v=0;v<n;v++) {
				if(cc + 1 <= c) chiket[v][cc+1] = min(chiket[v][cc+1], chiket[u][cc] + map[v][u]/2);
				chiket[v][cc] = min(chiket[v][cc], chiket[u][cc] + map[v][u]);
			}
			visited[u][cc] = true;
		}
		int ans = INF;
		for(int i=0;i<=c;i++) ans = min(ans, chiket[e][i]);
		return ans;
	}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
bool compare(int i,int j){
    return i>j;
} 
 
int main()
{
    IOS;
 
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n;i++){
        cin>>arr[i];
    }
    ll ans=0;
    sort(arr,arr+n,compare);
    ans+=arr[0];
    for(ll i=1;i<=(n-2)/2;i++){
        ans+=2*arr[i];
    }
    if((n-2)%2==0){
        cout<<ans;
        return 0;
    }
    cout<<ans+arr[((n-2)/2)+1];
    return 0;
}


Measured memory_bytes: 5204
N = int(input())
X = list(map(int, input().split()))

X_g = sum(X)/N

if X_g%1<0.5:
    P = int(X_g)
else:
    P = int(X_g)+1
ans = 0
for i in range(N):
    ans += (X[i]-P)**2

print(ans)


Measured memory_bytes: 9108
s = input()

rev_s = s[::-1]
half_s = s[0:len(s)//2]
rev_half_s = half_s[::-1]
third_s = s[(len(s)+3)//2-1:]
rev_third_s = third_s[::-1]

if (s == rev_s) and (half_s == rev_half_s) and (third_s == rev_third_s):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef TEST
#include <mytest.h>
#else
#define open(...) 0
#define print(...) 42
#endif
using namespace std;
const int N = 1e5 + 5;
int a[N], dp[N];
int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (a[i] <= a[i-1]) dp[i] += dp[i-1] + 1;
    else dp[i] = 0;
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val s = sc.next()

  val key = "keyence"

  var ok = false
  for (i in 0 ..  key.length) {
    val key1 = key.substring(0, i)
    val key2 = key.substring(i, key.length)

    if (s.startsWith(key1) && s.endsWith(key2)) {
      ok = true
      break
    }
  }

  if (ok) {
    println("YES")
    return
  }
  println("NO")


}


Measured memory_bytes: 37512
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)1e9+7;
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

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

    void run() {
        long sum = modpow(2, n);

        long comA = nck(n, a);
        long comB = nck(n, b);

        long ans = sum-comA-comB-1+MOD*2;

        System.out.println(ans%MOD);

    }

    public long modpow(long a, long b){  // 計算量はlog(MOD);
        if (b==0) return 1;
        else if (b==1) return a;
        long x = modpow(a, b/2);
        return b%2==0 ? x*x%MOD : x*(x*a%MOD)%MOD;
    }
    public long inv(long n){ // 逆元。x^(-1)≡x^(p-2) (MOD p)
        return modpow(n, MOD-2);
    }
    public long nck(int n, int k){
        long res = 1;
        for (int i=0; i<k; i++){  // facts配列だとoverflowする
            res = (res*(n-i))%MOD;
            res = (res*inv(i+1))%MOD;
        }
        return res;
    }
}



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

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int s = sc.nextInt();
        int[] arr = new int[n];
        long MOD = 998244353;

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        long[] dp = new long[s + 1]; // dp[i] ... iになるようなf(T)の数
        dp[0] = 1;
        long[] dp2;

        for (int i = 0; i < n; i++) {
//            debug(dp);
            dp2 = new long[s + 1];
            int a = arr[i];
            for (int j = 0; j <= s; j++) {
                if (j - a >= 0) {
                    dp2[j] = dp[j] * 2 + dp[j - a];
                } else {
                    dp2[j] = dp[j] * 2;
                }
            }
            for (int j = 0; j <= s; j++) {
                dp[j] = dp2[j] % MOD;
            }
        }

        System.out.println(dp[s]);


        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

int main() {
    string s, t;
    cin >> s >> t;
    
    int ans = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    char c;
    char d;
    cin >> c;
    d = c;
    int count = 0;
    while (cin >> c)
    {
        if(c!=d)
        {
            count++;
        }
        d=c;
    }
    cout << count << endl;
}

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

UL N;
pair<LL,UL> X[200000];
LL ans=0;

struct RLQ{
 UL N;
 vector<UL> V;
 void init(UL n){
  N=1; while(N<n) N<<=1;
  V.resize(N*2-1);
  rep(i,N) V[N-1+i]=i+1;
  for(UL i=N-2; i!=~0u; i--) V[i]=min(V[(i<<1)+1],V[(i<<1)+2]);
 }
 void upd(UL p){
  UL i=N-1+p;
  V[i]=~0u;
  while(i){
   i=(i-1)>>1;
   V[i]=min(V[(i<<1)+1],V[(i<<1)+2]);
  }
 }
 UL query(UL l,UL r, UL a=0,UL b=0,UL i=~0u){
  if(i==~0u){ a=i=0; b=N; }
  if(r<=a || b<=l) return ~0u;
  if(l<=a && b<=r) return V[i];
  UL q1=query(l,r,a,(a+b)>>1,(i<<1)+1);
  UL q2=query(l,r,(a+b)>>1,b,(i<<1)+2);
  return min(q1,q2);
 }
};

struct RRQ{
 UL N;
 vector<UL> V;
 void init(UL n){
  N=1; while(N<n) N<<=1;
  V.resize(N*2-1);
  rep(i,N) V[N-1+i]=i+1;
  for(UL i=N-2; i!=~0u; i--) V[i]=max(V[(i<<1)+1],V[(i<<1)+2]);
 }
 void upd(UL p){
  UL i=N-1+p;
  V[i]=0;
  while(i){
   i=(i-1)>>1;
   V[i]=max(V[(i<<1)+1],V[(i<<1)+2]);
  }
 }
 UL query(UL l,UL r, UL a=0,UL b=0,UL i=~0u){
  if(i==~0u){ a=i=0; b=N; }
  if(r<=a || b<=l) return 0;
  if(l<=a && b<=r) return V[i];
  UL q1=query(l,r,a,(a+b)>>1,(i<<1)+1);
  UL q2=query(l,r,(a+b)>>1,b,(i<<1)+2);
  return max(q1,q2);
 }
};

int main() {
 UL T; scanf("%u",&T);
 while(T--){
  ans=0;
  scanf("%u",&N);
  priority_queue<pair<LL,UL>> Q;
  priority_queue<pair<LL,UL>> Q2;
  rep(i,N){
   UL K; LL L,R; scanf("%u%lld%lld",&K,&L,&R);
   ans+=min(L,R);
   if(L>R) Q.push({L-R,K});
   else Q2.push({R-L,K});
  }
  RLQ L; L.init(N);
  RRQ R; R.init(N);
  UL Lp=0;
  while(Q.size()){
   LL v=Q.top().first;
   UL r=Q.top().second;  Q.pop();
   UL p=R.query(0,r);
   if(p!=0){
    ans+=v;
    Lp++;
    R.upd(p-1);
   }
  }
  while(Q2.size()){
   LL v=Q2.top().first;
   UL l=Q2.top().second;  Q2.pop();
   UL p=L.query(max(l,Lp),N);
   if(p!=~0u){
    L.upd(p-1);
    ans+=v;
   }
  }
  printf("%lld\n",ans);
 }
 return 0;
}



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

#define ll long long
// #define endl '\n'

void max_self(int &a, int b){ a = max(a, b);}
void min_self(int &a, int b){ a = min(a, b);}

void solve(){
	int x; cin>>x;
	if(x >= 30){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;// cin>>t;
	for(int i = 1; i<=t; i++){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3616
function Main(input) {
	if (input[0] === input[1] && input[2] === input[3] && input[0] !== input[2]) console.log('Yes')
	else if (input[0] === input[2] && input[1] === input[3] && input[0] !== input[1]) console.log('Yes')
	else if (input[0] === input[3] && input[1] === input[2] && input[0] !== input[1]) console.log('Yes')
	else console.log('No')
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 11468
N,M = map(int,input().split())

ac = [0]*N
p = [0]*N
ans = 0
for _ in range(M):
    a,b = input().split()
    a = int(a)-1

    if not ac[a]:
        if b == "AC":
            ac[a] = 1
            ans += p[a]
        else:
            p[a] += 1

print(sum(ac),ans)


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

const int INFY = numeric_limits<int>().max();
typedef pair<int, int> pa;

class graph {
public:
    graph(int n): n_(n), adj_(n) {
    }
    void add(int u, int v, int weight) {
        adj_[u].push_back(pa(weight, v));
    }
    vector<int> dijkstra(int start) {
        vector<int> d(n_, INFY);
        vector<bool> visited(n_, false);
        priority_queue<pa, vector<pa>, greater<pa>> q;
        d[0] = 0;
        q.push(pa(0, start));
        while(!q.empty()) {
            int uw = q.top().first;
            int u = q.top().second;
            q.pop();
            visited[u] = true;
            if (d[u] < uw) continue;
            for (auto pav : adj_[u]) {
                int v = pav.second;
                int w = pav.first;
                if (visited[v]) continue;
                if(d[u] + w < d[v]) {
                    d[v] = d[u] + w;
                    q.push(pa(d[v], v));
                }
            }
        }
        return d;
    }
private:
    int n_;
    vector<vector<pa>> adj_;
};


int main() {
    int n;
    cin >> n;
    graph g(n);
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            g.add(u, v, c);
        }
    }
    auto d = g.dijkstra(0);
    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == INFY ? -1 : d[i]) << endl;
    }
}



Measured memory_bytes: 7852
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef pair<ll, P> TP;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//

ll n;
//-------------------関数----------------------//
int main() {
  ll h;
  vector<ll> a, b;
  cin >> n >> h;
  REP(i, n) {
    ll c, d;
    cin >> c >> d;
    a.pb(c);
    b.pb(d);
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<ll> B;
  REP(i, (signed)b.size()) {
    if (a.back() <= b[i]) {
      B.pb(b[i]);
    }
  }
  ll cntt = 0; // how many times to throw
  if (B.size()) {
    sort(B.begin(), B.end());
    EREP(i, (signed)B.size()) { // loop from back
      h -= B[i];
      cntt++;
      if (h <= 0) {
        cout << cntt << endl;
        return 0;
      }
    }
  }
  cout << h / a.back() + (h % a.back() == 0 ? 0 : 1) + cntt << endl;
}


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

int main(){
  int P,Q,R;
  cin >> P >> Q >> R;
  vector<int> S(3);
  S.at(0) = P;
  S.at(1) = Q;
  S.at(2) = R;
  sort(S.begin(),S.end());
  cout << S.at(0) + S.at(1) << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

s = list(input())
K = int(input())
d = defaultdict(int)
L = min(len(s), 5)

for i in range(L):
  for j in range(len(s)-i):
    x = s[j]
    for k in range(i):
      x += s[j+k+1]
    d[x] += 1

D = sorted(d.keys())

print(D[K-1])

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

#define READ freopen("alu.txt", "r", stdin);
#define WRITE freopen("vorta.txt", "w", stdout);
typedef long long int LL;

int x[60], y[60], px[60], py[60];

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    for(int i = 1; i <= n; i++) scanf("%d %d", &x[i], &y[i]);
    for(int i = 1; i <= m; i++) scanf("%d %d", &px[i], &py[i]);

    for(int i = 1; i <= n; i++){
        int dis = INT_MAX, index = 1;

        for(int j = 1; j <= m; j++){
            if(abs(x[i] - px[j]) + abs(y[i] - py[j]) < dis){
                dis = abs(x[i] - px[j]) + abs(y[i] - py[j]);
                index = j;
            }
        }

        printf("%d\n", index);
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ll x, y, step;
    
    while(cin >> x >> y && x && y) {
        if(x < y) swap(x, y);
        step = 0;
        do {
            x = x % y;
            swap(x, y);
            step++;
        } while(y != 0);
        cout << x << " " << step << endl;
    }
    return 0;
}

Measured memory_bytes: 0
N,*A=`dd`.split.map &:to_i;r={};B=[*1..N].sort_by{|i|r[A[i-1]-1]=i;A[i-1]};s=Hash.new 0;z=[];N.times{|i|n=B[N-i-1];z=[n]*~-n+z+[B[i]]*(N-B[i])};puts (N*N).times.any?{|i|z<<x=r[i]||z.shift;s[x]+=1;r[i]&&x!=s[x]}?:No:"Yes\n"+z*' '

Measured memory_bytes: 75964
#include <iostream>
#include <vector>

using namespace std;
// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }



#define debug(x) cout << #x << "==" << x << endl;

const int inf = 100000000;

typedef long long ll;

int main() {
  ios::sync_with_stdio(false);

  int N, W;
  cin >> N >> W;


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

  // dp[i][j] := i???????????§?????????????????£??????j??\??????????????§????????§??????
  // dp[i][j] =
  //   if w[i-1] <= j
  //      max( dp[i-1][j] , dp[i-1][j-w[i-1] + v[i-1]] )
  //   else
  //      dp[i-1][j]
  auto dp = make_2d_vector(N+1, W+1, 0);
  for(int i = 1; i <= N; i++) {
    for(int j = 1; j <= W; j++) {
      if( w[i-1] <= j ) {
        dp[i][j] = max( dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
      } else {
        dp[i][j] = dp[i-1][j];
      }
    }
  }

  cout << dp[N][W] << "\n";

  return 0;
}

Measured memory_bytes: 6820
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;



int main() {
	int n;
	cin >> n;
	
	vector<vector<int>> v(2,vector<int>(n/2));
	

	for (int i = 0; i < n / 2; i++) {
		cin >> v[0][i] >> v[1][i];
	}

	sort(v[0].begin(), v[0].end());
	sort(v[1].begin(), v[1].end());

	v[0].emplace_back(0);
	v[1].emplace_back(0);

	vector<vector<int>> max(2,vector<int>(2));
	vector<int> cnt(2,1);
	vector<int> num(2);
	num[0] = v[0][0];
	num[1] = v[1][0];
 
	for (int i = 0; i < 2; i++) {
		for (int j = 1; j <= n / 2; j++) {
			if (v[i][j] == v[i][j-1]) {
				cnt[i]++;
			}
			else {
				if (max[i][0] < cnt[i]) {
					max[i][1] = max[i][0];
					max[i][0] = cnt[i];
					num[i] = v[i][j-1];
				}
				else if(max[i][1] < cnt[i]){
					max[i][1] = cnt[i];
					
				}
				cnt[i] = 1;
				
			}

		}
	}

	int ans = n;
	if (num[0] == num[1]) {
		if (max[0][0] < max[1][0]) {
			ans -= max[1][0] + max[0][1];
		}
		else if (max[0][0] > max[1][0]) {
			ans -= max[0][0] + max[0][1];
		}
		else {
			if (max[0][1] < max[1][1]) {
				ans -= max[0][0] + max[1][1];
			}
			else {
				ans -= max[1][0] + max[0][1];
			}
		}
	}
	else {
		ans -= max[0][0] + max[1][0];
	}

	cout << ans << endl;
}

Measured memory_bytes: 888