akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    string s,t;    
    cin>>s>>t;
    int n=s.size(),m=t.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1));
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i<n && j<m && s[i]==t[j]) dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
            if(i<n) dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j<m) dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
        }
    }
    int i=n,j=m;
    string res;
    while(i!=0 && j!=0){
        if(dp[i-1][j-1]+1==dp[i][j] && s[i-1]==t[j-1]){
            res+=s[i-1];
            i--,j--;
        }
        else{
            if(dp[i-1][j]==dp[i][j]) i--;
            else j--;
        }
    }
    reverse(res.begin(),res.end());
    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 35584
size = int(input())

r_str = input().split()

rabs = []
for r in r_str:
    rabs.append(int(r) - 1)

#visited = []
t = 0

for i in range(0, size):
    if rabs[rabs[i]] == i and (not rabs[i] < i):
        #visited.append(i)
        #visited.append(rabs[i])
        t += 1

print(t)


Measured memory_bytes: 14008
#include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 // #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define mod        1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        2e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}


set<int> factorize(int a)
{
 set<int>an;

 for(int i=1;i*i<=a;i++)
 if(a%i==0)
 {
   if(i!=1)an.insert(i);
   if(a/i!=1) an.insert(a/i);
 }
 return an;
}

void solve()
{
 
 int n;
 cin >> n ;

 set<int>result = factorize(n-1);
 set<int>check   = factorize(n);
 
 for(auto x:check)
 {
  int d = n;
  while(d%x==0) d/=x;
  if(d%x==1) result.insert(x);
 }

 cout<<sz(result);

}

int32_t main()
{
  //pr_init();
  fastio;
  solve();

 }


Measured memory_bytes: 3804
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.cos

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

data class Point(val x: Int, val y: Int)
data class Delta(val x: Int, val y: Int)

fun solve() {
    val n = readInteger()
    val pointArray = Array(n) {
        val (x, y) = readIntegerList()
        Point(x, y)
    }.sortedWith(compareBy({ it.x }, { it.y }))

    val deltaMap = mutableMapOf<Delta, Int>()
    for (i in pointArray.indices) {
        for (j in (i + 1) until pointArray.size) {
            val delta = Delta(pointArray[j].x - pointArray[i].x, pointArray[j].y - pointArray[i].y)
            deltaMap.merge(delta, 1) { old, new -> old + new}
        }
    }
    val mostCommonDelta = deltaMap.entries.maxBy { it.value }?.key
    if (mostCommonDelta == null) {
        out.println(1)
        return
    }

    val checkedPointHash = mutableMapOf<Point, Boolean>()
    for (p in pointArray) {
        checkedPointHash[p] = false
    }

    var ans = 0
    for ((i, p) in pointArray.withIndex()) {
        if (checkedPointHash[p]!!) {
            continue
        }
        ans++
        checkedPointHash[p] = true

        var prePoint = p
        while (true) {
            val nextPoint = Point(prePoint.x + mostCommonDelta.x, prePoint.y + mostCommonDelta.y)
            if (checkedPointHash[nextPoint] == null) {
                break
            }

            checkedPointHash[nextPoint] = true
            prePoint = nextPoint
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string x;
  while (cin >> x) {
    if (x == "0") break;
    int ans = 0;
    REP(i, x.size()) ans += x[i] - '0';
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int n,ans[202020],ct1,ct2;
vector<int>v[202020],md[4],vv,cr,cl[3];
void dfs(int x,int bf,int cll)
{
	cl[cll].push_back(x);
	if(cll==0)
	{
		ct1++;
	}
	else
	{
		ct2++;
	}
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if(y==bf)
		{
			continue;
		}
		dfs(y,x,cll^1);
	}
}
int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(0,-1,0);
	if(ct1>ct2)
	{
		swap(ct1,ct2);
		swap(cl[0],cl[1]);
	}
	for(int i=1;i<=n;i++)
	{
		md[i%3].push_back(i);
	}
	for(int i=0;i<cl[0].size();i++)
	{
		vv.push_back(cl[0][i]);
	}
	for(int i=0;i<cl[1].size();i++)
	{
		vv.push_back(cl[1][i]);
	}
	if(ct1>=md[2].size())
	{
		for(int i=0;i<md[2].size();i++)
		{
			cr.push_back(md[2][i]);
		}
		for(int i=0;i<md[0].size();i++)
		{
			cr.push_back(md[0][i]);
		}
		for(int i=0;i<md[1].size();i++)
		{
			cr.push_back(md[1][i]);
		}
	}
	else
	{
		for(int i=0;i<md[0].size();i++)
		{
			cr.push_back(md[0][i]);
		}
		for(int i=0;i<md[1].size();i++)
		{
			cr.push_back(md[1][i]);
		}
		for(int i=0;i<md[2].size();i++)
		{
			cr.push_back(md[2][i]);
		}
	}
	for(int i=0;i<n;i++)
	{
		ans[vv[i]]=cr[i];
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans[i]<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 22000
import math

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))


    ans=0
    for i in range(N):
        ans+=B[A[i]-1]
        if(i>=1):
            if(A[i]==A[i-1]+1):
                ans+=C[A[i-1]-1]
        
    print(ans)
  

resolve()


Measured memory_bytes: 9112
#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<deque>
#define ll long long
using namespace std;
#define BUF_SIZE 1048576
char _buf[BUF_SIZE],*_is=_buf,*_it=_buf;
inline char rdc(){
	if (_is==_it) _it=(_is=_buf)+fread(_buf,1,BUF_SIZE,stdin);
	return *_is++;
}
inline int rdi(){
	int x=0,f=0;
	register char ch=rdc();
	while ((ch<'0' or ch>'9') and (ch^'-')) ch=rdc();
	if (ch=='-') f=1,ch=rdc();
	while (ch>='0' and ch<='9') x=(x<<3)+(x<<1)+(ch^'0'),ch=rdc();
	return f?-x:x;
}
inline void write(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
inline void _write(int x){
	write(x);
	putchar(' ');
}
inline void print(int x){
	write(x);
	putchar('\n');
}
int h[100005],n;
ll dp[100005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	int i,j;
	for(i=1;i<=n;++i) cin>>h[i];
	memset(dp,63,sizeof(dp));
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[2]-h[1]);
	for(i=3;i<=n;++i) dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	cout<<dp[n]<<endl;
	return 0;
}

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

using ll = long long;

int main() {
    int N, K, A;
    cin >> N >> K;
    rep(i, N) cin >> A;
    cout << (N - 1 + K - 1 - 1) / (K - 1) << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
using namespace std;






int main(){
    int n,m;
    int a[25][25];
    cin>>n>>m;
    for(int i=0;i<25;i++){
        for(int t=0;t<25;t++){
            a[i][t]=-1;
        }
    }
    char q;
    for(int i=0;i<m;i++){
        int b,c,d,e;
        cin>>b>>q>>c>>q>>d>>q>>e;
        a[b][c]=d;
        a[c][b]=e;
    }
    int s,g,gold,p;
    cin>>s>>q>>g>>q>>gold>>q>>p;
    bool j=true;
    int count=0;
    //while(j){
        j=false;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int t=1;t<=n;t++){
                if(a[i][k]==-1 || a[k][t]==-1){continue;}
                if(a[i][t]==-1){a[i][t]=a[i][k]+a[k][t]; j=true; continue;}
                if(a[i][t]>a[i][k]+a[k][t]){a[i][t]=a[i][k]+a[k][t]; j=true;}
            }
        }
    }
        count++;
    //}
    cout<<gold-p-a[s][g]-a[g][s]<<endl;
    //cout<<count<<endl;
    
    
    return 0;
}


