akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int AC = 0;
        int WA = 0;
        int TLE = 0;
        int RE = 0;

        for (int i = 0; i < n; i++) {
            String check;
            check = scn.next();
            switch (check) {
                case "AC":
                    AC += 1;
                    break;
                case "WA":
                    WA += 1;
                    break;
                case "TLE":
                    TLE += 1;
                    break;
                default:
                    RE += 1;
                    break;
            }
        }

        System.out.println("AC x " + AC);
        System.out.println("WA x " + WA);
        System.out.println("TLE x " + TLE);
        System.out.println("RE x " + RE);


        scn.close();

    }


}

Measured memory_bytes: 48448
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	ll n, x, y, ans1 = 1, ans2 = 1;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x >> y;
		int f = 0, g = 0;
		if (ans1%x != 0)f++;
		if (ans2%y != 0)g++;
		ll e = max(ans1 / x + f, ans2 / y + g);
		ans1 = e * x, ans2 = e * y;
	}
	cout << ans1 + ans2 << endl;
	return 0;
}

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


signed main()
{
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 int n,k;
 cin>>n>>k;
 int arr[n];

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

  cout<<sum<<"\n";
 return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin>>H>>W;
    vector<vector<char>>s(H,vector<char>(W));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>s[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='#'){
                bool flag=false;
                if(i!=0){
                    if(s[i-1][j]=='#'){flag=true;}
                }
                if(j!=0){
                    if(s[i][j-1]=='#'){flag=true;}
                }
                if(i!=H-1){
                    if(s[i+1][j]=='#'){flag=true;}
                }
                if(j!=W-1){
                    if(s[i][j+1]=='#'){flag=true;}
                }
                if(flag==false){cout<<"No"<<endl;exit(0);}
            }
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int ans[1000000];

int main(){
  for(int i=2;i<=999999;i++){
    ans[i]=ans[i-1];
    for(int j=2;j<=sqrt(i);j++){
      if(i%j==0)goto f;
    }
    ans[i]++;
    f:;
  }
  while(cin>>n){
    cout<<ans[n]<<endl;
  }

  return 0;
}



Measured memory_bytes: 6992
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int n;

int search(int num, int a[20000]){
	int ref = a[num];
	int ans = 0;
	for(int i = 1; i <= 3; i++){
		a[num] = i;
		int ind1 = num;
		int ind2 = num;
		int ind1_p = ind1;
		int ind2_p = ind2;
		while(true){
			if(ind1 < 0 || ind2 > n - 1){
				break;
			}
			if(a[ind1] != a[ind2]){
				break;
			}
			int cnt = 2;
			if(ind1 == ind2){
				cnt--;
			}
			while(ind1 > 0 && a[ind1] == a[ind1 - 1]){
				ind1--;
				cnt++;
			}
			while(ind2 < n - 1 && a[ind2] == a[ind2 + 1]){
				ind2++;
				cnt++;
			}
			if(cnt < 4){
				break;
			}
			ind1_p = ind1;
			ind2_p = ind2;
			ind1--;
			ind2++;
		}
		//cout << num << " " << i << " " << ind1_p << " " << ind2_p << endl;
		ans = max(ans, ind2_p - ind1_p + 1);
	}
	a[num] = ref;
	if(ans < 4){
		ans = 0;
	}
	return ans;
}

int main(){
	
	int a[20000];
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		int ans = 0;
		for(int i = 0; i < n; i++){
			ans = max(ans, search(i, a));
		}
		cout << n - ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3136
// C++ 14
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)

using namespace std;

#define MAX_N 10000
#define MAX_Q 100000

#define UNITE 0
#define SAME 1

Int ds_rank[MAX_N];
Int parent[MAX_N];


Int root(Int x) {
    if (x != parent[x]) {
        parent[x] = root(parent[x]);
    }
    
    return parent[x];
}

void unite(Int x, Int y) {
    Int x_root = root(x), y_root = root(y);
    
    if (ds_rank[x_root] > ds_rank[y_root]) {
        parent[y_root] = x_root;
    } else {
        parent[x_root] = y_root;
        if (ds_rank[x_root] == ds_rank[y_root]) ds_rank[y_root]++;
    }
}

bool same(Int x, Int y) {
    return root(x) == root(y);
}

int main(void) {
    int n, q, com, x, y;
    cin >> n >> q;
    
    loop(i,0,n) ds_rank[i] = 0, parent[i] = i;
    
    loop(i,0,q) {
        cin >> com >> x >> y;
        if (com == UNITE) unite(x, y);
        else {
            if (same(x, y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
long long const inf = 1e18, linf = 2e9, mod = 1e9+7;
int const mxn = 4e5+10;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

string rev(string s){
	string b = "" ; 
	for (int i = s.size()-1 ; i >= 0; i--){
		b+=s[i];
	}
	return b ; 
	
}



int main(){
	string s , s1; 
	cin>>s;
	int n = s.size();
	int f = (n-1)/2 - 1; 
	int f2 = (n+3)/2 - 1; 
	s1="";
	for (int i = 0 ; i <=f ; i++ )
		s1+=s[i];
	if (s1!=rev(s1)){
		cout<<"No";
		return  0 ; 
	}
	for (int i = f2 ; i<n;i++)
		s1+=s[i];
	if (s1!=rev(s1)){
		cout<<"No";
		return 0 ;
	}
	if (s!=rev(s)){
		cout<<"No";
		return 0 ;
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=1
m=10**18
flag=False
for i in range(N):
    if A[i]==0:
        print(0)
        exit()
for i in range(N):
    ans*=A[i]
    if ans>m:
        print(-1)
        exit()

print(ans)

Measured memory_bytes: 21652
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimization ("unroll-loops")
#define int ll
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii = pair<int, int>;
using ppp = pair<int , pii>;
const int MOD = 1000000007;
int t1, t2, a1, a2, b1, b2;
int lena, lenb;
int32_t main()
{
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	lena = (t1*a1 + t2*a2);
	lenb = (t1*b1 + t2*b2);
	if (lena == lenb)
	{
		cout << "infinity\n";
		return 0;
	}
	if ((a1 > b1 && a2 > b2) || (a1 < b1 && a2 < b2))
	{
		cout << "0\n";
		return 0;
	}
	if ((lena > lenb && a1 > b1) || (lena < lenb && a1 < b1))
	{
		cout << "0\n";
		return 0;
	}
	if (b1 > a1)
	{
		swap(a1, b1);
		swap(a2, b2);
		swap(lena, lenb);
	}
	int gap = (t1*a1 - t1*b1);
	int take = (t2*b2 - t2*a2);
	//printf("Gap = %lld, take = %lld\n",gap,take);
	int loss = take-gap;
	cout << (gap/loss)*2 + (gap%loss==0?0:1) << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b,c;
  cin>>n;
  vector<ll> vec(9);
  for(ll i=0;i<9;i++){
    vec.at(i)=i+1;
  }
  ll count=9;
  ll j=0;
  if(n<=9){
    cout<<n<<endl;
  }else{
  while(count<n){
    if(vec.at(j)%10!=0){a=10*vec.at(j)+vec.at(j)%10-1;vec.push_back(a);count+=1;}
    if(count==n){cout<<a<<endl;break;}
    b=10*vec.at(j)+vec.at(j)%10;vec.push_back(b);count+=1;
    if(count==n){cout<<b<<endl;break;}
    if(vec.at(j)%10!=9){c=10*vec.at(j)+vec.at(j)%10+1;vec.push_back(c);count+=1;}
    if(count==n){cout<<c<<endl;break;}
    j++;
  }
  }
}

Measured memory_bytes: 1464
#include <stdio.h>
#include <string.h>
int main(){
  char line[1000000];
  int n,m;

  /*  */
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d %d", &n, &m);
  int A[n][m];
  int b[m];
  int i, j;
  char *str_ptr;
  int tmp=0;
  //配列Aへの格納
  for(i=0; i<n; ++i){
	fgets(line, sizeof(line), stdin);
	str_ptr=strtok(line, " ");
	sscanf(str_ptr, "%d", &A[i][0]);
	for(j=1; j<m; ++j){
	  if(str_ptr==NULL)
		break;
	  str_ptr=strtok(NULL, " ");
	  sscanf(str_ptr, "%d", &A[i][j]);
	}
  }
  /* ベクトルbの読み込み */
  for(j=0; j<m; ++j){
	fgets(line, sizeof(line),stdin);
	sscanf(line, "%d", &b[j]);
  }
  
  for(i=0; i<n; ++i){
	for(j=0; j<m; ++j){
	  tmp+=A[i][j]*b[j];
	}
	printf("%d\n", tmp);
	tmp=0;
  }

  return 0;
}



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

bool solve(int h,int w){
  
  vector<vector<char>> data(h+2,vector<char>(w+2));
  for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      cin >> data.at(i).at(j);
    }
  }
 
  
   for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
      if(data.at(i).at(j) == '#'){     
          if (data.at(i-1).at(j) !='#' && data.at(i).at(j-1) !='#' && 
               data.at(i+1).at(j) !='#' && data.at(i).at(j+1) !='#' )
              return false;
            }
       
      }
    }
  return true ;
}
            
  

int main() {
  int H , W ;
  cin >> H >> W ;
 
  
  if(solve(H,W))
    cout << "Yes";
  else 
    cout << "No";
  
  
}


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

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

    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    long long ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += p[i];
    }
    cout << ans << endl;
}


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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	cin >> n ;
	int CMAX=100/4;
	int DMAX=100/7;
	bool a = true;
	bool b =false;
	for(int i = 0 ; i <= CMAX;i++){
	  for(int j = 0 ;j <= DMAX;j++){
		int k = 4*i+7*j;
		if(k==n){
			cout<<"Yes"<<endl;
			a =false;
			b = true;
			break;
		  }

		}
		  if(b){
			break;
			}
	}
	if(a){
		cout<<"No"<<endl;
	  }
  }




Measured memory_bytes: 256
import math

l = [int(input()) for _ in range(5)]
q = []
for i in l:
    if 10 - (i % 10) != 10:
        q.append(10 - (i % 10))
    else:
        q.append(0)
total = 0
for i in l:
    total += math.ceil(i / 10) * 10
print(total - max(q))

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
a.sort()
cnt = [0 for i in range(100)]
for i in range(n):
    cnt[a[i]//400] += 1
mi = max(1, sum([1 if cnt[i]>0 else 0 for i in range(8)]))
ma = sum([1 if cnt[i]>0 else 0 for i in range(8)]) + sum(cnt[8:])
print(mi, ma)


Measured memory_bytes: 3064
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();

		int x3 = x2 + y1 - y2;
		int y3 = y2 + x2 - x1;

		int x4 = x3 + y2 - y3;
		int y4 = y3 + x3 - x2;

		System.out.println(x3+" "+y3+" "+x4+" "+y4);

	}


}

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

