akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>
//小文字を大文字 c-0x20;


#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define fix(k) fixed<<setprecision(k)
#define PI 3.141592653589793
using namespace std;



int main(){
  int n;cin>>n;
  int flag=0;
  for(int i=1;i<=n;i++){
      if(i==100000)break;
      flag++;
      if(i==9){
          i=99;
          continue;
      }else if(i==999){
          i=9999;
        continue;
      }
  }
cout<<flag<<endl;
}


Measured memory_bytes: 256
def main():
    s = input()
    for x in range(1, 10):
        t = 'hi' * x
        if t == s:
            print('Yes')
            return
    print('No')


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char strfull[110];
    char str1[110];
    
    
    scanf("%s",str1);
    strcpy(strfull,str1);
    strcat(strfull,str1);
    
    char p[110];
    scanf("%s",p);
    
    int sn=strlen(strfull);
    int pn=strlen(p);
    
    for(int i=0;i<sn;i++){
        
        for(int j=0;j<pn;j++){
            if(strfull[i+j] != p[j]) break;
            if(j == pn - 1) {
                printf("Yes\n");
                return 0;
                
            }
        }
        
    }
    printf("No\n");
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vector<bool> dp(k + 1);
	// dp[i] is true if the first player can win if there's i stones left
	for (int i = 0; i <= k; i++) {
		for (int x: a) {
			if (i - x >= 0 && !dp[i - x]) {
				dp[i] = true;
			}
		}
	}

	cout << (dp[k] ? "First" : "Second") << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i,j,k=0;
  int N,M,C;
  
  scanf("%d %d %d",&N,&M,&C);
  int B[M];
  int A[M];
  for(i=0;i<M;i++){
    scanf("%d ",&B[i]);
  }
  
  int tmp;
  for(i=0;i<N;i++){
    tmp=0;
    for(j=0;j<M;j++){
      scanf("%d ",&A[j]);
      tmp+=A[j]*B[j];
    }
    tmp+=C;
    if(tmp > 0)
      k++;
  }
  
  printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int w,h;
vector<string> board;
vector<vector<string> > memo;
int dx[]={1,0};
int dy[]={0,1};

inline bool outrange(int x,int y)
{
  return (x<0 || x>=w || y<0 || y>=h);
}

string cmp(string a,string b)
{
  if(a.size()>b.size()) return a;
  if(b.size()>a.size()) return b;
  return max(a,b);
}

string dfs(int x,int y)
{
  if(outrange(x,y)) return "";
  if(!isdigit(board[y][x])) return "";
  if(memo[y][x]!="") return memo[y][x];
  
  string res="";
  for(int d=0;d<2;d++)
    {
      res=cmp(res,board[y][x]+dfs(x+dx[d],y+dy[d]));
    }
  memo[y][x]=res;
  return res;
}

int main(int argc,char const* argv[])
{
  vector<vector<int> > num;
  int dp[105][105];
  memset(dp,0,sizeof(dp));
  string s;
  while(cin >> s)
    {
      vector<int> v;
      replace(s.begin(),s.end(),',',' ');
      stringstream ss(s);
      while(ss >> s)
	{
	  v.push_back(stoi(s.c_str()));
	}
      num.push_back(v);
    }
  int center=int(num.size())/2;
  dp[0][0]=num[0][0];
  for(int i=1;i<int(num.size());i++)
    {
      for(int j=0;j<int(num[i].size());j++)
	{
	  dp[i][j]=dp[i-1][j]+num[i][j];
	  if(i<=center && j) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+num[i][j]);
	  if(i>center) dp[i][j]=max(dp[i][j],dp[i-1][j+1]+num[i][j]);
	}
    }
  cout << dp[int(num.size())-1][0] << endl;
  return 0;
}