Measured memory_bytes: 3076
import math
def combi(n, r):
  if n >= r:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  elif r == 0:
    return 1
  else:
    return 0

N, P = map(int, input().split())
A = list(map(int, input().split()))

eo = ["e" if i % 2 == 0 else "o" for i in A]
e_num = eo.count("e")
o_num = eo.count("o")

o = [i for i in range(o_num + 1) if i % 2 == 0]
e = [i for i in range(o_num + 1) if i % 2 == 1]


if P == 0:
  oo = 0
  for i in o:
    oo += combi(o_num, i)
  ans = 2**e_num * oo
else:
  ee = 0
  for i in e:
    ee += combi(o_num, i)
  ans = 2**e_num * ee

print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

string itos(int s){
  string res="0000";
  rep(i,4){
    res[res.size()-i-1] = s%10 + '0';
    s /= 10;
  }
  return res;
}
int stoi(string s){
  int res = 0;
  int w = 1000;
  rep(i,4){
    //cout<<(int)(s[i]-'0')<<" "<<w<<endl;
    res += (s[i] - '0') * w;
    w /= 10;
  }
  return res;
}

int main(void){
  string s;
  while(cin>>s){
    bool brek = true;
    rep(i,4)if(s[i] != s[0])brek = false;
    if(brek&&s[0]=='0')break;
    if(brek&&s[0]!='0'){cout<<"NA"<<endl;continue;}
        
    int cnt = 0;
    while(s!="6174"){
      cnt ++;
      vector<char> used;
      rep(i,4){
	used.push_back(s[i]);
      }
    
      sort(used.begin(),used.end());
      string min,max;
      rep(i,used.size()){
	max += used[used.size()-i-1];
	min += used[i];
      }
      int maxv=stoi(max),minv=stoi(min);
      int diffv = maxv - minv;
      s = itos(diffv);
    }
    cout<<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = getchar();c < '0' || c > '9';c = getchar()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = getchar()) res = res * 10 + (c - '0');
  return res * sig;
}
char s[5];
int main(){
  scanf("%s",s);
  if(s[0] == 'A') puts("T");
  if(s[0] == 'T') puts("A");
  if(s[0] == 'C') puts("G");
  if(s[0] == 'G') puts("C");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/


using namespace std;

const int N=2e5+5,L=19;

int ans[N];

char s[N];

int to[N][L];

int jump(int u,int dif)
{
    for (int i=0;i<L;i++)
    {
        if (dif&(1<<i))
        {
            u=to[u][i];
        }
    }
    return u;
}

int main()
{
    int mx=0;
    scanf("%s",s);
    int len=strlen(s);
    for (int i=0;i<len;i++)
    {
        int cnt=1,j;
        for (j=i+1;j<len;j++)
        {
            if (s[j]==s[j-1])cnt++;
            else break;
        }
        i=j-1;
        mx=max(mx,cnt);
    }
    if (mx&1)mx++;
    for (int i=0;i<len;i++)
    {
        if (s[i]=='R')to[i][0]=i+1;
        else to[i][0]=i-1;
    }
    for (int j=1;j<L;j++)
    {
        for (int i=0;i<len;i++)
        {
            to[i][j]=to[to[i][j-1]][j-1];
        }
    }
    for (int i=0;i<len;i++)
    {
        ans[jump(i,mx)]++;
    }
    printf("%d",ans[0]);
    for (int i=1;i<len;i++)
    {
        printf(" %d",ans[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 9216
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort
OP = M.times.map{ gets.split.map(&:to_i) }.sort_by(&:last).reverse
ans = N.times.inject(0) do |s,i|
  if !OP.empty? && A[i] < OP[0][1]
    s += OP[0][1]
    OP[0][0] -= 1
    OP.shift if OP[0][0].zero?
  else
    s += A[i]
  end
  s
end
puts ans

Measured memory_bytes: 21032
#include<stdio.h>
int main()
{
   long long int N,K,Q,a[1000000],b[1000000],c[1000000],i,x;
   scanf("%lld%lld%lld",&N,&K,&Q);
   x=Q-K;
   for(i=0;i<N;i++)
   {
     c[i]=0;
   }
   for(i=0;i<Q;i++)
   {
     scanf("%lld",&b[i]);
     c[b[i]-1]=c[b[i]-1]+1;
   }
   for(i=0;i<N;i++)
   {
     if(c[i]>x)
     {
        printf("Yes\n");
     }
     else
     {
        printf("No\n");
     }
   }
   return 0;
}


Measured memory_bytes: 6784
import sys
#input = sys.stdin.buffer.readline


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	s = input()
	n = int(input())
	f = 0
	l = ""
	r = ""
	for i in range(n):
		q=input().split()
		if q[0] == "1":
			f ^= 1
		else:
			if (f == 0 and q[1] == "1") or (f == 1 and q[1] == "2"):
				l = l + q[2]
			else:
				r = r + q[2]
	if f == 0:
		ans = l[::-1] + s + r
	else:
		ans = r[::-1] + s[::-1] + l
	print(ans)


if __name__ == "__main__":
	main()


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

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

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vpii c(m);
    rep(i, m) cin >> c[i].first >> c[i].second;
    rep(x, 1000) {
        int xi = x;
        vi d;
        do {
            d.push_back(xi % 10);
            xi /= 10;
        } while (xi);
        reverse(d.begin(), d.end());
        if (int(d.size()) != n) continue;
        bool ans = true;
        rep(i, m) {
            if (d[c[i].first-1] != c[i].second) ans = false;
        }
        if (ans) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int x1, y1, x2, y2, x3, y3; 
	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3; 
	cout.precision(15); 
	double L1 = pow((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2), 0.5); 
	double L2 = pow((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3), 0.5); 
	double L3 = pow((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3), 0.5); 
	double S = (double) 0.5 * abs((x1-x3)*(y2-y3)-(y1-y3)*(x2-x3)); 
	double L = max({L1, L2, L3}); 
	cout << 2.0 * L * S / (L * (L1 + L2 + L3) + 4.0 * S) << endl; 
}

Measured memory_bytes: 384
N = input()
A = map(int,raw_input().split())

x = 0

for i in range(N):
    minj = i
    y = 0
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
            y = 1
            
    v = A[i]
    A[i] = A[minj]
    A[minj] = v
    x += y
    
for i in range(N-1):
    print A[i],
print A[-1]

print x

Measured memory_bytes: 6416
#include <iostream>
#include <cmath>
using namespace std;

const double eps=1e-10;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) {
        double x1, y1, x2, y2, x3, y3, x4, y4;
        cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
        if(fabs((x2-x1)*(y4-y3)-(y2-y1)*(x4-x3))<eps) cout<<"YES\n";
        else cout<<"NO\n";
    }
    return 0;
}

Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define ll long long
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
const  long double eps = 1e-2;
const long double pi = acos(-1.0);
using namespace std;

const int N = 5e5 + 1;
map <pair <int, int>, int> mp;
vector <pair <int, int> > g[N];
void solve(){   
    int n, m;
    cin >> n >> m;
    int cnt = n + 1;
    for (int i = 0; i < m; i++){
        int x, y, c;
        cin >> x >> y >> c;
        int a, b;
        if (mp.count({x, c})) a = mp[{x, c}];
        else{
            a = mp[{x, c}] = cnt++;
            g[a].pb({x, 1});
            g[x].pb({a, 1});
        }
        if (mp.count({y, c})) b = mp[{y, c}];
        else{
            b = mp[{y, c}] = cnt++;
            g[b].pb({y, 1});
            g[y].pb({b, 1});
        }
        g[a].pb({b, 0});
        g[b].pb({a, 0});
    }
    vector <int> dist(N, -1);
    deque <pair <int, int> > dq;
    dq.pb({1, 0});
    dist[1] = 0;
    while (dq.size() > 0){
        int v = dq.front().fr;
        int d = dq.front().sc;
        
        dq.pop_front();
        if (d > dist[v]) continue;
        for (auto x : g[v]){
            int nd = d + x.sc;
            if (dist[x.fr] == -1 || dist[x.fr] > nd){
                dist[x.fr] = nd;
                dq.pb({x.fr, nd});
            }
        }
    }
    if (dist[n] == -1) cout << -1;
    else
    cout << dist[n] / 2  << endl;
}
int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(3);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
  for (int i = 1; i <= step; i++){
         solve();
    }
}


Measured memory_bytes: 60988
import java.util.Scanner;

public class Main {

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

		boolean answer = w >= s;

		printBool(answer);
	}

	public static void printBool(boolean bool) {
		print(bool ? "unsafe" : "safe");
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}
}


Measured memory_bytes: 35764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main(){
	ll n; cin>>n;
	ll m[n+1]; for(ll i=0;i<=n;i++) cin>>m[i];
	ll h[n]; for(ll i=0;i<n;i++) cin>>h[i];
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll x=min(m[i],h[i]);
		h[i]-=x;
		m[i]-=x;
		ans+=x;
		x=min(m[i+1],h[i]);
		h[i]-=x;
		m[i+1]-=x;
		ans+=x;
	}
	cout<<ans;
}


