akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int dp[100100][3];

int max3int(int a, int b, int c) {
  if (b < c) swap(b, c);
  return max(a, b);
}

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  REP(i, n) cin >> a[i] >> b[i] >> c[i];
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  FOR(i, 1, n - 1) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
  }
  cout << max3int(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]) << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

using namespace std;

int main () {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int k, n;
  cin >> k >> n;
  map<int, bool> close;
  for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		close[x] = true;  	
  }
  int ans = -2;
  for (int i = 0; ans == -2; ++i) {
  	if (!close[k + i]) ans = k + i;
  	if (!close[k - i]) ans = k - i;
  }
  cout << ans;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define faster ios_base::sync_with_stdio(0);
#define faster_tie cin.tie(0);
#define fr(i,a,b) for(int i=a;i<=b;i++)

int main()
{
    // while(1){
        faster;
        ll n;
        cin>>n;
        ll ans=0;
        if(n>99999)
        {
            ans+=9+900+90000;
        }
        else if(n>9999){
            ans+=9+900+n-9999;
        }
        else if(n>99)
        {
            if(n>999)n=999;
            ans+=9+n-99;
        }
        else if(n>9)
        {
            ans=9;
        }
        else{
            ans+=n;
        }
        cout<<ans;
        //}
}


Measured memory_bytes: 256
s = [2,3,4,5,6,7,8,9,10,11,12,13,1]
a,b = map(int, input().split())
a = s.index(a)
b = s.index(b)
if a==b:
	print('Draw')
elif a>b:
	print('Alice')
else:
	print('Bob')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, a[3000], ans=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		ans+=(a[i]-1);
	}
	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n,x=0;
	cin>>n;
	for(int i=0;i!=n;++i){
		int temp;
		cin>>temp;
		if(temp&1)
			++x;
	}
	if(!(x&1))
		cout<<"YES";
	else
		cout<<"NO";
}


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

int main() {
	int n;
	int h[100000];
	cin >> n;
	int han = 0;
	int max=0;
	int maxi;
	int min=100000001;
	int mini;
	for(int i=0; i!=n; i++){
		cin >> h[i];
		if(max < h[i]){
			max = h[i];
			maxi = i;
		}
		if(min > h[i]){
			min = h[i];
			mini = i;
		}
		if(i == 0){
			continue;
		}
		if(h[i] < h[i-1]){
			if(han == 1){
				cout << "No\n";
				return 0;
			}
			if(h[i-1] - h[i] == 1){
				han = 1;
			}else{
				cout << "No\n";
				return 0;
			}
		}else{
			if(han == 1 && h[i-1] == h[i]){
				continue;
			}
			han = 0;
		}
	}
	/*if(max - min >= 1){
		cout << "Yes\n";
	}else if(maxi > mini){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}*/
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define print(a) {\
    for (auto i : a) cout << i << ' ';\
    cout << '\n';\
}
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define mt make_tuple
#define pii pair<int,int> 
#define pdd pair<ld,ld> 
#define ld double
#define pll pair<lli,lli>
#define tiii tuple<int,int,int>
#define all(a) a.begin(), a.end()
#define X first
#define Y second
#define oset tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>
auto SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
const int x = 864197532, N = 50000;
const long long mod = 9223372036854775807;
const double eps = 1e-6, Pi = 3.1415926535;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b ;
	cin >> a >> b;
	cout << a * b << endl;
}

Measured memory_bytes: 3656
import static java.lang.System.out;
import java.util.Scanner;

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

        double area = r * r * Math.PI;
        double circumference = r * 2 * Math.PI;

        out.printf("%f %f%n", area, circumference);
    }
}

