akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
memo = [[[-1]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

def dp(a, b, c):
    if a == b == c == 0: return 0
    if memo[a][b][c] != -1:
        return memo[a][b][c]
    
    res = N
    if a > 0: res += a*dp(a-1, b, c)
    if b > 0: res += b*dp(a+1, b-1, c)
    if c > 0: res += c*dp(a, b+1, c-1)
    res /= a+b+c
    
    memo[a][b][c] = res
    return res

def main():
    A = list(map(int, input().split()))
    
    count = Counter(A)
    for i in range(1, 4):
        if not i in count: count[i] = 0
    x, y, z = count[1], count[2], count[3]

    
    ans = dp(x, y, z)
    
    print(ans)
        

    
if __name__ == "__main__":
    main()



Measured memory_bytes: 401004
#include <stdio.h>
int main(void){
    int n,m,i,j,h[100];
    int mu,md;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        mu=0;md=0;
        scanf("%d",&m);
        for(j=0;j<m;j++){
            scanf("%d",&h[j]);
        }
        for(j=1;j<m;j++){
            if(h[j]-h[j-1]>mu){
                mu=h[j]-h[j-1];
            }else if(h[j]-h[j-1]<-1*md){
                md=h[j-1]-h[j];
            }
        }
        printf("%d %d\n",mu,md);
    }
    return 0;
}

Measured memory_bytes: 596
def bmi(a):
	a=map(int,a.split())
	return a[0], abs(22-a[2]/((a[1]/100.0)**2))
	
while 1:
	n=input()
	if n==0:break
	print sorted(sorted([bmi(raw_input()) for i in range(n)]),key=lambda x:x[1])[0][0]

Measured memory_bytes: 4380
from sys import stdin
H, W, A, B = [int(x) for x in stdin.readline().rstrip().split()]
if (W >= (2*A+1)) and (H >= (2*B+1)):
    for i in range(B):
        print(A*"0"+"1"*(W-A))
    for j in range(H-B):
        print(A*"1"+"0"*(W-A))
    
else:
    print("No")

Measured memory_bytes: 3956
import math
a,b,h,m=map(int,input().split())
d=h*60+m
a2=d/720
b2=m/60
d2=((a2-b2)**2)**0.5


x=360*d2
cos=math.cos(math.radians(x))
c=(a**2+b**2-2*a*b*cos)**0.5
print(c)

Measured memory_bytes: 9508
#include <iostream>
#include <unordered_map>
using namespace std;
typedef long long int LLI;
int main()
{
	int n, ans = 0, tmp;
	cin >> n;
	unordered_map <int, int> arr;
	for(int i = 0; i < n; i++)
	{
		cin >> tmp;
		arr[tmp]++;
		if( arr[tmp] % 2 == 1 )
			ans++;
		else
			ans--;
	}
	cout << ans;
}

Measured memory_bytes: 7296
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

from math import sqrt
N = int(input())
a = make_divisors(N)

l = len(a)
if (l%2 == 0):
    print(a[-1] + a[-2] - 2)
else:
    print(a[-1]*2 - 2)

Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int root[100000];
int getRoot(int v){ return root[v] == -1 ? v : root[v] = getRoot(root[v]); }

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<vector<int>> l(M);
		for(int i=0;i<N;i++){
			int K; cin >> K;
			for(int j=0;j<K;j++){
				int L; cin >> L;
				l[L-1].push_back(i);
			}
		}
		memset(root, -1, sizeof(root));
		int c = N;
		for(int i=0;i<M;i++){
			for(int j=0;j+1<l[i].size();j++){
				int p = getRoot(l[i][j]);
				int q = getRoot(l[i][j+1]);
				if(p != q){
					root[q] = p;
					--c;
				}
			}
		}
		cout << (c == 1 ? "YES" : "NO") << endl;
	}
}


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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define fst first
#define snd second
#define FIN ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

typedef long long ll;

int main() {
  int n, m, x; cin >> n >> m >> x;
  int c[n];
  int a[n][m];
  fore(i, 0, n) {
    cin >> c[i];
    fore(j, 0, m) cin >> a[i][j];
  }
  int res = 1e9;
  fore(i, 0, 1<<n) {
    int cost = 0;
    int levels[m]; fore(k, 0, m) levels[k] = 0;
    fore(j, 0, n) if((1<<j) & i) {
      cost += c[j];
      fore(k, 0, m) levels[k] += a[j][k];
    }
    // cout << cost << endl;
    bool f = true;
    fore(k, 0, m) f = f && (levels[k] >= x);
    if(f) res = min(res, cost);
  }
  if(res == 1e9) cout << -1 << endl;
  else cout << res << endl;
  return 0;
}

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

const int MAXN=1<<18;

int n;
vector<int> e[MAXN];
int cnt[MAXN];
vector<int> vct;
int frst;

