akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<string> s(n);
    vector<vector<int>> p(n, {1, 0});
    for (int i = 0; i < n; i++)
    {
        cin >> s[i] >> p[i][1];
    }

    string strtmp = s[0];
    int res = p[0][1];
    int check;
    int cnt = 0;
    while (cnt < n)
    {
        for (int ii = 0; ii < n; ii++)
        {
            if (p[ii][0])
            {
                strtmp = s[ii];
                res = p[ii][1];
                check=ii;
                // cout << ii << strtmp << res << endl;
                break;
            }
        }

        for (int ii = 0; ii < n; ii++)
        {
            if (p[ii][0])
            {
                if (strtmp > s[ii])
                {
                    res = p[ii][1];
                    strtmp = s[ii];
                    check = ii;
                }
                else if (strtmp == s[ii])
                {
                    if (res < p[ii][1])
                    {
                        res = p[ii][1];
                        check = ii;
                    }
                }
            }
            // cout << ii << strtmp << res << endl;
        }
        cout << check + 1 << endl;
        p[check][0] = 0;
        cnt++;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
  {
     char ch[3];
     int count = 0;
     cin>>ch;
     for(int i = 0;i<3;i++)
     {
       if(ch[i]=='1')
       count++;
     }
     cout<<count<<endl;
  } 

Measured memory_bytes: 3584
#include <stdio.h>
#include <math.h>
#include <string.h>
#define inf 1000000007;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
	long long int a,b,c,i,j,k,N,M;
	scanf("%lld %lld",&N,&M);
	j=pow(2.0,M);
	a=(100*N+1800*M)*j;
	printf("%d\n",a);
	return 0;
}


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

int main() {
  double r;
  cin >> r;
  double pai = 3.141592653589;
  
  cout << fixed << setprecision(6) << r * r * pai << " ";
  cout << fixed << setprecision(6) << 2 * r * pai << endl;
}