Measured memory_bytes: 28104
#include <iostream>
using namespace std;
int main()
{
    int h1, h2, m1, m2, k, wu;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    wu = (h2 - (h1+1)) * 60 + m2 + 60 - m1;
    cout << wu - k << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

char s[30];

int main()
{
	scanf("%s\n", s);
	
	for (int i = 0 ; i < 3 ; i++)
		printf("%c", s[i]);
	printf("\n");
	
	return 0;
}


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

int n,m;
int g[50][50];
int vi[50];
pair<int,int> e[50];

void dfs(int a) {
    vi[a]=1;
    for (int i=0;i<n;i++)
        if (g[a][i]&&!vi[i])
            dfs(i);
}

int main() {
    cin>>n>>m;
    for (int i=0;i<m;i++) {
        int u,v;
        cin>>u>>v;
        u--,v--;
        g[u][v]=g[v][u]=1;
        e[i]={u,v};
    }
    int ans=0;
    for (int i=0;i<m;i++) {
        int u=e[i].first;
        int v=e[i].second;
        g[u][v]=g[v][u]=0;
        fill(vi,vi+n,0);
        dfs(0);
        int f=1;
        for (int j=0;j<n;j++)
            f&=vi[j];
        ans+=1-f;
        g[u][v]=g[v][u]=1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String str[] = new String[100];
		for(int i = 0; i < n; i++) {
			str[i] = scan.next();
		}
		int ans = 0;
		String str1 = "Y";
		for(int i = 0; i < n; i++) {
			if(str[i].equals(str1)) {
				ans = 1;
			}
		}
		
		if(ans == 1) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
	}
}

Measured memory_bytes: 21844
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<=9&&b<=9)
    {
        printf("%d\n",a*b);

    }
    else if(a>=10||b>=10)
    {
        printf("-1\n");

    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define db double
#define RE register
#define ll long long
#define P 1000000007
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define pb(x) push_back(x)
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define getc(a) scanf("%s",a+1)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=51;
ll link[N],tot,n,m,s,vis[N][2510],C[N],D[N];
ll dis[N];
struct edge{ll y,next,A,B;}a[N<<2];
struct wy
{
	ll x,v,s;
	ll friend operator < (wy a,wy b) {return a.v>b.v;}
};
priority_queue<wy>q;
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline void add(int x,int y,int v,int c)
{
	a[++tot].y=y;a[tot].A=v;a[tot].B=c;a[tot].next=link[x];link[x]=tot;
	a[++tot].y=x;a[tot].A=v;a[tot].B=c;a[tot].next=link[y];link[y]=tot;
}

inline void dij()
{
	q.push((wy){1,0,min(s,2500ll)}); 
	int cnt=1;dis[1]=1;
	while(!q.empty())
	{
		wy c=q.top();q.pop();
		if(dis[c.x]==0) dis[c.x]=c.v,cnt++;
		if(cnt>=n) return;
		if(vis[c.x][c.s]) continue;
		vis[c.x][c.s]=1;	
		if(c.s<2500) q.push((wy){c.x,c.v+D[c.x],min(c.s+C[c.x],2500ll)});
		go(c.x) if(c.s>=a[i].A) q.push((wy){y,c.v+a[i].B,c.s-a[i].A});
	}
}

int main()
{
//	freopen("1.in","r",stdin);
	get(n);get(m);get(s);
	rep(i,1,m)
	{
		int get(x),get(y),get(v),get(c);
		add(x,y,v,c);
	} 
	rep(i,1,n) get(C[i]),get(D[i]);
	dij();
	rep(i,2,n) putl(dis[i]);
	return 0; 
}





Measured memory_bytes: 10364
import java.util.Scanner;

class Main {

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

			double[] p = new double[4];

			for (int i=0; i<n; i++) {
				x[i] = sc.nextDouble();
			}

			for (int i=0; i<n; i++) {
				y[i] = sc.nextDouble();
			}

			double max = 0;
			
			for (int i=0; i<n; i++) {
				p[0] += Math.abs(x[i]-y[i]);  //p1
				p[1] += Math.pow(Math.abs(x[i]-y[i]),2);  //p2
				p[2] += Math.pow(Math.abs(x[i]-y[i]),3);  //p3
				max = Math.max(max,Math.abs(x[i]-y[i]));
			}
			p[1] = Math.sqrt(p[1]);
			p[2] = Math.cbrt(p[2]);
			p[3] = max;


			for (int i=0; i<4; i++) System.out.printf("%.8f\n", p[i]);
		}
	}
}



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

