akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int INF = 1000000;
char s[202];
int a[102][102], n;

int solve(char c) {
    memset(a, 0, sizeof(a));
    int cnt = 0;
    for(int i=1;i<=n;i++) {
        if(s[i] == c) {
            a[0][i] = 1; cnt ++;
        }
    }
    if(cnt == 0) return INF;

    for(int t = 0; t <= n-1; t ++) {
        int ok = 1;
        for(int i=1;i<=n-t;i++) {
            if(a[t][i] == 0) {
                ok = 0;
            } 
        }
        if(ok) return t;

        for(int i = n-t-1; i >= 1; i--) {
            if(a[t][i+1] || a[t][i]) {
                a[t+1][i] = 1;
            }
        }
    }
}
int main() {
    scanf("%s", s+1);
    n = strlen(s+1);
    int ans = INF;
    for(int c = 'a'; c <= 'z'; c++) {
        ans = min(ans, solve((char)c));
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cctype>
#include <algorithm>
#include <string>
#include <cstdlib>
using namespace std;


int main(){
	string T, W;
	int count = 0;

	cin >> W;
	while(1){
		cin >> T;
		if (T.find("END_OF_TEXT") != string::npos) break;
		transform(T.begin(), T.end(), T.begin(), ::tolower);
		//cout << "[" << T << "]";
		if(T.find(W) != string::npos && T.length() == W.length()) count++;
	}
	
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3240
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    string S;
    cin >> S;
    string ans = "";
    for(int i = 0; i < S.size();i+=2) {
        ans += S.substr(i,1);
    }
    print(ans);
    return 0;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int l[3 * mx5], r[3 * mx5];

int main()
{
    int L;
    cin >> L;
    string s;
    cin >> s;

    s = "." + s;

    L++;
    for(int i = 1; i <= L; i++){
        if(s[i] == 'W')
            l[i]++;
        l[i] += l[i - 1];
    }

    for(int i = L; i; i--){
        if(s[i] == 'E')
            r[i]++;
        r[i] += r[i + 1];
    }

    int ans = INT_MAX;
    for(int i = 1; i <= L; i++)
        ans = min(ans, l[i - 1] + r[i + 1]);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 6112
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
const int N = 1e5 + 10, INF = 1e9 + 10;

int p[N], q[N], r[N];

void solve() {
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; ++i) {
		cin >> p[i];
	}
	for (int i = 0; i < b; ++i) {
		cin >> q[i];
	}
	for (int i = 0; i < c; ++i){
		cin >> r[i];
	}
	sort(p, p + a);
	sort(q, q + b);
	sort(r, r + c);
	multiset <int> s1, s2;
	for (int i = a - 1; i >= a - x; --i) {
		s1.ins(p[i]);
	}
	for (int i = b - 1; i >= b - y; --i) {
		s2.ins(q[i]);
	}
	for (int i = c - 1; i >= 0; --i) {
		int lol1 = *(s1.begin());
		int lol2 = *(s2.begin());
		if (lol1 < lol2) {
			if (r[i] > lol1) {
				s1.ers(s1.begin());
				s1.ins(r[i]);
			}
		} else {
			if (r[i] > lol2) {
				s2.ers(s2.begin());
				s2.ins(r[i]);
			}
		}
	}
	ll ans = 0;
	for (auto x : s1) {
		ans += (ll)(x);
	}
	for (auto x : s2) {
		ans += (ll)(x);
	}
	cout << ans;
}
 
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    solve();
    return 0;
}

Measured memory_bytes: 9856
n,m = (int(i) for i in input().split())
x,v,z = [],[0]*n,[None]*m
for i in range(m):
	p,y = (int(i) for i in input().split())
	x.append([p-1,y,i])
x.sort()
for i in range(m):
	s,t = len(str(x[i][0]+1)),len(str(v[x[i][0]]+1))
	z[x[i][2]] = "0"*(6-s)+str(x[i][0]+1)+"0"*(6-t)+str(v[x[i][0]]+1)
	v[x[i][0]]+=1
for i in z: print(i)

Measured memory_bytes: 32108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,max,min,mid,s=0;
  cin >>a>>b>>c;
  if(a != b && b != c && a != c){ 
      max = a;
    if(max < b) max = b;
    if(max < c) max = c;
      min = a;
    if(min > b) min = b;
    if(min > c) min = c;
      mid = a;
    if(min < b && b < max) mid = b;
    if(min < c && c < max) mid = c;
  }
  if( a == b && a < c){
    max = c;
    mid = b;
    min = a;
  }
  if( a == b && a > c){
    min = c;
    mid = b;
    max = a;
  }
  if( a == c && a < b){
    max = b;
    mid = c;
    min = a;
  }
  if( a == c && a > b){
    max = a;
    mid = c;
    min = b;
  }
  if( b == c && b > a){
    max = b;
    mid = c;
    min = a;
  }
  if( b == c && b < a){
    max = a;
    mid = c;
    min = b;
  }
  if( a == b && b == c){
    max = a;
    mid = b;
    min = c;
  }
    
    s = (max-min)+(max-mid);
    if(s%2 == 1){s = s+3;}
    cout << s/2 << endl;
  return 0;
}
  

Measured memory_bytes: 256
from collections import deque

class Dinic:
    def __init__(self, v, inf=10**9+7):
        self.V = v
        self.inf = inf
        self.G = [list() for _ in range(v)]
        self.level = [-1 for _ in range(v)]
        self.iter = [0]*v

    def addedge(self,fr,to,cap):
        """
        G[fr] = [to, cap, rev]
        """
        go = [to, cap, None]
        go[2] = back = [fr, 0, go]
        self.G[fr].append(go)
        self.G[to].append(back)

    def bfs(self,st,en):
        q = deque([st])
        self.level = [-1 for _ in range(self.V)]
        self.level[st] = 0
        while q:
            cur = q.popleft()
            for x,cap,_ in self.G[cur]:
                if cap and self.level[x]<0:
                    self.level[x] = self.level[cur] + 1
                    q.append(x)
        return self.level[en] > 0

    def dfs(self,v,t,f):
        if v == t:
            return f
        for e in self.iter[v]:
            w,cap,rev = e
            if cap and self.level[v]<self.level[w]:
                d = self.dfs(w,t,min(f,cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self,s,t):
        flow = 0
        while self.bfs(s,t):
            self.iter = list(map(iter, self.G))
            f = self.dfs(s,t,self.inf)
            while f:
                flow += f
                f = self.dfs(s,t,self.inf)
        return flow
n = int(input())
dinic = Dinic(n*2+2)
red = [tuple(map(int, input().split())) for _ in range(n)]
blue = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
  dinic.addedge(0,1+i,1)
  dinic.addedge(n+1+i,2*n+1,1)
for i in range(n):
  for j in range(n):
    if red[i][0] < blue[j][0] and red[i][1] < blue[j][1]:
      dinic.addedge(1+i,n+1+j,1)
print(dinic.flow(0,2*n+1))

Measured memory_bytes: 4080
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
ll a,b,s;

int main(){
for (int q=read();q--;pl){
  read(a),read(b),s=a*b;
  ll t=sqrt(s);
  if (t*(t+1)<s) cout<<t*2-1;
  else if (t*t==s) cout<<t*2-2-(a!=b);
  else cout<<t*2-2;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
constexpr double PI=3.14159265358979323846;
constexpr int INF = INT_MAX/2;

int main() {
	string S, T;
	cin >> S >> T;
	int a=0, b=0, c=0, x, y, z;
	rep(i, S.size()) {
		if (S.at(i)!=T.at(i)) {
			a++;
		}
	}
	std::cout << a << '\n';
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s; cin>>s;
	int cnt=0;
	for(int i=0;i<s.length();i++)
	{
		cnt+=(s[i]=='x');
	}
	cout<<(cnt>=8?"NO":"YES")<<'\n';
}


Measured memory_bytes: 256
/*;

THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i,s,l) for(int i=s;i>=l;i--)
#define mod 1000000007
#define int long long
#define INT_BITS 32
#define ld long double
#define pp pair<int,int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define endl "\n"
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{

    int x,n;
    cin>>x>>n;

    unordered_map<int,int> mp;

    r(i,0,n)
    {
        int x;
        cin>>x;
        mp[x]++;
    }

    vector<int> ans;


    r(i,0,102)
    {
       if(mp[i]==0)
       ans.pb(i);
    }

    vector<pp> vec;
    r(i,0,ans.size())
    {
        vec.pb(make_pair(abs(x-ans[i]),ans[i]));
    }

    sort(all(vec));
    cout<<vec[0].ss;

	return 0;
}



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

int main() {

  int A,B,X;
  cin >> A >> B >> X;
  
  if((A<=X)&&((A+B)>=X)){
   cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		switch(new Scanner(System.in).nextInt()%10) {
		
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			System.out.println("hon");
			return;
			
		case 0:
		case 1:
		case 6:
		case 8:
			System.out.println("pon");
			return;
			
		case 3:
			System.out.println("bon");
			return;
			
		}
	}

}


Measured memory_bytes: 35632
#include<bits/stdc++.h>
using namespace std;
int JC(int k)
{  int m=sqrt(k);
   for(int i=2;i<=m;i++)
   {
     if(k%i==0)  return 0;
   } 
   return 1;
}
int main()
{  int n,k=11;
   cin>>n;
   while(n!=0)
   {
     if(JC(k)==1)
	 {
	   cout<<k<<' ';
	   n--;  
	 }  
	 k+=10;
   }
   return 0;
}

Measured memory_bytes: 256
<?php
$num = rtrim(fgets(STDIN));
$res_arr = array();
for($i=0;$i<$num;$i++){
  $res_arr[]=rtrim(fgets(STDIN));
}
// print_r($res_arr);
$kind_arr = array_count_values($res_arr);
// print_r($kind_arr);
$cnt = count($kind_arr);
echo $cnt;
?>

Measured memory_bytes: 40624
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll N;
ll M;
string s;

int main(){
    
    cin >> N >> M;

    vector<ll > x(N, 0);

    //cin >> x[0];
    ll sunuke = 0;
    
    for(ll i = 0; i < N; i++){
        cin >> x[i];
    }
    //即落ちパターン
  	/*
    if(M == 1){
        cout << 0 << endl;
        return 0;
    }
    if(x[0] > 0){
        cout << x[M - 1] << endl;
        return 0;
    }
    if(x[M - 1] < 0){
        cout << abs(x[N - M]) << endl;
        return 0;
    }
    */
    
    
    ll distance = 11451419191919;
    for(ll i = 0; i < N - M + 1; i++){
        //cout << i << endl;
        //distance = min(distance, min(abs(x[i]), abs(x[i+M-1])) + x[i+M-1] - x[i]);
        ll left = x[i];
        ll right = x[i + M - 1];

        distance = min(min(abs(left), abs(right)) + right - left, distance);

        /* 
        if(right > sunuke){
            
        }
        if(left < sunuke){
            distance = min((sunuke - left) + (right - left), distance);
        }  
        */
    }

    cout << distance << endl;

} 

Measured memory_bytes: 1024
#include<stdio.h>

 
#define N 101
#define BLACK 2
#define WHITE 0
#define GRAY  1
 
 
 
int n=0;
//int z=0;
int G[N][N];
int d[N];
//int f[N];
int color[N];
int que[N];
int head=WHITE;
int tail=WHITE;
 
void Enqueue(int s){
  que[tail] = s;
  tail++;
}
 
int Dequeue(){
  int y;
  y = que[head];
  head+=1;
  return y;
} 
   
 
void bfs(int s){
  int u,w;
  for(u=1;u<=n;u++){
    color[u] = WHITE;
    d[u] = -1;
  }
  color[s] = GRAY;
  d[s] = 0;
  Enqueue(s);
  while(head != tail){
    u = Dequeue();
    for(w=1;w<=n;w++){
      if(color[w] == WHITE && G[u][w] == GRAY){
        color[w] = GRAY;
        d[w] = d[u] + 1;
        Enqueue(w);
      }
    }
    color[u] = BLACK;
  }
}
 
 
 
main(){
  int i,j,s,v,r;
  int p = 1;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1; j<=n;j++){
      G[i][j] = 0;
    }
  }
  for(i=1;i<=n;i++){
    scanf("%d%d", &v,&r);
    for(j=1;j<=r;j++){
      scanf("%d",&s);
      G[i][s] = 1;
    }
  }
  bfs(p);
  for(i=1;i<=n;i++){
    printf("%d %d\n",i, d[i]);
  }
  return 0;
}



Measured memory_bytes: 2036
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
const int INF =100000;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
typedef pair<int,int> P;


int main(){
    int N,M;
    cin>>N>>M;
    char maze[N][M+1];
    int d[N][M+1];
    int i,j;
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
           cin>>maze[i][j];
        }
    }
    int count=0;
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            if(maze[i][j]=='#')count++;
        }
    }
    queue<P> que;
    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            d[i][j]=INF;
        }
    }
    que.push(P(0,0));
    d[0][0]=0;

    while(que.size()){
        P p=que.front();
        que.pop();
        if(p.first==N && p.second ==M)break;
        for(i=0;i<4;i++){
            int nx=p.first+dx[i],ny=p.second+dy[i];
        if(0<=nx && nx<N && 0<=ny && ny<M && maze[nx][ny]!='#' && d[nx][ny]==INF){
            que.push(P(nx,ny));
            d[nx][ny]=d[p.first][p.second]+1;
        }
        }
    }
    if(d[N-1][M-1]==INF){
        cout<<-1<<endl;
    }else{
    int ans=(N*M)-(d[N-1][M-1]+1)-count;
    cout<<ans<<endl;
    }
    return 0;

}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int N,M,Q,a,b;
vpi r;

