akhauriyash/Code-Regression huggingface dataset:
// YOU THINK YOU KNOW ME.//


#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int                      long long
#define MOD                     1000000007
#define inf                     9e18
#define ld                      long double
#define countbit                __builtin_popcount
#define loop(i,a,n)				for(int i=a;i<n;i++)
#define pb                      push_back
#define pf                      push_front
#define mp                      make_pair
#define f                       first
#define s                       second
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define boost                   ios_base::sync_with_stdio();cin.tie(0);cout.tie(0);
#define cases                   int tests;cin>>tests;while(tests--)
#define all(s)                  s.begin(),s.end()
#define line                    cout<<endl;
#define watch(x)                cout<<(#x)<<" is "<<x<<endl
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rich_set;
bool isprime(int n){if(n==1)return false;if(n==2)return true;for(int i=2;i<=sqrt(n);i++){if(n%i==0){ return false;}}return true;}
int poww(int b,int e){if(e==0)return 1;else if(e%2==0){int a=pow(b,e/2);return a*a;}else {int a=pow(b,e/2);return b*a*a;}}
int powm(int x,int y,int m=MOD){x=x%m;int res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
int modInverse(int a, int m=MOD) { return powm(a, m-2, m);}
void print(vector<int>v){for(int i=0;i<v.size();i++){cout<<v[i]<<" ";}}
void print(int arr[]){int size = *(&arr + 1) - arr; for(int i=0;i<size;i++){cout<<arr[i]<<" ";}}
string to_bin(int n){string res="";int i=0;while(n>0){if(n%2==1){res=res+'1';}else{res=res+'0';}n/=2;i++;}reverse(all(res));return res;}
int to_dec(string s){int n=s.size(),ans=0,temp=1;for(int i=n-1; i>=0; i--){int x=s[i]-'0';ans+=x*temp;temp*=2;}return ans;}
void result(bool f){if(f)cout<<"YES"<<endl;else cout<<"NO"<<endl;}



void solve(){
	int n;
    cin>>n;
    int w;
    cin>>w;
    int wt[n+1]={0};
    int val[n+1]={0};
    int sum=0;
    loop(i,1,n+1){
        cin>>wt[i]>>val[i];
        sum+=val[i];
    }
    int dp[100005]={10000000000};
    loop(i,0,100005)dp[i]=1e10;
    dp[0]=0;
    loop(i,1,n+1){
        for(int j=sum;j>=val[i];j--){
            dp[j]= min(dp[j], dp[j-val[i]]+wt[i]);
        }
    }
    for(int j=sum;j>=0;j--){
        if(dp[j]<=w){
            cout<<j<<endl;
            break;
        }
    }

}
int32_t main(){
	boost
  //cases
	solve();	
	
	//return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
#define P 1000000007
using namespace std;

int powmp(long long x,long long n){
	const long long p = 1000000007;
	if(n==0) return 1;
	long long y = x%p;
	if(n==1) return y;
	long long tmp = (powmp(y,n/2))%p;
	if(n%2==0) return (tmp*tmp)%p;
	else return (powmp(y,n-1)*y)%p;
}

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	long long cur = 1;
	long long ans = 0;
	long long t;
	cin >> t;
	ans += t-1;
	cur = 2;
	REP(i,n-1){
		cin >> t;
		if(t<cur){}
		else if(t==cur){
			cur++;
		}else{
			long long a;
			a = (t-1)/cur;
			ans += a;
		}
	}
	cout << ans << "\n";
	return 0;
}	

Measured memory_bytes: 384
from operator import itemgetter
from bisect import bisect_left


def main():
    n, q = list(map(int, input().split()))
    stops = []
    for _ in range(n):
        s, t, x = list(map(int, input().split()))
        stops.append((s, t, x))
    delay = []
    for i in range(q):
        delay.append(int(input()))

    stops = sorted(stops, key=itemgetter(2))
    delay = sorted(delay)

    result = [-1] * q
    skips = [-1] * q

    for s, t, x in stops:
        sx = bisect_left(delay, s - x)
        tx = bisect_left(delay, t - x)
        while sx < tx:
            if skips[sx] == -1:
                result[sx] = x
                skips[sx] = tx
                sx += 1
            else:
                sx = skips[sx]

    for r in result:
        print(r)


main()

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

int main()
{
  int N, x;
  std::cin >> N >> x;
  int a[100];
  for (int i=0; i<N; i++) std::cin >> a[i];
  std::sort(a, a+N);
  int cnt = 0;
  for (; cnt < N && x >= a[cnt]; cnt++) x -= a[cnt];
  if (cnt == N && x>0) std::cout << cnt-1 << std::endl;
  else std::cout << cnt << std::endl;
  return 0;
}


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

int main(){
	int x,n;
	cin >> x >> n;
	vector<int> p;
	rep(i,n){
		int t; cin >> t;
		p.push_back(t);
	}
	vector<int> np;
	for(int i=0; i<=101; i++){
		bool f=true;
		for(int j=0; j<(int)p.size(); j++){ if(i==p[j]) f=false;}
		if(f)np.push_back(i);
	}
	sort(np.begin(),np.end());

	int diff=1e9;
	int ans=0;
	for(int i=0; i<(int)np.size(); i++){
		if(diff > abs(np[i]-x)){
			diff = abs(np[i]-x);
			ans = np[i];
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 3620
#include <iostream>

int main(){
    int n;
    std::string s;
    std::cin >> n >> s;
    for(char c : s){
        char ch = c + n;
        while(ch > 'Z') ch -= 26;
        std::cout << ch;
    }
    std::cout << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {        
    public static void main(String args[]) {
        int n=II();
        int d=II();
        int ctr=0;
        int arr[]=new int[n];
        for(int i=0;i<n;i++){
            long a=II();
            long b=II();
            long x=(long)(a*a);
            long y=(long)(b*b);
            double val=Math.sqrt((double)(x+y));
            if(val<=d){
                ctr++;
            }
        }
        System.out.println(ctr);
    }
    
    ////////////////////////////////////
    static scan in=new scan(System.in);
    static int II() {
        return in.nextInt();
    }
    static long IL() {
        return in.nextLong();
    }
    static int[] IIA(int n) {
        int a[]=new int[n];
        for(int i=0;i<n;i++) {
            a[i]=II();
        }
        return a;
    }
    static String IS() {
        return in.next();
    }
    static char IC(){
        return in.next().charAt(0);
    }
    static String[] ISA(int n) {
        String a[]=new String[n];
        for(int i=0;i<n;i++) {
            a[i]=IS();
        }
        return a;
    }
    static char[] ICA(int n) {
        char a[]=new char[n];
        for(int i=0;i<n;i++) {
            a[i]=IC();
        }
        return a;
    }
}
class scan
{
    public static BufferedReader reader;
    public static StringTokenizer token;

    scan(InputStream str)
    {
        reader=new BufferedReader(new InputStreamReader(str));
        token=null;
    }

    static int nextInt()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Integer.parseInt(token.nextToken());
    }

    static long nextLong()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return Long.parseLong(token.nextToken());
    }

    static String next()
    {
        while(token==null||!token.hasMoreTokens())
        {
            try { token=new StringTokenizer(reader.readLine());   }
            catch(IOException e){  throw new RuntimeException(e); }
        }
        return token.nextToken();
    }

}

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

int main(){
  int i, j;
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int pat = 0;
  for(int r=0; r*R<=N; r++){
  int ball = 0;
    for(int g=0; r*R+g*G<=N; g++){
      ball = r*R + g*G;
      if((N-ball)/B>=0 && (N-ball)%B==0){
        pat++;
      }
    }
  }
  cout << pat << endl;
  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, int> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;


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

    vector<ll> apples(n);
    rep(i, n) cin >> apples[i];

    vector<ll> max_prices(n);
    max_prices.back() = apples.back();
    for (int i = n - 2; i >= 0; i--) {
        max_prices[i] = max(max_prices[i + 1], apples[i]);
    }

    ll max_diff = 0;
    rep(i, n) cmax(max_diff, max_prices[i] - apples[i]);


    int ans = 0;
    rep(i, n) if (max_prices[i] - apples[i] == max_diff) ans++;
    cout << ans << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 10000000000000000


int main(){
	string S;
	cin>>S;
	int N = S.size();
	vector<vector<vector<int>>> dp(N,vector<vector<int>> (10,vector<int>(13,0)));//dp[i][j][k] i文字目が[j]で13で割るとk余る
	
	if(S[0]=='?'){
		for(int i=0;i<10;i++){
			dp[0][i][i] = 1;
		}
	}
	else{
		dp[0][S[0]-'0'][S[0]-'0'] = 1;
	}
	
	for(int i=0;i<N-1;i++){
		for(int j=0;j<10;j++){
			for(int k=0;k<13;k++){
				if(S[i+1]!='?'){
					int a = S[i+1]-'0';
					dp[i+1][a][(10*k+a)%13]=mod(dp[i][j][k]+dp[i+1][a][(10*k+a)%13]);
				}
				else{
					for(int a=0;a<10;a++){
						dp[i+1][a][(10*k+a)%13]=mod(dp[i+1][a][(10*k+a)%13]+dp[i][j][k]);
					}
				}
			}
		}
	}
	int ans = 0;
	for(int i=0;i<10;i++){
		ans = mod(ans + dp[N-1][i][5]);
	}
	
	cout<<ans<<endl;

	
	return 0;
}




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

int main()
{
  int bingo[9];
  for(int i=0;i<9;i++){
    cin>>bingo[i];
  }
  int n;
  cin>>n;
  vector<int> arr(n);
  for(int j=0;j<n;j++){
    cin>>arr.at(j);
    for(int k=0;k<9;k++){
      if(arr.at(j)==bingo[k]){
        bingo[k]=0;
      }
    }
  }
  if((bingo[0]==bingo[1]&&bingo[1]==bingo[2]&&bingo[1]==0)||(bingo[3]==bingo[4]&&bingo[3]==bingo[5]&&bingo[3]==0)||(bingo[6]==bingo[7]&&bingo[6]==bingo[8]&&bingo[6]==0)||
  (bingo[0]==bingo[3]&&bingo[0]==bingo[6]&&bingo[0]==0)||(bingo[1]==bingo[4]&&bingo[1]==bingo[7]&&bingo[1]==0)||(bingo[2]==bingo[5]&&bingo[2]==bingo[8]&&bingo[2]==0)
  ||(bingo[0]==bingo[4]&&bingo[0]==bingo[8]&&bingo[0]==0)||(bingo[2]==bingo[4]&&bingo[2]==bingo[6]&&bingo[2]==0)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import math
from collections import defaultdict
N = int(input())

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

f = prime_factors(N)
f_dict = defaultdict(int)
for i in f:
    f_dict[i] += 1

def triangle_map(m):
    # return math.ceil((-1+math.sqrt(1+8*m))/2)
    i = 1
    while i*(i+1) <= 2*m:
        i += 1
    return i-1

ans = 0
for i in f_dict:
    ans += triangle_map(f_dict[i])

print(ans)

Measured memory_bytes: 9484
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,c,k,people,sign,bus;
int timer[100010];
int main()
{
	cin>>n>>c>>k;
	for(int i=1; i<=n; i++)
		scanf("%d",&timer[i]);
	sort(timer+1,timer+1+n);
	people=1;
	bus=1;
	sign=timer[1]+k;
	for(int i=2; i<=n; i++)
		if(sign<timer[i]||people==c)
		{
			bus++;
			people=1;
			sign=timer[i]+k;
		}
		else people++;
	cout<<bus<<endl;
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;


int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d[256];
  cin>>a>>b>>c;
  d[0]=a;
  d[1]=b;
  d[2]=c;
  sort(d,d+3);
  cout<<d[0]+d[1]<<'\n';
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d",&n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for(i=0;i<=VMAX;i++){
    C[i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i]+=C[i-1];
  }

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9588
#include <stdio.h>
#include <string.h>
int main()
{
     int n,i,m,sum,p,x,j,v;
     scanf("%d",&n);
     int a[n+2];
     for(i=0;i<n;i++)
     {
         scanf("%d",&a[i]);
     }
     scanf("%d",&m);
     for(i=0;i<m;i++)
     {
         scanf("%d %d",&p,&x);
         v=a[p-1];
         sum=0;
         for(j=0;j<n;j++)
         {
             a[p-1]=x;
             sum+=a[j];
         }
         a[p-1]=v;
         printf("%d\n",sum);
     }
     return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int n,l; cin>>n>>l;
    vector <int> a(n); 
    rep(i,n) cin>>a[i];
    int key = -1;
    for(int i=0;i<n-1;i++) if(a[i]+a[i+1] >= l) {key = i+1; break;}
    if(key == -1) {cout<<"Impossible"<<endl; return 0;}
    else cout<<"Possible"<<endl;
    int x = 1;
    while(x<key) cout<<x++<<endl;
    x = n-1;
    while(x>=key) cout<<x--<<endl;
}


Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e11;
const long double PI = (acos(-1));

struct mint {
	int x;
	mint(int 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 {
		return mint(*this) += a;
	}
	mint operator-(const mint a)const {
		return mint(*this) -= a;
	}
	mint operator*(const mint a)const {
		return mint(*this) *= a;
	}
	mint pow(int 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;
	}
};
ostream& operator<<(ostream & os, const mint & m) {
	os << m.x;
	return os;
}

signed main() {
	int N;
	string S1, S2;
	cin >> N >> S1 >> S2;
	mint ans = 1;
	int now = 0;
	while (now < N) {
		if (S1[now] == S2[now]) {
			if (now == 0)ans *= 3;
			else {
				if (S1[now - 1] == S2[now - 1])ans *= 2;
				else ans *= 1;
			}
			now++;
		}
		else {
			if (now == 0)ans *= 6;
			else {
				if (S1[now - 1] == S2[now - 1])ans *= 2;
				else ans *= 3;
			}
			now += 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
# sr,sc,gr,gcの総当りでTLEした
# goalは各startに対して最も遠い地点とすればよい

def main():
    from collections import deque

    dd = 0, 1, 0, -1

    H, W = map(int, input().split())
    G = [input() for _ in range(H)]

    def dist(sr, sc):
        if G[sr][sc] == '#':
            return -1

        memo = [[-1] * W for _ in range(H)]

        dq = deque()
        dq.append((sr, sc, 0))
        memo[sr][sc] = 0
        while dq:
            r, c, d = dq.popleft()
            nd = d + 1
            for i in range(4):
                nr = r + dd[i]
                nc = c + dd[i ^ 1]
                if not (0 <= nr < H and 0 <= nc < W):
                    continue
                if ~memo[nr][nc]:
                    continue
                if G[nr][nc] == '#':
                    continue
                dq.append((nr, nc, nd))
                memo[nr][nc] = nd

        return d

    ans = 0
    for sr in range(H):
        for sc in range(W):
            ans = max(ans, dist(sr, sc))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;

int app() {
  int n,t;
  cin>>n>>t;

  vector<int> a(n+1),b(n+1);
  rep(i,n){
    cin>>a[i+1]>>b[i+1];
  }

  int dp[n+2][t];
  int dp2[n+2][t];
  rep(j,t){
    dp[0][j]=0;
    dp2[n+1][j]=0;
  }

  rep_range(i,1,n+1){
    rep(j,t){
      if(a[i]<=j) dp[i][j]=max(dp[i-1][j-a[i]]+b[i], dp[i-1][j]);
      else dp[i][j]=dp[i-1][j];
    }
  }
  rep_rev(i,n+1,0){
    rep(j,t){
      if(a[i]<=j) dp2[i][j]=max(dp2[i+1][j-a[i]]+b[i], dp2[i+1][j]);
      else dp2[i][j]=dp2[i+1][j];
    }
  }

  int out=0;
  rep_range(i,1,n+1){
    rep(j,t){
      out=max(out,dp[i-1][j]+dp2[i+1][t-1-j]+b[i]);
    }
  }

  return out;
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 70656
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define ALL(v) v.begin(),v.end()
string calc(string a,string b){
	reverse(ALL(a));
	reverse(ALL(b));
	while(a.size() < b.size())a += '0';
	while(b.size() < a.size())b += '0';
	int c=0;
	string res;
	for(int i=0;i<a.size();i++){
		c = c+a[i]-'0'+b[i]-'0';
		res += c%10+'0';
		c /= 10;
	}
	if(c)res += c+'0';
	if(res.size() > 80)return "overflow";
	reverse(ALL(res));
	return res;
}
int main(){
	int n;
	string a,b;
	cin>>n;
	while(n--){
		cin>>a>>b;
		cout<<calc(a,b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd __gcd
//#define int ll

using namespace std;
//using namespace __gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 40, T = 4 * N, inf = 1e9 + 7;

int n, m, f, r, l, e, w, o, z, test, id;
ll a[N], d[N];

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

main()
{
    //freop();
    boos();
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        d[i] = inf;
    }
    d[0] = 0;
    d[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; i++)
    {
        for (int j = 1; j <= m && i - j > -1; j++)
        {
            d[i] = min(d[i - j] + abs(a[i] - a[i - j]), d[i]);
        }
    }
    cout << d[n - 1];
}


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

int main() {
	string s;
	cin>>s;
	if (s[0]=='R'&&s[1]=='R'&&s[2]=='R') cout<<3<<endl;
	else if (s[0]=='R'&&s[1]=='R') cout<<2<<endl;
	else if (s[1]=='R'&&s[2]=='R') cout<<2<<endl;
	else if (s[0]=='R'||s[1]=='R'||s[2]=='R') cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        int ans = 0;
        int c = 1;
        while(c < n){
            c+= k-1;
            ans ++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 49508
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

void main(void)
{
	int N, K;
	char *str;

	scanf("%d %d", &N, &K);

	str = (char*)malloc(N+1);
	scanf("%s", str);

	str[K-1] = tolower(str[K-1]);

	printf("%s\n", str);

	free(str);
}

Measured memory_bytes: 128
#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()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	vector<char> vect;
	for(char ch ='A'; ch<='Z'; ch++)
	{
		vect.push_back(ch);
	}
	int n;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0; i<s.length(); i++)
	{
		int val = ((s[i]-'A')+n)%26;
		cout<<vect[val];
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
const int mod = 1000000007;
int n, a[100009];
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	int ret = 1, ptr = 0;
	for (int i = 0; i < n; i++) {
		while (ptr < n && a[ptr] > (ptr - i) * 2) ptr++;
		if (ptr < n && a[ptr] == (ptr - i) * 2) ptr++;
		ret = 1LL * ret * (ptr - i) % mod;
	}
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

//最大公約数

ll mod = pow(10, 9) + 7;
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}

int main() {
	int Q, i, r_max = 0;
	cin >> Q;
	vector<int> l(100000), r(100000),ans(100000);
	REP(i, Q) {
		cin >> l[i] >> r[i];
		r_max = max(r_max, r[i]);
	}
	ans[1] = 1;
	for (i = 3; i <= r_max; i+=2) {
		if (sosuu_check(i)&&sosuu_check((i+1)/2))
			ans[i] = ans[i-2] +1;
		else
			ans[i] = ans[i-2];

	}
	REP(i, Q) {
		cout << ans[r[i]] - ans[max(1,l[i]-2)] << endl;
//		cout << ans[r[i]] <<" "<< ans[l[i]-2] << endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>

using namespace std;
long long n[1001];
long long mlt=1;

void div(int k){
    int i=2;
    while(k>=i){
        if(k%i==0){
            k/=i; n[i]++;
        }
        else i++;
    }
}

int main(int argc, const char * argv[]) {
    int d;
    scanf("%d", &d);
    
    for(int i=2;i<=d;i++)
        div(i);
    for(int i=2;i<=d;i++){
        mlt*=(n[i]+1);
        mlt%=(1000000000+7);
    }
    
    cout<<mlt%(1000000000+7)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin, s;
    int ans = 0;
    int cnt = 0;
    for (auto c : s) {
        if (c == 'R') {
            cnt++;
        } else {
            cnt = 0;
        }
        chmax(ans, cnt);
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3648
require 'matrix'

def cross(p1, p2)
  return p1[0]*p2[1] - p1[1]*p2[0]
end

q = gets.to_i
q.times do
  x0, y0, x1, y1, x2, y2, x3, y3 = gets.split.map &:to_i
  p0 = Vector[x0, y0]
  p1 = Vector[x1, y1]
  p2 = Vector[x2, y2]
  p3 = Vector[x3, y3]

  d1 = cross(p3-p2, p0-p2).abs / (p3-p2).norm
  d2 = cross(p3-p2, p1-p2).abs / (p3-p2).norm
  t = d1 / (d1 + d2)
  x = p0 + (p1 - p0) * t
  puts "%.8f %.8f" % [ x[0], x[1] ]
end

Measured memory_bytes: 9328
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
def main():
    h=int(input())
    count=0
    while True:
        if h==1:
            count+=1
            break
        else:
            h//=2
            count+=1

    print(2**count-1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3444
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>
#include <functional>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* ---------- Functions */
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
int powmod(int a, int p, int mod) {
    int ans = 1;
    int mul = a;

    for (; p > 0; p >>= 1, mul = (mul * mul) % mod) {
        if ((p & 1) == 1) ans = (ans * mul) % mod;
    }

    return ans;
}

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

signed main() {
    cin.sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

    map<P, int> m;
    for (int i = 0; i < N; i++) {
        if (A[i] == 0 && B[i] == 0) {
            m[P(0, 0)]++;
        } else {
            int g = gcd(abs(A[i]), abs(B[i]));
            A[i] /= g;
            B[i] /= g;

            if (A[i] <= 0 && B[i] <= 0) {
                A[i] *= -1;
                B[i] *= -1;
            } else if (A[i] >= 0 && B[i] <= 0) {
                A[i] *= -1;
                B[i] *= -1;
            }

            m[P(A[i], B[i])]++;
        }
    }

    int ret = 1;
    set<P> seen;
    for (auto it = m.begin(); it != m.end(); it++) {
        P value = it->first;
        int count = it->second;

        if (seen.find(value) != seen.end()) continue;
        seen.insert(value);

        P inv = P(-value.second, value.first);
        if (inv.second < 0) {
            inv.first *= -1;
            inv.second *= -1;
        }

        if (value == P(0, 0)) {
            continue;
        } else if (m.find(inv) == m.end()) {
            (ret *= powmod(2, count, MOD)) %= MOD;
        } else {
            seen.insert(inv);
            (ret *= ((powmod(2, m[inv], MOD) + powmod(2, count, MOD)) % MOD + MOD - 1) % MOD) %= MOD;
        }
    }

    /*
    for (auto it = seen.begin(); it != seen.end(); it++) {
        cout << it->first << " " << it->second << endl;
    }
     */

    (ret += m[P(0, 0)]) %= MOD;
    (ret += MOD - 1) %= MOD;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 31356
#include<iostream>
#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 >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

ll dfs(int N, int M, int Q, const vector<int>& A, const vector<int>& B, const vector<int>& C, const vector<int>& D, vector<int>& V) {
    if ((int)V.size() == N) {
        ll res = 0;
        rep(i, 0, Q) {
            if (V[B[i]] - V[A[i]] == C[i]) {
                res += D[i];
            }
        }
        return res;
    }
    int lower_value = 1;
    if (!V.empty()) {
        lower_value = V.back();
    }
    ll res = 0;
    rep(v, lower_value, M + 1) {
        V.push_back(v);
        chmax(res, dfs(N, M, Q, A, B, C, D, V));
        V.pop_back();
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> A(Q), B(Q), C(Q), D(Q);
    rep(i, 0, Q) {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        --A[i], --B[i];
    }
    vector<int> V;
    cout << dfs(N, M, Q, A, B, C, D, V) << endl;
    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define _GLIBCXX_DEBUG
const int INF=1e15;

signed main(){
    int A,B,C,D,ans;
    cin>>A>>B>>C>>D;
    ans=min(B,D)-max(A,C);
    if(ans<0)ans=0;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# tenka1-2018-beginnerC - Align
def main():
    N, *A = map(int, open(0).read().split())
    A.sort()
    if N & 1:
        low, high, mid = A[: N // 2], A[N // 2 + 1 :], A[N // 2]
        x = (sum(high) - sum(low)) * 2 - mid + low[-1]
        y = (sum(high) - sum(low)) * 2 + mid - high[0]
        ans = max(x, y)
    else:
        low, high = A[: N // 2], A[N // 2 :]
        ans = (sum(high) - sum(low)) * 2 - high[0] + low[-1]
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;


int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> decrease(n+1,0);
    vector<int> num(n+1);

    vector<int> sumNum(n+1);


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


    if(n>1){
        for(int i = 2; i < n; ++i){
            int minus = (v[i-1])/2;
            if((v[i-1]) % 2 == 1) minus ++;
            minus = i - minus;


            decrease[i] = max(decrease[i-1],minus);
        }
    }


    for(int i=0;i<n;++i){
//        cout << decrease[i]<<" ";
        num[decrease[i]]++;
    }

    sumNum[0] = num[0];

    for(int i = 1;i<=n;++i){
        sumNum[i] = num[i]+sumNum[i-1];
    }
//    cout << endl;
//    for(int i=0;i<n;++i){
//        cout <<i<<" "<< sumNum[i]<<endl;
//    }


    long long ans = num[0];
    for(int i=1;i<n;++i){
//        if(num[i] == 0) break;
        ans *= (sumNum[i] - i);
        ans %=1000000007;
    }

    cout << ans;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
long long n,k,sum,s,p;
int i,j;
int main(){
	cin>>n>>k;
	for(i=2;i<7;i++){
		s=0;
		for(j=2;j<n;j++){
			p=(j*63+i*9-63);
			if(p%11==k){s=j;break;}
		}
		if(!s)continue;
		sum+=((n-1)-s)/11+1;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const long long INF = 1e18;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y);
long long dp[20][20];

vector<long long>calc(vector<pair<int,int>>&A) {
	int n = A.size();
	sort(A.begin(),A.end());
	for (int i = 0;i<n + 1;++i) {
		for (int j = 0;j<n + 1;++j) {
			dp[i][j] = INF;
		}
		dp[0][0] = 0;
		for (int l = 0;l<n;++l) {
			for (int r = l + 1;r<=n;++r) {
				{
					long long now = INF;
					for (int k = l;k<r;++k) {
						long long s = 0;
						for (int i = l;i<r;++i) {
							s += abs(A[i].first - A[k].first)*ll(A[i].second);
						}
						chmin(now, s);
					}
					rep(j, n) chmin(dp[r][j + 1], dp[l][j] + now);
				}
				{ 
					ll now = 0;
					for (int i = l; i < r; ++i) {
						now += abs(A[i].first)*ll(A[i].second);
					}
					rep(j, n + 1) chmin(dp[r][j], dp[l][j] + now);
				}
			}
		}
	}
	vector<long long>res(n + 1, INF); 
	rep(j, n + 1) res[j] = dp[n][j];
	return res;
}

int main() {
	int N;
	cin >> N;
	vector<int>X(N), Y(N), P(N);
	vector<long long >Ans(N + 1, INF);
	for (int n = 0;n<N; ++n) {
		cin >> X[n] >> Y[n] >> P[n];
	}
	for (int n = 0;n<(1<<N);++n) {
		vector<pair<int, int>>Ax,Ay;
		for (int m = 0;m<N;++m) {
			if (n>>m&1) {
				Ax.emplace_back(X[m],P[m]);
			}
			else {
				Ay.emplace_back(Y[m], P[m]);
			}
		}
		vector<long long> dx = calc(Ax); 
		vector<long long> dy = calc(Ay);
		for (int p = 0;p<dx.size();++p) {
			for (int q = 0;q<dy.size();++q) {
				Ans[p + q] = min(Ans[p + q], dx[p] + dy[q]);
			}
		}
	}
	for (int i = 0; i < N+1; ++i) {
		cout << Ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 31 15:24:23 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    Int Q;
    std::cin >> Q;
    REP(q, Q) {
        Int b, e, t;
        std::cin >> b >> e >> t;
        REP(k, e - b) std::swap(a[b + k], a[t + k]);
    }
    REP(i, n) std::cout << a[i] << " \n"[i == n - 1];
}



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

using namespace std;

typedef pair<int, int> Point;
#define xx first
#define yy second

void rotate(vector<Point> &p)
{
  for(int i = 0; i < p.size(); i++){
    Point o = p[i];
    p[i].xx = o.yy;
    p[i].yy = -o.xx;
  }
  return;
}

bool overlap(vector<Point> &o, vector<Point> &p)
{
  for(int i = 0; i < o.size(); i++){
    if(o[i].xx - o[0].xx != p[i].xx - p[0].xx ||
       o[i].yy - o[0].yy != p[i].yy - p[0].yy){
      return false;
    }
  }
  return true;
}

vector<Point> reverse(vector<Point> &p)
{
  vector<Point> q = p;
  reverse(q.begin(), q.end());
  return q;
}

bool same(vector<Point> &o, vector<Point> &p)
{
  vector<Point> q = reverse(p);
  return overlap(o, p) | overlap(o, q);
}

int main()
{
  int n;
  while(cin >> n, n){
    vector< vector<Point> > ps(n + 1);
    for(int i = 0; i <= n; i++){
      int m;
      cin >> m;
      for(int j = 0; j < m; j++){
	Point p;
	cin >> p.xx >> p.yy;
	ps[i].push_back(p);
      }
    }
    for(int i = 1; i <= n; i++){
      if(ps[0].size() != ps[i].size()) continue;
      bool flag = false;
      for(int dig = 0; dig < 4; dig++){
	rotate(ps[i]);	
	flag |= same(ps[0], ps[i]);
      }
      if(flag) cout << i << endl;
    }
    cout << "+++++" << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'







int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){
    
// }

int n,k;
cin >> n >> k;
int arr[n];
fo(i,0,n)cin >> arr[i];
sort(arr,arr+n);
int sum = 0;
fo(i,0,k)sum += arr[i];
cout << sum << endl;   
 
return 0;
}




Measured memory_bytes: 3596
#include<iostream>
using namespace std;
static const int MAX = 30;

int main(){
    int N, M, K, A, ans = 0;
    int C[MAX];
    for(int i = 0; i < MAX; i++){
        C[i] = 0;
    }
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> K;
        for(int j = 0; j < K; j++){
            cin >> A;
            C[A-1]++;
        }
    }
    for(int i = 0; i < MAX; i++){
        if(C[i] == N) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define mod 1000000007

ll n;

vector<vector<ll>> mul(vector<vector<ll>> &a, vector<vector<ll>> &b) {
    vector<vector<ll>> res(n);
    for (auto &i : res) {
        i.resize(n);
    }

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n; j++) {
            ll s = 0;
            for (ll k = 0; k < n; k++) {
                s = (s + a[i][k] * b[k][j]) % mod;
            }
            res[i][j] = s;
        }
    }
    return res;
}

vector<vector<ll>> po(vector<vector<ll>> a, ll b) {
    vector<vector<ll>> identity(n);
    for (auto &i : identity) {
        i.resize(n);
    }
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n; j++) {
            if (i == j) {
                identity[i][j] = 1;
            }
        }
    }

    while (b) {
        if (b % 2) {
            identity = mul(identity, a);
            b--;
        } else {
            a = mul(a, a);
            b /= 2;
        }
    }
    return identity;
}

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

    ll k;
    cin >> n >> k;

    vector<vector<ll>> mat(n);
    for (auto &i : mat) {
        i.resize(n);
    }

    for (auto &i : mat) {
        for (auto &j : i) {
            cin >> j;
        }
    }

    vector<vector<ll>> v = po(mat, k);

    ll ans = 0;
    for (auto &i : v) {
        for (auto j : i) {
            ans = (ans + j) % mod;
        }
    }

    cout << ans << "\n";
}


Measured memory_bytes: 3708
n,m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a.sort(key=lambda x:(x[0]))
c = 0
mony = 0
for i in a:
    if c + i[1] < m:
        c += i[1]
        mony += i[0]*i[1]
    else:
        for j in range(i[1]):
            c += 1
            mony += i[0]
            if c >= m:
                break
        break
print(mony) 

Measured memory_bytes: 29028
import math
a, b, h, m = map(int, input().split())
time = h * 60 + m
px = a * math.sin(math.radians(time / 2))
py = a * math.cos(math.radians(time / 2))
cx = b * math.sin(math.radians(m * 6))
cy = b * math.cos(math.radians(m * 6))
print(((px - cx) ** 2 + (py - cy) ** 2) ** 0.5)

Measured memory_bytes: 9520
#include <stdio.h>
#define N 250

main(){
  int i, n, heap[N];

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    scanf("%d", &heap[i]);
  }
  
  for(i = 1; i <= n ; i++){
    printf("node %d: key = %d, ", i, heap[i]);
    if(i != 1){
      printf("parent key = %d, ", heap[i/2]);
    }
    if(2 * i <= n){
      printf("left key = %d, ", heap[2*i]);
    }
    if(2 * i + 1 <= n){
      printf("right key = %d, ", heap[2*i+1]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define vi vector<int>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vvi vector< vector<int> >
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<ll, ll>, ll > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define pi pair<int, int>
#define ppi pair<pair<int, int>, int>
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000001
#define MOD 1000000007
#define INF (ll)1e18
#define s(v) v.size()
#define e(v) v.empty()

using namespace std;

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);} 
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    while(t--){
        ll a, b, c;
        cin>>a>>b>>c;
        if(c >= a+b){
            ll x = (c-a-b)*(c-a-b);
            ll y =  4*a*b; 
            if(x > y)   cout<<"Yes";
            else cout<<"No";
        }
        else cout<<"No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N, M, K; cin >> N >> M >> K;
	vector<int64> A(N), SA(N + 1), B(M), SB(M + 1);
	for (int i = 0; i < N; ++i) cin >> A[i];
	for (int i = 0; i < M; ++i) cin >> B[i];
	for (int i = 0; i < N; ++i) {
		SA[i + 1] = SA[i] + A[i];
	}
	for (int i = 0; i < M; ++i) {
		SB[i + 1] = SB[i] + B[i];
	}
	int64 ans = 0;
	for (int i = 0; i <= N; ++i) {
		if (SA[i] <= K) {
			int64 res = i;
			res += (upper_bound(SB.begin(), SB.end(), K - SA[i]) - SB.begin()) - 1;
			ans = max(ans, res);
		}
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 9600
loop {
m,f,r=gets.split(" ").map(&:to_i)
break if m==-1 && f==-1 && r==-1

grade="F"
if m == -1 || f == -1
    #grade="F"

elsif (m + f) >=80 
    grade= "A"
elsif (m + f) >=65
    grade= "B"
elsif (m + f)>=50
    grade="C"
elsif (m + f)>=30
    if r >= 50
        grade= "C"
    else
        grade= "D"
    end
end

puts grade


}








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

typedef long long ll;
struct Data {
    ll start,end,id;
    Data* next;
    Data *prev;
    Data(ll s,ll e,int i) : start(s), end(e), id(i) {;}
};

void insert(int id,ll size,Data *d) {
    while(true) {
        //cout<<(d->start)<<","<<(d->end)<<":"<<(d->id)<<endl;
        if(size == 0) return;
        if(d->id != -1) {
            d = d->next;
            continue;
        }
        ll use = min(size, (d->end) - (d->start) + 1);
        if(use == size) {
            ll remain = (d->end)-(d->start)+1 - size;
            if(remain == 0) d->id = id;
            else{
                Data* nd = new Data(d->start+size,d->end,-1);
                nd->prev = d;
                nd->next = d->next;
                d->next = nd;
                d->end = d->start+size-1;
                d->id = id;
            }
            break;
        }else{
            ll remain = size - ((d->end)-(d->start)+1);
            d->id = id;
            size = remain;
            d = d->next;
        }
    }
}

int lookup(Data *n,ll p) {
    while(true) {
        if(n == NULL) return -1;
        if(n->start <= p && n->end >= p) return n->id;
        n = n->next;
    }
}

void remove(int id,Data *n) {
    while(n != NULL) {
        if(n == NULL) return;
        if((n->id) != id) {
            n = n->next;
            continue;
        }

        n->id = -1;
        n = n->next;
    }
}

void dump(Data *n) {
    while(true) {
        if(n == NULL) return;
        //cout<<(n->start)<<" "<<(n->end)<<" "<<(n->id)<<endl;
        n = n->next;
    }
}

int main() {
    int n;
    string op;
    while(cin>>n, n) {
        Data root(0, 1ll<<60, -1);
        Data *rp = &root;
        root.prev = &root;
        root.next = NULL;

        ll id,size;
        for(int i=0; i<n; ++i) {
            cin>>op;
            if(op == "W") {
                cin>>id>>size;
                //cout<<"W "<<id<<" "<<size<<endl;
                insert(id,size,rp);
                //dump(rp);
                //cout<<endl;
            }else if(op == "D") {
                cin>>id;
                //cout<<"D "<<id<<endl;
                remove(id,rp);
                //dump(rp);
                //cout<<endl;
            }else if(op == "R") {
                cin>>size;
                cout<<lookup(rp,size)<<endl;
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1332