akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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(){
	ll n,k;cin>>n>>k;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	for(int i = k; i < n; i++) {
		if (a[i - (k)] < a[i]){
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int n,minn=1000000,maxn=-1000000,x;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		maxn=max(maxn,x);
		minn=min(minn,x);
	}
	cout<<maxn-minn;
	return 0;
}

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

const int MOD = 1e9 + 7;
ll dp[10005][2][100];

int main(){
	
	string s;
	cin >> s;
	int d;
	cin >> d;
	
	// 1桁目
	int first = s[0] - '0';
	rep(i,first+1) dp[0][i < first][i%d]++;
	
	// 2桁目以降
	rep(i,s.size()-1) rep(j,2) rep(k,d){
		int lim = j? 9 : s[i+1] - '0';
		rep(next, lim+1){
			dp[i+1][j || next < lim][(k + next) % d] = (dp[i+1][j || next < lim][(k + next) % d] + dp[i][j][k]) % MOD;
		}
	}
	
	ll res = 0;
	rep(j,2) res = (res + dp[s.size()-1][j][0]) % MOD;
	
	cout << (res -1 + MOD) % MOD << endl; // 0を含んでいる為1減算
	
	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string ch;
    cin>>ch;
    if(ch[0]=='S' && ch[1]=='A' && ch[2]=='T')
    {
        cout<<"1"<<endl;
    }
    else if(ch[0]=='S' && ch[1]=='U' && ch[2]=='N')
    {
        cout<<"7"<<endl;
    }
    else if(ch[0]=='M' && ch[1]=='O' && ch[2]=='N')
    {
       cout<<"6"<<endl;
    }
    else if(ch[0]=='T' && ch[1]=='U' && ch[2]=='E')
    {
        cout<<"5"<<endl;
    }
    else if(ch[0]=='W' && ch[1]=='E' && ch[2]=='D')
    {
        cout<<"4"<<endl;
    }
    else if(ch[0]=='T' && ch[1]=='H' && ch[2]=='U')
    {
        cout<<"3"<<endl;
    }
    else if(ch[0]=='F' && ch[1]=='R' && ch[2]=='I')
    {
        cout<<"2"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		// 出力
		System.out.println((a*b)-(a+b-1));
	}
}

Measured memory_bytes: 22484
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
using namespace std;
#define LATTE 10000

int main(){
	int S;
	cin>>S;
	printf("%d:%d:%d\n",S/3600,(S%3600)/60,S%60);
    return 0;
}

Measured memory_bytes: 1148
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			long n = sc.nextLong();
			long a = sc.nextLong();
			long b = sc.nextLong();
			long ret = 0;
			// 離れ方が偶数の場合
			if((b - a) % 2 == 0) {
				ret = (b - a) / 2;
			} else {
				// aの端までの回数
				long aMax = a - 1;
				// bの端までの回数
				long bMax = n - b;
				if(aMax < bMax) {
					ret += aMax;
					ret += 1;
					ret += (b - a - 1) / 2;
				} else {
					ret += bMax;
					ret += 1;
					ret += (b - a - 1) / 2;
				}
			}
			System.out.println(ret);
		}

	}

}


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

int main(){
  int k;
  string s;
  cin >> k >> s;
  if(s.size()<=k) cout << s << endl;
  else cout << s.substr(0,k) << "..." << endl;
  return 0;


}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
   int a,b,c,d,n_max,n_min;
   cin>>a>>b>>c>>d;
   n_max=max(a,c);
   n_min=min(b,d);
   if(n_min-n_max<0){
       cout<<0<<endl;
   }else{
       cout<<n_min-n_max<<endl;
   }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;

class Edge
{
public:
	int src,dst,cst;
	Edge(int src, int dst, int cst)
	:src(src),dst(dst),cst(cst)
	{}
};

class State
{
public:
	int p,c,d;
	State(int p, int c, int d)
	:p(p),c(c),d(d)
	{}
	
	bool operator<(const State& s) const {
		if(c != s.c) return c > s.c;

		return d > s.d;
	}
};

typedef vector<vector<Edge> > Graph;

int N,M,C,S,G;
int COST[10001][20];
int P[20], Q[20][51], R[20][51];
int ct[100][100];
bool vis[100];

void dijkstra(int Start, int com, Graph& graph)
{
	memset(vis, 0, sizeof(vis));

	priority_queue<State> q;
	q.push(State(Start, 0, 0));

	while(!q.empty()) {
		State s=q.top(); q.pop();
		if(vis[s.p]) continue;
		vis[s.p] = 1;

		if(ct[Start][s.p] == -1) ct[Start][s.p] = s.c;
		else ct[Start][s.p] = min(ct[Start][s.p], s.c);

		for(int i=0; i<graph[s.p].size(); i++) {
			Edge& e = graph[s.p][i];

			int td = s.d + e.cst;
			int nc = 0;
			if(td > Q[com][P[com] - 1]) {
				nc = COST[Q[com][P[com] - 1]][com] + abs(td - Q[com][P[com]-1]) * R[com][P[com]-1];
			}
			else nc = COST[td][com];

			if(vis[e.dst]) continue;
			q.push(State(e.dst, nc, td));
		} 
	}
}

