akhauriyash/Code-Regression huggingface dataset:
num_of_probs, num_of_submission = [ int(i) for i in input().split(" ") ]

solution_table = {}

for i in range(0, num_of_submission):
  prob, result = [ i for i in input().split(" ") ]

  if solution_table.get(int(prob)) == None:
    solution_table[int(prob)] = {"WA": 0, "AC": 0}

  if result == "WA":
    if solution_table[int(prob)]["AC"] == 0:
      solution_table[int(prob)]["WA"] += 1
  else:
    if solution_table[int(prob)]["AC"] == 0:
      solution_table[int(prob)]["AC"] += 1

total_ac = 0
total_wa = 0
for value in solution_table.values():
  if value['AC'] > 0:
    total_wa += value['WA']
    total_ac += value['AC']

print( total_ac, total_wa )

Measured memory_bytes: 42036
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
const int maxn=1005;
const int mod=1e9+7;
int dp[22][maxn];
int C[maxn][maxn];
void init()
{
	for(int i=0;i<maxn;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
	}
}
int main()
{
	init();
	int n,k;
	cin>>n>>k;
	vi a(k+1);
	int tot=0;
	for(int i=1;i<=k;i++) cin>>a[i],tot+=a[i];
	dp[0][0]=1;
	for(int i=1;i<=k;i++)
		for(int j=0;j<=n;j++)
			for(int l=0;l<=a[i]&&j+l<=n;l++)
				dp[i][j+l]=(dp[i][j+l]+1LL*dp[i-1][j]*C[n-j][l]%mod*C[n-l][a[i]-l]%mod)%mod;
	cout<<dp[k][n]<<'\n';
}

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

int main()
{
    string str;
    cin >> str;
    int len=str.length();
    int half;
    if(len%2==0)
        half=len/2;
    else
        half=(len-1)/2;
        int cnt=0;
    for(int i=0; i<half; i++)
    {
        if(str[i]!=str[len-1-i])
            cnt++;
    }
    cout<<cnt;
    return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

vector<ll> prime(mxN+50);
vector<vll> pref(mxN,vll(5,0));

void solve(){
	vector<vll> A(3,vll(3,0));
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			cin>>A[i][j];
	ll n;
	cin>>n;
	for(int y=0;y<n;y++) {
		ll x,ok=1;
		cin>>x;
		for(int i=0;i<3&&ok;i++)
			for(int j=0;j<3&&ok;j++)
				if(A[i][j]==x){A[i][j]=-1;ok=0;}
	}
	if(A[0][0]==-1 && A[1][1]==-1 && A[2][2]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[0][2]==-1 && A[1][1]==-1 && A[2][0]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[0][0]==-1 && A[0][1]==-1 && A[0][2]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[1][0]==-1 && A[1][1]==-1 && A[1][2]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[2][0]==-1 && A[2][1]==-1 && A[2][2]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[0][0]==-1 && A[1][0]==-1 && A[2][0]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[0][1]==-1 && A[1][1]==-1 && A[2][1]==-1) {
		cout<<"Yes\n";return;
	}
	if(A[0][2]==-1 && A[1][2]==-1 && A[2][2]==-1) {
		cout<<"Yes\n";return;
	}
	cout<<"No";


}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	ll t;cin>>t;while(t--)
	solve();

}


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    ll A[30];
    ll B[30];
    ll C[30];
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N-1; i++) {
        cin >> C[i];
    }
    C[N-1] = 0;
    ll cnt = B[A[0]];
    for (int i = 1; i < N; i++) {
        cnt += B[A[i]];
        if(A[i] == A[i-1]+1){
            cnt += C[A[i-1]];
        }
    }
    cout << cnt << endl;
}

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

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

    double sum = 0.0;
    for(int i=0; i<n; i++){
        double x;
        string u;
        cin >> x >> u;
        if(u == "BTC") x *= 380000.0;
        sum += x;
    }

    cout << fixed << setprecision(10) << sum << endl;
    return 0;
}

Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

N, M = getNM()
U = UnionFind(N)
for i in range(M):
    a, b = getNM()
    a -= 1
    b -= 1
    U.union(a, b)

ans = 1
for i in range(N):
    ans = max(ans, U.size(i))
print(ans)

Measured memory_bytes: 85388
#include<iostream>
using namespace std;
int main(){
int A,B,C,X;
cin>>A>>B>>C>>X;
int r[A+1];
for(int i=0;i<=A;i++)r[i]=X-i*500;
int res;
int temp;
for(int i=0;i<=A;i++){
  for(int j=0;j<=B;j++){
    temp=(r[i]-j*100)/50;
    if(temp>=0&&temp<=C)res++;
  }
}
cout<<res;
return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  long long a,b;
  cin>>s;
  rep(i,19){
    if(i==5 || i==13){
      cout<<' ';
    }
    else{
      cout<<s[i];
    }
  }
  return(0);
}


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