void dfs(int v, int pr){
	cnt[v] = 1;
	vct.push_back(v);
	
	if(v==n-1) frst = vct[((int)vct.size()+1)/2];
	for(int i=0; i<e[v].size(); i++){
		if(e[v][i]==pr) continue;
		dfs(e[v][i], v);
		cnt[v] += cnt[e[v][i]];
	}
	vct.pop_back();
}

int main(){
	while(scanf("%d", &n)==1){
		for(int i=0; i<n; i++) e[i].clear();
		for(int i=0; i<n-1; i++){
			int u, v;
			scanf("%d%d", &u, &v);
			--u;--v;
			e[u].push_back(v);
			e[v].push_back(u);
		}
		frst = -1;
		dfs(0, 0);
		bool win=cnt[frst]*2<n;
		string ans=win?"Fennec":"Snuke";
		cout << ans;
		return 0;
	}
}

Measured memory_bytes: 15096
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
        t: String,
    }

    let mut cnt = 0;
    let v: Vec<char> = t.chars().collect();

    for (i, c) in s.chars().enumerate() {
        if c != v[i] {
            cnt += 1;
        }
    }

    println!("{}", cnt)
}


Measured memory_bytes: 3620
#! usr/bin/env python
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))

    idx, t = 0, 0
    while idx < n:
        cnt = 1
        while idx < n-1 and a[idx] == a[idx+1]:
            cnt += 1
            idx += 1
        t += cnt // 2
        idx += 1

    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <stdio.h>
#include<math.h>
int main()
{
 long int x,y,z,i,j,sum,temp;

scanf("%ld%ld%ld",&x,&y,&z);
if(x>y && x>z)
{
    printf("%ld",y+z);

}else{
    if(z>x && z>y)
    {
        printf("%ld",y+x);
    }else{
        printf("%ld",x+z);
    }
}


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	UnionFind Uni(n);
	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		Uni.connect(x, y);
	}
	set<int> st;
	rep(i, n) {
		st.insert(Uni.root(i));
	}
	cout << st.size() << endl;
	return 0;
}

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

int n, a[200005];

inline bool check(const int &k) {
  if ((a[n - 1] <= k && a[n] <= k) || (a[n] <= k && a[n + 1] <= k)) return 1;
  if ((a[n - 1] > k && a[n] > k) || (a[n] > k && a[n + 1] > k)) return 0;
  for (int i = 1; i < n - 1; i++) {
    if ((a[n + i] <= k && a[n + i + 1] <= k) ||
        (a[n - i] <= k && a[n - i - 1] <= k))
      return 1;
    if ((a[n + i] > k && a[n + i + 1] > k) ||
        (a[n - i] > k && a[n - i - 1] > k))
      return 0;
  }
  return a[1] <= k;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n << 1; i++) scanf("%d", a + i);
  int l = 1, r = (n << 1) - 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d", l);
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;

int main(){
    int N;
    cin >> N;
    int sum=0;
    int W[100];
    for(int i=0; i<N; i++){
        cin >> W[i];
        sum += W[i];
    }
    
    int sum2=0;
    int ans = 1000000;
    for(int i=0; i<N-1; i++){
        sum2+=W[i];
        sum-=W[i];
        ans = min(ans, abs(sum-sum2));
    }
    
    cout<<ans<<endl;
    return 0;
}






Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    cout.precision(9);
    long double l;
    in(l);
    out(pow(l/3.0L, 3.0L));

	return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <vector>
#define N 100005
using namespace std;
int n, a, b, c, x[N], y[N];
vector<int> v[N];

void f(int p, int q) {
	if(x[p]!=0) return;
	x[p] = q;
	for(int i=0; i<v[p].size(); i++) f(v[p][i], q+1);
}

void g(int p, int q) {
	if(y[p]!=0) return;
	y[p] = q;
	for(int i=0; i<v[p].size(); i++) g(v[p][i], q+1);
}