int main() {
  int h, w;
  cin >> h >> w;
  rep(j, w+2) cout << "#";
  cout << endl;
  rep(i, h) {
    string a;
    cin >> a;
    cout << "#" << a << "#" << endl;
  }
  rep(j, w+2) cout << "#";
  cout << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N; cin >> N;
    vector<ll> A(N); REP(i,N) cin >> A[i];

    vector<ll> ans(N,0);
    REP(i,N){
        if(i%2) ans[0] -= A[i];
        else ans[0] += A[i];
    }
    ans[0] /= 2;

    REP(i,N-1){
        ans[i+1] = A[i]-ans[i];
    }

    REP(i,N) cout << 2*ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i + 100*j + 50*k == x:
        count += 1
print(count)

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

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  long long kotae=a*x+b*y;
  for(int i=1;i<=max(x,y);i++){
    int a_mai=max(x-i,0);
    int b_mai=max(y-i,0);
    long long tmp=a*a_mai+b*b_mai+c*2*i;
    if(kotae>tmp)kotae=tmp;
    else break;
  }
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

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

ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return a/g*b;
}

int main(){
  int n; cin >> n;
  vector<int> d1(n),d2(n);

  int count = 0;
  int ans = -1;
  rep(i,n){
    cin >> d1.at(i) >> d2.at(i);
    if(d1.at(i)==d2.at(i)) count++;
    else count = 0;

    ans = max(ans,count);
  }

  if(ans>=3) puts("Yes");
  else puts("No");
}


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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve(int &test) {
	int d, t, s;
	cin >> d >> t >> s;
	if(t*s >= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

   
    
  
    int test = 1;
    // cin >> test;

    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= test; ++i){
        solve(i); 
    }

    cerr << time(start);
    return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A,B,C,D;
	scan(N);scan(A);scan(B);scan(C);scan(D);
	double centerbase=(double)(D+C)/2;
	double widthbase=(double)(D-C)/2;
	double width=widthbase*(N-1);
	int nearest=(int)((B-A+eps)/centerbase);
	//printf("base:%f width:%f nearest:%d\n",centerbase,width,nearest);
	/*rep(i,N){
		printf("%f %f\n",centerbase*i-width,centerbase*i+width);
	}*/
	int sa=B-A;
	if((ll)(N-1)*D<abs(sa)){
		prin("NO");
	}
	else{
		if((N-1)%2==nearest%2){
			double base1=centerbase*nearest,base2=centerbase*(nearest+2);
			if((base1-width-eps<=sa&&sa<=base1+width+eps)||(base2-width-eps<=sa&&sa<=base2+width+eps)){
				prin("YES");
			}
			else{
				prin("NO");
			}
		}
		else{
			double base1=centerbase*(nearest-1),base2=centerbase*(nearest+1);
			if((base1-width-eps<=sa&&sa<=base1+width+eps)||(base2-width-eps<=sa&&sa<=base2+width+eps)){
				prin("YES");
			}
			else{
				prin("NO");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
H, W, K = map(int, input().split())
C = [input() for _ in range(H)]

c = [[] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if C[i][j] == ".":
            c[i].append(0)
        elif C[i][j] == "#":
            c[i].append(1)


sw = []
for i in range(H):
    sw.append(sum(c[i]))

sh = []
for i in range(W):
    s = 0
    for j in range(H):
        s += c[j][i]
    sh.append(s)

S = sum(sw)
ans = 0

for i in range(2 ** H):
    Y = []
    ds = 0
    for h in range(H):
        if (i >> h) & 1:
            ds += sw[h]
            Y.append(h)

    for j in range(2 ** W):
        s = S - ds
        X = []
        for w in range(W):
            if (j >> w) & 1:
                s -= sh[w]
                X.append(w)
        
        for y in Y:
            for x in X:
                s += c[y][x]
        
        if s == K:
            ans += 1

print(ans)




Measured memory_bytes: 9168
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  string n;cin >> n;
  int ans = 0;
  for(int i=0;i<n.size();i++){
    ans += (n[i]-'0');
  }
  cout << (stoi(n)%ans==0?"Yes":"No") << endl;
}


Measured memory_bytes: 256
N, M, R = map(int, input().split())
R_LIST = list(map(int, input().split()))
ABC = []
for _ in range(M):
    a,b,c = map(int, input().split())
    ABC.append((a,b,c))
    

    
edges = ABC[:]


def warshall_floyd(d, n):
    # d: グラフ二次元リスト
    # n: 頂点数 (0始まり)
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]
                
    return d

# グラフ無効グラフ化
graph = [[float("inf") for i in range(N+1)] for i in range(N+1)] 
for x,y,z in edges:
    graph[x][y] = z
    graph[y][x] = z
for i in range(N+1):
    graph[i][i] = 0 #自身のところに行くコストは０

#最短経路
shortest =  warshall_floyd(graph, N+1)
    
# 順列全探索
import sys
INT_MAX = sys.maxsize # 9223372036854775807
ans = INT_MAX

import queue

rest = set(R_LIST[:])

import copy  
def dfs(cost,pre,rest):
    if len(rest) == 0:
        return cost
    
    ret = INT_MAX
    for r in rest:
        if pre == None:
            next_cost = 0
        else:
            next_cost = cost + shortest[pre][r]
        next_rest = copy.copy(rest)
        next_rest.remove(r)
        
        tmp_ret = dfs(next_cost, r, next_rest)
        ret = min(ret, tmp_ret)
        
    return ret
        
    

print(dfs(0, None, rest))
            
      
        
        



Measured memory_bytes: 8760
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
import sys
from collections import deque, defaultdict, Counter; from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20; INF = float("INF"); ans = 0; tmp = 0; ansli = []; tmpli = []; candili = []
eps = 1.0 / 10 ** 10; mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]; ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]; ddn9 = ddn + [(0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

n, m = wi()
a = hi(m)
aset = set(a)
dp = [0] * (n + 1)
dp[0] = 1
if 1 not in aset:
    dp[1] = 1

for i in range(2, n + 1):
    if i - 1 not in aset:
        if i - 2 not in aset:
            dp[i] = dp[i - 1] + dp[i - 2]
        else:
            dp[i] = dp[i - 1]
    else:
        if i - 2 not in aset:
            dp[i] = dp[i - 2]
        else:
            pass
    dp[i] %= mod
print(dp[n] % mod)

Measured memory_bytes: 15716
//
//  main.cpp
//  task1
//
//  Created by Aly Hesham on 05/08/2018.
//  Copyright © 2018 Aly Hesham. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 3;

int main() {
    
    
    int a[N], n;
  
        n = 3;
        for(int i = 0 ; i <n ; ++ i)
            
            cin>>a[i];
            sort(a, a + 3);
        int ans = abs(a[1] - a[0]) + abs(a[2] - a[1]);
        do {
            ans = min(ans, abs(a[1] - a[0]) + abs(a[2] - a[1]));
        } while(next_permutation(a , a +  3));
    
    
    cout << ans << endl;
    
    return 0;
}



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

int main(){
	int a, b, c, d, n;
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &n);
	b = min(b, a << 1);
	c = min(c, b << 1);
	d = min(d, c << 1);
	printf("%lld\n", (ll)(n >> 1) * d + (n & 1) * c);
}

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

long long int factorial(long long int x){
    if(x==0) return 1;
    else return factorial(x-1)*x;
}
int main(){
    
    long long int n,p;
    cin >> n >> p;
    int a;
    int even=0;
    long long int ans=1;
    for(int i=0; i<n; i++){
        cin >> a;
        if(a%2==1) even++;
        if(i!=0) ans*=2;
    }
    
    if(even==0 && p==1) ans=0;
    if(even==0 && p==0) ans*=2;

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<string.h>

#define N 1007

char x[N],y[N];
int c[N][N];

int L[N];

int m,n;

int LCSlength(char *,char *);

int  main(){
  int i,j,n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",x+1);
    scanf("%s",y+1);
    L[i] =  LCSlength(x,y);
  }
  for(i=0;i<n;i++){
     printf("%d\n",L[i]);
  }
  return 0;
}



int LCSlength(char *x,char *y){
  int m,n;
  int i,j;
  int max=0;

  m = strlen(x+1);
  n = strlen(y+1);
  
  for(i=0;i<=m;i++) c[i][0] = 0;
  for(j=0;j<=n;j++) c[0][j] = 0;

  for(i=1;i<=m;i++){
    for(j=1;j<=n;j++){
      
      if(x[i] == y[j]){
	c[i][j] = c[i-1][j-1] + 1;
      }

      else if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }

      else c[i][j] = c[i][j-1];
      if(max < c[i][j]) max = c[i][j];      
    }
  }

  return max;

}


Measured memory_bytes: 5672
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int D = Integer.parseInt(tokens[1]);
		int[][] X = new int[N][D];
		for (int i = 0; i < N; ++i) {
			tokens = in.readLine().split(" ");
			for (int j = 0; j < D; ++j) {
				X[i][j] = Integer.parseInt(tokens[j]);
			}
		}
		int count = 0;
		for (int i = 0; i + 1 < N; ++i) {
			for (int j = i + 1; j < N; ++j) {
				if (check(X[i], X[j])) {
					++count;
				}
			}
		}
		System.out.println(count);

		in.close();
	}

	static boolean check(int[] a, int[] b) {
		double dist = 0.0;
		for (int i = 0; i < a.length; ++i) {
			dist += Math.pow(Math.abs((double) b[i] - (double) a[i]), 2.0);
		}
		dist = Math.sqrt(dist);
		return Math.floor(dist) == dist;
	}
}