Measured memory_bytes: 3300
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			int m = scan.nextInt() - 2*n;
			char[] ch = (scan.next()).toCharArray();
			int count = 0;
			for(int i = 0;i < m;i++){
				if(ch[i] == 'I'){
					for(int j = 1;j < 2*n+1;j+=2){
						if(ch[i+j] != 'O' || ch[i+j+1] != 'I'){
							break;
						}else if(j == 2*n-1){
							count++;
							i++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 32884
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

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

int main() {
  int N;
  cin >> N;
  ll ans = 0;
  rep(i, N){
    ans += i;
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<cctype>

#define MP make_pair
#define PB push_back
#define REP(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long LL;
typedef vector<int> VI;

const int DX[] = { 1, 0, -1, 0 }, DY[] = { 0, -1, 0, 1 };

int main(){
	int n, m, p,x,y=0;
	VI X;
	while (1){
		cin >> n >> m >> p;
		if (n == 0 && m == 0 && p == 0)
			break;
		for (int i = 0; i < n; i++){
			cin >> x;
			y += x;
			X.PB(x);
		}
		if (X[m - 1] == 0)
			cout << 0 << endl;
		else
			cout << (int)(((y *100) - (y * 100 * ((float)p / 100)))/ X[m - 1]) << endl;
		y = 0;
		X.clear();
	}
	return 0;
}

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

int main() {
  int N, A, B, X;
  string op;
  cin >> N >> A >> B ;

  X = N * A ;
  
  if (X >= B) {
    cout << B << endl;
  }
  
  else {
    cout << X << endl;
  }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    var a = 1000000000
    var b = 0L
    for(i in 1 .. Math.sqrt(n.toDouble()).toInt()){
        b = (n / i.toLong())
        if((i * b) == n){
            var ta = Math.max(i.toLong(), b).toString().count()
            a = Math.min(a, ta)
        }
    }
    println(a)
}

Measured memory_bytes: 31864
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n,y=0,c=0;
    string s;
    cin>>n>>s;
    for(int x=0;x<n;x++)
    {
        if(s[x]=='I')
            ++y;
        if(s[x]=='D')
            --y;
        if(y>c)
            c=y;
    }
    cout<<c;
}

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

using namespace std;

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

int dp[3][3][9];



int main(void){

    int w, h, n;
    cin >> w >> h >> n;

    vector<vector<int>> area(h, vector<int>(w));

    roop(i, n){
        int x, y, s;
        cin >> x >> y >> s;
        if(s == 1){
            for(int j = 0;j < h;j++){
                for(int k = 0;k < x;k++){
                    area[j][k] = 1;
                }
            }
        }else if(s == 2){
            for(int j = 0;j < h;j++){
                for(int k = x;k < w;k++){
                    area[j][k] = 1;
                }
            }
        }else if(s == 3){
            for(int j = 0;j < y;j++){
                for(int k = 0;k < w;k++){
                    area[j][k] = 1;
                }
            }
        }else {
            for(int j = y;j < h;j++){
                for(int k = 0;k < w;k++){
                    area[j][k] = 1;
                }
            }
        }
    }


    int ans = 0;
    roop(i, h){
        roop(j, w){
            if(area[i][j] == 0) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

char s[105], t[105];

int main(){
	int n, pos, flag;
	scanf("%d",&n);
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	pos = 0;
	for (int i = 1; i <= n; i++){
		flag = 1;
		for (int j = 1; j <= n - i + 1; j++){
			if (s[i + j - 1] != t[j]){
				flag = 0;
				break;
			}
		}
		if (flag){
			pos = i;
			break;
		}
	}
	if (!pos) printf("%d\n", n * 2);
	else printf("%d\n", n + pos - 1);
	return 0;
}

Measured memory_bytes: 256
N = int(input())
G = [dict() for n in range(N)] ## 各頂点間の距離を一旦格納する

for n in range(N-1):
  u,v,w = map(int,input().split())
  G[u-1][v-1] = w
  G[v-1][u-1] = w
  
colors = [-1 for n in range(N)]
dists = [-1 for n in range(N)]
dists[0] = 0

"""考え方
現在、各頂点間の距離を求めた。
ここから「根」から各頂点への距離を求める。(dists)
そして、その値に基づいて適当に色を決める。(colors)
"""

q = [0]

while len(q) > 0:
  ## 計算済みの最大の頂点の値を取得
  ## 全ての頂点の距離を計算している場合は、whileが終了する
  r = q.pop()
  
  for node in G[r]:
    if dists[node] != -1: ## 距離を計算している頂点に関しては処理をスキップ
      continue
    
    dists[node] = dists[r] + G[r][node] # 根-対象の頂点間の距離を格納
    
    ## 次回は計算ずみの頂点の最大点から処理を進める。
    ## Gには値の順に登録されている
    q.append(node) 


## 偶奇だけを見ればいいので、色は下記で求まる。
## また、必ず答えが１つ存在する、ということが前提なのでこのようなシンプルな形で求めてしまって問題無い
for n in range(N):
  colors[n] = dists[n] % 2

for color in colors:
  print(color)

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

const int MAXN = 60;
int N;
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	int bads = 0;
	for (int i = 0; i < N; i++) {
		int v; cin >> v; v--;
		bads += (v != i);
	}
	cout << ((bads == 0 || bads == 2) ? "YES" : "NO") << '\n';

	return 0;
}


Measured memory_bytes: 256
n = int(input())
blue = [input() for _ in range(n)]

m = int(input())
red = [input() for _ in range(m)]

price_max = 0
for a in blue:
    if (blue.count(a) - red.count(a)) > price_max:
        price_max = blue.count(a) - red.count(a)
print(price_max)

Measured memory_bytes: 9000
#include <iostream>
using namespace std;
int main()
{
	int n, a;
	bool f = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0)	f = false;
		}
	}
	if (f)	cout << "APPROVED" << endl;
	else {
		cout << "DENIED" << endl;
	}
	return 0;
}

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

int main() {
	int N,K,x,sums,la,lb;
  	cin >> N >> K;
  	for (int i = 0; i < N; i++){
    cin >> x;
    la = 2 * x;
    lb = (K - x) * 2;
    if (lb < 0){
    	lb /= -1;
    }
    if (la <= lb){
    	sums +=	la; 
    }
    else {
    	sums += lb;
    }
    }
  	cout << sums << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int count = 0;
        for(int i = 0; i < n; i++){
            if(Integer.parseInt(sc.next()) >= k){
                count++;
            }
        }
        
        System.out.println(count);
    }
}

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

int main(){
  int N;
  cin>>N;
  int i;
  for(i=1;i*(i+1)/2<N;i++){}
  if(i*(i+1)/2==N)for(int j=1;j<=i;j++)cout<<j<<endl;
  else{
    int k=i*(i+1)/2-N;
    for(int j=1;j<=i;j++){
      if(j!=k)cout<<j<<endl;
    }
  }
}


Measured memory_bytes: 256
from collections import deque
def dfs(path):
    global visited, A
    q = deque([])
    q.append(path)
    for d in A[1]:
        q.append(d)
    while q:
        p = q.pop()
        for d in A[p]:
            if visited[d] == True:
                pass
            else:
                visited[d] = True


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [[] for _ in range(N+1)]
    for _ in range(M):
        a, b = map(int, input().split())
        A[a].append(b)
        A[b].append(a)
    visited = [False] * (N+1)
    dfs(1)
    if visited[N]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


Measured memory_bytes: 40444
//0654 菅野美怜　未完成 //
#include<iostream>
#include<queue>
using namespace std;
int main(void){
  int N;
  int count = 0;
  char x;
  cin >> N;
  queue<char> data;
  
  for (int i = 0; i < N;i++){
    cin >> x;
    data.push(x);
  }

  //set<string> data2 = data;
  while(true)
  {
    if(data.front()=='O'){
      data.pop();
      if(data.front()=='X'){
        data.pop();
        count++;
      }
    }
      if(data.front()=='X'){
        data.pop();
        if(data.front()=='O'){
          data.pop();
          count++;
        }
      }
      if(data.size()==0){
      break;
    }
    
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3268
#include <bits/stdc++.h>
    #define ll long long
    using namespace std;
     
    int main() {
      //freopen("in.txt", "r", stdin);
      //freopen("out.txt", "w", stdout);
      int n;
      cin >> n;
      int a[2][n];
      for(int i = 0;i < n;i++){
        cin >> a[0][i];
        if(i)
          a[0][i] += a[0][i - 1];
      }
      for(int i = 0;i < n;i++){
        cin >> a[1][i];
        if(i)
          a[1][i] += a[1][i - 1];
      }
      int res = 0;
      for(int i = 0;i < n;i++){
        res = max(res, a[0][i] + a[1][n - 1] - (i ? a[1][i - 1] : 0));
      }
      cout << res;
      return 0;
    }

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

int main(){
    int64_t x, k, d; cin >> x >> k >> d; x = abs(x);
    if((x / d) > k) {
        x -= d * k; k = 0;
    } else {
        k -= (x / d); x -= d * (x / d);
    }
    if(k > 0) {
        if(k % 2 == 1) x = min(abs(x - d), abs(x + d));
        else x = min(min(abs(x - 2 * d), abs(x + 2 * d)), abs(x));
    }
    cout << abs(x) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	vi a(n);
	rep(i, n)cin >> a[i];
	
	map<int, int> mp;

	ll ans = 0;
	rep(i, n - 1) {
		mp[a[i] + i]++;
		ans += mp[i + 1 - a[i + 1]];
	}

	cout << ans << endl;

}

Measured memory_bytes: 21068
// #include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>

using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    int n;
    cin >> n;
    if (n == 3 || n == 5 || n == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int sz = 1e5+1;
ll mod=1e9+7;

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    t=1;
    // cin>>t;
    //sieve();
    for(int cs=1;cs<=t;cs++)
    {
        
        ll n,m,k;
        cin>>n>>m>>k;
        char ch[n][m];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                cin>>ch[i][j];
            }
        }
        ll ans=0;
        for(int i=0;i<(1<<n);i++)
        {
            for(int j=0;j<(1<<m);j++)
            {
                ll cnt=0;
                for(int row=0;row<n;row++)
                {
                    for(int col=0;col<m;col++)
                    {
                        if((j & (1 << col )) or ( i & (1 << row)))
                            continue;
                        if(ch[row][col]=='#')
                            cnt++;
                    }
                }
                if(cnt==k)
                {
                    ans++;
                }
            }
        }

        cout<<ans<<endl;

        
 
    }
    return 0;
} 

Measured memory_bytes: 3680
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top;
int array[1001];
//atoi 文字 から number


void push(int x){
  
  array[++top] = x;
}


int pop(){
  top--;
  return array[top+1];
  
}





int main(){

  int a,b;
  top = 0;
  
  char s[101];
  
  while( scanf("%s",s)!= EOF){
   
    if(s[0] == '+'){

      a = pop();
      b = pop();
      push( a + b );
      }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a - b);
      
    }

    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a * b);
      
    }
    else{
      push(atoi(s));
      
    
  }
}
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int cnt=0;
void swap(int& a,int& b){
	cnt++;
	int t=a;
	a=b;
	b=t;
	return;
}