int main() {
	int i;
	scanf("%d", &n);
	for(i=0; i<n-1; i++) {
		scanf("%d%d", &a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	f(1, 1);
	g(n, 1);
	for(i=1; i<=n; i++) x[i]<=y[i] ? c++ : c--;
	puts(c>0 ? "Fennec":"Snuke");
	return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
    int n,m,i,p=1,pen=0,ans=0,x,y=0;
    cin>>n>>m;
    vector<bool>ac(n);
    vector<int>cnt(n);
    for(i=1;i<=m;i++)
    {
        int dex;
        string s;
        cin>>dex>>s;
        dex--;
        if(ac[dex])
            continue;
        if(s=="AC")
        {
            ac[dex]=true;
            pen+=cnt[dex];
            ans++;
        }
        else
            cnt[dex]++;
        
    }
    cout<<ans<<" "<<pen<<"\n";
    return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){	
	long long a, b, k;
	cin >> a >> b >> k;
	if(a <= k){
		k -= a;
		a = 0;
	}
	else{
		a -= k;
		k = 0;
	}
	if(b <= k){
		k -= b;
		b = 0;
	}
	else{
		b -= k;
		k = 0;	
	}
	cout << a << " " << b;
	return 0;
}

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

int main() {
    int i, n, tmp;
    long long mi = pow(10, 10), maxdiff = -1 * pow(10, 10);

    cin >> n;
    for (i=0; i<n; i++) {
        cin >> tmp;
        if (maxdiff < tmp - mi) {
            maxdiff = tmp - mi;
        }
        if (tmp < mi) {
            mi = tmp;
        }
    }
    cout << maxdiff << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
typedef long long ll;

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

    vector<int> x;
    x.resize(m);
    for(int i=0; i<m; i++) cin >> x[i];

    sort(x.begin(),x.end());

    int sum(0);
    if(n<m){
        vector<int> diff;
        diff.resize(m-1);
        for(int i=0; i<m-1; i++){
            diff[i] = x[i+1]-x[i];
        }
        sort(diff.begin(), diff.end(), greater<int>());

        sum += x[m-1]-x[0];
        for(int i=0; i<n-1; i++){
            sum -= diff[i];
        }
    }

    cout << sum << endl;

    return 0;
}

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

int main()
{
    vector<int> x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << x[k - 1] << endl;
}

Measured memory_bytes: 764
#include<cstdio>
#include<iostream>
#include<algorithm>
#define RI register int
#define CI const int&
using namespace std;
const int N=100005,INF=1e9;
struct interval
{
	int l,r;
	friend inline bool operator < (const interval& A,const interval& B)
	{
		return A.l<B.l;
	}
}a[N],b[N]; int n,mxl=-1,mir=INF,mlen,tot,p,q,sufr[N],ans;
int main()
{
	RI i; for (scanf("%d",&n),i=1;i<=n;++i)
	{
		scanf("%d%d",&a[i].l,&a[i].r);
		if (a[i].l>mxl) mxl=a[i].l,p=i; if (a[i].r<mir) mir=a[i].r,q=i;
	}
	if (n==2) return printf("%d",a[1].r-a[1].l+1+a[2].r-a[2].l+1),0;
	for (i=1;i<=n;++i) if (i!=p&&i!=q) b[++tot]=a[i],mlen=max(mlen,a[i].r-a[i].l+1);
	for (sort(b+1,b+tot+1),i=tot-1,sufr[tot]=b[tot].r;i>0;--i) sufr[i]=min(sufr[i+1],b[i].r);
	for (ans=mlen+max(mir-mxl+1,0),i=1;i<tot;++i)
	ans=max(ans,max(mir-b[i].l+1,0)+max(sufr[i+1]-mxl+1,0));
	ans=max(ans,a[q].r-a[q].l+1+max(sufr[1]-mxl+1,0));
	ans=max(ans,max(mir-b[tot].l+1,0)+a[p].r-a[p].l+1);
	return printf("%d",ans),0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        if (s[0] == "H") {
            if (s[1] == "H")
            {
                Console.WriteLine("H");
            }
            else if (s[1] == "D")
            {
                Console.WriteLine("D");
            }
        }
        else if (s[0] == "D")
        {
            if (s[1] == "H")
            {
                Console.WriteLine("D");
            }
            else if (s[1] == "D")
            {
                Console.WriteLine("H");
            }
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a>0)cout<<"Positive\n";
	else if(a<=0&&b>=0)cout<<"Zero\n";
	else
	{
		if((abs(a)+abs(b)-1)%2==0)cout<<"Positive\n";
		else cout<<"Negative\n";
	}
}

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

const int N_MAX = 15;

int shoujiki(int N, vector<vector<int>> &p, bitset<N_MAX> &bs) {
  rep1(i, N) {
    if (!bs.test(i - 1)) continue;
    rep1(j, N) {
      if (p.at(i).at(j) == -1) continue;
      if (p.at(i).at(j) != (bs.test(j - 1) ? 1 : 0)) return -1;
    }
  }

  return bs.count();
}

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

  vector<vector<int>> p(N + 1, vector<int>(N + 1, -1));

  rep1(i, N) {
    int a, x, y;
    cin >> a;
    rep(j, a) {
      cin >> x >> y;
      p.at(i).at(x) = y;
    }
  }

  int ans = 0;
  for (int i = 1; i < (1 << N); i++) {
    bitset<N_MAX> bs(i);
    int tmp = shoujiki(N, p, bs);
    if (tmp > 0) {
      ans = max(ans, tmp);
    }
  }

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


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
//#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

const ll mod = 1e9 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}



const int MAXN = 1e6 + 9;

int spf[MAXN];
map<int , int> mp;
void sieve()
{
	spf[1] = 1;
	for (int i = 2; i < MAXN; i++)
		spf[i] = i;
	for (int i = 4; i < MAXN; i += 2)
		spf[i] = 2;

	for (int i = 3; i * i < MAXN; i++) {

		if (spf[i] == i) {
			for (int j = i * i; j < MAXN; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

void getFactorization(int x)
{
	int temp;
	while (x != 1) {
		temp = spf[x];
		if (x % temp == 0) {

			mp[spf[x]]++;
			x = x / spf[x];
		}
		while (x % temp == 0)
			x = x / temp;
	}
}

bool check(int x)
{
	int temp;
	while (x != 1) {
		temp = spf[x];

		if (x % temp == 0 && mp[temp] > 1)
			return false;
		if (x && temp == 0)
			mp[temp]--;
		while (x % temp == 0)
			x = x / temp;
	}
	return true;
}

void solve() {

	int n;
	cin >> n;

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

		getFactorization(a[i]);
	}

	int g = a[0];
	bool setwise = false , pairwise = false;

	for (int i = 1 ; i < n ; i++)
		g = __gcd(g , a[i]);

	if (g == 1) setwise = true;

	bool ok = true;
	for (int i = 0; i < n - 1 ; i++) {

		ok &= check(a[i]);
	}

	if (ok) pairwise = true;

	if (pairwise)
		cout << "pairwise coprime\n";
	else if (setwise)
		cout << "setwise coprime\n";
	else cout << "not coprime\n";
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	sieve();
	int t = 1;
	//cin >> t;

	while (t--)
		solve();
	return 0;
}





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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  string s;cin>>s;
  if(s<="2019/04/30")puts("Heisei");
  else puts("TBD");
  
  return 0;
}


Measured memory_bytes: 3644
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n = int(input())
line = list(map(int,input().split()))

ans = line[0]

for i in range(1,n):
    ans = gcd(ans,line[i])

print(ans)

Measured memory_bytes: 14252
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        char arr[] = sc.next().toCharArray();
        int dp[] = new int[arr.length];
        for(int i = 1 ; i < dp.length ; i++){
            if(arr[i]=='C' && arr[i-1] == 'A'){
                dp[i] = 1;
            }
        }
        for(int i = 1; i < dp.length;i++){
            dp[i] += dp[i-1];
        }
        while(Q-->0){
            int l = sc.nextInt();
            int r = sc.nextInt();
            l--;
            r--;
            int val = dp[r] - dp[l];
            System.out.println(val);
        }
    }
}

Measured memory_bytes: 78532
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
    
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(a*n, b) << endl;

}

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

