akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

main(){
  int i,j,a[100],n,min;
  int k,d=0;

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

  for(i=0;i<n;i++){
    min=i;
    for(j=min;j<n;j++){
      if(a[j]<a[min]) min=j;
      if(j==n-1 && a[i]>a[min]){
	k=a[i];
	a[i]=a[min];
	a[min]=k;
	d++;
      }
    }
  }
  
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]); 
  printf("%d\n",d);
  return 0;
}

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

int main(){

  int n; cin >> n;
  for(int i=1; i<=n; i++){
    int x=i;
    if(x%3 == 0){
      cout << " " << i;
    }else if(x%10 == 3){
      cout << " " << i;
    }else{
      while(x/=10){
        if(x%10 == 3){
          cout << " " << i;
          break;
        }
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 3076
N,M=map(int, input().split())
G=[list() for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)
ans=0
index=-1
for i in range(1,N):
    for p in G[i]:
        if index<p<i:
            ans+=1
            index=i-1
import time
time.sleep(1.5)
print(ans)


Measured memory_bytes: 22676
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int) x.size())
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {sws;

    int n;
    ll l[105];
    cin >> n;
    fo(i, n) cin >> l[i];

    int ans = 0;

    for ( int i = 0; i < n; i++ ) {
        for ( int j = i + 1; j < n; j++ ) {
            if ( l[i] == l[j] ) continue;
            for ( int k = j + 1; k < n; k++ ) {
                if ( l[k] == l[i] or l[k] == l[j] ) continue;
                int a = l[i], b = l[j], c = l[k];

                if ( abs(b - c) < a and a < b + c and abs(a - c) < b and b < a + c and abs(a - b) < c and c < a + b ) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define ll long long
#define P pair<int, int>
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(c <= (a + b)){
        cout << "No" << endl;
    }
    else{
    unsigned long long left;
    left = (c - (a + b)) * (c - (a + b));
    unsigned long long right;
    right = 4 * a * b;
    if(left > right){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    }
    solve();
    return 0;
}



Measured memory_bytes: 256
ary = Array.new
while line = $stdin.gets
  ary << line.chomp.split
end
m = ary[0][1].to_i
c = ary[0][2].to_i
ary.delete_at(0)
b = ary[0]
ary.delete_at(0)
kai = 0
ary.each{|item|
f = Array.new
m.times{|t|
f.push(b[t].to_i*item[t].to_i)
}
if f.inject(:+) + c > 0 then
    kai = kai + 1
end
}
  print kai

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}

int main(){
  vector<char> S(4);
  int count=0;

  for(int i=0; i<4; i++){
    cin >> S[i];
  }
    
  for(int i=1; i<4; i++){
    if(S[0]==S[i]){
      count++;
    }
  }

  set<char> U(S.begin(), S.end());
  vector<char> S2(U.begin(), U.end());
  
  if(count==1 and S2.size()==2){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
   return 0;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

def lcm(x, y):
    return (x * y) // gcd(x, y) #math.gcd(x, y)

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

# n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = B - A + 1 -Cdiv - Ddiv + CDdiv#- n_C - n_D + CDdiv#n_CD
print('{}'.format(ans))


Measured memory_bytes: 13552
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    from collections import Counter

    ball_count, kind_count = map(int, input().split())
    ball_numbers = Counter(list(map(int, input().split())))
    sorted_ball_numbers = sorted(ball_numbers.values())
    print(sum(sorted_ball_numbers[:-kind_count]))


Measured memory_bytes: 32564
#include<cstdio>
using namespace std;

int getd(int t){
	if(t < 10)return 1;
	if(t < 100)return 2;
	if(t < 1000)return 3;
	if(t < 10000)return 4;
	if(t < 100000)return 5;
	return 6;
}
int getnum(int d[], int i, int x){
	int res = 0;
	for(int j = 0;j < x;j++){
		res *= 10;
		res += d[i + j];
	}
	return res;
} 
int main(void){
	int n;
	scanf("%d", &n);
	int d[n];
	for(int i = 0;i < n;i++)scanf("%d", &d[i]);
	
	for(int t = 0;;t++){
		int x = getd(t);
		bool fl = false;
		for(int i = 0;i < n - x + 1;i++){
			if(t == getnum(d, i, x)){
				fl = true;
				break;
			}
		}
		if(!fl){
			printf("%d\n", t);
			break;
		}
	}
}

Measured memory_bytes: 1032
import java.io.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        String s = sc.next();
        s = s.replaceAll(",", " ");
        _out.println(s);
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
typedef long long ll;
typedef unsigned un;
typedef std::string str;
typedef std::pair<ll,ll> pll;
ll read(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return f*x;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
void umax(ll& a,ll t){if(t>a)a=t;}
void umin(ll& a,ll t){if(t<a)a=t;}
const ll INF=1ll<<58;
#define MAXN 500011
ll res=0;
struct DSU
{
	ll fa[MAXN],size[MAXN],p[MAXN];
	ll s[MAXN],top;
	void build(ll n){for(ll i=1;i<=n;++i)fa[i]=i,size[i]=1;top=0;}
	ll find(ll x)
	{
		if(fa[x]==x)return x;
		return find(fa[x]); 
	}
	void uni(ll u,ll v)
	{
		u=find(u),v=find(v);
		if(u==v)
		{
			if(!p[u])++res;
			++p[u];
			s[++top]=-u;
		}
		else
		{
			if(size[u]>size[v])std::swap(u,v);
			if(!p[u]||!p[v])++res;
			p[v]+=p[u],fa[u]=v,size[v]+=size[u];
			s[++top]=u;
		}
	}
	void back(ll x)
	{
		for(;top>x;--top)
			if(s[top]<0)
			{
				if(!--p[-s[top]])--res;
			}
			else
			{
				ll u=s[top];
				p[fa[u]]-=p[u],size[fa[u]]-=size[u];
				if(!p[u]||!p[fa[u]])--res;
				fa[u]=u;
			}
	}
}s;
ll fa[MAXN],size[MAXN],mson[MAXN],a[MAXN],b[MAXN],ans[MAXN];
std::vector<ll>g[MAXN];
void dfs1(ll u)
{
	size[u]=1;
	for(auto v:g[u])
	{
		if(v==fa[u])continue;
		fa[v]=u;
		dfs1(v);
		size[u]+=size[v];
		if(size[v]>size[mson[u]])mson[u]=v;
	}
}
void brute(ll u)
{
	s.uni(a[u],b[u]);
	for(auto v:g[u])
		if(v!=fa[u])brute(v);
}
void solve(ll u)
{
	ll pre;
	for(auto v:g[u])
		if(v!=fa[u]&&v!=mson[u])pre=s.top, solve(v),s.back(pre);
	if(mson[u])solve(mson[u]);
	s.uni(a[u],b[u]);
	for(auto v:g[u])
		if(v!=fa[u]&&v!=mson[u])brute(v);
	ans[u]=res;
}
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("out","w",stdout);
	ll n=read(),k=read();
	s.build(k);
	for(ll i=1;i<n;++i)
	{
		ll u=read(),v=read();
		g[u].push_back(v),g[v].push_back(u);
	}
	for(ll i=1;i<=n;++i)a[i]=read(),b[i]=read();
	dfs1(1);
	solve(1);
	for(ll i=1;i<=n;++i)printf("%lld\n",ans[i]);
	return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
    if (ref < value) ref = value;
}

constexpr ll mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int prev = 0;
    int u = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'S') {
            prev = 0;
        }
        else {
            prev++;
            chmax(u, prev);
        }
    }
    cout << u << endl;
    return 0;
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main(){
    int n,k,q;
    cin >>n >>k >>q;
    int a[q];
    rep(i,q) cin >>a[i];
    vector<int> l (n, k-q);
    rep(i,q){
            l[a[i]-1]++;
    }
    rep(i,n){
        if (l[i]<=0) cout << "No" <<endl;
        else cout <<"Yes" <<endl;
    }
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    l = list(map(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'.replace(',', '').split()))
    K = int(input()) - 1
    print(l[K])

if __name__ == '__main__':
    main()


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

ll num[111], N;

ll miman[111][5];
ll eq[111][5];

int main(){

    string s;
    cin >> s;
    N = s.size();
    rep(i, N)num[i + 1] = s[i] - '0';
    eq[0][0] = 1;
    rep(i, N){
        ll to = i + 1;
        rep(j, 4){
            miman[to][j] += miman[i][j];
            miman[to][j + 1] += miman[i][j] * 9;
            if(num[to] == 0)eq[to][j] += eq[i][j];
            else miman[to][j] += eq[i][j];
            rep1(k, 9){
                if(k == num[to])eq[to][j + 1] += eq[i][j];
                if(k < num[i + 1])miman[to][j + 1] += eq[i][j];
            }
        }
    }
    
    ll K;
    cin >> K;
    cout << miman[N][K] + eq[N][K] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI 2*acos(0.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false
///................function.....................///
#define siz(s) (int)(s.size())
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mod 1000000007
#define dbg(a) cout << #a << " = " << a << " ";
///...........knight moves.....................///
///int dx[] = {+1,+1,-1,-1,+2,+2,-2,-2};
///int dy[] = {+2,-2,+2,-2,+1,-1,+1,-1};

int main()
{
    FIO;
    ///t_c
    {
        string s;
        cin>>s;
        int n=siz(s),i,j=0;
        for(i=0; i<n; i++)
        {
            j+=(s[i]-'0');
            j%=9;
        }
        if(j%9==0)
            cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }

}


Measured memory_bytes: 3776
=begin
N
s1
...
sn
=end

n = gets.chomp.to_i
ss = n.times.map do
  s = gets.chomp
  s.each_char.sort.join
end

h = {}

ss.each do |s|
  h[s] ||= 0
  h[s] += 1
end

def total(n)
  (n + 1) * n / 2
end

res = 0

h.each do |k, v|
  if v < 2
    next
  end

  res += total(v - 1)
end

puts res


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

using namespace std;
typedef long long ll;

int main() {
    ll N, D, A; cin >> N >> D >> A;
    vector<pair<ll, ll> > mon(N);
    for (int i = 0; i < N; i++) {
        cin >> mon[i].first;
        cin >> mon[i].second;
    }
    sort(mon.begin(), mon.end(), less<pair<ll, ll> >());
    vector<ll> right(N);
    for (int i = 0; i < N; i++) {
        int ok = i; int ng = N; int c = (ok + ng) / 2;
        while (ng - ok != 1) {
            c = (ok + ng) / 2;
            if (mon[i].first + 2 * D < mon[c].first) {
                ng = c;
            } else {
                ok = c;
            }
        }
        right[i] = ok;
    }
    vector<ll> imos(N+1, 0);
    ll ans = 0;
    ll now = 0;
    for (int i = 0; i < N; i++) {
        now += imos[i];
        ll hp = mon[i].second - now;
        if (hp > 0) {
            ans += (hp + (A-1)) / A;
            now += A * ((hp + (A-1)) / A);
            imos[right[i]+1] -= A * ((hp + (A-1)) / A);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
long long int merge(int a[], int left,int mid, int right){
	long long int inv = 0;
	int b[right+1];//array
	int i = left;
	int j = mid;
	for(int k=left; k<=right; k++){
		//if left left and (no right || a[])
		if(i<mid && (j>right||a[i]<a[j])){
			b[k] = a[i++];
		}
		else{
			b[k] = a[j++];
			inv = inv + (mid-i);
		}
		
	}
	for(int k = left; k<=right; k++)
		a[k] = b[k];
	//printf("%d\n", inv);
	return inv;
}

long long int divide(int a[], int left, int right){
	long long int inv = 0;
	if(left>=right) return inv;
	int mid = (left+right)/2;
	inv = divide(a,left,mid);
	inv += divide(a,mid+1,right);
	inv = inv + merge(a,left,mid+1,right);
	return inv;
}
int main(){
	int n;
	scanf("%d",&n);
	int a[n+1];
	for(int i=0; i<n;i++) scanf("%d",&a[i]);
	long long int res = divide(a,0,n-1);
	printf("%lld\n",res);
	  
	return 0;
} 


Measured memory_bytes: 4312
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
# include <bits/stdc++.h>
using namespace std;
long long powerexp(long long base, long long exp, int mod) {
   long long res = 1;
   while (exp > 0) {
      if (exp % 2 == 1)
         res= (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
int gcd(int a, int b)
{
    int c = a % b;
    while(c != 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}
void PrintVector(vector<long long int> v,long long int n)
{
 
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void Takevector(vector<long long int> &v,long long int n)
{
  for(long long int i=0;i <n;i++)
  { long long int number;
    cin>>number;
    v.push_back(number);
  }
}
typedef long long int ll;
typedef vector<long long int> vi;
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define scl(x)         ll x;       scanf("%lld", &x);
#define scll(x, y)     ll x, y;    scanf("%lld %lld", &x, &y);
#define sclll(x, y, z) ll x, y, z; scanf("%lld %lld %lld", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define rep(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define repi(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
#define nl cout<<"\n";
int min(int x, int y)  
{  
    return (x < y)? x: y;  
      
}  

int main()
{
	int flag=1,flag1=0;
  ll sum=0,tot=0,ans=0;
  map<int,int>mp;
  vi v,v1;
  set<int>st,st1;
  string s;
  
  sciii(a,b,c);
  int x=c%b;
  rep(i,1,100)
  {
  	if((a*i)%b==x) {
  		cout<<"YES";
  		return 0;
  	}
  }
  cout<<"NO";








return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

ll Pow(ll x,ll n) {
	ll res = 1;
	while (n > 0) {
		if(n&1) res = res * x % MOD;
		x = x * x % MOD;
		n >>= 1;
	}
	return res;
}

int main() {
	int a[3][3] = {};
	rep(i,3) rep(j,3) cin >> a[i][j];
	int n;
	cin >> n;
	rep(i,n){
		int b;
		cin >> b;
		rep(i,3) rep(j,3){
			if(a[i][j] == b) a[i][j] = INF;
		}
	}
	int flag = 0;
	for(int i = 0; i < 3; i++){
		if(a[i][0] == a[i][1] && a[i][1] == a[i][2] && a[i][2] == INF) flag = 1;
		if(a[0][i] == a[1][i] && a[1][i] == a[2][i] && a[2][i] == INF) flag = 1;
	}
	if(a[0][0] == a[1][1] && a[1][1] == a[2][2] && a[2][2] == INF) flag = 1;
	if(a[0][2] == a[1][1] && a[1][1] == a[2][0] && a[2][0] == INF) flag = 1;

	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);

	int n;cin>>n;
	vc<pi> lr;
	const int inf=LLONG_MAX/3;
	int mx=-inf,mn=inf;
	rep(i,n){
		int l,r;cin>>l>>r;
		l--;
		chmax(mx,l);
		chmin(mn,r);
		lr.eb(l,r);
	}

	int ans=0;
	for(auto z:lr){
		chmax(ans,max(int(0),mn-mx)+z.b-z.a);
	}
	vc<pi> t;
	rep(i,n){
		int a=max(int(0),mn-lr[i].a);
		int b=max(int(0),lr[i].b-mx);
		t.eb(b,-a);
	}
	sort(all(t));
	int w=inf;
	rep(i,n){
		auto z=t[i];
		z.b=-z.b;
		if(i)
			chmax(ans,w+z.a);
		chmin(w,z.b);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4848
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int N = in.nextInt();
    long K = in.nextLong();

    int[] numbers = new int[N];

    for (int i = 0; i < N; i++) {
      numbers[i] = in.nextInt() - 1;
    }

    HashMap<Long, int[]> map = new HashMap<>();

    long index = 1L;
    map.put(index, numbers);
    index *= 2L;

    while (index < K) {
      int[] newNumbers = new int[N];
      long preIndex = index / 2;

      for (int i = 0; i < N; i++) {
        int preLoc = map.get(preIndex)[i];
        int curLoc = map.get(preIndex)[preLoc];
        newNumbers[i] = curLoc;
      }

      map.put(index, newNumbers);
      index *= 2;
    }

    int ans = 0;
    index /= 2;

    while (index > 0) {
      if (K >= index) {
        ans = map.get(index)[ans];
        K -= index;
      }
      index /= 2;
    }

    System.out.println(ans + 1);
  }
}


Measured memory_bytes: 118784
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int x; cin >> x;
  if(30 <= x) cout << "Yes";
  else cout << "No";
  cout << "\n";
  return 0;
}


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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
#define double long double

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

    int a, b;
    string s;
    cin >> a >> s;
    b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
    cout << a * b / 100 << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


Measured memory_bytes: 3652
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextLong
    val K = sc.nextLong

    var result = 0L
    if (N >= K) {
      val i1 = (N - K) / K + 1
      result += i1 * i1 * i1
    }
    if (K % 2 == 0 && N >= K / 2) {
      val i2 = (N - K / 2) / K + 1
      result += i2 * i2 * i2
    }

    result.toString
  }
}


Measured memory_bytes: 25524
#include <bits/stdc++.h>
#define N 20

using namespace std;

int n;
long long a[N];

long long f(int l, int r, long long x, long long y) {
	if(l + 1 == r) return 0;
	long long res = 1e18;
	for(int i = l + 1; i <= r - 1; ++i) {
		res = min(res, 
		f(l, i, x, x + y) + 
		f(i, r, x + y, y) + 
		(x + y) * a[i]);
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", &a[i]);
	printf("%lld\n", a[1] + f(1, n, 1, 1) + a[n]);
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    int N, M; cin >> N >> M;
    priority_queue<ll> A;
    REP(i, N) {
        int a;
        cin >> a;
        A.push(a);
    }

    for(int i = 0; i < M; ++i) {
        ll b = A.top();
        A.pop();
        A.push(b / 2);
    }

    ll res = 0;
    for(int i = 0; i < N; ++i) {
        res += A.top();
        A.pop();
    }

    cout << res << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n; cin >> n;
  vector<ll> v(n+1);
  v[0] = 2; v[1] = 1;
  for(int i = 2; i <= n; i++){
    v[i] = v[i-1]+v[i-2];
  }
  cout << v[n] << endl;
  system("pause");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

bool isprime(int x) {
    int n = 2;
    while (n * n <= x) {
        if (x % n == 0) return false;
        n++;
    }
    return true;
}

int main() {

    int N;
    cin >> N;
    int x = 11;
    while (N > 0) {
        if (isprime(x)) {
            cout << x << (N > 1 ? " " : "");
            N--;
        }
        x += 5;
    }

    cout << endl;
    
    return 0;
}

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

using namespace std;

int main() {
  int N = 0;
  cin >> N;
  int64_t answer = 0;
  for (int A = 1; A <= N; A++) {
    int B_min = 1;
    int B_max = (N - 1) / A;
    answer += max(B_max - B_min + 1, 0);
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)



main(){
	string r,a;
	while(cin>>r>>a){
		if(a=="0")break;
		
		int h=0,b=0;
		for(int i=0;i<4;i++)if(r[i]==a[i])++h;
		for(int i=0;i<4;i++)if(string::npos!=r.find(a[i]))++b;
		
		cout<<h<<" "<<b-h<<endl;
	}
}

Measured memory_bytes: 912
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

ll calc(ll start, ll top, ll now){
	if(top-start >= now-top){
		ll l = top - start;
		ll r = now - top -1;
		return l*(l+1)/2 + r*(r+1)/2;
	}else{
		ll l = top - start -1;
		ll r = now - top;
		return l*(l+1)/2 + r*(r+1)/2;
	}
}

int main(){
	string s;
	cin >> s;
	ll n = s.size() + 1;
	
	vector<ll> a(n,0);
	ll sum=0;
	for(int i=0; i<n-1; ++i){
		if(s[i]=='<'){
			sum++;
			chmax(a[i+1], sum);
		}else{
			sum=0;
		}
	}
	sum=0;
	for(int i=n-2; i>=0; --i){
		if(s[i]=='>'){
			sum++;
			chmax(a[i], sum);
		}else{
			sum=0;
		}
	}
	
	ll ans=0;
	REP(i,n){
		ans += a[i];
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7676
import collections
s = input()
cnt = collections.Counter(s)
cnt = cnt.most_common()
# print(cnt)
if len(cnt) == 1:
    if len(s) == 1:
        print('YES')
    else:
        print('NO')
    # print('YES')
    exit()
if len(cnt) == 2:
    if len(s) == 2:
        print('YES')
    else:
        print('NO')
    exit()

if cnt[0][1] > cnt[-1][1] + 1:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3444
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<stdio.h>
using namespace std;
int main(){
    int ma,mi;
    int n;
    mi=10000000;
    ma=-10000000;
    // https://msdn.microsoft.com/ja-jp/library/s3f49ktz.aspx
    long long sums;
    sums = 0;
    cin >> n ;
    int c;
    for (int i = 0; i < n ; i++){
        cin >> c;
        sums = sums + c;
        mi = min(mi,c);
        ma = max(ma,c);
    }
    cout << mi << " " << ma << " " << sums << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    vector<ll> p(n);
    rep(i,n) cin>>p[i];
    sort(etob(p));
    ll ans=0;
    ans+=p[0];
    n-=2;
    int m=n/2;
    rep(i,m) ans+=p[i+1]*2;
    if(n%2==1){
        ans+=p[m+1];
    }
    cout<<ans<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  vector<int> tmp(n);
  rep(i,n) cin >> a[i];
  rep(i,n) {
    tmp[a[i]-1] = i;
  }
  
  rep(i,n) {
  cout << tmp[i]+1 << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


signed main() {
	int x, y; cin >> x >> y;
	int ans = 0;
	if (x == 3)ans += 100000;
	else if (x == 2)ans += 200000;
	else if (x == 1)ans += 300000;
	if (y == 3)ans += 100000;
	else if (y == 2)ans += 200000;
	else if (y == 1)ans += 300000;
	if (x == 1 && y == 1)ans += 400000;
	cout << ans << endl;
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (long long  i = 0; i < n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ll long long
using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef  long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int main()
{

i64 n,ans=0,tot,s[103][2];
// vi64 v;
cin>>n>>tot;
forn(i,n)
{
	forn(j,2)
	{
		cin>>s[i][j];

	}
}
i64 dp[103][100003];
forn(i,n+1)
{

	forn(j,tot+1)
	{
		if(j==0||i==0)
	{	dp[i][j]=0;
		// cout<<dp[i][j]<<" ";
continue;
}
		if(s[i-1][0]>j)

		{dp[i][j]=dp[i-1][j];
			// cout<<dp[i][j]<<" ";
			continue;
}
		dp[i][j]=max(dp[i-1][j-s[i-1][0]]+s[i-1][1],dp[i-1][j]);
		// cout<<dp[i][j]<<" ";


	}
	// cout<<"\n";
}

cout<<dp[n][tot]<<"\n";

	return 0;
}


Measured memory_bytes: 80384
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		for (int i=0;i<n;i++) {
			int [] a = new int[81];
			int [] b = new int[81];
			Arrays.fill(a, 0);
			Arrays.fill(b, 0);
			String [] as = s.next().split("");
			String [] bs = s.next().split("");
			if (as.length > 80 | bs.length > 80) {
				System.out.println("overflow");
				continue;
			}
			for (int j=0;j<as.length;j++) {
				a[j] = Integer.valueOf(as[as.length - 1 - j]);
			}
			for (int j=0;j<bs.length;j++) {
				b[j] = Integer.valueOf(bs[bs.length - 1 - j]);
			}
			int ansLen = 0;
			for (int j=0;j<80;j++) {
				int temp = a[j] + b[j];
				int c = temp / 10;
				int r = temp % 10;
				a[j] = r;
				a[j + 1] += c;
				if (a[j] != 0) ansLen = j;
			}
			if (a[80] != 0) {
				System.out.println("overflow");
				continue;
			}
			String ans = "";
			for (int j=0;j<=ansLen;j++) {
				ans = a[j] + ans;
			}
			System.out.println(ans);
			
		}
	}
}



Measured memory_bytes: 26252
import java.util.*;

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();
    if((a-c)*(c-b)>0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.

int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	double n,t,a;
	cin>>n>>t>>a;
	double h;
	double mul = 0.006;
	double min = 1e9;
	int ind = -1;
	rep(i,0,n){
		cin>>h;
		double p = t - h*mul;
		double d = abs(p - a);
		if(min > d){
			min = d;
			ind = i+1;
		}
	}
	cout<<ind;
  	return 0;
}

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


int n, a[300000];

int main(void) {
  cin >> n;
  for (int i = 0; i < 3*n; ++i) {
    cin >> a[i];
  }
  sort(a, a + 3*n);
  long long ans = 0;
  for (int i = 0, j = 3*n-2; i < n; ++i, j -= 2) {
    ans += a[j];
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cmath>
using namespace std;
int a[105];
int main(){
	float n,sum=0,x,res=0;
	float ave;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	ave=sum/n;
	x=round(ave);
	for(int i=0;i<n;i++){
		res+=(x-a[i])*(x-a[i]);
	}
	cout<<res;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    bool flag=1;
    bool cflag=0;
    for (int i=0;i<s.size();i++) {
        if (i==0) {
            if (s[i]!='A') flag=0;
        } else if (i>1 && i<s.size()-1) {
            if (s[i]=='C') {
                if (!cflag) cflag=1;
                else flag=0;
            } else if (s[i]-'a'<0) flag=0;
        } else {
            if (s[i]-'a'<0) flag=0;
        }
    }
    if (flag && cflag) cout << "AC" << endl;
    else cout << "WA" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0022
{
    public class Program

    {
        public static void Main(string[] args)
        {

            while (true)
            {
                int n = ReadInt();
                if (n == 0) break;

                int sum = 0;
                int max = int.MinValue;
                for (int i = 0 ; i < n ; i++)
                {
                    int a = ReadInt();
                    if (sum < 0) sum = 0;
                    sum += a;
                    max = Math.Max(max, sum);
                }
                Console.WriteLine(max);
            }

        }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }
        static string WriteAr(int[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(double[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }
        static string WriteAr(long[] array, string sep = " ") { return String.Join(sep, array.Select(x => x.ToString()).ToArray()); }

    }

}



Measured memory_bytes: 13836
N, M = map(int, input().split())
s = set(range(1, M + 1))


for _ in range(N):
    t = set()
    value = list(map(int, input().split()))
    for i in range(1, value[0] + 1):
        t.add(value[i])
    s = t & s

print(len(s))


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

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

int main()
{
   long long a,b;
   cin>>a>>b;

   if(a==b)
    cout<<a*2;
   else
   {
       cout<<(a*b)/gcd(a,b);
   }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=1e5+50;
const int mod=1e9+7;
using namespace std;
int k,i,j,t;
string s,tmp;
set<string>st;
set<string>::iterator it;
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>s>>k;
    for(i=1;i<=k;i++)
	{
		for(j=0;j<s.size();j++)
		{
			tmp="";
			for(t=j;t<min((int)s.size(),j+i);t++)tmp+=s[t];
			st.in(tmp);
		}
	}
	i=0;
	for(it=st.begin();it!=st.end();it++)
	{
		i++;
		if(i==k)rc((*it));
	}
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>

using namespace std;

int checkA(string);
int checkB(string);

int main(){
  int i, n;
  string snake;

  cin >> n;

  for(i=0; i<n; ++i){
    cin >> snake;

    if(checkA(snake) == 1)
      cout << "A" << endl;
    else if(checkB(snake) == 1)
      cout << "B" << endl;
    else
      cout << "NA" << endl;
  }

  return 0;
}

int checkA(string snake){
  int i, j, count1=0, count2=0;

  if(snake[0] != '>' || snake[1] != '\'' || snake[2] != '=') return 0;

  for(i=2; snake[i] == '='; ++i) ++count1;
  if(snake[count1 + 2] != '#') return 0;

  for(j=count1+3; snake[j] == '='; ++j) ++count2;
  if(count1 != count2 || j != snake.size()-1 || snake[snake.size()-1] != '~') return 0;

  return 1;
}

int checkB(string snake){
  int i;

  if(snake[0] != '>' || snake[1] != '^' || snake[2] != 'Q' || snake[3] != '=') return 0;

  for(i=2; i < snake.size()-2; i+=2){
    if(snake[i] != 'Q' || snake[i+1] != '=') return 0;
  }

  if(snake[snake.size()-2] != '~' || snake[snake.size()-1] != '~') return 0;

  return 1;
}

Measured memory_bytes: 0
import math
x, y = input().strip().split(' ')
x, y = [int(x), int(y)]
get = 0
if x == 3:
    get = get + 100000
if y == 3:
    get = get + 100000
if x == 2:
    get = get + 200000
if y == 2:
    get = get + 200000
if x == 1:
    get = get + 300000
if y == 1:
    get = get + 300000
if x == 1 and y == 1:
    get = get + 400000

print(get)


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

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

lli n, k;

int main(void){
    cin >> n >> k;
    n %= k;
    if(n < k/2+1) cout << n << endl;
    else cout << k-n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>


int main(int argc, char const* argv[])
{
    int a, b, c, d, e, k;
    std::cin >> a >> b >> c >> d >> e >> k;

    if((e - a) > k)
    {
        goto fail;
    }

    std::cout << "Yay!" << std::endl;
    return 0;
fail:
    std::cout << ":(" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main() {
    int a[100][100], b[100][100], m, n, l, i, j, k;
    long long c = 0;
    scanf("%d %d %d", &m, &n ,&l);
    for(i = 0; i < m; ++i) {
        for(j = 0; j < n; ++j) {
            scanf("%d", &a[i][j]);
        }
    }
    for(i = 0; i < n; ++i) {
        for(j = 0; j < l; ++j) {
            scanf("%d", &b[i][j]);
        }
    }
    for(i = 0; i < m; ++i) {
        for(j = 0; j < l; ++j) {
            for(k = 0; k < n; ++k) {
                c += a[i][k] * b[k][j];
            }
            if(j == l - 1) {
                printf("%lld\n", c);
                c = 0;
                continue;
            }
            printf("%lld ", c);
            c = 0;
        }
        // printf("\n");
    }
    // puts("");
    return 0;
}


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

const int MAXN = 100005;
struct node {
	int to, next;
} edge[MAXN*4];
int head[MAXN], top = 0;
auto push = [](int i, int j)
{ edge[++top] = (node) {j, head[i]}, head[i] = top;  };
int n, m, u, v;

int vis[MAXN], siz[MAXN];

bool dfs(int nd)
{ 
	bool ans = true;
	siz[nd] = 1;
	for (int i = head[nd]; i; i = edge[i].next) {
		int to = edge[i].to;
		if (vis[to] == -1) vis[to] = vis[nd]^1, ans = (dfs(to)&&ans), siz[nd] += siz[to];
		else if (vis[to] == vis[nd]) ans = false;
	}
	return ans;
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m;
	fill(vis+1, vis+n+1, -1);
	for (int i = 1; i <= m; i++) {
	        cin >> u >> v;
		push(u, v), push(v, u);
	}
	int odd = 0, even = 0, single = 0;
	long long ans = 0;
	for (int i = 1; i <= n; i++)
		if (vis[i] == -1) {
			vis[i] = 0;
			int ans = dfs(i);
			if (siz[i] == 1) single++;
			else if (ans) even++;
			else odd++;
		}
	ans = 1ll*odd*odd+2ll*odd*even+2ll*even*even+1ll*single*single+2ll*single*(n-single);
	cout << ans << endl;
	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

typedef pair<string,int> sip;

int n;
string a[11],b[11];
string g,d;

string sed(string s,string aa,string bb){
	//dbg(aa); dbg(bb);
	string res=s;
	rep(i,res.length()){
		if(res.substr(i,aa.length())==aa){
			res=res.substr(0,i)+bb+res.substr(i+aa.length(),res.length()-(i+aa.length()));
			i+=bb.length()-1;
		}
	}
	return res;
}

int bfs(string s){
	int res=0;
	queue<sip> que;
	map<string,bool> vis;
	que.push(sip(s,0));
	while(!que.empty()){
		string ns=que.front().fi;
		int ni=que.front().se; que.pop();
		if(ns==d)return ni;
		if(vis[ns]||ns.length()>d.length())continue;
		vis[ns]=true;
		//dbg(ns);
		rep(i,n){
			que.push(sip(sed(ns,a[i],b[i]),ni+1));
		}
	}
	return INF;
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		rep(i,n)cin>>a[i]>>b[i];
		cin>>g>>d;
		int res=bfs(g);
		if(res==INF)cout<<-1<<endl;
		else cout<<res<<endl;
	}
	return 0;
}

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

#define ll long long

using namespace std;

int main(){
    string str;
    int k;
    cin >> str;
    cin >> k;

    for(int i = 0;i < str.length();i++){
        int diff = ('z' + 1) - str[i];
        if(str[i] != 'a' && k >= diff){
            k -= diff;
            str[i] = 'a';
        }
    }

    bool flag = false;
    for(int i = str.length() - 1;i >= 0;i--){
        if(str[i] != 'a'){
            str[i] += (k % 26);
            flag = true;
            break;
        }
    }
    if(!flag){
        str[str.length() - 1] += (k % 26);
    }
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 512