int main() {
	int N,P[Nmax];
	cin >> N;
	REP(i,N) cin >> P[i];
	REP(i,N-1) if(P[i]==i+1) swap(P[i],P[i+1]);
	if(P[N-1]==N) cnt++;
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    int alice, bob;
    cin >> alice >> bob;

    if (alice == 1) {
        alice = 14;
    }
    if (bob == 1) {
        bob = 14;
    }

    if (alice == bob) {
        cout << "Draw" << endl;
    } else if (alice > bob) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }

    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <=d || (abs(a-b) <= d && abs(b-c) <= d))  puts("Yes"); else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i,a,b,c) for (ll i=a;(c>0?i<b:i>b) and c!=0;i+= c)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define all(name) (name.begin(), name.end())
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) power(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
const int INF = 1e9;
ll digit(long long n) 
{ 
    return floor(log10(n) + 1); 
} 
vector<ll> ft(1, 1LL);
vector<bool> is_prime(1000000, 1);
void sieve(){
	is_prime[0] = is_prime[1] = 0;
	for(int i = 2; i*i <= 1000000; i++)
		if(is_prime[i])
			repc(j, i*i, 1000000, i)is_prime[j] = 0;
}
ll power(ll x, ll y);
ll gcd(ll a, ll b);
vector<ll> adj[10];
ll visited[10]={0};
int main()
{   flash;
    ll h,w;
    cin>>h>>w;
    ll dp[h+1][w+1];
    rep(i,1,h+1) {
        rep(j,1,w+1) {
            dp[i][j]=INF;
        }
    }
    string s[h+1];
    rep(i,1,h+1) {
        cin>>s[i];
    }
    if(s[1][0]=='#'){
        dp[1][1]=1;
    }
    else {
        dp[1][1]=0;
    }
    rep(i,1,h+1){
        rep(j,1,w+1){
            if(i<h){
                if(s[i+1][j-1]=='#'&&s[i][j-1]=='.'){
                    dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1);
                }
                else {
                    dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
                }
            }
            if(j<w){
                if(s[i][j]=='#'&&s[i][j-1]=='.'){
                    dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1);
                }
                else {
                    dp[i][j+1]=min(dp[i][j+1],dp[i][j]);
                }
            }
        }
    }
    cout<<dp[h][w]<<endl;
}
//
//
//
//
//kaam ke functions
ll power(ll x, ll y) {
    ll res = 1;x %= mod;
    while (y > 0) {
        if (y & 1)res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)
        return b;
 
    return gcd(b%a,a);
    
}

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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    vector<bool> f(1e9+100);
    rep(i,n){
        cin >> a[i];
        f[a[i]] = i % 2;
    }
    sort(all(a));

    ll ans = 0;
    rep(i,n){
        if(f[a[i]] && i % 2 == 0)ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 123136
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
int main()
{
          int m,d;
          cin >> m >> d;
          int count=0;
          for(int i=22;i<=d;i++)
          {
              if(i%10>=2)
              {


              if((i/10)*(i%10)<=m)
              {
                  
                count++;
              }
              }

          }
          cout << count << endl;



                    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector< vector<int> >
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

const double EPS = 1e-10;
#define equals(a, b) (fabs((a) - (b)) < EPS)

struct Point{
    double x, y;
    Point(){}
    Point(double x0, double y0){
        x = x0; y = y0;
    }

    Point operator +(const Point &p){
        return Point(x + p.x, y + p.y);
    }
    Point operator -(const Point &p){
        return Point(x - p.x, y - p.y);
    }
    Point operator *(const double &a){
        return Point(a * x, a * y);
    }
    Point operator /(const double &a){
        return Point(x / a, y / a);
    }

    bool operator == (const Point &p){
        return equals(x, p.x) && equals(y, p.y);
    }

    bool operator < (const Point &p){
        return x != p.x ? x < p.x : y < p.y ;
    }

};

double norm(Point p){
    return p.x * p.x + p.y * p.y;
}

double v_abs(Point p){
    return sqrt(norm(p));
}

typedef Point Vector;

double dot(Vector a, Vector b){
    return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
    return a.x * b.y - a.y * b.x;
}


int ccw(Point p0, Point p1, Point p2){
    int COUNTER_CLOCKWISE = 1;
    int CLOCKWISE = -1;
    int ON_SEGMENT = 0;
    int ONLINE_FRONT = 2;
    int ONLINE_BACK = -2;
    Vector a = p1 - p0, b = p2 - p0;
    if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    else if(cross(a, b) < -EPS) return CLOCKWISE;
    else if(dot(a, b) < -EPS) return ONLINE_BACK;
    else if(norm(a) < norm(b)) return ONLINE_FRONT;
    else return ON_SEGMENT;
}

double getDistance(Point p1, Point p2, Point p){
    Vector a = p2 - p1, b = p - p1;
    if(dot(a, b) < -EPS) return v_abs(b);

    a = p1 - p2, b = p - p2;
    if(dot(a, b) < -EPS) return v_abs(b);

    return abs(cross(a, b)) / v_abs(a);
}

int main(){
    int Q;
    cin >> Q;
    rep(i, Q){
        Point p0, p1, p2, p3;
        cin >> p0.x >> p0.y;
        cin >> p1.x >> p1.y;
        cin >> p2.x >> p2.y;
        cin >> p3.x >> p3.y;
        if(ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0 && ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0 ){
            printf("%.10lf\n", 0.0);
        } else {
            double ans = min(min(getDistance(p0, p1, p2), getDistance(p0, p1, p3)),
                         min(getDistance(p2, p3, p0), getDistance(p2, p3, p1)));
            printf("%.10lf\n", ans);
        }
    }
}


Measured memory_bytes: 3292
def F(x,y):
    return max(len(str(x)),len(str(y)))
N = int(input())
dmin = 100
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        n = N//i
        dmin = min(dmin,F(i,n))
print(dmin)

Measured memory_bytes: 39024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    int X,Y;cin >> X >> Y;
    vector<int> x,y;
    bool tox=true;
    int n=s.size();
    int cnt=0;
    REP(i,n){
        if(s[i]=='T'){
            if(tox){
                x.push_back(cnt);
            }
            else{
                y.push_back(cnt);
            }
            cnt=0;
            tox=!tox;
        }
        else{
            cnt++;
        }
    }
    if(cnt){
        (tox?x:y).push_back(cnt);
    }
    vector<bool> vix(16001),viy(16001);
    vix[8000]=true;
    viy[8000]=true;
    REP(i,x.size()){
        vector<bool> tmp(16001);
        REP(j,16001){
            if(vix[j]){
                if(!i&&s[0]=='F'){
                    tmp[j+x[i]]=true;
                }
                else{
                    tmp[j+x[i]]=true;
                    tmp[j-x[i]]=true;
                }
            }
        }
        swap(vix,tmp);
    }
    REP(i,y.size()){
        vector<bool> tmp(16001);
        REP(j,16001){
            if(viy[j]){
                tmp[j+y[i]]=true;
                tmp[j-y[i]]=true;
            }
        }
        swap(viy,tmp);
    }
    cout << (vix[X+8000]&&viy[Y+8000]?"Yes":"No") << endl;
}

Measured memory_bytes: 3692
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static void Main(){
        var s = System.Console.ReadLine().Split(' ').Select(t => Int32.Parse(t)).ToList();
        for(var i = 1; i <= 1000; ++i){
            if(s[0] == (int)(i * 0.08) && s[1] == (int)(i * 0.10)){
                Console.WriteLine(i);
                return;
            } 
        }
        Console.WriteLine("-1");
    }
}