// dept / dest
int dia[501][501];

signed main(){
    I(N); I(M); I(Q);
    REP(i,M){
        I(a); I(b);
        a--; b--;
        r.eb(a,b);
        dia[a][b]++;
    }
    REP(i,N) REP(j,N) dia[i][j+1] += dia[i][j];

    REP(i,Q){
        I(a); I(b);
        a--; b--;
        int ret = 0;
        FOR(i,a,b+1){
            ret += dia[i][b];
        }
        printf("%lld\n", ret);
    } 
}

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

#pragma warning(disable:4996)
using namespace std;
using ld = long double;

int S=203;

vector<pair<int,int>> dfs(const vector<vector<int>>&field, vector<vector<int>>&used, int y, int x) {
	if(used[y][x])return vector<pair<int,int>>(0);
	else {
		vector<pair<int,int>>anss(1,make_pair(x,y));
		used[y][x]=true;
		int dx[] = { -1,0,1,0 };
		int dy[] = { 0,1,0,-1 };

		for (int way = 0; way < 4; ++way) {
			int nexty=y+dy[way];
			int nextx=x+dx[way];

			if (field[nexty][nextx]) {
				auto p=dfs(field,used,nexty,nextx);
				anss.insert(anss.end(),p.begin(),p.end());
			}
		}
		return anss;
	}
}