int main() {
  int A, B, sum, w5, w4, w3, w2, w1;
  cin >> A >> B;
  sum = 0;
  for (int i = A; i <= B; i++){
    w5 = i/10000;
    w4 = (i - w5*10000)/1000;
    w3 = (i - w5*10000 - w4*1000)/100;
    w2 = (i - w5*10000 - w4*1000 - w3*100)/10;
    w1 = (i - w5*10000 - w4*1000 - w3*100 - w2*10);
    if (w4 - w2 == 0 && w5 - w1 ==0){
      sum++;
    }
  }
   cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string str;
   ll i,k;
    cin>>str>>k;
  ll sz=str.size();
    if(sz==1) cout<<str[0]<<endl;
    else{
     if(str[0]!='1') cout<<str[0]<<endl;
     else if(str[0]=='1'){
 
       ll  cnt=0;
         for(i=1;i<sz;i++)
         {
             if(str[i]!='1')
                {
                    cnt=i;
                     break;
                }
         }
         if(k<=cnt) cout<<1<<endl;
         else cout<<str[cnt]<<endl;
     }
     }
 
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int count=0;
		for(int i=a;i<=b;i++) {
			if(c%i==0) {
				count+=1;
			}
		}
	System.out.println(count);
	}
}



Measured memory_bytes: 26416
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