Measured memory_bytes: 13268
//In the Name of God
//Ya Ali
 
#include<bits/stdc++.h>
 
#define int long long
 
#define pb push_back
 
#define err(A) cout<<#A<<" = "<<(A)<<endl
 
using namespace std;
 
const int M=1e9+7+0;
const int maxn=1024;
 
int n;
 
vector<int> g[maxn];
 
int lvl[maxn];
 
int d0[maxn];
int d1[maxn];
 
int D,D1,D2;
int far;
 
int r0,r1;
 
int dp[maxn][maxn/2];
int cp[maxn][maxn/2];
 
int ans;
 
void pfs(int v,int par=n)
{
  lvl[v]=lvl[par]+1;
  for(int u:g[v])
    if(u!=par)
      pfs(u,v);
  if(lvl[v]>lvl[far])
    far=v;
}
 
void dfs(int v,int par=n)
{
  lvl[v]=lvl[par]+1;
  for(int i=0;i<=D2;i++)
    {
      if(D1-lvl[v]>=i)
	dp[v][i]=1;
      if(D1-lvl[v]>=i-1)
	cp[v][i]=1;
    }
  for(int u:g[v])
    if(u!=par)
      {
	dfs(u,v);
	for(int i=0;i<=D2;i++)
	  {
	    (dp[v][i]*=dp[u][i]+(i?dp[u][i-1]:0))%=M;
	    (cp[v][i]*=cp[u][i]+(i?cp[u][i-1]:0))%=M;
	  }
      }
}
 