Measured memory_bytes: 5132
#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 ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

 const int nmmax=50;
 char A[nmmax][nmmax],B[nmmax][nmmax];


  for(int y=0;y<N;++y){
    for(int x=0;x<N;++x){
      cin >> A[y][x];
    }
  }

  for(int y=0;y<M;++y){
    for(int x=0;x<M;++x){
      cin >> B[y][x];
    }
  }

 bool exist=false;

  for(int ly=0;ly<N;++ly){
    for(int lx=0;lx<N;++lx){
      if(ly+M-1>=N or lx+M-1>=N) continue;

      bool match=true;
      for(int y=0;y<M;++y){
        for(int x=0;x<M;++x){
          if(A[ly+y][lx+x]!=B[y][x]) match=false;
        }
      }
      if(match) exist=true;
    }
  }

  if(exist)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Random;
import java.util.Scanner;

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

		int x = scanner.nextInt();
		
		int[][] n = new int[x][6];
		for(int i=0; i<x; i++)
		{
			for(int j=0; j<6; j++)
			{
				n[i][j] = scanner.nextInt();
			}
		}
		
		for(int l=0; l<x; l++)
		{
			for(int k=l+1; k<x; k++)
			{
				for(int i=0; i<1000; i++)
				{
					Random random = new Random();
					int d = random.nextInt(4);
						
					int[] buf = new int[6];
					for(int j=0; j<6; j++)
					{
						buf[j] = n[k][j];
					}
							
					switch(d)
					{
						case 0:
							n[k][0] = buf[4];
							n[k][1] = buf[0];
							n[k][5] = buf[1];
							n[k][4] = buf[5];
							break;
						case 1:
							n[k][0] = buf[1];
							n[k][1] = buf[5];
							n[k][5] = buf[4];
							n[k][4] = buf[0];
							break;
						case 2:
							n[k][0] = buf[2];
							n[k][2] = buf[5];
							n[k][5] = buf[3];
							n[k][3] = buf[0];
							break;
						case 3:
							n[k][0] = buf[3];
							n[k][3] = buf[5];
							n[k][5] = buf[2];
							n[k][2] = buf[0];
							break;
					}
					
					boolean is = true;
					for(int j=0; j<6; j++)
					{
						if(n[l][j] != n[k][j])
						{
							is = false;
							break;
						}
					}
					if(is)
					{
						System.out.println("No");
						return;
					}
				}
			}
		}
		
		System.out.println("Yes");
	}
}