Measured memory_bytes: 21204
from bisect import bisect_left
n,m = [int(i) for i in input().split()]
l = [[int(i) for i in input().split()] for _ in range(m)]
l2 = sorted(l,key = lambda x:(x[0],x[1]))
t = [[] for _ in range(n)]

for p,y in l2:
    t[p-1].append(y)
    
for i in l:
    order = bisect_left(t[i[0]-1],i[1])
    print(str(i[0]).zfill(6)+str(order+1).zfill(6))



Measured memory_bytes: 35212
#include <cstdio>
int main(){
	int x, y;
	for(int i = 0; ; i++){
		scanf("%d%d", &x, &y);
		if(x == 0 && y == 0) return 0;
		for(int j = 0; j < y; j++){
			putchar('#');
		}
		for(int k = 0; k < x-2; k++){
			printf("\n#");
			for(int j = 0; j < y-2; j++){
				putchar('.');
			}
			putchar('#');
		}
		putchar('\n');
		for(int j = 0; j < y; j++){
			putchar('#');
		}
		puts("\n");
	}
}


Measured memory_bytes: 2692
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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

typedef long long ll;

ll c[30],s[370][30];
int a[370],last[30];

unsigned seed=chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(seed);

void f(int d)
{
    ll x=0;
    memset(last,-1,sizeof(last));
    for(int i=0;i<d;i++){
        x+=s[i][a[i]];
        last[a[i]]=i;
        for(int j=0;j<26;j++){
            x-=c[j]*(ll)(i-last[j]);
        }
        printf("%lld\n",x);
    }
}