int32_t main()
{
  ios::sync_with_stdio(0);cin.tie(0);
 
  cin>>n;
  for(int v,u,i=0;i<n-1;i++)
    {
      cin>>v>>u;
      v--,u--;
      g[v].pb(u);
      g[u].pb(v);
    }
 
  lvl[n]=-1;
  pfs(far);
  pfs(far);
  for(int i=0;i<n;i++)
    d0[i]=lvl[i];
  pfs(far);
  for(int i=0;i<n;i++)
    d1[i]=lvl[i];
 
  D=lvl[far];
  D1=(D+0)/2;
  D2=(D+1)/2;
  
  if(D&1)
    {
      for(int i=0;i<n;i++)
	if(d0[i]+d1[i]==D)
	  if(d0[i]==d1[i]-1)
	    r0=i;
	  else if(d0[i]==d1[i]+1)
	    r1=i;
      lvl[r1]=-1;
      dfs(r0,r1);
      lvl[r0]=-1;
      dfs(r1,r0);
      for(int i=0;i<=D2;i++)
	{
	  ans+=dp[r0][i]*cp[r1][i]%M;
	  ans+=cp[r0][i+1]*dp[r1][i]%M;
	  ans-=dp[r0][i]*dp[r1][i]%M;
	  ans-=dp[r0][i+1]*dp[r1][i]%M;
	  ans+=dp[r1][i]*cp[r0][i]%M;
	  ans+=cp[r1][i+1]*dp[r0][i]%M;
	  ans-=dp[r1][i]*dp[r0][i]%M;
	  ans-=dp[r1][i+1]*dp[r0][i]%M;
	  ans%=M;
	}
    }
  else
    {
      for(int i=0;i<n;i++)
	if(d0[i]+d1[i]==D and d0[i]==d1[i])
	  r0=i;
      dfs(r0);
      for(int i=0;i<=D2;i++)
	ans+=dp[r0][i];
    }
 
  ans=(ans%M+M)%M;
  
  cout<<ans<<endl;
    
  return 0;
}


Measured memory_bytes: 8576
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        SimpleKnapsack solver = new SimpleKnapsack();
        solver.solve(1, in, out);
        out.close();
    }

    static class SimpleKnapsack {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long w = in.nextLong();

            long[] weights = new long[n];
            long[] values = new long[n];

            // i番目 | 選んだ個数 | weightの和
            long[][][] dp = new long[n + 1][n + 1][3 * n + 1];
            for (int i = 0; i < n; i++) {
                weights[i] = Long.parseLong(in.next());
                values[i] = Long.parseLong(in.next());
            }

            for (int i = 0; i < n; i++) {
                int diff = (int) (weights[i] - weights[0]);
                for (int j = 0; j <= i; j++) {
                    for (int k = 0; k <= 3 * n; k++) {
                        // i のときの値をコピペ
                        dp[i + 1][j][k] = Math.max(dp[i + 1][j][k], dp[i][j][k]);
                        if (diff <= k) {
                            // j+1のときの値か、jのときの値にv加算した値
                            dp[i + 1][j + 1][k] = Math.max(dp[i][j + 1][k], dp[i][j][k - diff] + values[i]);
                        }
                    }
                }
            }

            long result = 0;
            for (int i = 0; i <= n; i++) {
                for (int j = 0; j <= 3 * n; j++) {
                    if (i * weights[0] + j <= w) {
                        result = Math.max(result, dp[n][i][j]);
                    }
                }
            }

            out.println(result);

//        long[] weights = new long[n];
//        long[] values = new long[n];
//
//        //  選んだ個数 | weightの和
//        long[][] dp = new long[n + 1][3 * n + 1];
//        for (int i = 0; i < n; i++) {
//            weights[i] = Long.parseLong(in.next());
//            values[i] = Long.parseLong(in.next());
//        }
//
//        int sum = 0;
//        for (int i = 0; i < n; i++) {
//            int diff = (int) (weights[i] - weights[0]);
//            for (int j = i; 0 <= j; j--) {
//                for (int k = sum; 0 <= k; k--) {
//                    dp[j + 1][k + diff] = Math.max(dp[j + 1][k + diff], dp[j][k] + values[i]);
//                }
//            }
//            sum += diff;
//        }
//        long result = 0;
//        for (int i = 0; i <= n; i++) {
//            for (int j = 0; j <= sum; j++) {
//                if (w < i * weights[0] + j) {
//                    continue;
//                }
//                result = Math.max(result, dp[i][j]);
//            }
//        }
//
//        out.println(result);

        }

    }
}