char check(vector<pair<int, int>>v) {
	int sz=v.size();
	int xsum=0;
	int ysum=0;
	sort(v.begin(),v.end());
	for (auto p : v) {
		xsum+=p.first;
		ysum+=p.second;
	}
	if (sz == 1) {
		return '*';
	}
	else if (sz == 3) {
		return '-';
	}
	else if (sz == 5) {
		if(xsum==0)return '1';
		else return '+';
	}
	else if (sz == 7) {
		return '7';
	}
	else if (sz == 9) {
		return '4';
	}
	else if (sz == 11) {
		if (xsum == 13) {
			return '3';
		}else {
			assert(xsum==11);
			auto it=find(v.begin(),v.end(),make_pair(0,1));
			if(it==v.end())return '2';
			else return '5';
		}

	}
	else if (sz == 12) {
		if (xsum == 11)return '6';
		if (xsum == 12)return '0';
		{
			assert(xsum == 13);
			return '9';
		}
	}
	else {
		assert(xsum==13);
		return '8';
	}

}

string st;
int a=0;

int num() {
	assert(isdigit(st[a]));
	int num=0;
	while (st.size() != a&&isdigit(st[a])) {
		num*=10;
		num+=st[a]-'0';
		a++;
	}
	return num;
}
int mul() {
	int k=num();
	while (st.size() != a&&st[a] == '*') {
		a++;
		int x=num();
		k*=x;
	}
	return k;
}