Measured memory_bytes: 94060
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int a1,b1,c1,a2,b2,c2;
vector<pair<int,int> >A_to_B,B_to_A;
int dp1[5005],dp2[5005*5005];
signed main(){
	cin>>n>>a1>>b1>>c1>>a2>>b2>>c2;
	if(a1!=a2){
		if(a1<a2){
			A_to_B.push_back(make_pair(a1,a2));
		}else{
			B_to_A.push_back(make_pair(a2,a1));
		}
	}
	if(b1!=b2){
		if(b1<b2){
			A_to_B.push_back(make_pair(b1,b2));
		}else{
			B_to_A.push_back(make_pair(b2,b1));
		}
	}
	if(c1!=c2){
		if(c1<c2){
			A_to_B.push_back(make_pair(c1,c2));
		}else{
			B_to_A.push_back(make_pair(c2,c1));
		}
	}
	dp1[0]=0;
	for(auto p:A_to_B){
		for(int j=0;j+p.first<=n;j++){
			dp1[j+p.first]=max(dp1[j+p.first],dp1[j]+p.second);
		}
	}
	int now=0;
	for(int i=0;i<=n;i++)now=max(now,n-i+dp1[i]);
	dp2[0]=0;
	for(auto p:B_to_A){
		for(int j=0;j+p.first<=now;j++){
			dp2[j+p.first]=max(dp2[j+p.first],dp2[j]+p.second);
		}
	}
	int ans=0;
	for(int i=0;i<=now;i++)ans=max(ans,now-i+dp2[i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 195584
from itertools import accumulate
def compress(arr):
    *XS, = set(arr)
    XS.sort()
    return {e: i for i, e in enumerate(XS)}
n, k = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(n)]
X, Y = zip(*XY)
comp_X = compress(X)
comp_Y = compress(Y)
len_X = len(comp_X)
len_Y = len(comp_Y)
rev_X = {j:i for i, j in comp_X.items()}
rev_Y = {j:i for i, j in comp_Y.items()}
C = [[0]*(len_Y+1) for _ in range(len_X+1)]
for x, y in XY:
  C[comp_X[x]+1][comp_Y[y]+1] = 1
for i in range(1, len_X+1):
  C[i] = list(accumulate(C[i]))
C = list(zip(*C))
for j in range(1, len_Y+1):
  C[j] = list(accumulate(C[j]))
C = list(zip(*C))
def test(x1, x2, y1, y2):
  cnt = C[x2][y2] - C[x1][y2] - C[x2][y1] + C[x1][y1]
  if cnt >= k:
    temp = (rev_X[x2-1] - rev_X[x1]) * (rev_Y[y2-1] - rev_Y[y1])
    return temp
  return float("inf")
ans = float("inf")
for x1 in range(len_X):
  for x2 in range(x1+1, len_X+1):
    for y1 in range(len_Y):
      for y2 in range(y1+1, len_Y+1):
        ans = min(ans, test(x1, x2, y1, y2))
print(ans)

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

int main() {
  int N; cin >> N;
  vector<string> S(N);
  for (int i=0; i<N; i++) cin >> S.at(i);

  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());

  int ans = S.size();
  cout << ans << endl;

  return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#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()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n, x;
  cin >> n >> x;
  x--;

  vector<ll> v(n+1), p(n+1);
  v[0] = 1, p[0] = 1;
  FOR(i, 1, n+1) {
    p[i] = p[i-1] * 2 + 1;
    v[i] = v[i-1] * 2 + 3;
  }

  ll ret = 0;
  for(ll i=n; i>=0; --i) {
    // レベルiのハンバーガーで下からx個食べるときにPが何枚あるか
    if(x == 0) {
      if(i == 0) ret++;
      break;
    } else if(x < v[i-1]+1) {
      x--;
    } else if(x == v[i-1]+1) {
      ret += p[i-1] + 1;
      break;
    } else if(x < v[i-1]*2+2) {
      ret += p[i-1] + 1;
      x -= v[i-1] + 2;
    } else if(x == v[i-1]*2+2) {
      ret += p[i-1] * 2 + 1;
      break;
    }
  }
  cout << ret << endl;

  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353
ll N,M;
ll Fa[5050505],Finv[5050505];
ll i,j,k,ans;
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}
ll C(ll a,ll b){
    return Fa[a] * Finv[a - b]%MOD * Finv[b]%MOD;
}
int main(){
    scanf("%lld%lld", &N,&M);
    Fa[0] = 1;
    fornum(i,0,N+M*3){
        Fa[i + 1] = (Fa[i] * (i + 1)) % MOD;
    }
    Finv[i] = moddiv(1, Fa[i]);
    for (i = i; i > 0;i--){
        Finv[i - 1] = Finv[i] * i % MOD;
    }

    for (i = M % 2; i <= N && i <= M; i += 2)
    {
        ll b = 3 * M - i;
        ans = (ans + C(N,i) * C(b / 2 + N - 1, N - 1)) % MOD;
        ll c = M - i;
        if (i == N)
        {
            ans = (ans - C(c / 2 + N - 1, N - 1) * N % MOD + MOD) % MOD;
        }
        else
        {
            ans = (ans - (C(N, i) * C(c / 2 + N - 1, N - 1) % MOD * N % MOD) + (C(N - 1, i) * C(c / 2 + N - 2, N - 2) % MOD * N % MOD) + MOD) % MOD;
        }
        //printf("%lld\n", ans);
    }
    printf("%lld",ans);

    return 0;
}

Measured memory_bytes: 41216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0xfff;
const int maxn = 100005;
ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n>=30)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{

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

        // input
        String inputS = scan.next();
        int answer = 1;
        for(int i = 1; i < inputS.length(); i++){
            if(inputS.charAt(0) == inputS.charAt(i)){
                answer++;
            }
        }
        if(answer == inputS.length()){
            System.out.println(0);
            return;
        }
        
        // search
        int min = Integer.MAX_VALUE;
        char temp = 'a';
        while(true){
            char[] input = inputS.toCharArray();
            int count = 0;
            while(true){
                boolean flag = true;
                for(int i = 0; i < input.length - count - 1; i++){
                    if(input[i] == temp || input[i+1] == temp){
                        input[i] = temp;
                    } else {
                        flag = false;
                    }
                }
                count++;
                if(flag){
                    break;
                }
                
            }

            if(count < min){
                min = count;
            }
            if(temp == 'z'){
                break;
            }
            temp++;

        }

        // answer
        System.out.println(min);

    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, d, i, j, k;
	int sumCoordinate = 0;
	int count = 0;
	int x[10][10];


	scanf("%d%d", &n, &d);

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

	//座標の距離を調べる
	for (i = 0; i < n - 1; i++) {
		for (j = i + 1; j < n; j++) {
			sumCoordinate = 0;
			for (k = 0; k < d; k++) {
				//座標の差を合計する(sumCoordinate)
				sumCoordinate += (x[j][k] - x[i][k]) * (x[j][k] - x[i][k]);
			}
			//sumCoordinateの平方根が整数か調べる
			for (k = 0; k * k <= sumCoordinate; k++) {
				if (k * k == sumCoordinate) {
					count++;//整数ならカウント
				}
			}
		}
	}
	
	printf("%d\n", count);

	return 0;
}

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