Measured memory_bytes: 67596
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5, mod = 998244353;
int fac[N];
int fp(int a, int p) {
	if (!p) return 1;
	int t = fp(a, p >> 1);
	t = (t * 1ll * t) % mod;
	if (p & 1) t = (t * 1ll * a) % mod;
	return t;
}
ll ncr(int n, int r) {
	return ((fac[n] * 1ll * fp(fac[r], mod - 2)) % mod * 1ll * fp(fac[n - r], mod - 2)) % mod;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	fac[0] = 1;
	for (int i = 1; i < N; i++)
		fac[i] = (fac[i - 1] * 1ll * i) % mod;
	int n, a, b;
	ll k;
	int ans = 0;
	cin >> n >> a >> b >> k;
	for (int i = 0; i <= n; i++) {
		ll x = i * 1ll * a;
		if (x > k || (k - x) % b) continue;
		ll y = (k - x) / b;
		if (y > n) continue;
		ans = (ans + (ncr(n, i) * 1ll * ncr(n, y)) % mod) % mod;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int x,a,b;
  cin>>x>>a>>b;
  if(b <= a) {
    cout << "delicious" << endl;
  } else if(b - a <= x) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  char ch;
  while(cin >> ch){
    if(ch == 'a' or ch == 'e' or ch == 'i' or ch == 'o' or ch == 'u'){
      cout << "vowel";
      
    }else{
      cout << "consonant";
    }
  }
  
}


Measured memory_bytes: 3548
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll a,b,ans=0;
    cin>>a>>b;
    lvec c(3);
    c[0]=300000;
    c[1]=200000;
    c[2]=100000;
    if(a==1&&b==1) cout<<2*c[0]+400000;
    else{
        if(a==1) ans+=c[0];
        if(b==1) ans+=c[0];
        if(a==2) ans+=c[1];
        if(b==2) ans+=c[1];
        if(a==3) ans+=c[2];
        if(b==3) ans+=c[2];
        cout<<ans;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
#define INF 1000000
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<int, int> P;

struct edge{ int u, v; lli cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
	vector< vector<lli> > distance_matrix;
};

template <typename T>
vector<int> argsort(const vector<T> &v) {

  // initialize original index locations
  vector<int> idx(v.size());
  iota(idx.begin(), idx.end(), 0);

  // sort indexes based on comparing values in v
  sort(idx.begin(), idx.end(),
       [&v](int i1, int i2) {return v[i1] < v[i2];});

  return idx;
}

template<typename T>
void displayVector(vector<T> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}

// p.first = 最小距離, p.second=頂点番号
vector<int> dijkstra(int s, DirectedGraph G)
{
/*
  s : 始点
  G : グラフ(vertex_num, adj_list, distance_matrix)
*/
  priority_queue<P, vector<P>, greater<P>> pq;
  vector<int> mindist(G.vertex_num, INF);
  mindist[s] = 0;
  pq.push( P(0,s) );
  
  while( !pq.empty() ){
    P tmp = pq.top(); pq.pop();
    int v = tmp.second;
    if( mindist[v] < tmp.first ){ continue; }
    REP(i, G.adj_list[v].size() ){
      int nv = G.adj_list[v][i];
      if( mindist[v]+1 < mindist[nv] ){
        mindist[nv] = mindist[v]+1;
        pq.push( P(mindist[nv],nv) );
      }
    }
  }

  return mindist;
}


int main(){
	DirectedGraph G;
	cin >> G.vertex_num;
	G.adj_list.resize( G.vertex_num );
	REP(i, G.vertex_num){
		int num; cin >> num;
		G.adj_list[i].push_back( num-1 );
	}
	vector<int> res = dijkstra(0, G);
	
	if( res[1] != INF ){ cout << res[1] << endl; }
	else{ cout << -1 << endl; }

	return 0;
}

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

int main() {
    int N, M;
    std::cin >> N >> M;

    int A[N];
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        sum += A[i];
    }

    std::sort(A, A + N, std::greater<int>());
    const int M4 = 4 * M;
    for (int i = 0; i < M; ++i) {
        if (sum % M4 == 0) {
            if (A[i] < (sum / M4)) {
                std::cout << "No\n";
                return 0;
            }
        } else {
            if (A[i] <= (sum / M4)) {
                std::cout << "No\n";
                return 0;
            }
        }
    }

    std::cout << "Yes\n";   

    return 0;
}


Measured memory_bytes: 256
num=[26**i for i in range(12)]
n=int(input())
s_num=[]
sss=0
e=0
for i in num:
    sss+=i
    if sss>n:
        break
    s_num.append(sss)
num=num[:len(s_num)][::-1]
n-=s_num[-1]

xxx=[]
ans=""
for i in num:
    x=n//i
    n-=x*i
    xxx.append(x+1)
    ans+=chr(ord('a')+x)
  
#print(xxx)
print(ans)


Measured memory_bytes: 9184
<?php
  
fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$d);

$ary = [];

$ary[] = $a*$c;
$ary[] = $a*$d;
$ary[] = $b*$c;
$ary[] = $b*$d;

echo max($ary)."\n";
// echo print_r($ary);

Measured memory_bytes: 16220
a = list(input())
ans = 0
i = 0

a_count = 0  # 連続ででたAの個数
# BC_count = 0  # BC出てきたらそれまでのAの数分

while i < len(a)-1:
    if a[i] == "A":
        count = "A"
        a_count += 1
    elif a[i]+a[i+1] == "BC":
        count = "BC"
        ans += a_count
        i += 1
    else:
        count = "VBNM"
        a_count = 0
    # print(a_count, ans, i, count)
    i += 1

print(ans)