int main() {
  int K;
  string s;
  cin >> K >> s;
  size_t a = s.length();
  if(K>=a) 
    cout << s << endl;
  else {
  	cout << s.substr(0,K) << "..." << endl;
  }
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c,a;
    cin >> n >> c;
    int d[c][c],color[3][30] = {0};
    rep(i,c){
        rep(j,c){
            cin >> d[i][j];
        }
    }
    rep(i,n){
        rep(j,n){
            cin >> a;
            color[(i+j)%3][a-1]++;
        }
    }
    int ans = 1e9;
    rep(x,c){
        rep(y,c){
            rep(z,c){
                if (x == y || y == z || z == x) continue;
                int cnt = 0;
                rep(j,c) cnt += color[0][j]*d[j][x];
                rep(j,c) cnt += color[1][j]*d[j][y];
                rep(j,c) cnt += color[2][j]*d[j][z];
                chmin(ans,cnt);
            }
        }
    }
    PRINT(ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
long long a,b,c;
int main(){
	cin>>a>>b>>c;
	if(c>a+b+1){
		cout<<b+a+b+1;
	}
	else
		cout<<b+c;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		int result = (N*(N-1))/2 + (M*(M-1))/2;
		System.out.println(result);
	}
}

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

using namespace std;

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

const long long INF10=1e10+1,ID_MAX=20;
const long mod=(1e9)+7;
const long long INF18=1e18+1;

struct edge{
    int to;
    long cost;
};

void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか(O(a/b))
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁(O(log n))
int bi_max(long n){
    int m=0;
    for(m;(1<<m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入(O(log^2 n))
void bi_exs(long n){
    memset(bi_e,0,sizeof(bi_e));
    if(n<(1<<ID_MAX)){
        for(int i=0;n>0;n=(n>>1),i++)bi_e[i]=n&1;
    }
}
//x^n mod m (nが負の時は０)(O(log n))
long myPow(long x, long n, long m){
  if(n<0)return 0;
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
//m以下のn以下の分割数のmodの表生成(O(nm))d[i][j]=jのi分割
long long d[10001][10001];
void divNum(int n,int m,long long md=mod){
    rep(j,n+1){
        d[j][0]=1;
    }
    rep(j,m){
        d[0][j+1]=0;
    }
    for(int j=1;j<=n;j++){
        for(int k=1;k<=m;k++){
            if(j>k)d[j][k]=d[j-1][k];
            else d[j][k]=(d[j-1][k]+d[j][k-j])%md;
        }
    }
}
const int N_MAX=1e5+1,M_MAX=1e9+1;
int n,m;
vector<int> a;
long long div_res[N_MAX][100];
void divide(int s,int t){
    div_res[0][0]=1;
    rep(i,s){
        rep(j,t+1){
            rep(k,t-j+1){
                div_res[i+1][j+k]=(div_res[i+1][j+k]+div_res[i][j])%mod;
            }
        }
    }
}

int main(){
    int i=0,maxa=0;
    //入力
    cin>>n>>m;
    int mm=m,x=2,r;
    for(int j=2;j<=ceil(sqrt(m));j++){
        r=0;
        while(mm%j==0){
            mm=mm/j;
            r++;
        }
        if(r!=0){
            if(maxa<r)maxa=r;
            a.push_back(r);
        }
    }
    if(mm!=1)a.push_back(1);
    //処理
    long long res=1;
    divide(n,maxa);
    rep(i,a.size()){
        res=(res*div_res[n][a.at(i)])%mod;
    }
    //出力
    cout<<res<<endl;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



//メイン関数
int main()
{
	// input
	ll N, K;
	cin >> N >> K;

	vector<ll> h(N);
	vector<ll> dp(N, INFL);
	REP(i, N)cin >> h[i];

	// dp
	dp[0] = 0;
	REP(i, N - 1)
	{
		FOR(j,1, K+1)
		{
			if(i + j >= N)break;
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}
	cout << dp.back() << endl;
	cin>>N;

	return 0;
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, K, Q;
    ll k = 0;
    vector<ll> A;
    cin >> N >> K >> Q;
    A.resize(N, K);
    for(ll i = 0;i < Q;i++) {
        ll temp;
        cin >> temp;
        A[temp - 1]++;
        k++;
    }
    for(auto &i: A) {
        if(i - k > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


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

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

const int N = 1e5;
vector<pair<int, int>> g[N];
int n, m;

vector<pair<ll, int>> f(int s) {
	vector<pair<ll, int>> dis(n, pair<ll, int>(1e18, 0));
	dis[s] = {0, 1};
	priority_queue<pair<ll, int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
	pq.emplace(0, s);
	while (!pq.empty()) {
		auto x = pq.top();
		pq.pop();
		if (dis[x.S].F == x.F) {
			for (auto v : g[x.S]) {
				if (v.S + x.F < dis[v.F].F) {
					pq.emplace(v.S + x.F, v.F);
					dis[v.F] = {v.S + x.F, dis[x.S].S};
				} else if (v.S + x.F == dis[v.F].F) {
					dis[v.F].S += dis[x.S].S;
					if (dis[v.F].S >= inf) dis[v.F].S -= inf;
				}
			}
		}
	}
	return dis;
}

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

	cin >> n >> m;
	int s, t; cin >> s >> t; --s, --t;
	FOR (_, 1, m) {
		int u, v, d; cin >> u >> v >> d;
		--u, --v;
		g[u].emplace_back(v, d);
		g[v].emplace_back(u, d);
	}

	auto x = f(s), y = f(t);

	ll D = x[t].F;

	int ans = (x[t].S * 1LL * y[s].S) % inf;
	vector<int> vis(n);
	FOR (i, 0, n - 1) {
		if (x[i].F == D/2 and y[i].F == D/2 and !(D & 1LL)) {
			int val = (x[i].S * 1LL * x[i].S) % inf;
			val = (val * 1LL * y[i].S) % inf;
			val = (val * 1LL * y[i].S) % inf;
			ans = (ans - val) % inf;
			if (ans < 0) ans += inf;
			vis[i] = 1;
		}
	}

	FOR (i, 0, n - 1) if (!vis[i]) {
		for (auto j : g[i]) if (!vis[j.F]) {
			if (x[i].F + y[j.F].F + j.S == D and x[i].F <= D/2 and x[i].F + j.S >= (D+1)/2) {
				int val = (x[i].S * 1LL * y[j.F].S) % inf;
				val = (val * 1LL * x[i].S) % inf;
				val = (val * 1LL * y[j.F].S) % inf;	
				ans = (ans - val) % inf;
				if (ans < 0) ans += inf;
			}
		}
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 15060
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#define pb push_back
typedef long long ll;
using namespace std;
int N,K,L;
const int MAX_N = 200001;
vector<int> vertices(MAX_N,0);
vector<vector<int> > railways(MAX_N,vector<int>());
vector<vector<int> > roads(MAX_N,vector<int>());
void read_input(){
	scanf("%d %d %d ", &N,&K,&L);
	int a,b;

	for(int i=0;i<K;i++){
		//roads
		scanf("%d %d",&a,&b);
		roads[a].pb(b);
		roads[b].pb(a);
	}

	for(int i=0;i<L;i++){
		scanf("%d %d",&a,&b);
		railways[a].pb(b);
		railways[b].pb(a);
	}

}
int main(){
	read_input();
	vector<bool> visited(MAX_N,false);
	vector<int> road_label(MAX_N,0);
	vector<int> railway_label(MAX_N,0);
	int cur = 1;
	for(int i=1;i<=N;i++){
		if (visited[i])
			continue;
		visited[i] = true;
		vector<int> l;
		l.pb(i);
		while(!l.empty()){
			int next =l[l.size()-1];
			road_label[next] = cur;
			l.pop_back();
			vector<int> adj= roads[next];
			for(int v:adj){
				if (!visited[v]){
					visited[v] = true;
					l.pb(v);
				}
			}
		}
		cur++;

	}
	vector<bool> visited2(MAX_N,false);
	cur = 1;
	for(int i=1;i<=N;i++){
		if (visited2[i])
			continue;
		visited2[i] = true;
		vector<int> l;
		l.pb(i);
		while(!l.empty()){
			int next =l[l.size()-1];
			railway_label[next] = cur;
			l.pop_back();
			vector<int> adj= railways[next];
			for(int v:adj){
				if (!visited2[v]){
					visited2[v] = true;
					l.pb(v);
				}
			}
		}
		cur++;
	}
	map<string,int> m;
	for(int i=1;i<=N;i++){
		string s= "";
		s+=to_string(road_label[i]);
		s+=":";
		s+=to_string(railway_label[i]);
		m[s]+=1;

	}
	for(int i =1;i<=N;i++){
		string s= "";
		s+=to_string(road_label[i]);
		s+=":";
		s+=to_string(railway_label[i]);
		cout<<m[s]<<" ";
	}
	cout<<endl;


	return 0;
}

Measured memory_bytes: 37800
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    string mirror(128, ' ');
    mirror['b'] = 'd';
    mirror['d'] = 'b';
    mirror['p'] = 'q';
    mirror['q'] = 'p';

    string s;
    cin >> s;
    int n = s.size();

    bool ok = true;
    for(int i=0; i<n; ++i){
        if(mirror[s[i]] != s[n-1-i])
            ok = false;
    }
    if(ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
vector<int> ans(200000);
vector<vector<int>> ab(200000);
 
void dfs(int p, int c){
	ans[c] += ans[p];
	for(int cc:ab[c]) if(cc!=p) dfs(c,cc);
}
 
int in(){int x;scanf("%d",&x);return x;}
 
int main(){
	int n=in(), q=in();
 
	for(int i=0; i<n-1; i++){
		int a=in()-1, b=in()-1;
		ab[a].push_back(b);
		ab[b].push_back(a);
	}
 
	for(int i=0; i<q; i++){
		int p=in()-1;
		ans[p] += in();
	}
 
	for(int c:ab[0]) if(c) dfs(0,c);
	for(int i=0; i<n; i++) cout<< ans[i] <<(i<n-1?" ":"\n");
}

Measured memory_bytes: 23424
from collections import deque
S = deque(input())
Q = int(input())
inversion_flag = False
for _ in range(Q):
    query_list = list(input().split())
    if query_list[0] == "1":
        inversion_flag = not inversion_flag
        continue
    C = query_list[2]
    if query_list[1] == "2":
        if inversion_flag:
            S.appendleft(C)
        else:
            S.append(C)
    else:
        if inversion_flag:
            S.append(C)
        else:
            S.appendleft(C)

S = list(S)
if inversion_flag:
    print(*S[::-1], sep="")
else:
    print(*S, sep="")



Measured memory_bytes: 12144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;

template<int um> class UF {
public:
	vector<int> par;
	UF() { par = vector<int>(um, 0); rep(i, 0, um) par[i] = i; }
	int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
	void operator()(int x, int y)
	{
		x = operator[](x); y = operator[](y);
		if (x != y) par[x] = y;
	}
};

int N, Q;
vector<int> E[101010];
int P[101010];

char O[101010];
int V[101010];

int marked[101010];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while (cin >> N >> Q)
	{
		if (N == 0) return 0;
		
		rep(i, 0, N) E[i].clear();
		rep(i, 0, N) marked[i] = 0;

		P[0] = -1;
		rep(i, 1, N)
		{
			int p; cin >> p; p--;
			P[i] = p;
			E[i].push_back(p);
			E[p].push_back(i);
		}

		marked[0] = 1;
		rep(i, 0, Q)
		{
			cin >> O[i] >> V[i];
			V[i]--;
			if(O[i] == 'M') marked[V[i]]++;
		}
		
		UF<101010> uf;
		rep(i, 0, N) if (marked[i] == 0) uf(i, P[i]);

		//rep(i, 0, N) cout << uf[i] << endl;

		ll ans = 0;
		rrep(i, Q - 1, 0)
		{
			int v = V[i];
			if (O[i] == 'M')
			{
				marked[v]--;
				if (marked[v] == 0) uf(v, P[v]);
			}
			else
			{
				ans += (ll)uf[v] + 1LL;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 10668
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(){
    string s; cin >> s;
    int cnt1 = 0,cnt2 = 0;
    rep(i,s.size()){
        if(i%2==0){
            if(s[i] == '0') cnt1++;
        }
        else{
            if(s[i] == '1') cnt1++;
        }
    }
    rep(i,s.size()){
        if(i%2==0){
            if(s[i] == '1') cnt2++;
        }
        else{
            if(s[i] == '0') cnt2++;
        }
    }
    cout << s.size() - max(cnt1,cnt2) << endl;
}

Measured memory_bytes: 512
def f(a,x,y):
    a[y][x]='0'
    for dx,dy in [[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]:
        if 0<=x+dx<8 and 0<=y+dy<8 and a[y+dy][x+dx]=='1':f(a,x+dx,y+dy)
    return a

for i in range(int(input())):
    print('Data %d:'%(i+1));input()
    [print(*x,sep='')for x in f([list(input()) for _ in [0]*8],int(input())-1,int(input())-1)]

Measured memory_bytes: 7656
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int k,a;
  cin>>k>>s;
  a=s.size();
  if(a>k){
    for(int i=0;i<k;i++){
      cout<<s[i];
    }
    cout<<"..."<<"\n";
    return(0);
  }
  cout<<s<<"\n";
  return(0);
}


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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  ll n;
  cin >> n;

  vll a(n), b(n);
  vector<pair<ll, ll>> ab(n);

  REP(i, n) {
    cin >> a[i];
    cin >> b[i];
    ab[i] = make_pair(a[i], b[i]);
  }

  vector<pair<ll, ll>> ba = ab;

  sort(ab.begin(), ab.end(),
       [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) {
         ll lmax = lhs.first + lhs.second;
         ll rmax = rhs.first + rhs.second;
         ll ldel = llabs(lhs.first - lhs.second);
         ll rdel = llabs(rhs.first - rhs.second);
         if (lmax == rmax) {
           if (ldel == rdel) {
             return (lhs.first - lhs.second) > (rhs.first - rhs.second);
           } else {
             return ldel < rdel;
           }
         } else {
           return lmax > rmax;
         }
       });

  sort(ba.begin(), ba.end(),
       [](const pair<ll, ll> &lhs, const pair<ll, ll> &rhs) {
         ll lmax = lhs.first + lhs.second;
         ll rmax = rhs.first + rhs.second;
         ll ldel = llabs(lhs.first - lhs.second);
         ll rdel = llabs(rhs.first - rhs.second);
         if (lmax == rmax) {
           if (ldel == rdel) {
             return (lhs.first - lhs.second) < (rhs.first - rhs.second);
           } else {
             return ldel < rdel;
           }
         } else {
           return lmax > rmax;
         }
       });

  //  for (auto p : ab) {
  //    cout << p.first << " " << p.second << endl;
  //  }
  //
  //  cout << " -- " << endl;
  //
  //  for (auto p : ba) {
  //    cout << p.first << " " << p.second << endl;
  //  }

  ll ans = 0;

  REP(i, n) {
    if (i % 2 == 0)
      ans += ab[i].first;
    else
      ans -= ba[i].second;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val hList = readLine()!!.split(" ").map { it.toInt() }.reversed().toMutableList()

  for (i in 0 until n - 1) {
    if (hList[i] < hList[i + 1]) hList[i + 1]--
  }

  for (i in 0 until n - 1) {
    if (hList[i] < hList[i + 1]) {
      println("No")
      return
    }
  }

  println("Yes")
}



Measured memory_bytes: 59732
#include <bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long a,b,c;
  cin >> a >> b >> c;
  if(c>a&&c>b){
  if(4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[100];
  int n;cin >> n;
  for(int j=0;j<n;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
   
  bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
    d[l].roll('R');
    for(int j=0;j<4;j++){
      d[l].roll('N');
      if(same(d[k],d[l])) f=true;
    }
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
    d[l].roll('N');
    if(same(d[k],d[l])) f=true;
      }
       
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
    d[l].roll('N');
    if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
   
  cout << (ff?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); }
int num[1005]; 
int main()
{
	int n,k;
	cin>>n>>k;
	int i,sum=0;
	for(i=1;i<=n;i++) cin>>num[i];
	sort(num+1,num+1+n);
	for(i=1;i<=k;i++) sum+=num[i];
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3636
A, B, C, D = map(int, input().split())


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


C_num = B // C - A // C

D_num = B // D - A // D

lcm = lcm(C, D)
CD_num = B // lcm - A // lcm


# Cで割れる時
tasu = 0
if (A % C == 0):
    tasu += 1
tasu += C_num

# Dで割れる時
if (A % D == 0):
    tasu += 1
tasu += D_num

# CでもDでも割れる
hiku = 0
if (A % lcm == 0):
    hiku += 1
hiku += CD_num

print((B - A + 1) - (tasu - hiku))


Measured memory_bytes: 38384
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] min = new int[2];
		int[] max = new int[2];

		min[0] = Integer.MAX_VALUE;
		max[0] = Integer.MIN_VALUE;

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (min[0] > a[i]) {
				min[0] = a[i];
				min[1] = i;
			}
			if (max[0] < a[i]) {
				max[0] = a[i];
				max[1] = i;
			}
		}

		List<int[]> answer = new ArrayList<>();
		if (min[0] >= 0) {
			for (int i = 1; i < n; i++) {
				answer.add(new int[]{i, i + 1});
			}
		} else if (max[0] <= 0) {
			for (int i = n - 1; i > 0; i--) {
				answer.add(new int[]{i + 1, i});
			}
		} else {
			if (Math.abs(min[0]) > Math.abs(max[0])) {
				for (int i = 0; i < n; i++) {
					if (a[i] > 0) answer.add(new int[]{min[1] + 1, i + 1});
				}
				for (int i = n - 1; i > 0; i--) {
					answer.add(new int[]{i + 1, i});
				}
			} else {
				for (int i = 0; i < n; i++) {
					if (a[i] < 0) answer.add(new int[]{max[1] + 1, i + 1});
				}
				for (int i = 1; i < n; i++) {
					answer.add(new int[]{i, i + 1});
				}
			}
		}

		System.out.println(answer.size());
		for (int[] x : answer) {
			System.out.println(x[0] + " " + x[1]);
		}

	}
}


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

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

using namespace std;

int main(){
  string s;cin>>s;
  if(s.size()==1){
    cout<<"YES";return 0;
  }
  map<char, int> m;
  rep(i, s.size()) m[s[i]]++;
  vector<int> counter(3);
  rep(i,3)counter[i]=m[(char)('a'+i)];
  sort(counter.begin(), counter.end());

  if(counter[0]==0 && counter[1]>1 || 
      counter[0]==0 && counter[2]>1 ||
      counter[2]-counter[0] > 1)cout<<"NO";
  else cout<<"YES";

  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3

from sys import *
from math import *

sx, sy, tx, ty = map(int, input().split())
length = abs(tx - sx)
vertical = abs(ty - sy) 

first_go = ("R" * length) + ("U" * vertical)
first_back =  ("L" * length) + ("D" * vertical)
second_go = "L" + ("U" * (vertical + 1)) + ("R" * (length + 1)) + "D" 
second_back = "R" + ("D" * (vertical + 1)) + ("L" * (length + 1)) + "U" 
print(first_go + first_back + second_go + second_back)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807
#define array(N, t) (t*)calloc(N, sizeof(t))

int main() {
  int N;
  scanf("%d", &N);

  int * L = array(N, int);
  rep(i, N) {
    scanf("%d", L + i);
  }

  int cnt = 0;
  for (int i = 0; i < N - 2; i += 1) {
    for (int j = 1; j < N - 1; j += 1) {
      if (L[i] == L[j]) {
        continue;
      }
      if (i >= j) {
        continue;
      }
      for (int k = 2; k < N; k += 1) {
        if (L[i] == L[k]) {
          continue;
        }
        if (L[j] == L[k]) {
          continue;
        }
        if (i >= k) {
          continue;
        }
        if (j >= k) {
          continue;
        }
        if (L[i] + L[j] > L[k]) {
          if (L[j] + L[k] > L[i]) {
            if (L[k] + L[i] > L[j]) {
              /* printf("i, k, j: %d, %d, %d\n", i, j, k); */
              /* printf("L[i], L[k], L[j]: %d, %d, %d\n", L[i], L[j], L[k]); */
              cnt += 1;
            }
          }
        }
      }
    }
  }


  printf("%d\n", cnt);
  free(L);
  return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 0, 1, -1};                                 // 4方向近傍
int dx[]={1, -1, 0, 0};                                 // 4方向近傍


/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

int main(){
    ll a, b;
    cin >> a >> b;
    if(a >= 10 || b >= 10) cout << "-1" << endl;
    else cout << a*b;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define TASK "task"

using namespace std;

void rwFile() {
    freopen(TASK ".in", "r", stdin);
    freopen(TASK ".out", "w", stdout);
}

void solveA() {
    int x, y, z; cin >> x >> y >> z;
    cout << z << ' ' << x << ' ' << y;
}

void solveB() {
    int n, m; cin >> n >> m;
    int S = 0, arr[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
        S += arr[i];
    }
    int t = m;
    for (int i = 0; i < n; i++) {
        if (4 * m * arr[i] >= S) t--;
    }
    if (t > 0) cout << "No";
    else cout << "Yes";
}

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

void solveC() {
    long long n, k; cin >> n >> k;
    if (n % k == 0) {
        cout << 0;
        return;
    }
    while (true) {
        long long tmp = fabs(n - n / k * k - k);
        if (tmp >= n) break;
        else n = tmp;
    }
    cout << n;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    //rwFile();
    solveC();
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
int n, m;
vector<pair<int, int>> vec[114514];
string ans[114514];
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int p, y;
		cin >> p >> y;
		vec[p].push_back(make_pair(y,i));
	}
	for (int i = 1; i <= n; i++) {
		sort(vec[i].begin(), vec[i].end());
		string s = to_string(i);
		while (s.size() <= 5)s = '0' + s;
		for (int j = 0; j < vec[i].size(); j++) {
			string t = to_string(j + 1);
			while (t.size() <= 5)t = '0' + t;
			ans[vec[i][j].second] = s + t;
		}
	}
	for (int i = 1; i <= m; i++)cout << ans[i] << endl;
}


Measured memory_bytes: 12928