int main()
{
    auto start=chrono::high_resolution_clock::now();
    int d;
    scanf("%d",&d);
    for(int i=0;i<26;i++){
        scanf("%lld",&c[i]);
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            scanf("%lld",&s[i][j]);
        }
    }
    for(int i=0;i<d;i++){
        scanf("%d",&a[i]);
        a[i]--;
    }
    f(d);
    return 0;
}

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

using ll = long long;
using P = pair<ll,pair<ll,ll>>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define zarray(x,n) x[n+1]; rep1(i,n) {x[i]=0;} 

int main() {
    int n, m, s;
    cin >> n >> m >> s;

    int MAX_SILVER = 2500;
    if (s > MAX_SILVER) {
        s = MAX_SILVER;
    }

    map<int,vector<pair<int,pair<int,int>>>> g;
    rep0(i,m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        g[u].push_back({v,{a,b}});
        g[v].push_back({u,{a,b}});
    }

    ll C[n + 1];
    ll D[n + 1];
    rep1(i, n) {
        ll c, d;
        cin >> c >> d;
        D[i] = c;
        C[i] = d;
    }


    ll time[n+1][2501];
    rep1(i,n) { 
        rep0(j,2501) {
            time[i][j] = INT64_MAX;
        }
    }
    priority_queue<P, vector<P>, greater<P>> q;
    //cout << "searching.." << endl;

    q.push({0,{1,s}});
    time[1][s] = 0;

    while (!q.empty()) {
        auto a = q.top();
        q.pop();
        ll d = a.first;
        int here = a.second.first;
        ll s = a.second.second;
        if (time[here][s] > d) continue;

        //cout << "d:" << d << " here:" << here << " s:" << s << " as:" << D[here] << " ts:" << C[here] << endl;

        ll ns = (s + D[here]);
        if (ns <= MAX_SILVER) {
            ll new_time = d + C[here];
            if (time[here][ns] > new_time) {
                time[here][ns] = new_time;
                q.push({new_time, {here, ns}});
                //cout << "pushed add: " << here << " " << new_time << " " << ns << endl;
            }
        }

        for (auto edge : g[here]) {
            int to = edge.first;
            ll travel_cost = edge.second.first;
            ll travel_time = edge.second.second;

            ll w = d + travel_time;
            ll ns = s - travel_cost;
            //cout << "to:" << to << " c:" << travel_cost << " time:" << travel_time << " w:" << w << " ss:" << ns << endl;
            if (ns < 0) continue;

            if (w < time[to][ns]) {
                time[to][ns] = w;
                q.push({w, {to, ns}});
                //cout << "pushed travel:" << to << " " << w << " " << ns << endl;
            }
        }
    }

    for(int i=2; i<n+1; i++) {
        ll min = INT64_MAX;
        rep0(j,MAX_SILVER+1) {
            //cout << "min:" << min << " j:" << j << " t:" << time[i][j] << endl;
            if (min > time[i][j]) {
                min = time[i][j];
            }
        }
        if (min == INT64_MAX) {
            min = 0;
        }
        cout << min << endl;
    }
}