int main(){
    string S;cin>>S;
    ll K;cin>>K;
    ll N=S.size();
    vector<ll> c;
    char a=S.at(0);ll count=0;
    for(int i=0;i<N;i++){
        if(a==S.at(i)){
            count++;
            if(i==N-1){
                c.push_back(count);
                break;
            }
        }
        else{
            c.push_back(count);
            count=0;
            a=S.at(i);
            i--;
        }
    }
    int cs=c.size();
    if(cs==1){
        cout<<ll(N*K/2)<<endl;
        return 0;
    }
    if(S.at(0)!=S.at(N-1)){
        ll ans=0;
        for(int i=0;i<cs;i++){
            ans+=c.at(i)/2;
        }
        ans*=K;
        cout<<ans<<endl;
    }
    else{
        ll p=c.at(cs-1);
        c.at(cs-1)+=c.at(0);
        ll ans=0;
        for(int i=1;i<cs;i++){
            ans+=c.at(i)/2;
        }
        ans*=K-1;
        for(int i=0;i<cs-1;i++){
            ans+=c.at(i)/2;
        }
        ans+=p/2;
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(void){
    char s[101];
    scanf("%s", s);
    int i=0;
    while(i<strlen(s)){
        if((i+1)%2){
            if(s[i]=='L'){
                printf("No");
                break;
            }
        }else{
            if(s[i]=='R'){
                printf("No");
                break;
            }
        }
        if(i==strlen(s)-1){
            printf("Yes");
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void) {
	int t, n=0, hyaku=0,zyu=0,iti=0;
	
	scanf("%d", &n);
	for (t = 0; n > 100; t++) {
		n = n - 100;
		hyaku++;
	}

	for (t = 0; n > 10; t++) {
		n = n - 10;
		zyu++;
	}

	for (t = 0; n > 0; t++) {
		n = n - 1;
		iti++;
	}

	if (hyaku == 7) {
		printf("Yes");
	}
	else {
		if (zyu == 7) {
			printf("Yes");
		}
		else {
			if (iti == 7) {
				printf("Yes");
			}
			else {
				printf("No");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1736
import numpy as np
def inpl(): return [int(i) for i in input().split()]

N = int(input())
A1 = np.cumsum(np.array(inpl()))
A2 = np.cumsum(np.array(inpl()))
ans = A1[0] + A2[-1]
for i in range(1,N):
    ans = max(ans, A1[i]+A2[-1]-A2[i-1])
print(ans)

Measured memory_bytes: 20272
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, N, res;
  rd(N);
  rd(A);
  rd(B);
  res =min_L(A*N, B);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// {
//   int N, A, B;
//   int res;
//   
//   rd(N,A,B);
//   res = min(A*N, B);
//   wt(res);
// }


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

int main() {
    double A, B;
    cin >> A >> B;
    double ans;
    bool ok = false;
    for (int i = 1; i <= 1100; i++) {
        if (floor(i*0.08) == A && floor(i*0.1) == B) {
            ans = i;
            ok = true;
            break;
        }
    }

    if (ok) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	// Code for C - Triangular Relationship
	var N, K int
	fmt.Scan(&N, &K)

	var ans int
	a := N / K
	ans += a * a * a
	if K%2 == 0 {
		b := (N + (K / 2)) / K
		ans += b * b * b
		fmt.Println(ans)
	} else {
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  vector<int> a(n);
  vector<int> b(n);
  
  for (int i = 0;i<n;i++) {
    cin >> p.at(i);
    for (int j = 0;j<i;j++) {
      if (p.at(j)<p.at(i)) a.at(i)++;
    };
  };
  
  for (int i = 0;i<n;i++) {
    p.at(i)-=a.at(i);
    cin >> q.at(i);
    for (int j = 0;j<i;j++) {
      if (q.at(j)<q.at(i)) b.at(i)++;
    };
  };
  for (int i = 0;i<n;i++) q.at(i)-=b.at(i);
  
  string big = "";
  for (int i = 0;big==""&&i<n;i++) {
    if (p.at(i)>q.at(i)) big = "p";
    else if (q.at(i)>p.at(i)) big = "q";
  };
  int ans = 0;
  int c = 1;
  for (int i = 0;i<n;i++) c = c*(i+1);
  if (big=="p") {
    for (int i = 0;i<n-1;i++) {
      c=c/(n-i);
      ans+= (p.at(i)-q.at(i))*c;
    };
  } else if (big=="q"){
    for (int i = 0;i<n-1;i++) {
      c=c/(n-i);
      ans+= (q.at(i)-p.at(i))*c;
    };
  };
  cout << ans;
}

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


void solve(long long N, std::vector<long long> A){
    map<int, int> mp;
    for(int i = 0;i < N;i++){
        mp[A[i]]++;
    }
    for(int i = 1;i <= N;i++){
        cout<<mp[i]<<endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-2+1);
    for(int i = 0 ; i < N-2+1 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

int main(){
  string s,t;

  cin >> s >> t;

  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());

  if (s < t) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;

}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

int n;
int x;
bool used[10];
int ma_diff = -1;
int ans;

int diff(int a, int b) {
    return min(abs(a - b), (int)pow(10ll, n) - abs(a - b));
}

void dfs(int i, int y) {
    if (i == n) {
        int t = diff(x, y);
        if (ma_diff < t || (ma_diff == t && y < ans)) {
            ma_diff = t;
            ans = y;
        }
        return ;
    }

    rep(d, 10) {
        if (used[d]) continue;
        used[d] = true;
        dfs(i + 1, 10 * y + d);
        used[d] = false;
    }
}

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

    string s;
    cin >> s;
    n = s.size();
    x = stoll(s);

    dfs(0, 0);

    cout << setw(n) << setfill('0') << ans << endl;
}

Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll MAX = 2000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


int main(){
  int n, k;
  cin >> n >> k;
  COMinit();
  ll ans[k+1] = {};
  for(int i = 1; i <= k; i++){
    if(n-k < i-1) ans[i] = 0;
    else ans[i] = COM(k-1, i-1)*COM(n-k+1,i)%MOD;
  }
  for(int i = 1; i <= k; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

ll a,b;
ll high(ll x){int t=0;while (x>1) x>>=1,++t;return 1ll<<t;}

int main()
{
	file();
	read(a,b);
	if (a==b) return puts("1"),0;
	while (a&&b&&high(a)==high(b)) a-=high(a),b-=high(b);
	if (a<b) swap(a,b);
	if (!b) return printf("%lld",high(a)<<1),0;
	ll aa=a-high(a);
	if (aa>=b) return printf("%lld",high(a)*2-b),0;
	if (!aa) return printf("%lld",a-b+1+a-1-b+1),0;
	if (2*high(aa)-1>=b) return printf("%lld",high(a)*2-b),0;
	printf("%lld",a-b+1+high(a)-b+2*high(aa)-aa-1);
	return 0;
}

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

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

    vector<int> v(n), w(n);
    for(int i=0; i<n; i++){
        scanf("%d %d", &v[i], &w[i]);
    }

    int q;
    scanf("%d", &q);

    for(int i=0; i<q; i++){
        int vertex, W;
        scanf("%d %d", &vertex, &W);

        int m = 1;
        vector<int> vq, wq;
        vq.push_back(v[vertex-1]);
        wq.push_back(w[vertex-1]);
        while(vertex != 1){
            vertex /= 2;
            //cout << vertex << " ";
            vq.push_back(v[vertex-1]);
            wq.push_back(w[vertex-1]);
            m += 1;
        }
        //cout << endl;

        vector<pair<int, int>> a = {{0,0}}, a1, a2;
        for(int i=0; i<m/2; i++){
            a1 = a;
            a2 = a;
            for(int j=0; j<a.size(); j++){
                a2[j].first  += wq[i];
                a2[j].second += vq[i];
            }
            a = {};
            int j1 = 0, j2 = 0;
            while(j2 < a2.size()){
                if(j1 == a1.size()){
                    if(a2[j2].first > W) break;
                    a.push_back(a2[j2]); j2 += 1; 
                }
                else if(a1[j1] < a2[j2]){ a.push_back(a1[j1]); j1 += 1; }
                else{                     a.push_back(a2[j2]); j2 += 1; }
            }
        }
        //sort(a.begin(),a.end());

        vector<pair<int, int>> b = {{0,0}}, b1, b2;
        for(int i=m/2; i<m; i++){
            b1 = b;
            b2 = b;
            for(int j=0; j<b.size(); j++){
                b2[j].first  += wq[i];
                b2[j].second += vq[i];
            }
            b = {};
            int j1 = 0, j2 = 0;
            while(j2 < b2.size()){
                if(j1 == b1.size()){
                    if(b2[j2].first > W) break;
                    b.push_back(b2[j2]); j2 += 1; 
                }
                else if(b1[j1] < b2[j2]){ b.push_back(b1[j1]); j1 += 1; }
                else{                     b.push_back(b2[j2]); j2 += 1; }
            }
        }

        vector<pair<int, int>> c, d;
        int cutoff = 0;
        for(int i=0; i<a.size(); i++){
            if(i > 0 && a[i].second <= cutoff) continue;
            c.push_back(a[i]);
            cutoff = a[i].second;
        }
        cutoff = 0;
        for(int i=0; i<b.size(); i++){
            if(i > 0 && b[i].second <= cutoff) continue;
            d.push_back(b[i]);
            cutoff = b[i].second;
        }

        /*
        cout << endl;
        for(auto aa : c) cout << aa.first << " " << aa.second << endl;
        cout << endl;
        for(auto bb : d) cout << bb.first << " " << bb.second << endl;
        cout << endl;
        */

        int ans = 0;
        for(int i=0; i<c.size(); i++){
            int test = c[i].second;
            int itr = lower_bound(d.begin(),d.end(),make_pair(W - c[i].first + 1,0)) - d.begin();
            if(itr >= 1) test += d[itr-1].second;
            ans = max(ans, test);
            //cout << i << " " << itr << " " << test << endl;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 5572
<?php
function eratosthenes5($max) {

    // max????????????
    $sqrt = floor(sqrt($max));

    // key??§?????????????°??????????
    $lists = array_fill(2, $max-1, true);

    // ?????£??¨????´?????????°?????????????????????
    for ($i=2; $i<=$sqrt; $i++) {
        if (isset($lists[$i])) {
            for ($j=$i*2; $j<=$max; $j+=$i) {
                unset($lists[$j]);
            }
        }
    }

    return array_keys($lists);
}

while(($max = trim(fgets(STDIN))) !== '') {
    echo count(eratosthenes5($max)) . "\n";
}

Measured memory_bytes: 110632
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    long long int n,i,j,k,t;
    cin>>n;
    t=sqrt(n);
    for(i=t;i>0;i--)
    {
        if(n%i==0)
        {
            j=i;
            k=n/i;
        cout<<(j-1)+(k-1)<<endl;
        break;
        }}
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define ALL(A)		(A).begin(),(A).end()
#define DUMP(A)    cout<<#A<<"="<<(A)<< endl
#define SIZE(A)    (int)((A).size())
#define P2(A)   ((A)*(A))
using namespace std;
typedef long long ll;

int main(){
    int n;
    for(;;){
        scanf("%d\n",&n);
        if(n==0) break;
        vector<double> xs(n),ys(n);
        for(int i=0;i<n;i++){
            scanf("%lf,%lf\n",&xs[i],&ys[i]);
        }
        if(n==1){
            printf("1\n");
            continue;
        }
        int ma=1;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                double mx=(xs[i]+xs[j])/2,my=(ys[i]+ys[j])/2,vlen=sqrt(P2(xs[i]-xs[j])+P2(ys[i]-ys[j])),llen=sqrt(1-(P2(xs[i]-mx)+P2(ys[i]-my)));
                double p1x=mx+(ys[i]-ys[j])*(llen/vlen),p1y=my-(xs[i]-xs[j])*(llen/vlen);
                double p2x=mx-(ys[i]-ys[j])*(llen/vlen),p2y=my+(xs[i]-xs[j])*(llen/vlen);
                int now=0;
                for(int k=0;k<n;k++){
                    if(sqrt(P2(xs[k]-p1x)+P2(ys[k]-p1y))<=1) now++;
                }
                ma=max(now,ma);
                now=0;
                for(int k=0;k<n;k++){
                    if(sqrt(P2(xs[k]-p2x)+P2(ys[k]-p2y))<=1) now++;
                }
                ma=max(now,ma);
            }
        }
        printf("%d\n",ma);
    }
}

Measured memory_bytes: 984
#include <functional>
 #include <algorithm>
 #include <iostream>
 #include <numeric>
 #include <iomanip>
 #include <utility>
 #include <cstdlib>
 #include <sstream>
 #include <bitset>
 #include <vector>
 #include <cstdio>
 #include <ctime>
 #include <queue>
 #include <deque>
 #include <cmath>
 #include <stack>
 #include <list>
 #include <map>
 #include <set>
 
 using namespace std;
 
 typedef vector<int> VI;
 typedef pair<int,int> pii;
 typedef long long ll;
 
 #define dump(x)  cerr << #x << " = " << (x) << endl
 #define rep(i,n) for(int i=0;i<(n);i++)
 #define ALL(a)  (a).begin(),(a).end()
 #define PB push_back
 #define sz size()
 
 const double EPS = 1e-10;
 const int INF = 100000000;
 
 int solve(int n){
 int ret=0;
 int m[]={500,100,50,10,5,1};
 rep(i,6){
 ret+=n/m[i];
 n-=m[i]*(n/m[i]);
 }
 return ret;
 }
 
 
 int main(){
 int n;
 while(cin>>n){
 if(n==0)break;
 cout<<solve(1000-n)<<endl;;
 }
 
 return 0;
 }

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

using namespace std;

int main(){

	int n,a,b,c,d;
	cin>> n >> a >> b >> c >> d;
	int na = a / c;
	if(a % c != 0)na++;
	int nb = b / d;
	if(b % d != 0)nb++;
	cout << n-max(na,nb) << endl;
	return 0;
}


Measured memory_bytes: 1160
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][];
        for (int i = 0; i < n; i++) {
            x[i] = new int[d];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }
        sc.close();

        long[] candidates = new long[n * n];
        int counter = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                candidates[counter] = 0;
                for (int k = 0; k < d; k++) {
                    candidates[counter] += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                }
                counter++;
            }
        }

        // for debug
//        for (int i = 0; i < n * n; i++) {
//            System.out.println(candidates[i]);
//        }

        Set<Long> answerSet = new HashSet<>();
        int max = (20 - (-20)) * (20 - (-20)) * 100;
//        System.out.println(max);
        for (int i = 1; i < max; i++) {
            long tmp = i * i;
            if (tmp > max) {
                break;
            }
            answerSet.add(tmp);
        }
        // for debug
//        System.out.println(answerSet);

        int ans = 0;
        for (long i : candidates) {
            if (answerSet.contains(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 22100
n, m, c = map(int, input().split())
b_array = [int(x) for x in input().split()]
a_array = [[int(x) for x in input().split()] for x in range(n)]
cnt = 0
for i in range(n):
    tmp = 0
    for x, y in zip(b_array, a_array[i]):
        tmp += x*y
    if tmp+c > 0:
        cnt += 1
else:
    print(cnt)

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

using namespace std;

const int MOD = 1e9 + 7;

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	map<int, int> mp;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		mp[x]++;
	}
	for (auto &p : mp) {
		if ((p.first == 0 && (p.second != 1 || n % 2 == 0))
		    || (p.first != 0 && p.second != 2)
		    || p.first % 2 == n % 2) {
			cout << "0\n";
			return 0;
		}
	}
	int res = 1;
	for (int i = 0; i < n / 2; i++) {
		res = (res * 2) % MOD;
	}
	cout << res << '\n';

	return 0;
}



Measured memory_bytes: 3200
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 5e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int T[maxN << 1], n;
string str;

void update(int w, int x) {
	w += n;
	T[w] = x;
	while(w > 1) w >>= 1, T[w] = T[w << 1] | T[w << 1 | 1];
}

int query(int l, int r) {
	int ret = 0;
	for(l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if(l & 1) ret |= T[l++];
		if(r & 1) ret |= T[--r];
	}
	return ret;
}

int cuenta(int x) {
	int ret = 0;
	while(x)
		ret += x & 1, x >>= 1;
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	cin >> n >> str;
	for(int i = 0; i < n; i++) T[n + i] = 1 << (str[i] - 'a');
	for(int i = n - 1; i >= 0; i--) T[i] = T[i << 1] | T[i << 1 | 1];
	int q;
	cin >> q;
	while(q--) {
		int ty;
		cin >> ty;
		if(ty == 1) {
			int w;
			char x;
			cin >> w >> x, w--;
			update(w, 1 << (x - 'a'));
		} else {
			int l, r;
			cin >> l >> r, l--;
			cout << cuenta(query(l, r)) << '\n';
		}
	}
}


Measured memory_bytes: 4892
#include <cmath>
typedef long long ll;

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

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

typedef vector<ll> vec;
typedef vector<vec> mat;

int mod;

mat operator * (const mat &lhs, const mat &rhs){
  const int n = lhs.size();
  mat ret(n, vec(n));

  REP(i,n) REP(j,n) REP(k,n){
    ret[i][j] += (lhs[i][k] * rhs[k][j]) % mod;
    ret[i][j] %= mod;
  }

  return ret;
}

vec operator * (const mat &lhs, const vec &rhs){
  const int n = lhs.size();
  vec ret(n);

  REP(i,n) REP(j,n){
    ret[i] += (lhs[i][j] * rhs[j]) % mod;
    ret[i] %= mod;
  }

  return ret;
}

mat pow(mat m, int p){
  const int n = m.size();
  mat ret(n, vec(n));

  REP(i,n) ret[i][i] = 1;

  while(p){
    if(p & 1) ret = ret * m;
    m = m * m;
    p >>= 1;
  }

  return ret;
}

int main(){
  while(true){
    const int n = getInt();
    const int m = getInt();
    const int a = getInt();
    const int b = getInt();
    const int c = getInt();
    const int t = getInt();

    if(n + m + a + b + c + t == 0) break;

    mod = m;

    vec s(n);
    REP(i,n) s[i] = getInt();
    mat mt(n, vec(n));

    REP(i,n){
      if(i - 1 >= 0) mt[i][i - 1] = a;
      mt[i][i] = b;
      if(i + 1 < n) mt[i][i + 1] = c;
    }

    vec ans = pow(mt, t) * s;

    REP(i,n) printf("%d%c", (int)ans[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 1144
S = gets.chomp

cond = true

S.each_char.with_index do |c, idx|
  if idx.even?
    cond &= %w(R U D).include?(c)
  else
    cond &= %w(L U D).include?(c)
  end
end

if cond
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 3836
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] str = sc.nextLine(). toCharArray();
        for(char a : str)
            if(Character.isLowerCase(a))
                System.out.print(Character.toUpperCase(a));
            else
                System.out.print(Character.toLowerCase(a));
        System.out.println();
        sc.close();
    }
}



Measured memory_bytes: 26856
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
LL read(){
    LL nm=0,fh=1; char cw=getchar();
    for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
    for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
    return nm*fh;
}
LL ans,sum0,sum1,sig;
LL n,m,fs[M],nt[M<<1],to[M<<1],col[M],f[M],sz[M],tmp;
LL fd(LL x){return x==f[x]?x:f[x]=fd(f[x]);}
void link(LL x,LL y){nt[tmp]=fs[x],fs[x]=tmp,to[tmp++]=y;}
void merge(LL x,LL y){x=fd(x),y=fd(y);if(x!=y) f[x]=y,sz[y]+=sz[x];}
bool check(LL x,LL now){
    if(col[x]) return col[x]==now; col[x]=now;
    for(LL i=fs[x];i!=-1;i=nt[i])
        if(!check(to[i],3-now)) return false;
    return true;
}
int main(){
    n=read(),m=read(),memset(fs,-1,sizeof(fs));
    for(LL i=1;i<=n;i++) f[i]=i,sz[i]=1;
    for(LL i=1;i<=m;i++){
        LL x=read(),y=read();
        link(x,y),link(y,x),merge(x,y);
    }
    for(LL i=1;i<=n;i++) if(fd(i)==i&&sz[i]==1) sig++;
    for(LL i=1;i<=n;i++){
        if(fd(i)!=i||sz[i]==1) continue;
        if(check(i,1)) sum0++;
        else sum1++;
    }
    ans+=sig*((n<<1)-1)-sig*(sig-1);
    ans+=((sum0*sum0)<<1);
    ans+=sum1*(sum0<<1)+sum1*sum1;
    printf("%lld\n",ans);
    return 0;
}

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

const int INF = 1e9;

struct sword {
    int atk, mc;
    bool operator < (sword that) {
        return atk > that.atk;
    }
};

int main() {
    int n, h;
    cin >> n >> h;
    vector<sword> s(2 * n);
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        s[2 * i] = {a, INF};
        s[2 * i + 1] = {b, 1};
    }
    sort(s.begin(), s.end());
    int ans = 0;
    for (int i = 0; i < 2 * n; i++) {
        int cnt = min((h + s[i].atk - 1)/ s[i].atk, s[i].mc);
        ans += cnt;
        h -= cnt * s[i].atk;
        if (h < 0) {
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int a = Integer.parseInt(sc.nextLine());
            String s = a >= 3200 ? sc.nextLine() : "red";
            System.out.println(s);
        }
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <cmath>
typedef long long int ll;
using namespace std;

int main(){

	ll N;

	scanf("%lld",&N);

	if(N%2 == 0){
		printf("1\n");
		return 0;
	}else{
		N++;

		ll ans = 1;

		while(N%2 == 0){
			N /= 2;
			ans *= 2;
		}
		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1N(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
using namespace std ;


int main()
{
  int N = 0 ;
  int L = 0 ;
  cin >> N >> L ;
  
  // 絶対値の最小値を見つけて、それ以外の総和をとる
  unsigned int minVal = 1e10 ;
  int sum = 0 ;
  REP1N( i, N ) {
    int aji = L + i - 1 ;
    int ajiAbs = abs( aji ) ;
    if ( ajiAbs < abs( minVal ) ) minVal = aji ;

    sum += aji ;
  }
  sum -= minVal ;
  cout << sum << endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vv<int> graph;
vector<int> deg;

bool dfs(int v, int from, int start, int goal) {
    for (int u : graph[v]) {
        if (u == from) continue;
        else if (u == goal) return true;
        else if (u == start) return false;
        return dfs(u, v, start, goal);
    }
    return false;
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    deg.resize(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        deg[a]++; deg[b]++;
    }

    int deg6 = 0;
    vector<int> deg4;
    rep(i, N) {
        if (deg[i] % 2) {
            write("No");
            return 0;
        }
        else if (deg[i] >= 6) deg6++;
        else if (deg[i] == 4) deg4.push_back(i);
    }

    if (deg6 > 0 || deg4.size() > 2) write("Yes");
    else if (deg4.size() < 2) write("No");
    else {
        int bridge = 0;
        for (int u : graph[deg4[0]]) {
            if (u == deg4[1]) bridge++;
            else bridge += dfs(u, deg4[0], deg4[0], deg4[1]);
        }
        if (bridge > 2) write("No");
        else write("Yes");
    }
}

Measured memory_bytes: 6144
import sys,math,copy,queue,itertools,bisect,collections
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(0,1),(-1,0),(0,-1))

S,W = LI()
if S > W :
    print ('safe')
else:
    print ('unsafe')

Measured memory_bytes: 68772
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
  // xの期待値は(1 2)->1.5 (1 4)->2.5 (1 5)->3.0
  int n,k; cin>>n>>k; double k2=k;
  double p[n];
  for(int i=0;i<n;i++) cin>>p[i];
  double an=0, sm=0;
  for(int i=0;i<k;i++) sm+=p[i];
  an=(sm+k2)/2; //cout<<sm<<" "<<an<<endl;
  for(int i=k;i<n;i++) {
    sm+=p[i]-p[i-k]; an=max(an,(sm+k2)/2);
    //cout<<sm<<" "<<an<<" "<<(sm+k2)<<" "<<2<<endl;
  }
  cout<<fixed<<setprecision(10);
  cout<<an<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
    int i;
    int n,m;
    int s[60] = {0};
    int r[60] = {0};
    int ans[60] = {0};
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=0;i<m;i++){
        scanf("%d %d",&s[i],&r[i]);
    }
    for(i=0;i<m;i++){
        ans[s[i]-1]++;
    }
    for(i=0;i<m;i++){
        ans[r[i]-1]++;
    }
    /*for(i=0;i<m;i++){
        printf("%d %d\n",s[i],r[i]);
    }*/
    for(i=0;i<n;i++){
        printf("%d\n",ans[i]);
    }
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int a, b;
    cin >> a >> b;
    cout << (a * b) << " " << (2 * a + 2 * b) << endl;
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3076
cin = open(0).read().strip().split('\n')
n = int(cin[0])
p = list(map(int, cin[1].split(' ')))
q = list(map(int, cin[2].split(' ')))

import itertools

a = 0
b = 0
for idx, case in enumerate(itertools.permutations(range(1, n+1))):
    if case == tuple(p):
        a = idx+1
    if case == tuple(q):
        b = idx+1

print(abs(a-b))

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<iomanip>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

string table[]={"qwertasdfgzxcvb","yuiophjklnm"};


int main(){

	while(true){
		int n,q;
		vector<int> date;
		
		cin >> n >> q;

		
		if(n==0&&q==0) break;


		for(int i=0;i<=100;i++){
			date.push_back(0);
		}

		for(int i=0;i<n;i++){
			int m,d;
			cin >> m;
			for(int k=0;k<m;k++){
				cin >> d;
				date[d]++;				
			}
		}

		int decide=0,day=0;

		for(int i=0;i<100;i++){
			if(date[i]>decide && date[i] >= q){
				decide=date[i];	
				day=i;
			}
		}

		cout << day << endl;
	}

}

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

int main () {
  int N ;
  cin >> N ;
  vector<long long> line(N) ;
  for(int i = 0 ; i < N ; i++ ) cin >> line[i] ;
  sort(line.begin(),line.end()) ;
  cout << line[N-1] - line[0] << endl ;
}

Measured memory_bytes: 256
// 0bd35dc5e428754fa574049b6be8efe0

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;

const int MAXN = (int) 1e5;

int n;

LL lim[2], a[MAXN + 5];

inline void input()
{
	n = read<int>();
	for(int i = 0; i < 2; ++i) lim[i] = read<LL>();
	for(int i = 1; i <= n; ++i) a[i] = read<LL>();
}

inline void solve()
{
	static LL d[MAXN + 5];

	d[1] = LLONG_MAX;
	for(int i = 2; i <= n; ++i) d[i] = a[i] - a[i - 1];

	static int f[MAXN + 5][2], pre[MAXN + 5][2];

	pre[0][0] = f[0][0] = 1;
	pre[0][1] = f[0][1] = 1;
	for(int i = 1, l[2] = {0, 0}, r[2] = {0, 0}; i <= n; ++i) for(int j = 0; j < 2; ++j)
	{
		while(r[j] + 1 < i && (a[i + 1] - a[r[j] + 1] >= lim[j] || i == n)) ++r[j];
		if(d[i] < lim[!j]) l[j] = i - 1;
		f[i][j] = l[j] <= r[j] ? (pre[r[j]][!j] - (l[j] > 0 ? pre[l[j] - 1][!j] : 0)) % MOD : 0;
		pre[i][j] = (pre[i - 1][j] + f[i][j]) % MOD;
	}

	int ans = (f[n][0] + f[n][1]) % MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifndef ONLINE_JUDGE
//	freopen("C.in", "r", stdin);
//	freopen("C.out", "w", stdout);
#endif

	input();
	solve();

	return 0;
}



Measured memory_bytes: 3328
#include <stdio.h>

void swap(int n, int p, int c, int* card){
  int *temp1 = new int[p-1];
  int *temp2 = new int[c];
  for(int i=0; i<p-1; i++){
    temp1[p-1-1-i] = card[n-1-i];
  }
  for(int i=0; i<c; i++){
    temp2[c-1-i] = card[n-p-i];
  }
  for(int i=0; i<c; i++){
    card[n-1-i] = temp2[c-1-i];
  }
  for(int i=0; i<p-1; i++){
    card[n-1-c-i] = temp1[p-1-1-i];
  }
  delete[] temp1;
  delete[] temp2;
}

int main(void){
  int n, r, p, c;
  int i;
  int card[50];

  while(1){
    for(i=0;i<50;i++){
      card[i]=i+1;
    }
    scanf("%d%d", &n, &r);
    if(n==0 && r==0){
      break;
    }
    for(i=0;i<r;i++){
      scanf("%d%d", &p, &c);
      swap(n, p, c, card);
    }
    printf("%d\n", card[n-1]);
  }
}

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

const int SUB = 6081; // '0' * 111 + 753
int main() {
	string S;
	cin >> S;
	int diff = 999;
	for (int i = 2, l = S.size();i < l;++ i) {
		diff = min(diff, abs(S[i - 2] * 100 + S[i - 1] * 10 + S[i] - SUB));
	}
	cout << diff;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけ
*/

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args){

        Scanner scan=new Scanner(System.in);
        int n=0;
        if(scan.hasNext())
            n=scan.nextInt();

        int[][] arr=new int[n][3],dp=new int[n][3];
        for(int i=0;i<n;i++){
            for(int j=0;j<3;j++) {
                if (scan.hasNext())
                    arr[i][j] = scan.nextInt();
                if(i==0){
                    dp[i][j]=arr[i][j];
                }
            }
        }
        for(int i=1;i<n;i++){
            for(int j=0;j<3;j++) {
                int max = Integer.MIN_VALUE;
                for(int k=0;k<3;k++){
                    if(k==j){
                        continue;
                    }
                    max=Math.max(dp[i-1][k],max);
                }
                dp[i][j]=arr[i][j]+max;
            }
        }
        System.out.println(Math.max(dp[n-1][0],Math.max(dp[n-1][1],dp[n-1][2])));


    }
}


Measured memory_bytes: 103748
#include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp>
  using namespace __gnu_pbds;
  using namespace std;
  #define int         long long
  #define mod         1000000007
  #define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  #define f(i,n)      for(int i=0;i<n;i++)
  #define fp(i,k,n)   for(int i=k;i<=n;i++)
  #define fr(i,k,n)   for(int i=k;i>=n;i--)
  #define pb          push_back
  #define pii         pair<int,int>
  #define vi          vector<int>
  #define vii         vector<pii>
  #define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
  #define F           first
  #define S           second
  #define sz(x)       (int)(x).size()
  #define lb          lower_bound
  #define ub          upper_bound
  #define mems(x)     memset(x,0,sizeof(x))
  #define all(a)      a.begin(),a.end()
  typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

  /*---------------------------------------------------------------------------------------------------*/

  void solve()
  {
      int n,cnt=0;
    string s;
      cin >> n>>s;
    f(i,s.length())
    {
        if(s[i]=='R')
        {
           cnt++;
        }
    }
    int ans=0;
    f(i,n)
    {
        if(cnt==0)
            break;
        if(s[i]=='R')
            cnt--;
        if(s[i]=='W')
           {cnt--;ans++;}
    }
    cout << ans << '\n';
    return;
  } 

  signed main()
  {
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    FAST
    int T=1;
    // cin >> T;
    while(T--)
    {
      solve();
    }
    return 0;
  }


Measured memory_bytes: 3756
n, m=map(int, input().split())
t=[list(map(int, input().split())) for i in range(n)]

l=sorted(t, key=lambda x: x[0])

money=0

for i in range(n):
    if m==0:
        break
    
    money+=l[i][0]*min(m, l[i][1])
    m-=min(m, l[i][1])


print(money)

Measured memory_bytes: 29796
#include<iostream>
using namespace std;
int main(){
  int n,r; cin>>n;
  cin>>r;
  int maxv=-1000000000,minv=r;
  for(int i=1;i<n;++i){
    cin>>r;
    if(maxv<r-minv) maxv=r-minv;
    if(minv>r) minv=r;
  }
  cout<<maxv<<endl;
  return 0;
}



Measured memory_bytes: 3104
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.ascii;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

bool calc(string s) {
    if (s[0] != 'A') return false;
    if (s[2..$-1].count('C') != 1) return false;
    if (s.count!(c => isUpper(c)) > 2) return false;
    return true;
}

void main() {
    auto s = readln.chomp;
    writeln(calc(s) ? "AC" : "WA");
}


Measured memory_bytes: 256