int calc() {
	int k=mul();
	while (st.size() != a&&(st[a] == '+'||st[a]=='-')) {
		char ch = st[a];
		a++;
		
		int x=mul();
		if(ch=='-')k-=x;
		else {
			assert(ch=='+');
			k+=x;
		}
		
	}
	return k;
}
int main() {
	
	vector<vector<int>>field(S,vector<int>(S));
	{

		int N;cin>>N;
		for (int i = 0; i < N; ++i) {
			int sx,sy;cin>>sx>>sy;
			int gx,gy;cin>>gx>>gy;
			sx++;sy++;gx++;gy++;
			if (sx == gx) {
				if(sy>gy)swap(sy,gy);
				for (int y = sy,x=sx; y <= gy; ++y) {
					field[y][x]=true;
				}
			}
			else {
				if(sx>gx)swap(sx,gx);
				for (int x = sx,y=sy; x <= gx; ++x) {
					field[y][x]=true;
				}
			}
		}

	}
	{
		map<int, char>mp;
		vector<vector<int>>used(S,vector<int>(S));
		for (int x = 1; x < S - 1; ++x) {
			for (int y = 1; y < S - 1; ++y) {
				if (!used[y][x]&&field[y][x]) {
					auto v=dfs(field,used,y,x);
					int ay=1e8;
					for (auto &p : v) {
						ay=min(ay,p.second);
					}
					for (auto &p : v) {
						p.first-=x;
						p.second-=ay;
					}
					mp[x]=check(v);
				}
			}
		}
		for (auto m : mp) {
			st.push_back(m.second);
		}
	}
	int answer=calc();
	cout<<answer<<endl;
	return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, k;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;
	map<int, int> mp;
	FOR(i, n) {
		int x;
		cin >> x;
		mp[x]++;
	}
	vector<int> v;
	FORR(x, mp) v.push_back(x.second);
	sort(ALL(v));
	int ret = 0;
	FOR(i, (int)v.size()-k) ret += v[i];
	cout << ret << endl;
	return 0;
}

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

int powpow(int x, int y){
    if(y == 0) return 1;
    int ans = x;
    for(int i = 1; i < y; i++){
        ans *= x;
    }
    return ans;
}