int main(){
  int w, a, b;
  cin >> w >> a >> b;
  if(a + w >= b && a + w <= b + w){
    cout << 0 << endl;
  }
  else if(a >= b && a <= b + w){
    cout << 0 << endl;
  }
  else{
    if(a + w < b){
      cout << b - (a + w) << endl;
    }
    if(a > b + w){
      cout << a - (b + w) << endl;
    }
  }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#include"bits/stdc++.h"
using namespace std;

int32_t main()
{
	string s;
	cin>>s;
	string x="",y="";
	x+=s[0];x+=s[1];y+=s[2];y+=s[3];
	bool yy=0,mm=0;
	int xi=stoi(x);int yi=stoi(y);
	//yymm
	if(yi>=1 and yi<=12)yy=1;
	
	//mmyy
	if(xi>=1 and xi<=12)mm=1;
	
	if(yy and mm)cout<<"AMBIGUOUS";
	else if(yy)cout<<"YYMM";
	else if(mm)cout<<"MMYY";
	else cout<<"NA";
	
}

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

int main() {
  int n;
  int t, a;
  cin >> n;
  cin >> t >> a;
  int h;
  int p = 1000000000;
  int ans = 1;
  for(int i=0; i<n; i++) {
    cin >> h;
    if (abs(1000*a-(1000*t-h*6))<p) {
      p = abs(1000*a-(1000*t-h*6));
      ans = i + 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
int a[3],i,j,temp;
scanf ("%d %d %d",&a[0],&a[1],&a[2]);

for (i=0;i<3;i++){
	for (j=0;j<3;j++){
	if (a[i]<a[j]){
	temp=a[i];
	a[i]=a[j];
	a[j]=temp;
		}
	}
}

printf ("%d %d %d\n",a[0],a[1],a[2]);

return 0;
} 

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>

using namespace std;
int main()
{
	set<string> dp;
	string str;
	int k;
	cin >> str >> k;
	int n = str.length();
	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= min(k, n); j++)
		{
			string t = str.substr(i, j);
			dp.insert(t);
         }
	}
	set<string>::iterator sit = dp.begin();
	for (int i = 0; i < k-1; i++)
	{
		sit++;
	}
	cout << *sit << endl;
	return 0;
}

Measured memory_bytes: 1664
k=int(input())
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]
print(a[k-1])

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