int solve(int Start, int Goal, Graph& graph)
{
	memset(vis, 0, sizeof(vis));
	
	priority_queue<State> q;
	q.push(State(Start, 0, 0));

	while(!q.empty()) {
		State s=q.top(); q.pop();
		if(vis[s.p]) continue;
		vis[s.p] = 1;

		if(s.p == Goal) return s.c;

		for(int i=0; i<graph[s.p].size(); i++) {
			Edge& e = graph[s.p][i];

			if(vis[e.dst]) continue;
			q.push(State(e.dst, s.c + e.cst, 0));
		}
	}

	return -1;
}

int main()
{
	std::ios::sync_with_stdio(false);

	while(cin >> N >> M >> C >> S >> G, (N||M||C||S||G)) {
		S--; G--;

		vector<Graph> graph(C);
		for(int i=0; i<C; i++)
			graph[i].resize(N);

		for(int i=0; i<M; i++) {
			int a,b,c,d;
			cin >> a >> b >> d >> c;
			a--; b--; c--;

			graph[c][a].push_back(Edge(a,b,d));
			graph[c][b].push_back(Edge(b,a,d));
		}

		for(int i=0; i<C; i++)
			cin >> P[i];

		for(int i=0; i<C; i++) {
			Q[i][0] = 0;

			for(int j=1; j<P[i]; j++)
				cin >> Q[i][j];
			
			for(int j=0; j<P[i]; j++)
				cin >> R[i][j];
		}

		for(int i=0; i<C; i++)
			COST[0][i] = 0;

		for(int i=0; i<C; i++)
		for(int j=1; j<P[i]; j++)
		for(int k=Q[i][j-1]+1; k<=Q[i][j]; k++) 
			COST[k][i] = COST[k-1][i] + R[i][j - 1];


		memset(ct, -1, sizeof(ct));
		for(int k=0; k<C; k++) 
		for(int i=0; i<N; i++) 
			dijkstra(i, k, graph[k]);


		Graph final(N);
		for(int i=0; i<N; i++)
		for(int j=i+1; j<N; j++) {
			if(ct[i][j] == -1) continue;
			final[i].push_back(Edge(i,j,ct[i][j]));
			final[j].push_back(Edge(j,i,ct[j][i]));
		}

		cout <<  solve(S, G, final) << endl;
	}
}

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

#define mod 1000000007
#define pi 2 * acos(0.0)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i >= b; i--)
void fun()
{
    ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

/* DON'T LIMIT YOUR CHALLENGES, CHALLENGE YOUR LIMITS */
void solve()
{
    int n, k;
    cin >> n >> k;

    vector<int> v(n);
    for (auto &i : v)
        cin >> i;
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        if (i <= k)
        {
            for (int j = 0; j < i; j++)
                dp[i] = min(dp[i], dp[j] + abs(v[j] - v[i]));
        }
        else
        {
            for (int j = i - k; j < i; j++)
                dp[i] = min(dp[i], dp[j] + abs(v[j] - v[i]));
        }
    }

    cout << dp[n - 1];
}

signed main()
{
    fun();
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;
public class Main {
     
    static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        double x1 = stdIn.nextDouble();
        double y1 = stdIn.nextDouble();
        double x2 = stdIn.nextDouble();
        double y2 = stdIn.nextDouble();
         
        double ans = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2) * (y1 - y2));
         
        System.out.println(ans);
    }
}


Measured memory_bytes: 28084
import sys
input = sys.stdin.readline
from collections import *

def judge(x):
    d = defaultdict(int)
    d[hash(S[:x])] = 0
    
    for i in range(1, len(S)-x+1):
        k = hash(S[i:i+x])
        
        if k in d:
            if i-d[k]>=x:
                return True
        else:
            d[k] = i
    
    return False

def binary_search():
    l, r = 0, N
    
    while l<=r:
        m = (l+r)//2
        
        if judge(m):
            l = m+1
        else:
            r = m-1
    
    return r

N = int(input())
S = input()[:-1]
print(binary_search())

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