int main(){
    while(1){
    int a; cin >> a;
    int L; cin >> L;
    if(a == 0 && L == 0) break;
    vector<int> array;
    array.push_back(a);
    while(1){
        //a?????????
        int MAX = 0, MIN = 0;
        vector<int> count(10, 0);
        vector<int> coun(10, 0);

        
        for(int i = 5; i >= 0; i--){
            //cout << a / (int)pow(10, i) << " ";
            count[a / powpow(10, i)]++;
            a = a % powpow(10, i);
        }

        for(int i = 0; i < 10; i++){
            coun[i] = count[i];
        }
        
        int j = 0;
        for(int i = 9; i > 0; i--){
            if(count[i] != 0){

                int temp = i*powpow(10, j);   //????????????
                MIN += temp;
                //cout << MIN << " " << temp << " " << powpow(10, j) << endl;
                //cout << i*pow(10, j) << endl;
                //cout << MIN << endl;
                j++;
                count[i]--;
                i++;
                //cout << (i+1)*pow(10, j+1) << endl;
                //cout << i+1 << " " << MIN << " " << j+1 << endl;
                continue;
            }
        }
        //cout << MIN << endl;
        //int input; cin >> input;
        j = L - 1;
        for(int i = 9; i >= 0; i--){
            if(coun[i] != 0){

                int temp = i*powpow(10, j);   //????????????
                MAX += temp;
                //cout << i << " " << j << " " << MAX << " " << temp << " " << powpow(10, j) << endl;
                //cout << i*pow(10, j) << endl;
                //cout << MIN << endl;
                j--;
                coun[i]--;
                i++;
                //cout << (i+1)*pow(10, j+1) << endl;
                //cout << i+1 << " " << MIN << " " << j+1 << endl;
                continue;
            }
        }

        //cout << MIN << " " << MAX << endl;
        a = MAX - MIN;
        array.push_back(a);

        //cout << MAX << " " << MIN << " " <<  a << endl;

        //????????????
        int flag = 0;
        for(int i = 0; i < array.size(); i++){
            for(int j = 0; j < i; j++){
                if(array[i] == array[j]){
                    cout << j << " " << array[i] << " " << i - j << endl;
                    flag = 1;
                    break;
                }
            }
            if(flag) break;
        }
        if(flag) break;
        
    }


    }
    return 0;
}

Measured memory_bytes: 3088
import Data.List
import Debug.Trace
import Data.Monoid

data Status = Safe | Danger | Queen deriving (Show, Eq)
type Position = (Int, Int)
type Cell = (Position, Status)
type Board = [Cell]

-- Prepare empty board
emptyBoard :: Board
emptyBoard = sortBy xtoy [((x,y), Safe) | x <- [0..7], y <- [0..7]]
  where xtoy ((x1, y1), _) ((x2, y2), _) = mappend (compare y1 y2) (compare x1 x2)


-- Board functions
getStatus :: Cell -> Status
getStatus (position, status) = status

getPosition :: Cell -> Position
getPosition (position, status) = position

setStatus :: Status -> Cell -> Board -> Board
setStatus status (position, _) board = former ++ [(position, status)] ++ latter
  where (former, target:latter) = break ((==) position . getPosition) board

getQueens :: Board -> [Position]
getQueens board = map fst $ filter ((==) Queen . getStatus) board

getSafes :: Board -> [Position]
getSafes board = map fst $ filter ((==) Safe . getStatus) board

findDangers :: Position -> Board -> [Cell]
findDangers (px,py) board = dangerRow ++ dangerCol ++ dangerSP ++ dangerSM
  where dangerRow = filter ((==) px . fst . getPosition) board
        dangerCol = filter ((==) py . snd . getPosition) board
        dangerSP  = filter (flip elem sp . getPosition) board
        dangerSM  = filter (flip elem sm . getPosition) board
        sp        = [(x,y) | x <- [0..7], y <- [0..7], y == -x+(py+px)]
        sm        = [(x,y) | x <- [0..7], y <- [0..7], y == x+(py-px)]

putQueen :: Position -> Board -> Board
putQueen position board = setStatus Queen (position, Safe) updatedBoard
  where updatedBoard    = foldr (setStatus Danger) board (findDangers position board)


-- Queen problem solver
solveQueens :: Int -> Board -> [Board]
solveQueens 0 board = [board]
solveQueens n board = do
  position <- getSafes board
  let newBoard = putQueen position board
  solveQueens (n-1) newBoard

format :: Board -> [String]
format []    = []
format board = let (row, remain) = splitAt 8 board
                   line          = concat . map (\x -> if getStatus x == Queen then "Q" else ".") $ row
               in line : (format remain)

main = do
  n <- fmap read getLine
  inputs <- fmap (map words . lines) getContents
  let positions = map (\[y, x] -> (read x, read y)) inputs
  let initialBoard = foldr putQueen emptyBoard positions
  mapM_ putStrLn . format . head . solveQueens (8-n) $ initialBoard

Measured memory_bytes: 5152
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vb=vector<bool>;
using pii=pair<int,int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n,m;
    cin>>n>>m;
    vi conne[n];
    rep(i,0,m){
        int s,t;
        cin>>s>>t;
        conne[s].push_back(t);
        conne[t].push_back(s);
    }
    int white=0;
    vi color(n,white);
    int c=1;
    rep(i,0,n){
        c++;
        if(color[i]==white){
        stack<int> st;
        st.push(i);
        while(!st.empty()){
            int n=st.top(); st.pop();
            color[n]=c;
            for(int itr:conne[n]){
                if(color[itr]!=c){
                    st.push(itr);
                }
            }
        }
        }
    }
    int q; cin>>q;
    rep(i,0,q){
        int from,to;
        cin>>from>>to;
        if(color[from]==color[to])cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}