using namespace std;

const string D = "^>v<";
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
const int inf = 1 << 25;
int fld[3000][3000], w, h;
int ans;


void compress(vector<int>& vec)
{
  vector<int> temp = vec;
  sort(temp.begin(), temp.end());
  temp.erase(unique(temp.begin(), temp.end()), temp.end());
  for(int i = 0; i < vec.size(); i++){
    vec[i] = find(temp.begin(), temp.end(), vec[i]) - temp.begin();
  }
}

int solve(int x, int y, int d)
{
  if(x < 0 || w < x || y < 0 || h < y) return 0;
  int nx = x + dx[d], ny = y + dy[d], nd = d;
  if(0 <= nx && nx <= w && 0 <= ny && ny <= h && fld[ny][nx] != -1) nd = fld[ny][nx];
  int hoge = fld[y][x];
  fld[y][x] = -1;
  int ret = solve(nx, ny, nd) + (hoge != -1);
  return ret;
}

int main()
{
  int n;
  cin >> n;
  vector<int> ix, iy, id;
  for(int i = 0; i < n; i++){
    int x, y; char d;
    cin >> x >> y >> d;
    ix.push_back(x);
    iy.push_back(y);
    id.push_back(D.find(d));
  }
  compress(ix);
  compress(iy);
  w = *max_element(ix.begin(), ix.end()), h = *max_element(iy.begin(), iy.end());
  ans = 0;
  memset(fld, -1, sizeof(fld));
  /*
  for(int j = 0; j < n; j++) fld[iy[j]][ix[j]] = id[j];
  for(int i = 0; i <= h; i++){
    for(int j = 0; j <= w; j++) printf("%2d", fld[i][j]); 
    cout << endl;
  }
  */
  for(int i = 0; i < n; i++){
    //memset(fld, -1, sizeof(fld));
    for(int j = 0; j < n; j++) fld[iy[j]][ix[j]] = id[j];
    ans = max(ans, solve(ix[i], iy[i], id[i]));
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n; cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    sum += 1LL * i;
  }
  cout << sum << '\n';
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;


int main(){
	
	ll a,b,c;cin >> a >> b >> c;
	cout << (a - b + 1) * (a - c + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline

MOD = 10**9 + 7

N = int(input())
A = np.array(list(map(int, input().split())), np.int64)

ans = 0
for n in range(64):
	Anb = (A >> n) & 1
	cnt_one = np.count_nonzero(Anb)
	cnt_zero = N - cnt_one
	x = cnt_one * cnt_zero
	for i in range(n):
		x *= 2
		x %= MOD
	ans = (ans+x)%MOD
print(ans)

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

vector<int> coins = {500, 5};
vector<int> happiness = {1000, 5};

int main() {
  long long X;
  cin >> X;

  long long ans = 0;
  for (int i = 0; i < coins.size(); i++) {
    ans += happiness.at(i) * (X / coins.at(i));
    X = X % coins.at(i);
  }

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


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
typedef struct{
  float x;
  float y;
}Koch;
 
void kochCurve(int, Koch, Koch);//????????????????????£?¨?
 
int main(void){
  int n;
  Koch p1, p2;
 
  p1.x = 0;
  p1.y = 0;
 
  p2.x = 100;
  p2.y = 0;
 
  scanf("%d", &n);
 
  printf("%f %f\n", p1.x, p1.y);
  kochCurve(n, p1, p2);
  printf("%f %f\n", p2.x, p2.y);
 
  return 0;
}
 
void kochCurve(int n, Koch p1, Koch p2){ //ToKoch
  Koch s, t, u;
 
  if(n == 0) return;
 
  s.x = (p2.x - p1.x)/3 + p1.x;
  s.y = (p2.y - p1.y)/3 + p1.y;
  t.x = 2*(p2.x - p1.x)/3 + p1.x;
  t.y = 2*(p2.y - p1.y)/3 + p1.y;
  u.x = (t.x - s.x)/2 + s.x - sqrt(3)/2 * (t.y - s.y);
  u.y = (t.y - s.y)/2 + s.y + sqrt(3)/2 * (t.x - s.x);
 
//p1 to s
  kochCurve(n - 1, p1, s);
  printf("%f %f\n", s.x, s.y);
 
//s to u
  kochCurve(n - 1, s, u);
  printf("%f %f\n",u.x, u.y);
 
//u to t
  kochCurve(n - 1, u, t);
  printf("%f %f\n",t.x, t.y);
 
//t to p2
  kochCurve(n - 1, t, p2);
}

Measured memory_bytes: 636
import collections
n = input()

li = list(map(int, input().split()))
odd_li = li[::2]
even_li = li[1::2]
odd_counter = collections.Counter(odd_li)
even_counter = collections.Counter(even_li)

odd_max = max(odd_counter.values())
even_max = max(even_counter.values())
odd_max_value = [key for key, value in odd_counter.items() if value == odd_max]
even_max_value = [key for key, value in even_counter.items() if value == even_max]

if len(odd_max_value) == 1 and odd_max_value == even_max_value:
    odd_counter.pop(odd_max_value[0])
    even_counter.pop(even_max_value[0])
    if len(odd_counter) == 0 and len(even_counter) == 0:
        print(len(odd_li)*2 - odd_max)
    elif len(odd_counter) == 0:
        print(len(odd_li)*2 - odd_max - max(even_counter.values()))
    elif len(even_counter) == 0:
        print(len(odd_li)*2 - odd_max - max(odd_counter.values()))
    else:
        second_max = max(max(odd_counter.values()),max(even_counter.values()) )
        print(len(odd_li)*2 - odd_max - second_max)
else:
    print(len(odd_li)*2 - odd_max - even_max)

Measured memory_bytes: 19032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
 
ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll fact[200000+10], fact_inv[200000+10], inv[200000+10], mem[200000+10];
const ll MOD = 1000000000+7;

ll mod_pow(ll x, ll n){
    if(n == 0) return 1;
    ll res = mod_pow(x * x % MOD, n / 2);
    if(n & 1) res = res * x % MOD;
    return res;
}
ll comb(ll n, ll k){
    return (fact[n] * inv[k] % MOD) * inv[n - k] % MOD;
}

ll a,b,h,w;

int main(){
    cin >> h >> w >> a >> b;

    fact[0] = inv[0] = 1;
    for(int i = 1; i <= h+w; i++){
        fact[i] = (fact[i-1]*i) % MOD;
        inv[i] = mod_pow(fact[i], MOD-2);
    }

    ll ans = 0, mem_cul;
    for(int i = b; i < w; i++){
        mem_cul = 0;
        mem_cul = comb(h-a-1+i, i) * comb((w-i-1)+(a-1), a-1) % MOD;
        ans += mem_cul;
        ans %= MOD;
    }

    cout << ans % MOD <<endl;
}

Measured memory_bytes: 4992
using System;
class Program
{
  static void Main(string[] args)
  {
    int day = int.Parse(Console.ReadLine());
    if(day==25){
    	Console.WriteLine("Christmas");
    } else if(day==24){
    	Console.WriteLine("Christmas Eve");
    } else if(day==23){
    	Console.WriteLine("Christmas Eve Eve");
    } else if(day==22){
    	Console.WriteLine("Christmas Eve Eve Eve");
    }
    
  }
}

Measured memory_bytes: 11092
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	vector<int> d = { A, B, C };
	sort(d.begin(), d.end());
	cout << d[0] * d[1] / 2 << endl;
	return 0;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx != ry) par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    UnionFind tree(N);
    vector<int> p(N), x(M), y(M);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> x[i] >> y[i];
        tree.unite(x[i]-1, y[i]-1);
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (tree.same(i, p[i]-1))
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m, L;
    cin >> n >> m >> L;    
    
    vector<vector<P>> G(n);  // 辺の重みがすべて0以上のグラフ
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].pb(make_pair(b, c));
        G[b].pb(make_pair(a, c));
    }

    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    vector<vector<P>> dist(n, vector<P>(n, make_pair(INF, INF)));  // dist[sv][v] : (頂点svから頂点vへの補給回数の最小値, そのときの満タンの状態から使用した燃料量)
    rep(sv, n) {
        dist[sv][sv] = make_pair(0, 0);
        priority_queue<pair<P, ll>, vector<pair<P, ll>>, greater<pair<P, ll>>> prQ;
        prQ.push(make_pair(make_pair(0, 0), sv));  // ((補給回数kaisuu, 満タンの状態から使用した燃料量used), いまいる頂点v)
        while(!prQ.empty()) {
            auto p1 = prQ.top();
            prQ.pop();
            ll v = p1.second;
            ll kaisuu = p1.first.first;
            ll used = p1.first.second;
            if(dist[sv][v] < p1.first) {
                continue;
            }
            for(auto p2 : G[v]) {
                ll u = p2.first;
                ll cost = p2.second;
                if(cost > L) {
                    continue;
                }
                P np;
                if(used + cost > L) {
                    np = make_pair(kaisuu + 1, cost);
                }
                else {
                    np = make_pair(kaisuu, used + cost);
                }
                if(dist[sv][u] > np) {
                    dist[sv][u] = np;
                    prQ.push(make_pair(np, u));
                }
            }
        }
    }
    
    ll q;
    cin >> q;
    vl ans(q);
    rep(i, q) {
        ll sv, gv;
        cin >> sv >> gv;
        sv--;  gv--;
        if(dist[sv][gv].first == INF) {
            ans[i] = -1;
        }
        else {
            ans[i] = dist[sv][gv].first;
        }
    }
    
    rep(i, q) {
        out(ans[i]);
    }

    re0;
}