Measured memory_bytes: 3232
# ruby 少数 誤差 対応
# 705513400978450 8.28 誤差の出るやつ
# bのパターン 1.10 1.01 1.00 #必ず小数第二位まであるらしい
a,b=gets.split(" ")
a_int=a.to_i
b_int=b[0].to_i*100+b[2].to_i*10+b[3].to_i
print a_int*b_int/100


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  string N; cin >> N;
  int dp[11][2][2][2][2][2][2];
  memset(dp,0,sizeof(dp));
  dp[0][0][0][0][0][0][0] = 1;
  for ( int i = 0; i < N.length(); i++ ) {
    for ( int j = 0; j < 2; j++ ) {
      for ( int k = 0; k < 2; k++ ) {
	for ( int l = 0; l < 2; l++ ) {
	  for ( int m = 0; m < 2; m++ ) {
	    for ( int n = 0; n < 2; n++ ) {
	      for ( int o = 0; o < 2; o++ ) {
	    int x = j? 9:N[i]-'0';
	    for ( int d = 0; d <= x; d++ ) {
	      bool no357= n? (d!=3&&d!=5&&d!=7)
		:(d!=0&&d!=3&&d!=5&&d!=7);
	      dp[i+1][j||d<x][k||d==3][l||d==5][m||d==7][n||d][o||no357]
	      += dp[i][j][k][l][m][n][o];
	    }
	    }
	    }
	  }
	}
      }
    }
  }
  int ans = 0;
  for ( int j = 0; j < 2; j++ ) {
    ans += dp[N.length()][j][1][1][1][1][0];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n;
    string s;
    cin >> n;
    cin >> s;

    string ans = s;

    for(int i = 0;i < ans.size();i++){
        if(ans[i] == '('){
            continue;
        }
        int opcnt = 0;
        int clcnt = 0;
        REP(j,i+1){
            if(ans[j] == '('){
                opcnt++;
            }
            else{
                clcnt++;
            }
        }
        if(opcnt < clcnt){
            ans = '(' + ans;
            i++;
        }
    }

    REPR(i,s.size()-1){
        if(ans[i] == ')'){
            continue;
        }
        int opcnt = 0;
        int clcnt = 0;
        for(int j = ans.size() - 1;j >= i;j--){
            if(ans[j] == '('){
                opcnt++;
            }
            else{
                clcnt++;
            }
        }
        if(opcnt > clcnt){
            ans = ans + ')';
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)

pnt = 0
last = -1
for i in 1..n do
    tar = a[i-1]
    pnt += b[tar-1]
    if tar-last == 1
        pnt += c[last-1]
    end
    last = tar
end

p pnt

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define LL long long
using namespace std;
 
int nums[55]; 

int n;

bool issort(){
	for(int i = 1; i < n; ++i){
		if(nums[i] < nums[i - 1]){
			return false;
		}
	}
	return true;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; ++i){
		cin >> nums[i];
    }
    bool ok = false;
	for(int i = 0; i < n; ++i){
		for(int j = i; j < n; ++j){
			swap(nums[i], nums[j]);
			if(issort()){
				ok = true;
			}
			swap(nums[i], nums[j]);
		}
    }
    if(ok){
		cout << "YES" << endl;
    }
    else{
		cout << "NO" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

signed main() {
    int a,b;
    cin >> a >> b;
    for (int i = 1; i <= 499500; ++i) {
        if((facctorialMethod(i) - a) == (facctorialMethod(i+1) - b)){
           cout << (facctorialMethod(i) - a - 1) << endl;
           return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#include "string"
#define int long long
#define pi pair <int, int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'

const int N = 5e6 + 5;
const int M = 1e9 + 7;

int mod( int m ,int mod = M) {
   m %= mod;
   return (m + mod) % mod;
}

int power(int x,int y) {
   int res = 1;
   x = mod(x);
   while (y > 0) {
      if (y & 1)
         res =mod(res * x);
      y = y / 2;
      x = mod(x * x);
   }
   return mod(res);
}

int f[N],invf[N];
void fact() {
   f[0] = f[1] = 1;
   for(int i=2;i<N;i++)
      f[i] = mod(f[i-1] * i);

   invf[N-1] = power(f[N-1],M-2);
   for(int i=N-1;i>0;i--)
      invf[i-1] = mod(invf[i] * i);

}

int nCr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   ans = mod(ans*invf[r]);
   return ans;
}

int nPr(int n,int r) {
   if(r>n)
      return 0;
   int ans = f[n];
   ans = mod(ans*invf[n-r]);
   return ans;
}

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

	int ans = mod(power(10, n) - power(8, n));
	for(int i = 1; i <= n; i++) {
		int tt = mod(2 * nCr(n , i));
		ans = mod(ans - mod(tt * power(8, n - i)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 81748
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <map>

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  double R;
  cin >> R;
  
  double ans = 2.0*R*3.1416;
  
  cout << ans << endl;
}

Measured memory_bytes: 3788
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

struct city {
  int id;
  int pref;
  ll year;
  int index;
};

bool compID(const city& first, const city& second) {
  return first.id < second.id;
}
bool compYear(const city& first, const city& second) {
  return first.year < second.year;
}

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  int ans = 0;
  cin >> n >> m;
  vector<city> v(m);
  vector<int> y(n + 1, 0);
  for (int i = 0; i < m; ++i)  {
    v[i].id = i;
    cin >> v[i].pref >> v[i].year;
  }
  sort(v.begin(), v.end(), compYear);
  for (int i = 0; i < m; i++) {
    v[i].index = ++y[v[i].pref]; //評価前に足す
  }

  sort(v.begin(), v.end(), compID);

  for (int i = 0; i < m; i++) {
    printf("%06d%06d\n", v[i].pref, v[i].index);

  }
  return 0;
}

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

int main(){
    ll n,k,q;cin>>n>>k>>q;
    vector<int> a(q);
    rep(i,q) cin>>a[i];

    vector<int> dic(n+1,0);

    rep(i,q) {
        dic[a[i]]++;
    }
    for (int i=1;i<n+1;i++) {
        if (dic[i]  >= 1-k+q ){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }

}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

ll N,X;
ll B[100010],L[100010],U[100010];
ll Usum[100010],Lsum[100010] = {};

int main(){
    cin >> N >> X;
    vector<pair<ll,int>> v;
    v.push_back({1e9,1e9});
    for(int i=1;i<=N;i++){
        cin >> B[i] >> L[i] >> U[i];
        v.push_back({(X-B[i])*U[i]+B[i]*L[i],i});
    }
    sort(v.begin()+1,v.end(),greater<pair<ll,int>>());
    for(int i=1;i<=N;i++){
        int id = v[i].second;
        Usum[i] = Usum[i-1]+(X-B[id])*U[id];
        Lsum[i] = Lsum[i-1]-B[id]*L[id];
    }
    ll l = -1,r = X*N;
    while(l+1<r){
        ll m = (l+r)/2;
        ll x = m/X,y = m%X;
        bool ok = false;
        for(ll i=1;i<=N;i++){
            ll value = 0,res = x;
            value += Usum[min(i-1,res)]+Lsum[i-1]-Lsum[min(i-1,res)];
            res -= min(i-1,res);
            value += Usum[i+res]-Usum[i]+Lsum[N]-Lsum[i+res];
            int id = v[i].second;
            if(y-B[id]>=0) value += U[id]*(y-B[id]);
            else value -= L[id]*(B[id]-y);
            if(value>=0) ok = true;
        }
        if(ok) r = m;
        else l = m;
    }
    cout << r << endl;
}

Measured memory_bytes: 5872
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    A,B = map(int, readline().split())

    for i in range(1, 1300):
        x1 = int(i * 0.08)
        x2 = int(i * 0.1)

        if x1 == A and x2 == B:
            print(i)
            exit()

    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[300000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0;
  string s,u;
  cin >>s;
  for(int n=0;n<s.size();n++){
    for(int m=n+1;m<s.size();m++){
      if(s[n]==s[m]){
	d++;
	break;
      }
    }
    if(d>0) break;
  }
  if(d>0) cout <<"no\n";
  else cout <<"yes\n";
  return (0);
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
bool cmp(pair <int,int> a,pair <int,int> b){
    return a.second>b.second;
}
int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    pair <int,int> p[m];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<m;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+m,cmp);
    int curr=0,f=0;
    long long int ans=0;
    for(int i=0;i<m;i++){
        int cnt=1;
        while(curr<n&&cnt++<=p[i].first){
            if(a[curr]>p[i].second){
                f=1;
                break;
            }
            else{
                a[curr]=p[i].second;
            }
            curr++;
        }
        if(f) break;
    }
    for(int i=0;i<n;i++) ans+=a[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys
from math import pow


def solve(X: int):
    def func(A):
        return pow(X+A**5, 1/5)

    for A in range(-1000, 1000):
        for B in range(-1000, 1000):
            if X == A**5-B**5:
                print(A, B)
                return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 64868
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e4;
const ll inf = 1e9+7;

int main() {
	fastio;
	ll n,x,cont=0;
	cin>>n;
	f(i,1,n+1){
	 	cin>>x;
	 	if(x%2==1 && i%2==1) cont++;
	}
	cout<<cont<<"\n";
	return 0;
}

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

int main(){
  int c[9];
  for(int i=0;i<9;i++){
  	cin >> c[i];
  }
  int a1 = c[0]+c[4]+c[8],
  a2 = c[0]+c[5]+c[7],
  a3 = c[1]+c[3]+c[8],
  a4 = c[1]+c[5]+c[6],
  a5 = c[2]+c[3]+c[7],
  a6 = c[2]+c[4]+c[6];
  if(a1==a2&&a2==a3&&a3==a4&&a4==a5&&a5==a6)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 384
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[][10^^5*2] T;
long[10^^5*2] C;

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];
    foreach (i; 0..N-1) {
        auto ab = readln.split.to!(int[]);
        auto a = ab[0] - 1;
        auto b = ab[1] - 1;
        T[a] ~= b;
        T[b] ~= a;
    }
    foreach (_; 0..Q) {
        auto px = readln.split.to!(int[]);
        auto P = px[0] - 1;
        long X = px[1];
        C[P] += X;
    }

    void walk(int i, int p) {
        foreach (j; T[i]) if (j != p) {
            C[j] += C[i];
            walk(j, i);
        }
    }
    walk(0, -1);

    writeln(C[0..N].to!(string[]).join(" "));
}

Measured memory_bytes: 42620
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  char c;
  cin >> c;
  string ans;
  if(c == 'A') ans = "T";
  else if(c == 'T') ans = "A";
  else if(c == 'G') ans = "C";
  else ans = "G";
  cout << ans << endl;
}

Measured memory_bytes: 256
_, num = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
# a_uniq = a.uniq
# a_count = []
# a_uniq.each do |n|
#   a_count << a.count{ |c| c == n }
# end
a_uniq = []
current = nil
a.sort.each do |_a|
  if a_uniq.last.nil? || current != _a
    a_uniq << 1
  else
    a_uniq[-1] += 1
  end
  current = _a
end
a_sorted = a_uniq.sort
delete_num = (a_uniq.size - num)
if delete_num > 0
  p a_sorted[0..delete_num - 1].inject(:+)
else
  p 0
end


Measured memory_bytes: 23268
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;
    vector<long long> a(n+3,0);
    for(int i=1; i<=n; i++) cin >> a[i];
    vector<long long> dp(n+3,MOD);
    dp[1]=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=k; j++){
            if(i+j>n)break;
            dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[101000];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	long long Max1=0,Max2=0;
	int i=n;
	while (i>0)
	{
		if (a[i-1]!=a[i]) { i--;continue;}
		if (Max1==0) Max1=a[i];else {Max2=a[i];break;}
		i-=2;
	}
	printf("%lld\n",Max1*Max2);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define MAX 2000000
#define N 1000000000

int H,A[MAX+1];

void maxHeapify(int i){
  int a = 2 * i;
  int b = 2 * i  +1;
  int largest,t;
 
  if(a<=H && A[a]>A[i]) largest = a;
  else largest = i;
  if(b<=H && A[b]>A[largest]) largest = b;

  if(largest != i){
    t=A[i];
    A[i]=A[largest];
    A[largest]=t;
    maxHeapify(largest);
  }
}


int extract(){
  int maxv;
  if(H<1) return -N;
  maxv = A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}

void increaseKey(int i, int key) {
  if ( key < A[i] ) return;
  int tmp;
  A[i] = key;
  while ( i > 1 && A[i / 2] < A[i] ) {
    tmp = A[i];
    A[i]=A[i/2];
    A[i/2]=tmp;

    i = i / 2;
  }
}

void insert(int key) {
  H++;
  A[H] = -N;
  increaseKey(H, key);
}

int main(){
  int key;
  char com[10];

  while (1) {
    scanf("%s", com);
    if (com[0] == 'e' && com[1] == 'n') break;
    if (com[0] == 'i') {
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extract());
    }
  }
  return 0;
}



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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

LL N;
int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	LL ans = 0, S = 0;
	int i;

	for(i = 1; i<=N; i++){
		S += i;
		if(S >= N){
			break;
		}
	}
	LL e = S - N;
	for(LL j=1; j<=i; j++){
		if(j != e){
			printf("%lld\n", j);
		}
	}
	return 0;
}

Measured memory_bytes: 3792
#include<iostream>
using namespace std;
int mp[2][31][31]={};
int sai[7][4]= {{0,0,0,0},{3,5,4,2},{1,4,6,3},{1,2,6,5},{5,6,2,1},{3,6,4,1},{2,4,5,3}};
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

void die(int t,int f,int x,int y){
  int i,j,x2,y2,mx=3,f2,t2;
  mp[1][y][x]++;
  for(i=0;i<4;i++){
    if(sai[t][i]==f){
      for(j=i;j<i+4;j++){
	int m=j%4,x1=x+dx[j-i],y1=y+dy[j-i];
	if(mp[1][y][x]-1>mp[1][y1][x1]&&sai[t][m]>mx){
	  mx=sai[t][m];
	  x2=x1,y2=y1;
	  t2=7-mx;
	  if(j-i==2)f2=7-t;
	  else if(j-i==-0)f2=t;
	  else f2=f;
	}
      }
      break;
    }
  }
  if(mx!=3)mp[1][y][x]--,die(t2,f2,x2,y2);
  else mp[0][y][x]=t;
}

int main(){
  while(1){
    int n;cin>>n;if(n==0)break;
    int i,j,t,f,c[7]={};
    for(i=0;i<n;i++){
      cin>>t>>f;
      die(t,f,15,15);
    }
    for(i=0;i<31;i++)
      for(j=0;j<31;j++){
	c[mp[0][i][j]]++;
	mp[0][i][j]=mp[1][i][j]=0;
      }
    for(i=1;i<6;i++)cout<<c[i]<<" ";cout<<c[6]<<endl;
  }
  return 0;
}

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

int main(){
	int n;	cin>>n;
	double ans=0;

	double x;
	for(int i=0;i<n;i++){
		cin>>x;
		ans+=1.0/x;
	}

	ans=1.0/ans;

	printf("%.6lf\n", ans);



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

string s;
int segtree[500000*4+1][26],a[500001],fre[26],i;

void makeSegTree(int index,int start,int end)
{
	if(start==end)
	{
		segtree[index][a[start]]++;
		return;	
	}	
	
	int mid=(start+end)>>1;
	
	makeSegTree(index<<1,start,mid);
	makeSegTree(index<<1|1,mid+1,end);
	
	for(i=0;i<26;i++)
		segtree[index][i]=segtree[index<<1][i]+segtree[index<<1|1][i];
}

void update(int index,int start,int end,int i,int pos)
{
	if(start==end)
	{
		segtree[index][a[i]]--;
		a[i]=pos;
		segtree[index][a[i]]++;
		return;
	}
	
	int mid=(start+end)>>1;
	
	if(i<=mid)
		update(index<<1,start,mid,i,pos);
	else
		update(index<<1|1,mid+1,end,i,pos);
	
	for(i=0;i<26;i++)
		segtree[index][i]=segtree[index<<1][i]+segtree[index<<1|1][i];
}

void query(int index,int start,int end,int l,int r)
{
	if(start==l && end==r)
	{
		for(i=0;i<26;i++)
			fre[i]+=segtree[index][i];
		return;
	}
	
	int mid=(start+end)>>1;
	
	if(r<=mid)
		query(index<<1,start,mid,l,r);
	else if(l>=mid+1)
		query(index<<1|1,mid+1,end,l,r);
	else
	{
		query(index<<1,start,mid,l,mid);
		query(index<<1|1,mid+1,end,mid+1,r);
	}
}

int main()
{
	fastio;
	int n,i,j,q,l,r,type,ans;
	char ch;
	
	cin>>n>>s>>q;
	
	for(i=0;i<n;i++)
		a[i]=s[i]-'a';
	
	makeSegTree(1,0,n-1);
	
	while(q--)
	{
		cin>>type;
	
		if(type==1)
		{
			cin>>l>>ch;
			update(1,0,n-1,l-1,ch-'a');
		}
		else
		{
			cin>>l>>r;
			ans=0;
			memset(fre,0,sizeof(fre));
			query(1,0,n-1,l-1,r-1);
			for(i=0;i<26;i++)
				if(fre[i])
					ans++;
			cout<<ans<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 112380
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;

public class Main {
	static ContestScanner in;
	static Writer out;
	public static void main(String[] args) {
		Main main = new Main();
		try {
			in = new ContestScanner();
			out = new Writer();
			main.solve();
			out.close();
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	void solve() throws IOException {
		int n = in.nextInt();
		int[] a = new int[n];
		long sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = in.nextInt();
			sum += a[i];
		}
		long t = 0;
		long min = Long.MAX_VALUE;
		for(int i = 0; i < n - 1; i++) {
			t += a[i];
			min = Math.min(min, Math.abs(sum - 2*t));
		}
		System.out.println(min);
	}
}

@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Integer>{
	@Override public Integer get(Object key){return containsKey(key)?super.get(key):0;}
	public void add(T key,int v){put(key,get(key)+v);}
	public void add(T key){put(key,get(key)+1);}
	public void sub(T key){final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
	public MultiSet<T> merge(MultiSet<T> set)
	{MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
	for(Entry<T,Integer>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}

class Writer extends PrintWriter{
	public Writer(String filename)throws IOException
	{super(new BufferedWriter(new FileWriter(filename)));}
	public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
	private BufferedReader in;private int c=-2;
	public ContestScanner()throws IOException 
	{in=new BufferedReader(new InputStreamReader(System.in));}
	public ContestScanner(String filename)throws IOException
	{in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
	public String nextToken()throws IOException {
		StringBuilder sb=new StringBuilder();
		while((c=in.read())!=-1&&Character.isWhitespace(c));
		while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public String readLine()throws IOException{
		StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
		while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
		return sb.toString();
	}
	public long nextLong()throws IOException,NumberFormatException
	{return Long.parseLong(nextToken());}
	public int nextInt()throws NumberFormatException,IOException
	{return(int)nextLong();}
	public double nextDouble()throws NumberFormatException,IOException 
	{return Double.parseDouble(nextToken());}
	public void close() throws IOException {in.close();}
}

Measured memory_bytes: 44708
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}

lli dp[51][51];
lli fun(lli n, lli r)
{

    double ans =1;
    if(dp[n][r] != 0)
    {
        return dp[n][r];
    }
    for(int i = 1;i<=r;i++)
    {
        ans *= n-i+1;
        ans /= i;
    }
    // cout<<n<<" "<<r<<" "<<ans<<endl;
    return dp[n][r] = ans;
}

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        int n,p;
        cin>>n>>p;
        int o = 0;
        int e = 0;
        while(n--)
        {
            int x;
            cin>>x;
            if(x%2)
                o++;
            else
                e++;
        }
        // cout<<o<<" "<<e;
        lli ans = 0;
        if(p%2)
        {
            for(int i = 1;i<=o;i+=2)
            {
                ans += fun(o,i);
            }

            ans = (lli)ans*long(pow(2,e));
            cout<<ans;        }
        else
        {
            for(int i = 0;i<=o;i+=2)
            {
                ans += fun(o,i);
            }

            ans = (lli)ans*long(pow(2,e));
            cout<<ans;
        }

    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 256
#include <stdio.h>

char s[110005];

int main(){
    scanf("%s", &s[10]);
    int len;
    int ok = 0;
    for(len=10; s[len]; len++);
    for(int i=len-1; i>=10; i--){
        if(s[i-6] == 'd' && s[i-5] == 'r' && s[i-4] == 'e' && s[i-3] == 'a' && s[i-2] == 'm' && s[i-1] == 'e' && s[i] == 'r') ok += 7, i -= 6;
        else if(s[i-4] == 'd' && s[i-3] == 'r' && s[i-2] == 'e' && s[i-1] == 'a' && s[i] == 'm') ok += 5, i -= 4;
        if(s[i-5] == 'e' && s[i-4] == 'r' && s[i-3] == 'a' && s[i-2] == 's' && s[i-1] == 'e' && s[i] == 'r') ok += 6, i -= 5;
        else if(s[i-4] == 'e' && s[i-3] == 'r' && s[i-2] == 'a' && s[i-1] == 's' && s[i] == 'e') ok += 5, i -= 4;
        
    }
    if(ok == len-10) printf("YES");
    else printf("NO");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
int main() {
	int h,w,n,a,b, i;
	long long num[10] = {};
	scanf("%d%d%d", &h,&w,&n);
	if (n > 0) {
		std::vector<std::pair<int, int>> square;
		for (i = 0; i < n; i++) {
			scanf("%d%d", &a, &b);
			if (a >= 3) {
				if (b >= 3) square.push_back(std::make_pair(a - 1, b - 1));
				if (b >= 2 && b <= w - 1) square.push_back(std::make_pair(a - 1, b));
				if (b <= w - 2) square.push_back(std::make_pair(a - 1, b + 1));
			}
			if (a >= 2 && a <= h - 1) {
				if (b >= 3) square.push_back(std::make_pair(a, b - 1));
				if (b >= 2 && b <= w - 1) square.push_back(std::make_pair(a, b));
				if (b <= w - 2) square.push_back(std::make_pair(a, b + 1));
			}
			if (a <= h - 2) {
				if (b >= 3) square.push_back(std::make_pair(a + 1, b - 1));
				if (b >= 2 && b <= w - 1) square.push_back(std::make_pair(a + 1, b));
				if (b <= w - 2) square.push_back(std::make_pair(a + 1, b + 1));
			}
		}
		std::sort(square.begin(), square.end());
		a = 1;
		for (i = 1; i < square.size(); i++) {
			if (square[i] == square[i - 1]) {
				a++;
			}
			else {
				num[a]++;
				a = 1;
			}
		}
		num[a]++;
	}
	num[0] = (long long)(h-2)*(w-2);
	for (i = 1; i < 10; i++) {
		num[0] -= num[i];
	}
	for (i = 0; i < 10; i++) {
		printf("%lld\n", num[i]);
	}
	return 0;
}

Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
 int n,m;
 cin >> n >> m;
 map<int,int> a,w;
 rep(i,m){
   int p;
   string m;
   cin >> p >> m;
   if(a[p]) continue;
   if(m == "AC") a[p]++;
   else w[p]++;
 }
 int sums = 0,sump = 0;
 for(int i = 1; i <= n; i++){
   sums+=a[i];
   if(a[i])sump+=w[i];
 }
 cout << sums << " " << sump << endl;
}

Measured memory_bytes: 12948
using System;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int kazu = int.Parse(ReadLine());
        string[] suuji = ReadLine().Split(' ');
        int[] suujii = new int[kazu];
        for(int i=0;i<kazu;i++){
            suujii[i] = int.Parse(suuji[i]);
        }
        int count = 0;
        for(int i=1;i<kazu;i++){
            if(suujii[i] == suujii[i-1]){
                suujii[i] = suujii[i-1] + 10000;
                count++;
            }
        }
        WriteLine(count);
    }
}

Measured memory_bytes: 13140
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	var n int
	var m int
	fmt.Scan(&n, &m)
	l := 1
	r := n
	for i := 0; i< m; i++ {
		line := nextLine()
		li, _ := strconv.Atoi(strings.Split(line, " ")[0])
		ri, _ := strconv.Atoi(strings.Split(line, " ")[1])
		if li > l {
			l = li
		}
		if ri < r {
			r = ri
		}
	}
	if r-l >= 0 {
		fmt.Println(r-l+1)
	} else {
		fmt.Println(0)
	}
}

Measured memory_bytes: 5504
#include <stdio.h>
#include <math.h>

long modpow(long a, long n, long mod){
	if (n == 0) {
		return 1;
	}
	long answer;
	if (n%2 == 0) {
		answer = modpow(a, n/2, mod);
		answer *= answer;
	} else {
		answer = modpow(a, n-1, mod);
		answer *= a;
	}
	answer %= mod;
	return answer;
}
long modCombination(long n, long r, long mod) {
  long answer;
  if (n-r < r) {
    r = n-r;
  }
  long nu = 1;
  long de = 1;
  for (long i = 1; i <= r; i++) {
    nu *= n+1-i;
    nu %= mod;
    de *= i;
    de %= mod;
  }
  answer = nu;
  answer *= modpow(de,mod-2,mod);
  answer %= mod;
  return answer;
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long mod = pow(10,9)+7;
  long blue_dev[k+1],red_dev[n-k+1];
  for (long i = 1; i <= k; i++) {
    blue_dev[i] = modCombination(k-1,i-1,mod);
  }
  for (long i = 1; i <= n-k; i++) {
    red_dev[i] = modCombination(n-k-1,i-1,mod);
  }
  long answer;
  for (long i = 1; i <= k; i++) {
    if (i == 1 && n-k == 0) {
      answer = 1;
    } else {
      answer = 0;
    }
    if (i-1 >= 1 && i-1 <= n-k) {
      answer += blue_dev[i]*red_dev[i-1];
      answer %= mod;
    }
    if (i >= 1 && i <= n-k) {
      answer += blue_dev[i]*red_dev[i]*2;
      answer %= mod;
    }
    if (i+1 >= 1 && i+1 <= n-k) {
      answer += blue_dev[i]*red_dev[i+1];
      answer %= mod;
    }
    printf("%ld\n", answer);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 20;
int ans[N+1][N+1];

int main(){
    for(int i=2; i<=N; ++i){
        vector<bool> vis(i+1);
        vector<int> a(i+1);
        a[0] = i;
        vis[0] = true;

        int t = 0;
        while(!vis[i-1]){
            ++t;

            vector<int> na(i+1);
            rep(j,i){
                na[j+1] += a[j]/2;
                na[0] += a[j]/2;
                na[j] += a[j]%2;

                if(!vis[j] && na[j]>0){
                    vis[j] = true;
                    ans[i][j] = t;
                }
            }

            a = na;
        }
    }

    int C = 1;
    int n,m;
    while(scanf(" %d %d", &n, &m),n) printf("Case %d: %d\n", C++, ans[n][m]);
    return 0;
}



Measured memory_bytes: 3224
def main():
    n, k = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    h.sort()
    answer = float("inf")
    for i in range(n - k + 1):
        answer = min(answer, h[i + k - 1] - h[i])
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec; typedef pair<int, int> pi;
int dd[] = { 0, 1, 0, -1, 0 };


int main()
{
	//string s = "";
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)break;
		ivec A[31];
		//??\?????????1?§?????????????????????????1?§???????
		for (int i = 1; i <= n; i++)//????????????
		{
			int f;
			cin >> f;
			for (int j = 0; j < f; j++)
			{
				int k;
				cin >> k;
				A[k].push_back(i);
			}
		}
		if (n == 1)
		{
			for (int i = 1; i < 31; i++)
			{
				if (A[i].size() > 0)
				{
					cout << i << endl;
					//s += to_string(i) + "\n";
					break;
				}
			}
			continue;
		}


		set<int> ds[100];//????????°
		for (int i = 1; i <= n; i++)
		{
			ds[i].insert(i);
		}
		int ok = 0;

		for (int k = 1; k < 31; k++)//??\?????????
		{
			set<int> today;
			for (auto i: A[k])//????????????
			{
				for (auto j : ds[i])
				{
					today.insert(j);
				}
			}
			if (today.size() == n)
			{
				cout << k << endl;
				//s += to_string(i) + "\n";
				ok = 1;
				break;
			}
			for (auto i : A[k])
			{
				ds[i] = today;
			}
		
		}
		if (!ok)
		{
			cout << -1 << endl;
			//s += to_string(-1) + "\n";
		}

	}
	
	//cout << s;

	return 0;
}

Measured memory_bytes: 3160
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: i64,
        ab: [(i64, i64); n]
    }
    let mut ab = ab;
    ab.sort();

    let mut ans = 0;
    let mut sum = 0;
    let mut i = 0;
    while sum < m {
        let n = std::cmp::min(m - sum, ab[i].1);
        sum += n;
        ans += ab[i].0 * n;
        i += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 8444
int compare(const void *a,const void *b){
    return *(int*)b-*(int*)a;
}
int main(){
    int n,i,r=0,t=1;
    int arr[999];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&arr[i]);
    qsort(arr,n,4,compare);
    for(i=0;i<n;i++){
        r+=t*arr[i];
        t=-t;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def check(a,n):
    if a == [0 for i in range(n)]:
        return False
    for i in range(n-1):
        if a[i] != 0:
            return True
    return False
n = int(input())
a = input().split()  
for i in range(n):
    a[i] = int(a[i])
a.sort()
while(check(a,n)):
    j = 0
    while(a[j] == 0):
        j += 1
    for i in range(j+1,len(a)):
        a[i] = a[i] % a[j]
    a.sort()
j = 0
while(a[j] == 0):
    j += 1
print(a[j])

Measured memory_bytes: 11172
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, k;
	cin >> n >> k;
	set<int> s;
	rep(i,k) {
		int a;
		cin >> a;
		s.insert(a);
	}
	int ans = 0;
	for (int i = n; i <= pow(10, 6); i++) {
		int t = i;
		bool b = true;
		while (t != 0) {
			if (!s.count(t % 10)) t /= 10;
			else {
				b = false;
				break;
			}
		}
		if (b) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

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

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

using namespace std;

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N >> S;
  int ans = 1;
  for (int i = 1; i < N; ++i) {
    if (S[i] != S[i - 1]) ++ans;
  }
  cout << ans << endl;
}


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

long long cnt = 0;
vector<int> G;

void insertionSort(int A[], int n, int g) {
        
    for (int i = g; i <n; i++) {
        int v = A[i];
        int j = i-g;
        
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        
        A[j+g] = v;
    }
}

void shellSort(int A[], int n) {
    int h = 1;

    while (h <= n) {
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i = G.size()-1; i >= 0; i--) {
        insertionSort(A, n, G[i]);
    }
}

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    int A[n];

    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    shellSort(A, n);

    cout << G.size() << endl;

    for (int i = G.size()-1; i > 0; i--) {
        cout << G[i] << ' ';
    }

    cout << G[0] << endl;
    cout << cnt << endl;

    for (int i = 0; i < n; i++) {
        cout << A[i] << endl;
    }


    return 0;
}



Measured memory_bytes: 7056
#include<stdio.h>
#include<iostream>
#define ll long long
using namespace std;
int main()
{
	int k,s;
	scanf("%d %d",&k,&s);
	ll int ans=0;
	int j=0;
	if(k>s)
	k=s;
	for(int i=0;i<=k;i++)
	{
		while(s-i-j>k && j<=k)
		j++;
//		printf("%d %d %d\n",i,j,s-i-j);
		if(j<=k)
		ans+=(s-i-j)-j+1;
		j=0;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

    string s;
    while (true)
    {
        getline(cin, s);
        //cout << s << endl;
        if (s == ".")
            break;
        int len = s.length();
        std::vector<char> v;
        for (int i = 0; i < len; i++)
        {
            if (s[i] == '(' || s[i] == ')' || s[i] == '[' || s[i] == ']')
            {
                v.push_back(s[i]);
            }
        }
        bool update = true;
        while (update)
        {
            update = false;
            int le = v.size();
            for (int i = 0; i < le - 1; i++)
            {
                if ((v[i] == '(' && v[i + 1] == ')') || (v[i] == '[' && v[i + 1] == ']'))
                {
                    v.erase(v.begin() + i, v.begin() + i + 2);
                    update = true;
                    i = le;
                }
            }
            //for(int i=0;i<v.size();i++) cout << v[i];
            //cout << endl;
        }
        if (v.empty())
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


Measured memory_bytes: 3120
data = [
    "{0} {1}".format(s, r)
    for s in ('S', 'H', 'C', 'D')
    for r in range(1, 13 + 1)
    ]

count = int(input())
for c in range(count):
    card = input()
    data.remove(card)

for c in data:
    print(c)

Measured memory_bytes: 7660
<?php
while(fscanf(STDIN,"%d",$v)) {
$r = 0;
for ($a = 0; $a < 10; $a++) {
   for ($b = 0; $b < 10; $b++) {
    for ($c = 0; $c < 10; $c++) {
    for ($d = 0; $d < 10; $d++) {
        if($a + $b + $c + $d == $v) {
            $r+=1;
        }
}
}
} 
}
echo $r.PHP_EOL;
}


Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double t,x;
  cin>>t>>x;

  printf("%.9f",t/x);
}


Measured memory_bytes: 256