Measured memory_bytes: 8640
def main():
    N = int(input())
    pl = list(map(float, input().split()))
    v = [1 - pl[0], pl[0]]
    mid = (N + 1) // 2
    for i, p in enumerate(pl[1:mid], 1):
        v = v + [0.0]
        t = v[0]
        v[0] = t * (1 - p)
        for j, uu in enumerate(v[1:], 1):
            v[j] = t * p + uu * (1 - p)
            t = uu
    for i, p in enumerate(pl[mid:], mid):
        t = v[i - mid + 1]
        for j, uu in enumerate(v[i - mid + 2:-1], i - mid + 2):
            v[j] = t * p + uu * (1 - p)
            t = uu
        v[mid] += t * p
    print(v[mid])

main()


Measured memory_bytes: 3316
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;

const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	ll ans = 1;
	while(n--){
		if(ans + k <= (ans<<1))
			ans += k;
		else
			ans <<= 1;
	}
	cout << ans;
	return 0;
}

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

const int maxn = 1e6 + 15;
bool is_prime[maxn];
int sieve(int x){
	int res = 0;
	fill(is_prime+2,is_prime+x+1,true);
	for(int i = 2; i <= x; i++) if(is_prime[i]){
		res++;
		for(int j = 2 * i; j <= x; j += i) is_prime[j] = false;
	}
	return res;
}

int main(){
	int n;
	while(scanf("%d", &n) == 1) printf("%d\n", sieve(n));
	return 0;
}

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

int main(){
    int N;
    string S;

    cin >> N;
    cin >> S;

    int x=0,max=0;
    for(int i=0;i<N;i++){
        if(S[i]=='I') x++;
        else x--;

        if(max<x) max=x;
    }

    cout << max << endl;

    return 0;
}

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

int main(){
    ll n;
    ll r=1e9+7;
    cin>>n;
    ll arr[n];
    ll sum=0;
    for(int i=0;i<n;i++){
        ll temp;
        cin>>temp;
        if(i==0)
            arr[i]=temp;
        else{
            sum+=(temp*arr[i-1])%r;
            arr[i]=(arr[i-1]%r+temp%r)%r;
        }
    }


    cout<<sum%r;
    return 0;
}


Measured memory_bytes: 5108
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();

		int[] num = new int[w];
		for(int i = 0;i < num.length;i++) {
			num[i] = i+1;
		}
		for(int i = 0;i<n;i++) {
			String ab_st = sc.next();
			String[] ab = ab_st.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;

			int sub=0;
			sub = num[a];
			num[a] = num[b];
			num[b] = sub;

		}
		for(int i = 0;i < num.length;i++) {
			System.out.printf("%d\n",num[i]);
		}
		sc.close();
	}
}



Measured memory_bytes: 25924
#ifdef _LOCAL
#	include <dbg_print.h>
#else
#	define NDEBUG
#	define dprint(...)
#endif