Measured memory_bytes: 82536
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s;
    cin >> s;
    cout << s.at(0) << s.size()-2 << s.at(s.size()-1) << endl;
    return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

total=0
cnt=0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            total=i*500 + j*100 + k*50
            if total == X:
                cnt+=1

print(cnt)

Measured memory_bytes: 9128
def solve():
    INF = 10**12

    N, K = map(int, input().split())
    Hs = list(map(int, input().split()))

    dp = [INF] * N
    dp[0] = 0
    for i, H in enumerate(Hs):
        dpi = dp[i]
        for j in range(i+1, min(N, i+K+1)):
            dp2 = dpi + abs(H-Hs[j])
            if dp2 < dp[j]:
                dp[j] = dp2

    print(dp[N-1])


solve()


Measured memory_bytes: 13980
package main

import (
	"fmt"
)

func main() {
	var n, mochi int
	fmt.Scan(&n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Scan(&mochi)
		m[mochi]++
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 512
import java.util.Scanner;

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

        int emp[] = new int[num];
        for (int i = 0; i < num - 1; i++) {
            int id = scanner.nextInt();
            emp[id - 1]++;
        }
        for (int i = 0; i < num; i++) {
            System.out.println(emp[i]);
        }
    }
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> p;

int n;
ll a[200200];
ll X=0, x=0;

int main(){
  cin >> n;
  rep(i,0,n){
    cin >> a[i];
    X += a[i];
  }
  ll ans = LONGMAX;
  rep(i,0,n-1){
    x += a[i];
    ans = min(ans, abs(X-2*x));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int h,w;
    cin >> h >> w;

    while(!(h==0&&w==0)){
        for (int y = 0; y < h;y++){
            for (int x = 0; x < w;x++)
                cout << "#";
            cout << endl;    
        }
        cout << endl;
        cin >> h >> w;
    }
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,n,flag=0,num=100,ans=0;
    int a[105];
    vector<int> vec;

    cin>>x>>n;
    for(int i=0;i<n;i++) cin>>a[i];

    sort(a,a+n);

    for(int i=0;i<=101;i++){
        if(a[flag]==i){
            flag++;
        }else{
            vec.push_back(i);
        }
    }

    for(int i=0;i<vec.size();i++){
        if(num>abs(x-vec[i])){
            ans=vec[i];
            num=abs(x-vec[i]);
        } 
    }

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

Measured memory_bytes: 3624
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<queue>
#include<cstdlib>
using namespace std ;

#define MAXN 1007

int n , m ;
vector < int > v[ MAXN ] ;

int pos = 0 ;
int st[ MAXN ] ;
int used[ MAXN ] ;
int depth[ MAXN ] ;


bool fl ;
vector < int > ans ;
int cycle_len ;

void extract ( int val ) {
    ans.clear ( ) ;
    for ( int i = pos ; i >= 1 ; -- i ) {
        ans.push_back ( st[ i ] ) ;
        if ( st[ i ] == val ) { return ; }
    }
}

void dfs ( int vertex ) {
    used[ vertex ] = 2 ;
    int sz = v[ vertex ].size ( ) ;
    st[ ++ pos ] = vertex ;
    depth[ vertex ] = pos ;
    for ( int i = 0 ; i < sz ; ++ i ) {
        int aux = v[ vertex ][ i ] ;
        if ( used[ aux ] == 2 ) {
            if ( depth[ vertex ] - depth[ aux ] < cycle_len || fl == false ) {
                fl = true ;
                extract ( aux ) ;
                cycle_len = depth[ vertex ] - depth[ aux ] ;
            }
        }
        if ( used[ aux ] == 0 ) {
            dfs ( aux ) ;
        }
    }
    used[ vertex ] = 1 ;
    -- pos ;
}

void input ( ) {
    scanf ( "%d%d" , &n , &m ) ;
    for ( int i = 1 ; i <= m ; ++ i ) {
        int x , y ;
        scanf ( "%d%d" , &x , &y ) ;
        v[ x ].push_back ( y ) ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j <= n ; ++ j ) { used[ j ] = 0 ; }
        dfs ( i ) ;
    }
    if ( fl == false ) { printf ( "-1\n" ) ; }
    else {
        printf ( "%d\n" , cycle_len + 1 ) ;
        for ( int i = 0 ; i <= cycle_len ; ++ i ) {
            printf ( "%d\n" , ans[ i ] ) ;
        }
    }
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] time = new int[N];
		for(int i = 0; i < N; i++) {
			time[i] = sc.nextInt();
		}

		int M = sc.nextInt();
		int[][] drink = new int[M][2];
		for(int i = 0 ; i < M; i++) {
			for(int l = 0 ; l < 2; l++) {
				drink[i][l] = sc.nextInt();
			}
		}

		int answer = 0;
		for(int i = 0 ; i < M; i++) {
			int p = drink[i][0]-1;
			for (int t= 0;t < time.length; t++) {
				if(p == t) {
					answer += drink[i][1];
				}else {
					answer += time[t];
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> D1(N);
  vector<int> D2(N);
  rep(i,N){
    cin >> D1.at(i) >> D2.at(i);
  }
  int zoro = 0;
  int ans = 0;
  rep(i,N){
    if(D1.at(i)==D2.at(i)){
      zoro += 1;
    }
    else{
      zoro = 0;
    }
    if(zoro>=3){
      ans = 1;
      break;
    }
  }
  if(ans==1){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  char now = s[0];
  int num = 0;
  vector<int> block;
  block.push_back(0);
  rep(i,s.size()){
    num += 1;
    if (s[i] != now){
      block.push_back(num-1);
      num = 1;
      now = s[i];
    }
  }
  block.push_back(num);

  int ans = 0;
  int bs = block.size();
  vector<int> acc(bs);
  acc[0] = block[0];
  rep(i,bs) if(i>0) acc[i] = block[i] +acc[i-1];
  rep(i,bs){
    if (i==0) continue;
    if((s[0]=='0'&&i%2==1)||(s[0]=='1'&&i%2==0)){
    ans = max(ans, acc[min(i+2*k-1,bs-1)] - acc[i-1]);
    }
    else ans = max(ans, acc[min(i+2*k,bs-1)] - acc[i-1]);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 1272
import java.util.Scanner;

/**
 * @author subaru
 */
public class Main {
    // Five Transportations
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long minCapacity = Long.MAX_VALUE;
        for (int i = 0; i < 5; i++) {
            long capacity = sc.nextLong();
            if (capacity < minCapacity) {
                minCapacity = capacity;
            }
        }
        long answer = 5 + (N / minCapacity) - 1 + (N % minCapacity == 0 ? 0 : 1);
        System.out.println(answer);
    }
}


Measured memory_bytes: 24020
#include <atcoder/all>
#include <iostream>

using namespace std;
using namespace atcoder;

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

    scc_graph g(N);
    while(M--) {
        int a, b;
        cin >> a >> b;
        g.add_edge(a, b);
    }

    auto s = g.scc();

    cout << s.size() << endl;
    for(auto e: s) {
        cout << e.size() << ' ';
        for(auto t: e) {
            cout << t << ' ';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 40608
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<sstream>
using namespace std;
typedef long long ll;
const ll maxn=1e6+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
void io(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
int main()
{
	io();
	string s;
	cin>>s;
	if(s[0]!=s[1]&&s[3]==s[2]&&s[5]==s[4])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
f n = if null(init(show n)) then n else n-read(init(show n))*10
gread n = if null n then 0 else read n
g p (s:ss) = if null ss then [0] else if s==p then ss else s:(g p ss)
main=do
 s<-map read.lines<$>getContents
 let p = foldl1 (\x y -> if y`mod`10/=0 && f y<=f x then y else x) s
 let t = map (\x -> if x`mod`10/=0 then gread(init(show x))*10+10 else x) (g p s)
 print$sum t + p

Measured memory_bytes: 508
# 演習1-10 Spreadsheet
r, c = map(int, input().split())

Sum = 0

c_sum = [0 for i in range(c)]

for i in range(r):
    temp = list(map(int, input().split()))
    Sum += sum(temp)
    r_sum = 0
    for j in range(c):
        print(temp[j], end=' ')
        r_sum += temp[j]
        c_sum[j] += temp[j]
    print(r_sum)
    
for i in range(c):
    print(c_sum[i], end=' ')
    
print(Sum)


Measured memory_bytes: 5632
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int h1, h2;  //浩のイワナ、ヤマメ
    int k1, k2; //健次郎のイワナ、ヤマメ
    int a, b;   //イワナ、ヤマメ一匹ごと
    int c, d;   //10匹ごとの点
    int x,y;
    cin >> h1 >> h2;
    cin >> k1 >> k2;
    cin >> a >> b >> c >> d;
    int l=h1/10;
    int m=h2/20;
    int n=k1/10;
    int o=k2/20;
    if(h1<10&&h2<10)
        x=h1*a+h2*b;
    else if(h1<10&&h2>10)
        x=h1*a+h2*b+d*m;
    else if(h1>10&&h2>10)
        x=h1*a+c*l+h2*b+d*m;
    else
        x=h1*a+c*l+h2*b;
    if(k1<10&&k2<10)
        y=k1*a+k2*b;
    else if(k1<10&&k2>10)
        y=k1*a+k2*b+d*o;
    else if(k1>10&&k2>10)
        y=k1*a+c*n+k2*b+d*o;
    else
        y=k1*a+c*n+k2*b;
        if(x>y)
            cout << "hiroshi" << endl;
        else if(x<y)
            cout << "kenjiro" << endl;
        else
            cout << "even" << endl;
}


Measured memory_bytes: 3096
#include<cstdio>
#include<algorithm>
using namespace std;
int v[201000], n, m;
int main() {
	int i, a, b;
	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		if (a == 1)v[b] |= 1;
		if (b == n)v[a] |= 2;
	}
	for (i = 1; i <= n; i++) {
		if (v[i] == 3) {
			puts("POSSIBLE");
			return 0;
		}
	}
	puts("IMPOSSIBLE");
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
typedef long long llong;

int main(){
    string s;
    llong ans;
    cin >> ans;

    s = to_string(ans);
    int l = s.size();

    int right;
    int cal;
    string s2;
    for (llong i = 1; i < (1 << (l - 1)); i++){
        right = 0;
        for (int j = 0; j < (l - 1); j++){
            if (!((i >> j) & 1)) continue;
            cal = 0;
            for (int k = right; k < j + 1; k++){
                s2 = s[l - k - 1];
                ans += atoi(s2.c_str()) * pow(10, cal);
                cal++;
            }
            right = j + 1;
        }
        cal = 0;
        for (int k = right; k < l; k++){
            s2 = s[l - k - 1];
            ans += atoi(s2.c_str()) * pow(10, cal);
            cal++;
        }
    }

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


Measured memory_bytes: 888