Measured memory_bytes: 7304
#include <stdio.h>

int main(void){
  int N,T;
  int c,t;
  scanf("%d%d",&N,&T);

  int min = 1001;
  for(int i = 0;i < N;i++){
    scanf("%d%d",&c,&t);
    if(t <= T){
      if(min > c){
        min = c;
      }
    }
  }

  if(min == 1001){
    printf("TLE\n");
  }else{
    printf("%d\n",min);
  }
  return 0;
}

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

int main(){

	long long x;
	cin >> x;
	
	long long res = 0;
	
	while (x >= 500){
		res += 1000;
		x -= 500;
	}
	
	while (x >= 5){
		res += 5;
		x -= 5;
	}
	
	cout << res << endl;







	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	ll t,t1,c,i,j,k,l,a,n,d;
		cin>>n>>t;
		k=0;
		for(i=0;i<n;i++)
		{
			cin>>c>>t1;
			if(t1<=t)
			{
				if(k==0)
					k=c;
				else
				{
					if(c<k)
						k=c;
				}
			}
		}
		if(k!=0)
			cout<<k<<"\n";
		else
			cout<<"TLE";
		return 0;
}
	

Measured memory_bytes: 3560
n,k = map(int,input().split())
lis = list(map(int,input().split()))
def shinchan(before,after):
    an = 1
    key = 1
    for i in range(k):
        if key and abs(lis[i]) == before:
            an *= after
            key = 0
        else:
            an *= abs(lis[i])
        an %= 10 ** 9 + 7
    return an
plus = 0
minus = 0
zero = 0
p,m = [],[]
for num in lis:
    if num > 0:
        plus += 1
        p.append(num)
    elif num < 0:
        minus += 1
        m.append(num)
    else:
        zero += 1
p.sort(reverse=True)
m.sort(key = lambda x:abs(x),reverse=True)
lis.sort(key=lambda x:abs(x),reverse=True)
zissaiplus = 0
zissaiminus = 0
zissaizero = 0
for i in range(k):
    if lis[i] > 0:
        zissaiplus += 1
    elif lis[i] < 0:
        zissaiminus += 1
    else:
        zissaizero += 1
if zissaizero > 0:
    print(0)
    exit()
if zissaiminus % 2 == 0:
    ans = shinchan(-1,-1)
    print(ans)
    exit()
else:
    key1,key2 = 0,0
    if zissaiminus > 0 and plus-zissaiplus > 0:
        be1 = -m[zissaiminus-1]
        af1 = p[zissaiplus]
        key1 = 1
    if zissaiplus > 0 and minus-zissaiminus > 0:
        be2 = p[zissaiplus-1]
        af2 = -m[zissaiminus]
        key2 = 1
    if key1 == 1 and key2 == 1:
        if be2 * af1 >= be1 * af2:
            ans = shinchan(be1,af1)
        else:
            ans = shinchan(be2,af2)
    elif key1 or key2:
        if key1:
            ans = shinchan(be1,af1)
        else:
            ans = shinchan(be2,af2)
    else:
        if zero > 0:
            print(0)
            exit()
        lis.sort(key=lambda x:abs(x))
        ans = -shinchan(0,0)+10 ** 9 + 7
    print(ans)

Measured memory_bytes: 31632
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)