Measured memory_bytes: 5644
from collections import deque


def main():
    while True:
        n, m = [int(i) for i in input().split()]
        if n == 0 and m == 0:
            return
        _, *a = [int(i) for i in input().split()]
        _, *b = [int(i) for i in input().split()]
        _, *c = [int(i) for i in input().split()]
        a.insert(0, 0)
        b.insert(0, 0)
        c.insert(0, 0)

        q = deque()
        q.appendleft([a, b, c, 0, -1])
        tmp = [i for i in range(0, n+1)]

        while q:
            # d はカウンタ
            a, b, c, d, t = q.pop()
            """
            print(a)
            print(b)
            print(c)
            print('=======')
            """
            # 終了
            if d > m:
                print(-1)
                break
            if a == tmp or c == tmp:
                print(d)
                break
            # a から b
            if a[-1] > b[-1] and t != 1:
                q.appendleft([a[:-1], b+[a[-1]], c[:], d+1, 0])
            # b から a
            if b[-1] > a[-1] and t != 0:
                q.appendleft([a+[b[-1]], b[:-1], c[:], d+1, 1])
            # b から c
            if b[-1] > c[-1] and t != 3:
                q.appendleft([a[:], b[:-1], c+[b[-1]], d+1, 2])
            # c から b
            if c[-1] > b[-1] and t != 2:
                q.appendleft([a[:], b+[c[-1]], c[:-1], d+1, 3])