int main(void) {

int N ;
scanf("%d",&N);
int array[N+1];
array[1]=1;

int count[N+1];

memset(count,0,sizeof(count[0])* (N+1));

for (int i = 2;i<=N;i++)
{
    scanf("%d",&array[i]);
    count[array[i]]++;
}
for (int i = 1 ; i<=N;i++)
{
printf("%d\n",count[i]);
}



 return EXIT_SUCCESS;
}



Measured memory_bytes: 3288
def main():
    n, l =map(int, input().split())
    taste = []
    for i in range(n):
        taste.append(i+l)

    #print(taste)
    abs_taste = []
    for i in taste:
        abs_taste.append(abs(i))

    m = abs_taste.index(min(abs_taste))
    #print(m)
    taste.pop(m)
    #print(taste)

    print(sum(taste))

main()

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

#define int long long
using namespace std;

string s;
char a[100] = { 'k','e','y','e','n','c','e' };
int b[110];


signed main()
{
	int x = 0;
	cin >> s;
	bool flag;
	flag = false;
	/*
	for (int i = 0; i < s.length(); i++) {
		if (a[x] == s[i] && x == i) {
			x++;
		}
	}*/
	int i = 0;
	int y = 0;
	while(true) {
		if (x >= 7) {
			break;
		}
		if (!flag) {
			if (a[x] == s[i]) {
				i++;
				x++;
			}
			else {
				i = s.length() - 1;
				flag = true;
				y = x;
			}
		}
		else {
			if (a[6 - x + y] == s[i]) {
				//cout << a[6 - x + y] << s[i] << endl;
				i--;
				x++;
				
			}
			else {
				//cout << a[6 - x + y] << s[i] << endl;
				break;
			}
		}
	}
	if (x >= 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
struct RUP{
  int n;
  vector<P> dat;
  RUP(){}
  RUP(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1);
    for(int i=0;i<2*n-1;i++) dat[i].first=-1,dat[i].second=INT_MAX;
  }
  int query(int k){
    k+=n-1;
    P p=dat[k];
    while(k>0){
      k=(k-1)/2;
      p=max(p,dat[k]);
    }
    return p.second;
  }
  void update(int a,int b,P p,int k,int l,int r){
    if(r<=a||b<=l) return;
    if(a<=l&&r<=b) {
      dat[k]=p;
    }else{
      update(a,b,p,k*2+1,l,(l+r)/2);
      update(a,b,p,k*2+2,(l+r)/2,r);
    }
  }
  
  void update(int a,int b,P p){
    update(a,b,p,0,0,n);
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  RUP rup(n);
  for(int i=0;i<q;i++){
    int f;
    cin>>f;
    if(!f){
      int s,t,x;
      cin>>s>>t>>x;
      rup.update(s,t+1,P(i,x));
    }else{
      int u;
      cin>>u;
      cout<<rup.query(u)<<endl;
    }
  }
  return 0;
}

/*
verified on 2017/02/24
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_D
*/

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

void main()
{
    auto S = readln.chomp;
    for (;;) {
        if (S.empty) break;
        if (S.length >= 2 && S[0..2] == "hi") {
            S = S[2..$];
        } else {
            writeln("No");
            return;
        }
    }
    writeln("Yes");
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n,m;
    cin >> n >> m;
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    vector<ll>a(m);
    rep(i,m){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll ans = a.back()-a.front();
    int t = n-1;
    priority_queue<ll>pq;
    rep(i,m-1){
        pq.push(a[i+1]-a[i]);
    }
    rep(i,t){
        ll x = pq.top();
        pq.pop();
        ans -= x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
package main

import "fmt"

func main(){
	var n[32] int = [32]int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	var k int
	fmt.Scan(&k)
	fmt.Println(n[k-1])
}


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

int main() {
  int a,b;
  cin>>a>>b;
  int cnt = 1;
  int tmp = a;
  while (a < b) {
    cnt++;
    a -= 1;
    a+=tmp;
  }
  if (b == 1) cnt=0;
  cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
enum POSITION{CLOCKWISE, COUNTER_CLOCKWISE, ONLINE_BACK,
              ONLINE_FRONT, ON_SEGMENT};
struct Point{
    double x;
    double y;
    Point(double x, double y) : x(x), y(y){}
    Point operator-(Point p){
        return Point(x - p.x, y - p.y);
    }
};
typedef Point Vector;
double get_cross(Vector v1, Vector v2){
    return v1.x * v2.y - v1.y * v2.x;
}
double get_dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}
struct Segment{
    Point p1;
    Point p2;
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
POSITION get_position(Point p, Segment s){
    Vector base = s.p2 - s.p1;
    Vector obj  = p    - s.p1;
    double cross = get_cross(base, obj);
    if (cross >  1e-10) return CLOCKWISE;
    if (cross < -1e-10) return COUNTER_CLOCKWISE;
    if (get_dot(base, obj) < 0) return ONLINE_BACK;
    if (get_dot(base, base) < get_dot(obj, obj)) return ONLINE_FRONT;
    return ON_SEGMENT;
}
bool is_intersection(Segment s1, Segment s2){
    POSITION s2p1_s1 = get_position(s2.p1, s1);
    POSITION s2p2_s1 = get_position(s2.p2, s1);
    POSITION s1p1_s2 = get_position(s1.p1, s2);
    POSITION s1p2_s2 = get_position(s1.p2, s2);
    if (s2p1_s1 == ON_SEGMENT || s2p2_s1 == ON_SEGMENT) return true;
    if (s1p1_s2 == ON_SEGMENT || s1p2_s2 == ON_SEGMENT) return true;
    if (s2p1_s1 == ONLINE_FRONT) {
        if (s2p2_s1 == ONLINE_BACK) return true;
        return false;
    }
    if (s2p1_s1 == ONLINE_BACK) {
        if (s2p2_s1 == ONLINE_FRONT) return true;
        return false;
    }
    if (s2p1_s1 != s2p2_s1 && s1p1_s2 != s1p2_s2) return true;
    return false;
}

int main(){
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3;
        cin >> x_p0 >> y_p0 >> x_p1 >> y_p1;
        cin >> x_p2 >> y_p2 >> x_p3 >> y_p3;
        Point p0(x_p0, y_p0);
        Point p1(x_p1, y_p1);
        Point p2(x_p2, y_p2);
        Point p3(x_p3, y_p3);
        Segment s1(p0, p1);
        Segment s2(p2, p3);
        int ans = 0;
        if (is_intersection(s1, s2)) ans = 1;
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

int main() {
    ll N, K;
    cin >> N >> K;
    V<ll> v(N);
    for(ll &e : v) cin >> e;

    ll ans = -inf;
    for(ll left = 0; left <= min(N, K); left++) {
        for(ll right = 0; left + right <= min(N, K); right++) {
            V<ll> vlis;
            for(ll i = 0; i < left; i++) vlis.push_back(v[i]);
            for(ll i = 0; i < right; i++) vlis.push_back(v[N - 1 - i]);
            sort(ALLR(vlis));
            ll rest = K - (left + right);
            for(ll r = 0; r < rest; r++) {
                if(vlis.empty()) break;
                if(vlis.back() >= 0) break;
                vlis.pop_back();
            }
            ll tmp = accumulate(ALL(vlis), 0ll);
            chmax(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
  	char[] n;
  	int d, l;
  	long mod = (long)1e9+7, tot;
  	long[][][] dp;
  
    Main(Scanner in, PrintWriter out)
    {
      n = in.next().toCharArray();
      d = in.nextInt();
      dp = new long[2][d][l = n.length];
      for (int i = 0; i < 2; i++)
        for (int j = 0; j < d; j++)
          Arrays.fill(dp[i][j], -1L);
      tot = dp(1, 0, 0);
      if (tot == 0) tot = mod;
      out.println(tot-1);
    }
  
  	long dp(int b, int s, int at)
    {
      if (s >= d) s %= d;
      if (at == l) return s == 0 ? 1L : 0L;
      if (dp[b][s][at] != -1L) return dp[b][s][at];
      
      long ans = 0L;
      int up = b == 1 ? n[at]-'1' : 9;
      if (b == 1)
        ans += dp(1, s+n[at]-'0', at+1);
      for (int i = 0; i <= up; i++)
        ans += dp(0, s+i, at+1);
      return dp[b][s][at] = ans % mod;
    }
	
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		new	Main(in, out);
		out.close();
	} 
}


Measured memory_bytes: 53064
import fractions

A, B, C, D = map(int, input().split())

def cantdivide(num, d1, d2):
  def lcm(num1, num2):
    return int(num1 * num2 / fractions.gcd(num1, num2))
  
  return num - (num//d1) - (num//d2) + (num//lcm(d1,d2))
  
ans = cantdivide(B, C, D) - cantdivide((A-1), C, D)

print(ans)

Measured memory_bytes: 5048
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

typedef long long ll;

using namespace std;
int main() {
    char i;
    cin >> i;
    char r;
    if (i == 'A'){
        r = 'T';
    }else if (i == 'T'){
        r = 'A';
    }else if (i == 'C'){
        r = 'G';
    }else if (i == 'G'){
        r = 'C';
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());
  
  vector<int> sum;
  rep(i,x) sum.push_back(p[i]);
  rep(i,y) sum.push_back(q[i]);
  rep(i,c) sum.push_back(r[i]);
  sort(sum.rbegin(), sum.rend());
  
  ll ans = 0;
  rep(i, x+y) ans += sum[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define arep(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef pair<string, bool> P;

vector<string> padding(vector<string> S, char pad_char) {
    rep(i, 0, S.size()) {
        rep(j, 0, S[i].size()) {
            if (S[i][j] == '?') S[i][j] = pad_char;
        }
    }
    return S;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i, 0, N) cin >> S[i];
    string T;
    cin >> T;
    // a
    vector<string> sa = padding(S, 'a');
    sa.push_back(T);
    sort(all(sa));
    int last_pos = -1;
    rep(i, 0, N + 1) {
        if (sa[i] == T) last_pos = max(last_pos, i);
    }
    // z
    vector<string> sz = padding(S, 'z');
    sz.push_back(T);
    sort(all(sz));
    int start_pos = -1;
    rep(i, 0, N + 1) {
        if (sz[i] == T) {
            start_pos = i;
            break;
        }
    }
    rep(i, start_pos, last_pos + 1) cout << i + 1 << " \n"[i == last_pos];
    return 0;
}

Measured memory_bytes: 2048
N=int(input())
A=list(map(int,input().split()))

B=[bin(A[i]) for i in range(N)]

ANS=1000

for i in range(N):
    count=0
    for j in range(1,100):

        if B[i][-j]=="0":
            count+=1
        else:
            break

    #print(count)

    if ANS>count:
        ANS=count



print(ANS)

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Combination{
	vector<ll> fac,finv,inv;
public:
	Combination(ll N){
		fac.resize(N+1);
		finv.resize(N+1);
		inv.resize(N+1);
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for(int i=2;i<=N;i++){
			fac[i] = fac[i-1] * i % atcoder_mod;
			inv[i] = atcoder_mod - inv[atcoder_mod%i] * (atcoder_mod/i) % atcoder_mod;
			finv[i] = finv[i-1] * inv[i] % atcoder_mod;
		}
	}
	ll Caluclation(ll n,ll r){
		if(n < r) return 0;
		if (n < 0 || r < 0) return 0;
		return fac[n] * (finv[r] * finv[n-r] % atcoder_mod) % atcoder_mod;
	}
	ll GetFInv(ll i){
		return finv[i];
	}

};
ll powermod(ll a,ll b,ll m){
	if(b==0){
		return 1LL;
	}
	if(b%2){
		return (a*powermod(a,b-1LL,m))%m;
	}
	return powermod((a*a)%m,b/2LL,m);
}
ll BallBoxCombination9(ll n,ll k){
	ll sum = 0;
	Combination comb(k);
	for(ll i=1;i<=k;i++){
		ll C = comb.Caluclation(k,i)%atcoder_mod;
		ll P = powermod(i,n,atcoder_mod)%atcoder_mod;
		ll V = (C*P)%atcoder_mod;
		if((k-i)%2){
			sum = (sum-V+atcoder_mod)%atcoder_mod;
		}
		else sum = (sum+V)%atcoder_mod;
	}
	return sum*comb.GetFInv(k)%atcoder_mod;
}

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

	ll N=in<ll>(),K=in<ll>();
	
	ll ans = BallBoxCombination9(N,K);
	out(ans);
	return 0;
}



Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
void Calc(){
	int A = rei();
	int B = rei();
	int C = rei();
	if(A == B && B == C){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

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

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

#define pb push_back
#define mp make_pair

const int N = 2e5 + 10;

int n, a, b, c, d;
char s[N];

bool ok(){
    if(c < d){
        swap(a, b);
        swap(c, d);
    }
    a--;
    b--;
    c--;
    d--;

    while(a < c){
        if(s[a+1] == '.'){
            if(a + 1 != b){
                a++;
            } else if(s[a+2] == '.'){
                a+=2;
            } else if(s[b+2] == '.'){
                b+=2;
                a++;
            } else {
                return 0;
            }
        } else if(s[a+2] == '.'){
            if(a + 2 != b){
                a += 2;
            } else if(s[b+1] == '.'){
                b++;
                a += 2;
            } else if(s[b+2] == '.'){
                b += 2;
                a += 2;
            } else {
                return 0;
            }
        } else {
            return 0;
        }
    }
    if(a > c || b > d)  return 0;
    while(b < d){
        if(s[b+1] == '.')   b++;
        else if(s[b+2] == '.')  b+=2;
        else    return 0;
    }
    return b == d;
}

int main(){
    while(~scanf("%d %d %d %d %d", &n, &a, &b, &c, &d)){
        scanf("%s", s);
        puts(ok()?"Yes":"No");
    }
    return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<P> pos, neg;
  int total = 0;
  rep(i, n) {
    string s; cin >> s;
    int res = 0, min = 0;
    for(auto c : s) {
      if(c == '(') ++res;
      else --res;
      chmin(min, res);
    }
    total += res;
    if(res >= 0) pos.emplace_back(min, res);
    else neg.emplace_back(min-res, -res);
  }
  sort(RALL(pos));
  sort(RALL(neg));

  auto check = [&](vector<P> vec) {
    int now = 0;
    for(auto x : vec) {
      if(now+x.first < 0) return false;
      now += x.second;
    }
    return true;
  };

  if(total == 0 && check(pos) && check(neg)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 18820
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    stack<int> sta;
    for(int i=0;i<s.size();i++){
        if(s[i]=='B'){
            sta.push(s.size()-i-1);
        }
    }
    long long ans=0;
    int a=0;
    while(!sta.empty()){
        ans+=sta.top()-a;
        sta.pop();
        a++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 1284
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w;
	int ans=0;
	cin >>h>>w;
	vector<string> s(h);
	input(s);
	rep(i, w + 2) { cout << "#"; }
	cout << endl;
	rep(i, h) { cout << "#" << s[i] << "#" << endl; }
	rep(i, w + 2) { cout << "#"; }
	cout << endl;
	
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

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

int main(){
    fast_io

    string s;
    cin>>s;
    int n=s.size();

    int one=0;
    int zero=0;

    rep(i,n){
        if(s[i]=='0') zero++;
        else one++;
    }
    cout<<2*min(zero, one)<<endl;
    return 0;
}

Measured memory_bytes: 512
from collections import Counter as C
n,*a=map(int,open(0).read().split())
a=C([a[i]-i-1 for i in range(n)])
a=sorted(a.items(),key=lambda x:x[0])
s=0
b=0
ans=0
for i in a:
  s+=i[1]
for i in a[::-1]:
  s-=2*i[1]
  if s<0:
    b=i[0]
    break
for i in a:
  ans+=i[1]*abs(i[0]-b)
print(ans)

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

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

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

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

    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; ++i){
        string s = to_string(i);
        if(s.size()%2 == 1) ++ans;
    }

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

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())
SP = [stdin.readline().rstrip().split() for _ in range(N)]
for i in range(N):
    SP[i].append(i+1)
    SP[i][1] = int(SP[i][1]) * -1

SP.sort(key=lambda x: (x[0], x[1]))

for i in range(N):
    print(SP[i][2])


Measured memory_bytes: 66156
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

vector<int> divisor(int n) {
	vector<int> res;
	for(int i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			res.push_back(i);
			if(i != n / i) res.push_back(n / i);
		}
	}
	return res;
}

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

	int N, M;
	cin >> N >> M;

	vector<int> d = divisor(M);
	vsort_r(d);
	rep(i, 0, d.size()) {
		if(M / N >= d[i]) {
			cout << d[i] << endl;
			return 0;
		}
	}

}


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

using namespace std;

#define mod 1000000007LL

struct line {
	long long int to, co, price, time;
};

int main() {
	long long int N, M, H, K;
	while( cin >> N >> M >> H >> K, N || M || H || K ) {
		vector<vector<line>>D( N );
		for( size_t i = 0; i < M; i++ ) {
			long long int a, b, c, h, r;
			cin >> a >> b >> c >> h >> r;
			a--; b--; r--;
			line val;
			val.to = b;
			val.price = c;
			val.time = h;
			val.co = r;
			D[a].push_back( val );
			val.to = a;
			D[b].push_back( val );
		}
		long long int S, T;
		cin >> S >> T;
		S--; T--;
		vector<long long int>ans1( 256, LLONG_MAX / 6 );
		for( int ticket = 0; ticket < 256; ticket++ ) {
			vector<vector<long long int>>dp( N, vector<long long int>( H + 1, LLONG_MAX / 6 ) );
			dp[S] = vector<long long int>( H + 1, 0 );
			priority_queue< pair<long long int, pair<long long int, long long int>>, vector < pair<long long int, pair<long long int, long long int>>>, greater<pair<long long int, pair<long long int, long long int>>>>que;
			que.push( make_pair( 0, make_pair( S, 0 ) ) );
			while( que.size() ) {
				auto now = que.top(); que.pop();
				if( now.second.first == T ) {
					ans1[ticket] = now.first;
					break;
				}
				if( dp[now.second.first][now.second.second] < now.first ) {
					continue;
				}
				long long int memo = now.first;
				for( long long int i = now.second.second; i < H + 1; i++ ) {
					if( memo > dp[now.second.first][i] ) {
						memo = dp[now.second.first][i];
					}
					dp[now.second.first][i] = memo;
				}
				for( auto x : D[now.second.first] ) {
					if( now.second.second + x.time <= H && ( dp[x.to][now.second.second + x.time] > ( ( ticket&( 1LL << x.co ) ) ? 0 : x.price ) + now.first ) ) {
						dp[x.to][now.second.second + x.time] = ( ( ticket&( 1LL << x.co ) ) ? 0 : x.price ) + now.first;
						que.push( make_pair( dp[x.to][now.second.second + x.time], make_pair( x.to, now.second.second + x.time ) ) );
					}
				}
			}
		}

		vector<long long int>ans2( 256, LLONG_MAX / 6 );
		ans2[0] = 0;
		long long int P;
		cin >> P;
		for( size_t i = 0; i < P; i++ ) {
			long long int l, d;
			cin >> l >> d;
			long long int use = 0;
			for( size_t i = 0; i < l; i++ ) {
				long long int k;
				cin >> k;
				k--;
				use |= 1LL << k;
			}
			for( long long int j = 0; j < 256; j++ ) {
				ans2[use | j] = min( ans2[use | j], ans2[j] + d );
			}
		}
		long long int ans = LLONG_MAX / 6;
		for( size_t i = 0; i < 256; i++ ) {
			ans = min( ans1[i] + ans2[i], ans );
		}
		if( ans == LLONG_MAX / 6 ) {
			ans = -1;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3272
#include <iostream>
#include <string>
using std::string;
using namespace std;
int main()
{
string s;
int total=1;
cin>>s;
string str[4];
str[1]="Sunny";
str[2]="Cloudy";
str[3]="Rainy";
if(s==str[1])
   cout<<str[2];
if(s==str[2])
   cout<<str[3];
if(s==str[3])
   cout<<str[1];

}


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

int main(){
  string S;
  cin >> S;
  int count=0,answer=0;
  for(int i=0; i<=S.size(); i++){
    if(i==S.size()){
      answer=max(answer,count);
    }
    else if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      count++;
    }
    else{
      answer=max(answer,count);
      count=0;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        x: f64,
    }

    let mut amount: f64 = 100.0;
    let mut year: u64 = 0;

    loop {
        amount = (amount * 1.01).floor();
        year += 1;
        if amount >= x {
            break;
        }
    }

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


Measured memory_bytes: 2708
#include<stdio.h>
int main(){
    int i,text,a,b;
    
    while(scanf("%d",&a)!=EOF){
        scanf("%d",&b);
          i=1;
          a+=b;
          
          while(a>=10){
              a/=10;
              i++;
          } 
    
        printf("%d\n",i);
        
    } 
    
    return 0; 
    
} 


Measured memory_bytes: 2100
N,T=map(int,input().split())
Tn=list(map(int,input().split()))
Tn.append(float('inf'))
ans=0
now=0
for t in Tn:
    if t-now<T:
        ans+=t-now
    elif t-now>=T:
        ans+=T
    now=t
print(ans)

Measured memory_bytes: 26708
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		for(int i = 0; i < N; i++){
			Point2D[] points = new Point2D[3];
			for(int j = 0; j < 3; j++){
				points[j] = new Point2D(sc.nextInt(), sc.nextInt());
			}
			
			Point2D start = new Point2D(sc.nextInt(), sc.nextInt());
			Point2D end = new Point2D(sc.nextInt(), sc.nextInt());
			
			int count = 0;
			
			for(int j = 0; j < 3; j++){
				int next = j + 1 >= 3 ? 0 : j + 1;
				
				if(Point2D.intersect_s(points[j], points[next], start, end)){
					count++;
				}
			}
			
			System.out.println(count % 2 == 0 ? "NG" : "OK");
		}

	}

}

class Point2D {
	public double x;
	public double y;
	
	public static final double EPS = 1e-10;
	
	public Point2D(double x, double y){
		this.x = x;
		this.y = y;
	}
	
	public Point2D(Point2D point){
		this.x = point.x;
		this.y = point.y;
	}
	
	public Point2D add(double x, double y){
		return new Point2D(this.x + x, this.y + y);
	}
	
	public Point2D sub(double x, double y){
		return add(-x, -y);
	}
	
	public Point2D add(Point2D another){
		return add(another.x, another.y);
	}
	
	public Point2D sub(Point2D another){
		return sub(another.x, another.y);
	}
	
	public Point2D mul(double d){
		return new Point2D(this.x * d, this.y * d);
	}
	
	public Point2D div(double d){
		return new Point2D(this.x / d, this.y / d);
	}
	
	public double dot(double x, double y){
		return this.x * x + this.y * y; 
	}
	
	public double dot(Point2D another){
		return dot(another.x, another.y);
	}
	
	public double cross(double x, double y){
		return this.x * y - this.y * x; 
	}
	
	public double cross(Point2D another){
		return cross(another.x, another.y);
	}
	
	public double dist(double x, double y){
		return Math.sqrt((this.x - x)*(this.x - x) + (this.y - y) * (this.y * y));
	}
	
	public double dist(Point2D another){
		return dist(another.x, another.y);
	}
	
	public double dist_o(){
		return dist(0, 0);
	}
	
	public Point2D unit(){
		return div(dist_o());
	}
	
	public boolean pol(Point2D start, Point2D end){
		return end.sub(start).cross(this.sub(start)) < EPS;
	}
	
	public boolean pos(Point2D start, Point2D end){
		return (start.dist(this) + this.dist(end) < start.dist(end) + EPS);
	}
	
	public double psd(Point2D start, Point2D end){
		if(end.sub(start).dot(this.sub(start)) < EPS){
			return this.dist(start);
		}else if(start.sub(end).dot(this.sub(end)) < EPS){
			return this.dist(end);
		}else{
			return end.sub(start).cross(this.sub(start)) / end.dist(start);
		}
	}
	
	public static boolean intersect_s(Point2D a1, Point2D a2, Point2D b1, Point2D b2){
		return (a2.sub(a1).cross(b1.sub(a1)) * a2.sub(a1).cross(b2.sub(a1)) < EPS) && (b2.sub(b1).cross(a1.sub(b1)) * b2.sub(b1).cross(a2.sub(b1)) < EPS);
	}
	
	public static Point2D interpoint_s(Point2D a1, Point2D a2, Point2D b1, Point2D b2){
		Point2D b = b2.sub(b1);
		double d1 = Math.abs(b.cross(a1.sub(b1)));
		double d2 = Math.abs(b.cross(a2.sub(b1)));
		double t = d1 / (d1 + d2);
		Point2D a = a2.sub(a1), v = a.mul(t);
		return a1.add(v);
	}
	
}

Measured memory_bytes: 12000