def solve():
    V, E = map(int, input().split())
    edges = [[INF] * V for _ in range(V)]

    for _ in range(E):
        s, t, d = map(int, input().split())
        edges[s][t] = d

    dp = [[INF] * (V + 1) for _ in range(2 ** V + 1)]
    dp[0][0] = 0
    for i in range(2 ** V):
        for j in range(V):
            for k in range(V):
                if (i >> k) & 1 == 0:
                    dp[i | (1 << k)][k] = min(dp[i | (1 << k)][k], dp[i][j] + edges[j][k])
    print(dp[2 ** V - 1][0] if dp[2 ** V - 1][0] != INF else -1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX 100000
vector<int> G[MAX];
int id[MAX],pa[MAX],dp[MAX],used[MAX];
void dfs(int v,int d){
  dp[v]=d;
  for(int i=0;i<(int)G[v].size();i++){
    dfs(G[v][i],d+1);
    pa[G[v][i]]=v;
  }
}
signed main(){
  int n;
  cin>>n;
  for(int i=0,k;i<n;i++){
    cin>>id[i]>>k;
    G[id[i]].resize(k);
    for(int j=0;j<k;j++){
      cin>>G[id[i]][j];
      used[G[id[i]][j]]=1;
    }
  }
  memset(pa,-1,sizeof(pa));
  for(int i=0;i<n;i++){
    if(!used[i]) dfs(i,0);
  }
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<pa[i]<<", depth = "<<dp[i];
    if(pa[i]<0) cout<<", root, [";
    else if(!G[i].size()) cout<<", leaf, [";
    else cout<<", internal node, [";
    for(int j=0;j<(int)G[i].size();j++){
      if(j) cout<<", ";
      cout<<G[i][j];
    }
    cout<<"]"<<endl;
  }
  return 0;
}



Measured memory_bytes: 9488
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);