if __name__ == '__main__':
    main()



Measured memory_bytes: 6016
//     . .. ... .... ..... be name khoda ..... .... ... .. .     \\

#include <bits/stdc++.h>
using namespace std;

inline int in() { int x; scanf("%d", &x); return x; }
const int N = 2002;

int main()
{
	int x, y;
	cin >> x >> y;
	if(x % y == 0)
		cout << "-1\n";
	else
		cout << x << endl;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    bool flg[3] = {false ,false ,false};
    rep(i, s.length()) {
        if ( s[i] == 'a' ) flg[0] = true;
        if ( s[i] == 'b' ) flg[1] = true;
        if ( s[i] == 'c' ) flg[2] = true;
    }
    if ( flg[0] & flg[1] & flg[2] ) cout << "Yes" << endl;
    else                            cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

ll H, W;

void solve()
{
	if(H==1 || W == 1){
		cout << 1 << '\n';
	}else{
		ll a = (W+1)/2, b=(W%2)?(a-1):(a);
		ll m = (H+1)/2, n=(H%2)?(m-1):(m);
		cout << a*m+b*n << '\n';
	}		
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> H >> W;
	solve();
	return 0;
}

Measured memory_bytes: 256
counter=gets.to_i
line=[]
counter.times do |count|
  x=gets.chomp.split().map(&:to_i)
  line[count]=x
end  


x= line.permutation(counter).to_a
len=0
x.each do |p|
  p.each_cons(2) do |p1,p2|
    len += Math.sqrt((p2[0] - p1[0]) ** 2 + (p2[1] - p1[1]) ** 2)
  end  
end  

puts len / x.length.to_f

Measured memory_bytes: 8700