int main(){
  int n,m;
  cin >> n>>m;
  vector<int> v(m),dis(m-1);
  rep(i,m){
    cin>>v.at(i);
  }
  if (n>=m){
    cout << 0 << endl;
    return 0;
  }
  sort(v.begin(),v.end());
  rep(i,m-1){
    dis.at(i) = abs(v.at(i+1) - v.at(i));
  }
  sort(dis.begin(),dis.end());
  int ans=0;
  rep(i,m-n){
    ans += dis.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    long long N,Q,i,j,m,n,ans,q,x;
    cin>>N>>Q;
    long long a[N-1],b[N-1];
    for(i=0;i<N-1;i++){
        a[i]=N-2;b[i]=N-2;
    }
    m=N-1;n=N-1;
    ans=(N-2)*(N-2);
    for(i=0;i<Q;i++){
        cin>>q>>x;
        x--;
        if(q==1){
            if(x>m){
                ans-=a[x];
            }else{
                ans-=n-1;
                while(m>x){
                    a[m]=n-1;
                    m--;
                }
            }
        }
        if(q==2){
            if(x>n){
                ans-=b[x];
            }else{
                ans-=m-1;
                while(n>x){
                    b[n]=m-1;
                    n--;
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6736
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    string s;
    int temp;
    while(true){
        getline(cin,s);
        if(s=="END OF INPUT")return 0;
        temp=0;
        for(int i=0;i<s.size();i++){
            if(s[i]==' '){
                printf("%d",temp);
                temp=0;
            }
            else temp++;
        }
        printf("%d\n",temp);
    }
}


Measured memory_bytes: 3112
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[allow(dead_code)]
fn solve(s: Vec<char>) -> i64 {
    let mut max = 0;
    let mut cur = 0;
    for c in s {
        match c {
            'I' => {
                cur += 1;
            }
            'D' => {
                cur -= 1;
            }
            _ => panic!{}
        }
        if cur > max {
            max = cur;
        }
    }
    max
}

fn main() {
    input!{
        _n: isize,
        s: chars,
    }
    println!("{}", solve(s));
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

string s;

signed main() {
	cin >> s;
	rep(i, s.size() - 1) {
		if (s[i] == s[i + 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

bool add(std::vector<int>& v,int size){
  v[v.size()-1]++;
  for(int i=size-1;i>=1;i--){
    if(v[i]==4){
      v[i]=0;
      v[i-1]++;
    }else{
      return true;
    }
  }
  return 0<=v[0]&&v[0]<4;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,a,b,c;
  const int UNITE_MP=10;
  cin>>n>>a>>b>>c;
  std::vector<int> target{a,b,c};
  std::sort(target.begin(), target.end());
  std::vector<int> len(n);
  for(int i=0;i<n;i++){
    cin>>len[i];
  }
  int result=INT32_MAX;
  std::vector<int> state(n);
  do{
    int temp_result=0;
    int make_a=0,make_b=0,make_c=0;
    for(int i=0;i<n;i++){
      if(state[i]==1){
        if(make_a>0){
          temp_result+=UNITE_MP;
        }
        make_a+=len[i];
        
      }else if(state[i]==2){
        if(make_b>0){
          temp_result+=UNITE_MP;
        }
        make_b+=len[i];
      }else if(state[i]==3){
        if(make_c>0){
          temp_result+=UNITE_MP;
        }
        make_c+=len[i];
      }
    }
    
    if(make_a==0||make_b==0||make_c==0) continue;
    
    std::vector<int> magicced={make_a,make_b,make_c};
    std::sort(magicced.begin(), magicced.end());
    for(int bi=0;bi<3;bi++){
      temp_result+=std::abs(magicced[bi]-target[bi]);
    }
    
    result=std::min(result,temp_result);
  }while(add(state,n));
  
  cout<<result<<endl;
  


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(int argc,char const* argv[])
{
  int i,n;
  long long ans=1;
  long long amari=1000000007;
  cin >> n;
  vector <int> a(n,0);
  vector <int> c(n,0);
  for(i=0;i<n;i++)
    {
      cin >> a[i];
      c[a[i]]++;
    }
  if(n%2 ==0)
    {
      for(i=1;i<n;i+=2)
	{
	  if(c[i] !=2){ ans=0;break;}
	  ans=ans*2%amari;
	}
    }
  else
    {
      if(c[0] != 1){ans=0; cout << ans << endl; return 0;}
      else
	{
	  for(int i=2;i<n;i+=2)
	    {
	      if(c[i] !=2) {ans=0;break;}
	      ans=ans*2%amari;
	    }
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)
#define int long long

using namespace std;
typedef pair<int, int> pii;

const int modp=1e+9+7;
int n,k,a[110]={0};
int dp[110][100010]={0};

signed main() {
	cin>>n>>k;
    rep(i,n){
        cin>>a[i+1];
    }
	
    dp[0][0]=1;
    rep(i,n+1){
        rep(j,k+1){
            if(i==0&&j==0){
                continue;
            }
            if(i>=1){
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=modp;
                if(j-a[i]-1>=0){
                    dp[i][j]+=modp;
                    dp[i][j]-=dp[i-1][j-a[i]-1];
                    dp[i][j]%=modp;
                }
            }
            if(j>=1){
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=modp;
            }
        }
    }

    if(k>=0){
        cout<<(dp[n][k]-dp[n][k-1]+modp)%modp<<endl;
    }
    else{
        cout<<dp[n][k]<<endl;
    }

	return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7L;

int N,K,X,Y;
int ans;
int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>K>>X>>Y;

ans+=min(K,N)*X;
if(N-K>0){
	ans+=(N-K)*Y;
}

cout<<ans<<endl;

}



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

int main(){
	int x;
  	cin >> x;
  
  	for(int a = -118; a < 120; a++){
    	for(int b = -119; b < 119; b++){
        	if(x == pow(a, 5)-pow(b, 5)){
            	cout << a << " " << b << endl;
              	return 0;
            }
        }
    }
}

Measured memory_bytes: 4020
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
#define INF 10e9+7
typedef long long ll;
using namespace std;
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() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int n;
	cin >> n;
	vector<int>dp(100000,INF);
	vector<int>a(100000,0);
	rep0(i, n)cin >> a[i];
	dp[0] = 0;
	rep0(j, n) {
		chmin(dp[j + 1], dp[j] + abs(a[j] - a[j+1]));
		chmin(dp[j + 2], dp[j] + abs(a[j] - a[j+2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

struct Point {
    ll x, y;
    Point() : x(0), y(0) {}
    Point(ll x, ll y) : x(x), y(y) {}
    int quadrant() const {
        if(x == 0 && y == 0){
            return 0;
        }
        if(x >= 0){
            if(y >= 0){
                return 1;
            }else{
                return 4;
            }
        }else{
            if(y >= 0){
                return 2;
            }else{
                return 3;
            }
        }
    }

    Point& operator+=(const Point& other){
        x += other.x;
        y += other.y;
        return *this;
    }

    bool operator<(const Point& q) const {
        int qp = quadrant();
        int qq = q.quadrant();
        if(qp != qq){ return qp < qq; }
        return (x * q.y - y * q.x) > 0;
    }

    ll norm2() const {
        return x * x + y * y;
    }

    double norm() const {
        return sqrt((double)norm2());
    }
};

int main(){
    ll n;
    cin >> n;
    vector<Point> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p.at(i).x >> p.at(i).y;
    }
    sort(p.begin(), p.end());

    double ans = 0;
    for(int i = 0; i < p.size(); ++i){
        Point a;
        for(int j = 0; j < p.size(); ++j){
            a += p.at((i + j) % p.size());
            ans = max(ans, a.norm());
        }
    }
    printf("%.11f\n", ans);
    return 0;
}


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

const int maxn = 405;
int N, a[maxn];
ll pre[maxn];
ll dp[maxn][maxn];


ll f(int l, int r) {
    if (dp[l][r] != -1) return dp[l][r];
    if (l == r) return dp[l][r] = 0;
    dp[l][r] = 1e18;
    for (int i = l; i < r; i++) {
        dp[l][r] = min(dp[l][r],(pre[i]-pre[l-1])+(pre[r]-pre[i])+f(l,i)+f(i+1,r));
    }
    return dp[l][r];
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> a[i];
    for (int i = 1; i <= N; i++) pre[i] = pre[i-1] + a[i];
    memset(dp,-1,sizeof dp);
    ll ans = f(1,N);
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<pair<int, int>> P(n);
  vector<int> id(n);
  rep(i, n) {
    cin >> P[i].first >> P[i].second;
    id[i] = i;
  }
  sort(all(id), [&](int i, int j) {
    return P[i] < P[j];
  });
  vector<int> A(n);
  rep(i, n) A[i] = P[id[i]].second;
  vector<int> ans(n);
  fenwick_tree<int> bit(n+1);
  int l = 0;
  rep(i, n+1) {
    if(bit.sum(n+1-i, n+1) == i) {
      int size = i-l;
      for(; l<i; l++) {
        ans[id[l]] = size;
      }
    }
    if(i < n) bit.add(A[i], 1);
  }
  rep(i, n) cout << ans[i] << endk;
  return 0;
}


Measured memory_bytes: 7928
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <math.h>
 
using namespace std;
typedef unsigned long ul;

int main() {
	int a,b,c,x,y,n=0;
	cin>>a>>b>>c>>x>>y;
	c*=2;
	if(a+b<=c){
		cout<<a*x+b*y<<endl;
		return 0;
	}
	int i = min(x,y);
	x-=i;
	y-=i;
	n+=c*i;
	n+=x*min(a,c);
	n+=y*min(b,c);
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[0]*N
for i in range(N):A[i]=int(input())
l=[0]*(N+1)

i=1
cnt=0
while True:
    if i==2:
        print(cnt)
        break
    
    if l[i]==1:
        print(-1)
        break
        
    l[i]=1
    i=A[i-1]
    cnt+=1


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std;
int a,b,c,k,mx;
int main(){
	ios::sync_with_stdio(0);
	cin>>a>>b>>c>>k;
	if(k>=a)
	{
		mx+=a;
		k-=a;
	}
	else
	{
		cout<<k<<endl;
		return 0;
	}
	if(k>=b)
	{
		k-=b;
	}
	else
	{
		cout<<mx<<endl;
		return 0;
	}
	mx-=k;
	cout<<mx<<endl;
}


Measured memory_bytes: 3636
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        long n1 = sc.nextInt();
        long n2 = sc.nextInt();
        long n3 = n1 * n2;
        long ans = 0;
        if(n1 == 1 || n2 == 1){
            ans = 1;
        }else if(n3 % 2 == 0){
        	ans = n3 / 2;
        }else{
        	ans = (n3 / 2) + 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35780
#include<iostream>
#define ll long long
using namespace std;

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

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

	ll a,b;
	cin >> a >> b;
	cout << lcm(a,b);
	return 0;
}

Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define DRACO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define GO ll t; cin>>t; while(t--)
#define mod  1000000007
#define vect vector<long long int>
#define fore(p) for(auto& x:p)
#define bins binary_search
#define vecti vector<int>::iterator
#define bitout __builtin_popcount
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(), x.rend()
#define PY 3.141592653589793238
#define F first
#define S second
ll power(ll a,ll b){
    ll res = 1;
    while(b > 0)
    {
        if(b%2 == 1) res *= a;
        a *= a;
        b /= 2;
    }
    return res;
}
double dis(double a,double b ,double c , double d)
{
    return (sqrt((a-c)*(a-c)+(b-d)*(b-d)));
}

int main() 
{   DRACO
    ll i,j,k,l,n,m;
    cout.precision(10);
    //GO
    {   
        cin >> n;
        vect v(n);
        
        fore(v)
        cin >> x;
        
        ll maxx = 0, ans = 0;
        
        fore(v)
        {
            if(x > maxx)
                maxx = x;
            else
                ans += maxx - x; 
        }
        
        cout << ans ;
    }
return 0;
}
//check the corner cases(n==1)
//try checking in reverse order
//check your logic again

Measured memory_bytes: 4708
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vs vector<string>
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin>>n;
    cout<<a[n-1];
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int p){
	for(int i=2;i<=sqrt(p);i++){
		if(!p%i)return false;
	}
	return true;
}
signed main(){
	int n,a[100000],cnt=1;
	cin>>n;
	int ans=n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	for(int i=1;i<n;i++)if(a[i]!=a[i-1])cnt++;
    if(cnt%2==0)cout<<cnt-1<<endl;
	else cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,num[200010],ans=1e9;
string s;
int main(){
	cin>>n>>s;
	for (int i=1;i<=n;i++){
		num[i]=num[i-1];
		if (s[i-1]=='#') num[i]++;
	}
	for (int i=0;i<=n;i++) ans=min(ans,num[i]+n-i-num[n]+num[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1412
IDENTIFICATION DIVISION.
PROGRAM-ID. A-Diagonal.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 C1     PIC X(3).
01 C2     PIC X(3).
01 C3     PIC X(3).
 
PROCEDURE DIVISION.
  ACCEPT C1.
  ACCEPT C2.
  ACCEPT C3.

  DISPLAY C1(1:1) C2(2:1) C3(3:1).

  STOP RUN.


Measured memory_bytes: 384
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int a, b;
            a = in.nextInt();
            b = in.nextInt();
            String ret = Integer.toString(a+b);
            System.out.println(ret.length());
        }
    }
}

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

int gcd(int x,int y){
	if(y==0)return x;
	return gcd(y,x%y);
}
int main(){
	int a,b;
	cin>>a>>b;
	cout<<gcd(b,a%b)<<endl;
	return 0 ;
	}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define ll long long

signed main()
{
    ll N, M;
    cin >> N >> M;

    vector<ll> d;

    for (int i = 1; i * i <= M; ++i) {
        if (M % i == 0) {
            d.push_back(i);
            if (M / i != i) {
                d.push_back(M / i);
            }
        }
    }

    sort(begin(d), end(d), greater<ll>());

    for (ll a : d) {
        if (a * N <= M) {
            cout << a << endl;
            return 0;
        }
    }
}


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

const int nax=105;
int a[nax];
int n;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int res=1e9;
    for(int m=-100;m<=100;m++)
    {
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            sum+=(a[i]-m)*(a[i]-m);
        }
        res=min(res,sum);
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define vi vector< int >
#define vii vector< pair< int,int > >
#define vc vector< char >
#define vvi vector < vector< int > >
#define vvl vector < vector< ll > >
#define vvc vector < vector< char > >
#define vl vector< ll >
#define vll vector< pair< ll,ll > >
#define pii pair< int, int >
#define pll pair<ll, ll>
#define pf push_front
#define pb push_back
// #define range(c) c.begin(), c.end()
// #define ranger(c) c.rbegin(), c.rend()
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define forn(i, n) for(ll i = 0; i < n; ++i)
#define fornr(i, n) for(ll i = n-1; i >= 0; --i)
#define foro(i, n) for(ll i = 1; i <= n; ++i)
#define foror(i, n) for(ll i = n; i >= 1; --i)
#define endl '\n'
#define MOD 998244353
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pr(a) for(auto it :a) cout << (it) << " "; cout << endl;
#define pr2(a) for(int i = 0; i<a.size(); ++i){ for(int j = 0; j<a[i].size(); ++j) cout << a[i][j] << ' '; cout << endl;}
#define test ll T; cin >> (T); while(T--)

#define present(container, element) (container.find(element) != container.end())
// for set and maps
#define cpresent(container, element) (find(all(container),element) != container.end())
// for vectors

using namespace std;

bool comp(pii &a, pii &b) {		// if returns false, then swap occurs
	return (a.first < b.first) || ((a.first == b.first) && a.second > b.second);
}

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("/home/shivam/input.txt", "r", stdin);
// 	freopen("/home/shivam/output.txt", "w", stdout);
// 	freopen("/home/shivam/error.txt", "w", stderr);
// #endif

	FIO;

	int n, w;
	cin >> n >> w;
	// vi w(n), v(n);
	vector< pii > wv(n);		// weight, value
	forn(i, n)
	cin >> wv[i].first >> wv[i].second;

	sort(all(wv), comp);

	// pr(w);
	// pr(v);
	// forn(i, n) {
	// 	cout << wv[i].first << ' ' << wv[i].second << endl;
	// }

	// vvl dp(n, vl(w + 1, 0));
	vl dp(w + 1, 0);

	for (int j = 0; j <= w; ++j) {
		if (j >= wv[0].first)
			// dp[0][j] = wv[0].second;
			dp[j] = wv[0].second;
		else
			// dp[0][j] = 0;
			dp[j] = 0;
	}

	for (int i = 1; i < n; ++i) {
		// for (int j = 1; j <= w; ++j) {
		for (int j = w; j >= 1; --j) {
			if (j >= wv[i].first)	//can take this item
				// dp[i][j] = max(dp[i - 1][j - wv[i].first] + wv[i].second, dp[i - 1][j]);
				dp[j] = max(dp[j - wv[i].first] + wv[i].second, dp[j]);
			// else
			// 	// dp[i][j] = dp[i - 1][j];
			// 	dp[0][j] = dp[0][j];
		}
	}

	// pr2(dp);
	// cout << dp[n - 1][w] << endl;
	cout << dp[w] << endl;

	return 0;
}


Measured memory_bytes: 3936
from collections import Counter

n = int(input())
v = [int(i) for i in input().split()]

# n = 8
# v = [33,4,33,4,33,4,33,2]


ki = v[::2]
gu = v[1::2]

ki = Counter(ki)
gu = Counter(gu)

ki = ki.most_common()
gu = gu.most_common()

ans = 0
if ki[0][0] == gu[0][0]:
    if len(ki) == 1 and len(gu) == 1:
        ans = int(n/2)

    elif len(ki) == 1:
        ans = n - ki[0][1] - gu[1][1]

    elif len(gu) == 1:
        ans = n - ki[1][1] - gu[0][1]

    else:
        if ki[1][1] > gu[1][1]:
            ans = n - ki[1][1] - gu[0][1]
        else:
            ans = n - ki[0][1] - gu[1][1]
else:
    ans = n - ki[0][1] - gu[0][1]
print(ans)

Measured memory_bytes: 18784
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int kouhosu = sc.nextInt();
    int kion = sc.nextInt();
    int kibou = sc.nextInt();
    double[] kouhoti = new double[kouhosu];
    for(int i = 0; i < kouhosu; i++) {
      kouhoti[i] = sc.nextInt();
    }
    for(int i = 0; i < kouhosu; i++) {
      kouhoti[i] = kion - kouhoti[i] * 0.006;
    }
    double min = 100000;
    int index = 0;
    for(int i = 0; i < kouhosu; i++) {
      if(Math.abs(kibou - kouhoti[i]) < min) {
        min = Math.abs(kibou - kouhoti[i]);
        index = i;
      }
    }
    System.out.println(index + 1);
  }

}


Measured memory_bytes: 24788
#include <stdio.h>
int main(void) {
    int price,amount,sum=0,average=0,count=0;
    double temp;
    while (scanf("%d,%d",&price,&amount)!=EOF) {
        sum+=price*amount;
        average+=amount;
        count++;
    }
    average = 1.0 * average/count + 0.5;
    printf("%d\n%d\n",sum,average);
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;

int main (){
   int N,M;
   cin >> N >> M;
   int p;
   char S[N+1];
   string h;
   int a = 0;
   int W[N+1] ;
   int w =0;
   for (int i = 1;i<=N; i++){
       S[i] = 'W';
       W[i] = 0;
   }
    
    for (int i=0;i<M;i++){
        cin >> p >> h;
        if(S[p]=='W'){
            if(h[0]=='W'){
                W[p] += 1;
            }
            else {
                a += 1;
                S[p] = 'A';
                w += W[p];
            }
        }
        
       
    
    }
    
    cout << a << " " << w;
   
   


}

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

int main(void) {
  int W,H,N,lx, ly, rx, ry;
  cin >> W >> H >> N;
  lx = 0;
  ly = 0;
  rx = W;
  ry = H;
  vector<int> x(N), y(N), a(N);
  for ( int i = 0 ; i < N ; i++){
    cin >> x.at(i) >> y.at(i) >> a.at(i);
    if( a.at(i) == 1 && lx < x.at(i)) lx = x.at(i);
    else if( a.at(i) == 2 && rx > x.at(i)) rx = x.at(i);
    else if( a.at(i) == 3 && ly < y.at(i)) ly = y.at(i);
    else if( a.at(i) == 4 && ry > y.at(i)) ry = y.at(i);
   }
  
  if ( rx > lx && ry > ly) cout << (rx - lx) * ( ry - ly ) << endl;
  else cout << 0 << endl; 
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

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

    int a;
    rep(i, n) cin >> a;

    OP(ceil((n - 1) / (k - 1)));

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a+b+c-max(a,max(b,c)) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

bool lose[105], back[105], rest[105];
double dp[105][105][2];
signed main(void)
{
	while(true) {
		int n, t, l, b;
		cin >> n >> t >> l >> b;
		if(!n && !t && !l && !b) break;
		memset(lose, false, sizeof(lose));
		memset(back, false, sizeof(back));
		memset(rest, false, sizeof(rest));
		REP(i, l) {
			int ll;
			cin >> ll;
			lose[ll] = true;
		}
		REP(i, b) {
			int bb;
			cin >> bb;
			back[bb] = true;
		}

		REP(i, t+1) REP(j, n+1) dp[i][j][0] = dp[i][j][1] = 0;
		dp[0][0][0] = 1;
		REP(i, t) {
			//cout << "i:" << i << endl;
			REP(j, n) {
				//cout << "0:" << dp[i][j][0] << " 1: " << dp[i][j][1] << endl;
				if(dp[i][j][0] > 0) {
					//cout << "ja:" << j << " ";
					if(lose[j]) {
						dp[i+1][j][1] += dp[i][j][0];
					} else {
						FOR(k, 1, 7) {
							int to = j+k;
							if(to > n) to = n - (to-n);
							if(back[to]) to = 0;
							//cout << to << " ";
							if(lose[to]) {
								//rest[to] = true;
								dp[i+1][to][0] += dp[i][j][0]/6;
								} else {
								dp[i+1][to][0] += dp[i][j][0]/6;
							}
						}
					}
					//cout << endl;
				}
				if(dp[i][j][1] > 0) {
					//cout << "jb:" << j << " ";
					FOR(k, 1, 7) {
						int to = j+k;
						if(to > n) to = n - (to-n);
						if(back[to]) to = 0;
						//cout << to << " ";
						if(lose[to]) {
							//rest[to] = true;
							dp[i+1][to][0] += dp[i][j][1]/6;
						} else {
							dp[i+1][to][0] += dp[i][j][1]/6;
						}
					}
					//cout << endl;
				}
			}
		}

		/*REP(i, t+1) {
			double sum = 0;
			REP(j, n+1) {
				cout << fixed << setprecision(9) << "(" << dp[i][j][0] << ", " << dp[i][j][1] << ") ";
				sum += dp[i][j][0] + dp[i][j][1];
			}
			cout << sum << endl;
		}*/

		double ans = 0;
		REP(i, t+1) ans += dp[i][n][0];
		cout << fixed << setprecision(9) << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

int main()
{
ll n,m;
cin >> n >> m ;
vector<vector<ll>> g(n);
vector<vector<ll>> gr(n);
rep(i, m)
{
    ll a,b;
    cin >> a>>b;
    g[a-1].push_back(b-1);
    gr[b-1].push_back(a-1);
}
ll mindist=INF;
ll str=-1;
rep(i,n){
  ll dist[n]={};
  queue<ll> q;
  q.push(i);
  dist[i]=1;
  while(!q.empty()){
    ll p=q.front();q.pop();
    rep(j,g[p].size()){
      if(dist[g[p][j]]==0){
        dist[g[p][j]]=dist[p]+1;
        q.push(g[p][j]);
      }
      if(dist[g[p][j]]==1&&mindist>=dist[p]){
        mindist=dist[p];
        str=i;
      }
    }
  }
}
if(str==-1){
  cout << -1 << endl;
  return 0;
}
ll dist[n]={};
queue<ll> q;
q.push(str);
dist[str]=1;
while(!q.empty()){
  ll p=q.front();q.pop();
  rep(j,g[p].size()){
    if(dist[g[p][j]]==0){
      dist[g[p][j]]=dist[p]+1;
      q.push(g[p][j]);
    }
  }
}
ll now=str;
cout << mindist << endl;
vector<ll> ans;
set<ll> s;
rep(i,mindist){
  ll num=0;
  rep(j,gr[now].size()){
    if(dist[gr[now][j]]==mindist-i){
      num++;
      ans.push_back(gr[now][j]) ;
      s.insert(gr[now][j]);
      now=gr[now][j];
      break;
    }
  }
  assert(num==1);
}

rep(i,ans.size()){
  ll num=0;
  rep(j,g[ans[i]].size()){
    if(s.find(g[ans[i]][j])!=s.end())num++;
  }
  //assert(num==1);
}
for(auto a:ans)cout << a+1 << endl;

return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//cin.exceptions(cin.failbit);
    
    long long n,p;
    cin >> n >> p;  
   	string s;
   	cin >> s;
   	long long res =0;
   	if (p==2 || p == 5)
   	{
   		for (int i =0;i<s.length();i++)
   		{
   			if ((s[i]-'0')%p==0) res+= i+1;
   		}
   		cout << res << '\n';
   		return 0;
   	}
   	map<long long,long long> mp;
   	mp[0] = 1;
   	long long powten = 1;
   	long long t = 0;
   	for (long long i=s.length()-1;i>=0;i--)
   	{
   		t = ((long long)(s[i]-'0')*powten%p + t) % p;
   		powten = powten*10%p;
   		res += mp[t];
   		mp[t]++;
   	}
   	cout << res << '\n';	
	return 0;
}
	

Measured memory_bytes: 1044
# 最長で5文字なのでN*Kでいける

s = input().rstrip()  # python、無駄に改行コードを扱いがち
k = int(input())

arr = set()
for i in range(len(s)):
    for j in range(1, min(k, len(s)-i)+1):
        arr.add(s[i:i+j])

arr = sorted(list(arr))
print(arr[k-1])


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

public class Main
{
    static class Reader {
		BufferedReader br;
		StringTokenizer st;
 
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
 
	}
    static class Ele implements Comparable<Ele> 
    {  
        public int x,y;  
        Ele(int x,int y) 
        {  
            this.x=x;this.y=y; 
        }  
        public int compareTo(Ele ob) {  
        if(ob.x!=x)return x-ob.x;
        return this.y-ob.y;  
        }   
    }
    int a[][];int b[][];
    
    long gcd(long a,long b)
    {
        long min=Math.min(a,b);
        long max=Math.max(a,b);
        while (max%min!=0)
        {
            a=max%min;
            max=min;min=a;
        }
        return min;
    }
	public static void main(String[] args) throws IOException 
	{
		Reader sc=new Reader();Main G=new Main();
		PrintWriter o = new PrintWriter(System.out);
		int t=1;//t=sc.nextInt();
		long x,x0,x1,x2;long y,y0,y1,y2;int s,s0,s1,s2;
		int n,m;int a[],b[],in[],in1[];
		long k,l;boolean b1,b2;String ss1[],ss;
		//long l;long a[]; 
		ArrayList<ArrayList<Integer>> ll=new ArrayList<>();
		ArrayList<Integer> a1=new ArrayList<>();
		ArrayList<Integer> a2=new ArrayList<>();
		ArrayList<Integer> a3=new ArrayList<>();
		ArrayDeque<Integer> deq=new ArrayDeque<>();
		TreeSet<Integer> h0=new TreeSet<>();
		TreeSet<Integer> h1=new TreeSet<>();
		HashMap<Integer,Integer> h=new HashMap<>();
		try{
		while (t-->0)
		{
		    x=sc.nextLong();x0=sc.nextLong();
		    x1=sc.nextLong();x2=sc.nextLong();
		    y=x*x1;y0=x*x2;y1=x0*x1;y2=x0*x2;
		    k=Math.max(y,y0);l=Math.max(y1,y2);
		    o.println(Math.max(k,l));
		    //o.println(h);
		    //o.println(x2);
		    //o.println();
		    h0.clear();ll.clear();a1.clear();a2.clear();h1.clear();
		}
		}
		catch (Throwable e)
		{
		    e.printStackTrace();
		}
		//o.println("HI");
		
        o.flush();
        o.close();
	}
} 

Measured memory_bytes: 33268
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

// bfsで解くバージョン
int main()
{
    int n, m;
    cin >> n >> m;

    Graph G(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 頂点 s をスタートとした探索
    vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    int ans = 0;
    for (int v = 0; v < n; ++v)
    {
        if (dist[v] != -1)
            continue; // v が探索済みならスルー
        dist[v] = 0, que.push(v);
        int count = 1;
        while (!que.empty())
        {
            int v = que.front();
            que.pop();
            for (auto nv : G[v])
            {
                if (dist[nv] == -1)
                {
                    dist[nv] = dist[v] + 1;
                    ++count;
                    que.push(nv);
                }
            }
        }
        ans = max(ans, count);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 15408
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<string> g;

int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    string n;
    cin >> n;
    if (n.end()[-1] == '2' || n.end()[-1] == '4' || n.end()[-1] == '5' || n.end()[-1] == '7' || n.end()[-1] == '9')
    {
        cout << "hon" << endl;
    }
    else if (n.end()[-1] == '0' || n.end()[-1] == '1' || n.end()[-1] == '6' || n.end()[-1] == '8')
    {
        cout << "pon" << endl;
    }
    else
    {
        cout << "bon" << endl;
    }
    

    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
int prime[50001];
void set(void){
    int i,o;
    for(i=4;i<=50000;i+=2)
        prime[i]=1;
    for(i=3;i*i<=50000;i+=2){
        if(prime[i]==0)
            for(o=i*2;o<=50000;o+=i)
                prime[o]=1;
    }
}
int main(void){
    int num,count,i;
    set();
    for(;count=0,scanf("%d",&num),num;){
        for(i=2;i<=num/2;i++)
            if(!(prime[i]||prime[num-i]))
                count++;
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 792