int main() {
	//IOS
	int n,q;
	string s;
	cin >> n >> s >> q;
	
	set<int> st[30];
	rep(i,n) st[s[i]-'a'].insert(i+1);
	rep(i,26) st[i].insert(INF);
	rep(i,q){
		int x;
		cin >> x;
		if(x == 1){
			int iq;
			char c;
			cin >> iq >> c;
			rep(j,26) st[j].erase(iq);
			st[c-'a'].insert(iq);
		}else{
			int l,r,cnt = 0;
			cin >> l >> r;
			rep(j,26) if(*st[j].lower_bound(l) <= r) cnt++;
			cout << cnt << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 24196
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val s = next()
    val ss = mutableMapOf<Char, Char>()

    for (i in 0 until s.length) {
        if (ss[s[i]] == null) {
            ss[s[i]] = s[i]
        } else {
            println("no")
            return
        }
    }

    println("yes")
}

fun next() = readLine()!!

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 35828
import math
N = int(input())
coordinates = []
total_distance = 0
for i in range(N):
    x,y = map(int,input().split())
    coordinates.append([x,y])
    
for j in range(N):
    start = coordinates[j]
    for k in range(N):
        if k == j:
            continue
        else:
            end = coordinates[k]
            distance = math.sqrt((end[0]-start[0])**2+(end[1]-start[1])**2)
            total_distance += distance
tmp = 2            
for l in range(2,N):
     tmp *=l
ans = tmp*total_distance/(2*math.factorial(N))
print(ans)

Measured memory_bytes: 3064
#!/usr/bin/env python

def main():
    X, Y, Z = map(int, input().split(" "))

    max_num = 0
    for i in range(100000):
        if Y * i + Z * (i + 1) <= X:
            max_num = i
        else:
            break
    print(max_num)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int beki(int a, int n)
{
    if(n == 0){
        return 1;
    }
    int ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * a;
    }
    return ans;
}

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

    int N; cin >> N;
    vel dp(100005);//dp[i] = x はi円引き出す操作の最小値がx回であること


    dp[0] = 0;
    rep1(i, N+1) {
        dp[i] = dp[i - 1] + 1;//一円が最小の時
        rep1(j,8) {
            if(i - beki(6, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(6,j)] + 1);//6のべき乗円が最小の時
            }
            if(i - beki(9, j) >= 0) {
                dp[i] = min(dp[i], dp[i - beki(9, j)] + 1);//9のべき乗円が最小の時
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  int N,C; cin >> N >> C;
  vvi D(C,vi(C));
  rep(i, C) rep(j, C) cin >> D[i][j];

  vvi c(N, vi(N));
  rep(i,N) rep(j,N){
    cin >> c[i][j];
    c[i][j]--;
  }

  ll ans = INF;
  vector<map<int,int>> G(3);
  rep(i,N) rep(j,N) {
    G[(i+j)%3][c[i][j]]++;
  }


  rep(i,C) rep(j,C) {
    if(i == j) continue;
    rep(k,C) {
      if(i == k || j == k) continue;
      // 色をi,j,kの三色で統一した場合
      vi v = {i,j,k};
      ll sum = 0;
      rep(q,3) {
        for(auto g : G[q]) {
          sum += D[g.first][v[q]] * g.second;
        }
      }
      
      chmin(ans,sum);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1280
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=998244353 ;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,K,i;cin>>n>>K;
	if((n+1)/2<K){cout<<-1<<endl;return 0;}
	for(i=0;i<n;i++){
		if(i%2==0){cout<<i/2+K<<' '<<i/2+n+n/2+K<<' '<<i+n+n+K<<endl;}
		else{cout<<i/2+(n+1)/2+K<<' '<<i/2+n+K<<' '<<i+n+n+K<<endl;}
	}
	return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.math;

void main()
{
  for (;;) {
    auto n = readln.chomp.to!size_t;
    if (n == 0) break;

    auto si = readln.split.map!(to!real).array;
    auto m = si.sum / n;
    auto sigma = si.map!(s => (s - m) ^^ 2).sum / n;
    writefln("%.5f", sqrt(sigma));
  }
}

Measured memory_bytes: 2500
#include<stdio.h>
#include<string.h>
#include<math.h>

void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}





int main(void){
   int A,B,num;
   scanf("%d %d",&A,&B);
   if((B-A)%2!=0){
      printf("IMPOSSIBLE");
   }else{
   if(B>A){
      num=(B-A)/2;
      printf("%d",num+A);
   }else{
      num=(A-B)/2;
      printf("%d",num+B);
   }
   }
   return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    double R;
    cin >> R;
    cout << M_PI * 2.0 * R << endl;
}


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

int main() {
  int N;
  cin >> N;
  if(N%10==2) {
    cout << "hon" << endl;
  }
  if(N%10==4 ) {
    cout << "hon" << endl;
  }
    if(N%10==5 ) {
    cout << "hon" << endl;
  }
    if(N%10==7 ) {
    cout << "hon" << endl;
  }
    if(N%10==9 ) {
    cout << "hon" << endl;
  }
    if(N%10==0 ) {
    cout << "pon" << endl;
  }
  if(N%10==1 ) {
    cout << "pon" << endl;
  }
  if(N%10==6 ) {
    cout << "pon" << endl;
  }
  if(N%10==8 ) {
    cout << "pon" << endl;
  }
  if(N%10==3 ) {
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
#include <map>
using namespace std;

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

typedef long long ll;

int gcd(int a, int b)
{
    if(a < b) swap(a, b);

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

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

    ll ans = a * b /gcd(a, b);
    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int fg=1;
	int qs=0,qx=0,qy=0;
	for(int i=1;i<=n;i++){
		int s,x,y;
		cin >> s >> x >> y;
		if(s-qs==abs(x-qx)+abs(y-qy)||(s-qs-(abs(x-qx)+abs(y-qy)))%2==0&&s-qs>(abs(x-qx)+abs(y-qy))){
			
		}
		else{
			fg=0;
		}
		qs=s;qx=x;qy=y;
	}
	if(fg)
        printf("Yes\n");
	else
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

while True:
    a.sort()
    for i in range(1,len(a)):
        a[i] = a[i] % a[0]
    
    if sum(a[1:]) == 0:
        print(a[0])
        exit()

    b = []
    for i in range(len(a)):
        if a[i] != 0:
            b.append(a[i])
    a = b

Measured memory_bytes: 14380
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	ll n;cin>>n;
	map<string,ll> m;
	for(ll i=0;i<n;i++){
		string s;cin>>s;
		sort(all(s));
		m[s]++;
	}
	ll ans=0;
	for(auto u:m){
		ans+=u.S*(u.S-1)/2;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
int tt[500];
int main() {
    string s;
    while(cin >> s) {
        int v = 0;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == '0') tt[v++] = 0;
            if(s[i] == '1') tt[v++] = 1;
            if(s[i] == 'B' && v > 0) v--;
        }
        for(int i = 0; i < v; i++)
            printf("%d", tt[i]);
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256