#include <cmath>
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for(int i=0; i<n; ++i)
	{
		cin >> h[i];
	}

	ll ans = 0;
	sort(h.begin(), h.end());
	for(int i=0; i<std::max(n-k,0); ++i)
	{
		ans += h[i];
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1024
import numpy as np
from itertools import combinations
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
count=0
for y,z in combinations(X,2):
    count+=(sum(diff**2 for diff in np.array(y)-np.array(z))**.5).is_integer()
print(count)

Measured memory_bytes: 12428
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    string str;
    cin >> str;

    LL w;
    cin >> w;

    string ans = "";

    for(int i = 0; i < str.size(); i += w){
        ans += str[i];
    }

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

Measured memory_bytes: 256
#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;


int h,w;
int p[222][222],mp[222][222];
bool used[222];

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

void dfs(int i,int j,int idx){
  mp[i][j]=idx;
  rep(d,maxd[p[i][j]]){
    int ni=i+dy[d],nj=j+dx[d];
    if(ni>=0&&ni<h&&nj>=0&&nj<w&&p[i][j]==p[ni][nj]&&mp[ni][nj]==-1){
      dfs(ni,nj,idx);
    }
  }
}

string tree(int par){
  used[par]=true;
  string res;
  res+="(";
  vector<string> tmp;
  rep(i,h)rep(j,w){
    if(mp[i][j]!=par)continue;
    rep(d,maxd[p[i][j]]){
      int ni=i+dy[d],nj=j+dx[d];
      if(ni>=0&&ni<h&&nj>=0&&nj<w&&par!=mp[ni][nj]&&!used[mp[ni][nj]]){
        tmp.push_back(tree(mp[ni][nj]));
      }
    }
  }
  sort(all(tmp));
  rep(i,tmp.size())res+=tmp[i];
  res+=")";
  return res;
}

int main(){
	cin.sync_with_stdio(false);
  while(1){
    string res[2];
    rep(hoge,2){
      cin>>h>>w;
      if(h==0&&w==0){
        return 0;
      }
      memset(p,0,sizeof(p));
      rep(i,h){
        string in;
        cin>>in;
        rep(j,w){
          p[i+1][j+1]=in[j]=='#'?1:0;
        }
      }
      h+=2; w+=2;
      memset(mp,-1,sizeof(mp));
      int idx=0;
      rep(i,h)rep(j,w){
        if(mp[i][j]==-1){
          dfs(i,j,idx++);
        }
      }
      memset(used,0,sizeof(used));
      res[hoge]=tree(0);
    }
    if(res[0]==res[1])cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
	return 0;
}

Measured memory_bytes: 3668
import fractions
a,b,c,d=map(int, input().split())
C=b//c - (a-1)//c
D=b//d - (a-1)//d
e=c*d//fractions.gcd(c, d)
E=b//e - (a-1)//e
ans=b-a-C-D+E+1
print(ans)

Measured memory_bytes: 5048
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
typedef long long LL;

using namespace std;

int main()
{
	int a[5];
	for(int i = 0;i <5;i++)
	{
		cin >> a[i];
		if(a[i] == 0)
		{
			cout << i+1;
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3628
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

a,b = inpl()

A = max(a,b)
B = min(a,b)

Alist =list()
i = 1
while i <= A/i :
    if A%i==0:
        Alist.append(i)
        Alist.append(A/i)
    i += 1
i=1
Blist =list()
while i <= B/i :
    if B%i==0:
        Blist.append(i)
        Blist.append(B/i)
    i += 1

Clist = list()
for i in range (len(Alist)):
    if Alist[i] in Blist:
        Clist.append(Alist[i])

Clist = list(set(Clist))
Clist.sort()

anslist = list()
for i in range(len(Clist)):
    if Clist[i]==1:
        anslist.append(Clist[i])
    elif len(anslist) == 1:
        anslist.append(Clist[i])
    elif len(anslist) >= 2:
        for j in range(1,len(anslist)):
            if Clist[i] % anslist[j] == 0:
                break
        else:
            anslist.append(Clist[i])

print(len(anslist))

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

#define ff first
#define ss second
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define w(x) int t; cin >> t; while(t--)
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define repd(i, b, a) for(int i = b; i >= a; i--)
#define mk(arr,n,type) type* arr = new type[n];
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define um unordered_map
#define us unordered_set
#define pqm priority_queue<int>
#define pqmi priority_queue<int, vi, greater<int>>
#define lb(v, val) lower_bound(v.begin(), v.end(), val) - v.begin();
#define ub(v, val) upper_bound(v.begin(), v.end(), val) - v.begin();
#define setbits(x) __builtin_popcountll(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define out(flag) flag ? cout << "NO" << endl : cout << "YES" << endl;
#define MAX 100001
#define MOD 1000000007
#define inf 1e18
#define PI 3.1415926535

void IO() {
	fast;
}

int main() {

	IO();

	int h, w;
	cin >> h >> w;
	vector<vector<char>> sq(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> sq[i][j];
		}
	}
	vector<vector<int>> dp(h, vector<int>(w, 0));
	for (int i = 0; i < h; i++) {
		if (sq[i][0] == '#') break;
		dp[i][0] = 1;
	}
	for (int i = 0; i < w; i++) {
		if (sq[0][i] == '#') break;
		dp[0][i] = 1;
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			if (sq[i][j] != '#') {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
			}
		}
	}
	cout << dp[h - 1][w - 1] << endl;

	return 0;
}


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

public class Main {
	private static void solve(){
	//Implement solution here.
		int r = ni();
		System.out.println(r*r);		
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        }
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 22484
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll N,M;
vector<vector<ll>> edge;
vector<vector<ll>> back;
vector<ll> dp;

void bfs(ll u){
  for(auto &I:dp){I=MOD;}
  queue<ll> Q;
  for(auto &I:edge[u]){
    dp[I]=1;
    Q.push(I);
  }
  while(!Q.empty()){
    ll u=Q.front(); Q.pop();
    for(auto &v:edge[u]){
      if(dp[v]>dp[u]+1){
        dp[v]=dp[u]+1;
        Q.push(v);
      }
    }
  }
}


int main(){
  cin>>N>>M;
  edge.resize(N);
  back.resize(N);
  dp.resize(N);
  for(int i=0;i<M;i++){
    ll a,b;
    cin>>a>>b;
    a--; b--;
    edge[a].push_back(b);
    back[b].push_back(a);
  }
  ll mi=MOD,idx=-1;
  for(int i=0;i<N;i++){
    bfs(i);
    if(dp[i]<mi){
      mi=dp[i];
      idx=i;
    }
  }
  if(idx==-1){cout<<-1<<endl; return 0;}
  bfs(idx);
  cout<<dp[idx]<<endl;
  int w=idx;
  while(dp[w]>1){
    cout<<w+1<<endl;
    for(auto &v:back[w]){
      if(dp[v]+1==dp[w]){w=v; break;}
    }
  }
  cout<<w+1<<endl;
  return 0;

  //cout<<-1<<endl;
  
  //return 0;
}


Measured memory_bytes: 384
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import Text.Printf

readInt = ( readLn :: IO Int )
getInts = map ( read :: String -> Int ) . words <$> getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	getLine
	as <- getInts

	print $ minimum $ map ( cost as ) [ -100 .. 100 ]

cost as b = sum $ map ( \d -> d * d ) $ zipWith (-) as $ repeat b


Measured memory_bytes: 1020
class UnionFind
  attr_accessor :sz, :id
  # @param {Integer} n
  def initialize(n)
    @id = Array.new(n)
    @sz = Array.new(n)
    n.times do |i|
      @id[i] = i
      @sz[i] = 1
    end
  end

  def connected?(i, j)
    root(i) == root(j)
  end

  def unite(i, j)
    iroot = root(i)
    jroot = root(j)
    return if iroot == jroot
    if @sz[iroot] < @sz[jroot]
      @id[iroot] = j
      @sz[jroot] += @sz[iroot]
    else
      @id[jroot] = i
      @sz[iroot] += @sz[jroot]
    end
  end
  
  def component_size(i)
    @sz[root(i)]
  end

  def root(i)
    if @id[i] == i
      i
    else
      @id[i] = @id[@id[i]] # pass compression
      root(@id[i])
    end
  end
end

n,k,l = gets.split.map(&:to_i)

rails = UnionFind.new(n+1)
roads = UnionFind.new(n+1)

k.times do
  a,b = gets.split.map(&:to_i)
  rails.unite(a,b)
end

l.times do
  c,d = gets.split.map(&:to_i)
  roads.unite(c,d)
end


counter = {}
 
(1..n).each do |i|
  counter[[rails.root(i), roads.root(i)]] ||= []
  counter[[rails.root(i), roads.root(i)]] << i
end
 
ans = Array.new(n+1, 0)

counter.values.each do |varr|
  varr.each do |i|
    ans[i] = varr.size
  end
end
 
ans.shift
 
puts ans.join(' ')

Measured memory_bytes: 47484
n,m,l=gets.chomp.split(" ").map(&:to_i)
a_matrix = []
n.times do
    arr = gets.chomp.split(" ").map(&:to_i)
    a_matrix.push(arr)
end
b_matrix = []
m.times do
    arr = gets.chomp.split(" ").map(&:to_i)
    b_matrix.push(arr)
end
(0..(n-1)).each do |i|
    first = true
    (0..(l-1)).each do |j|
        if first
            first = false
        else
            print " "
        end
        c = (0..(m-1)).map {|k| a_matrix[i][k]*b_matrix[k][j] }.inject(:+)
        print c
    end
    puts
end


Measured memory_bytes: 9728
N, M = map(int, input().split(" "))
L = 1
R = N
ans = 0
for m in range(M):
    L_in, R_in = map(int, input().split(" "))
    if L_in > L:
        L = L_in
    if R_in < R:
        R = R_in
if L > R:
    ans = 0
else:
    ans = R - L + 1
print(ans)


Measured memory_bytes: 3060
import * as fs from "fs";

function main(lines: string[][]) {
  const slimes = lines[1][0].split("");
  const unique = (data: string[]): string[] => {
    const uniq = [];
    data.forEach((d) => {
      if (uniq[uniq.length - 1] !== d) uniq.push(d);
    });
    return uniq;
  };
  const uniqueData = unique(slimes);
  console.log(uniqueData.length);
}

const lines = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")
  .map((l) => l.split(" "))
  .filter((input) => !(input.length === 1 && input[0] === ""));

main(lines);


Measured memory_bytes: 10828
#include <stdio.h>

int main(){
  int n, tmp, min = 1000001, max = -1000001;
  long sum = 0;

  scanf("%d", &n);

  for(int i = 0; i < n; i++) {
    scanf("%d", &tmp);

    sum += tmp;

    if(tmp < min) {
      min = tmp;
    }

    if(tmp > max) {
      max = tmp;
    }
  }
  printf("%d %d %ld\n", min, max, sum);
}


Measured memory_bytes: 2132
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string c;
  while(cin >> c){
    TSTART();
    string ans;
    if(c == "a" || c == "i" || c == "u" || c == "e" || c == "o")ans = "vowel";
    else ans = "consonant";
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ---------------------------------------------------------------------------

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  ll ans = 0;
  for(int i=0; i<N; i++){
    cin >> A[i] >> B[i];
    ans -= B[i];
  }
  vector<ll> sum(N);
  for(int i=0; i<N; i++){
    sum[i] = A[i] + B[i];
  }
  sort(sum.begin(),sum.end(),greater<ll>());
  for(int i=0; i<N; i+=2){
    ans += sum[i];
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int coin1 = N / 500; 
  int coin1_amari = N % 500;
  int coin2 = coin1_amari / 5; 
  cout << coin1 * 1000 + coin2 * 5 << endl;
}

Measured memory_bytes: 256