akhauriyash/Code-Regression huggingface dataset:
class Dice():

    def __init__(self, dice_list):
        self.state = [0 for _ in range(6)]
        self.state[0] = dice_list[0]
        self.state[1] = dice_list[1]
        self.state[2] = dice_list[2]
        self.state[3] = dice_list[3]
        self.state[4] = dice_list[4]
        self.state[5] = dice_list[5]

    def north(self):
        tmp = self.state[0]
        self.state[0] = self.state[1]
        self.state[1] = self.state[5]
        self.state[5] = self.state[4]
        self.state[4] = tmp

    def west(self):
        tmp = self.state[0]
        self.state[0] = self.state[2]
        self.state[2] = self.state[5]
        self.state[5] = self.state[3]
        self.state[3] = tmp

    def south(self):
        tmp = self.state[0]
        self.state[0] = self.state[4]
        self.state[4] = self.state[5]
        self.state[5] = self.state[1]
        self.state[1] = tmp


    def east(self):
        tmp = self.state[0]
        self.state[0] = self.state[3]
        self.state[3] = self.state[5]
        self.state[5] = self.state[2]
        self.state[2] = tmp

    
if __name__ == '__main__':
    def is_same(dice_num1, dice_num2):
        dice1 = Dice(dice_num1)

        flag = False
        dice2 = Dice(dice_num2)
        for i in range(4):
            for j in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.east()

            if dice1.state[1] == dice2.state[1]:
                flag = True
                break

            dice2.north()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.west()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    flag = True
                    break
                dice2.west()

        if flag == False:
            dice2 = Dice(dice_num2)
            dice2.east()
            dice2.south()
            for i in range(4):
                if dice1.state[1] == dice2.state[1]:
                    break
                dice2.west()

        ans = 'No'
        for i in range(4):
            if dice1.state == dice2.state:
                ans = 'Yes'
                break
            dice2.west()

        if ans == 'Yes':
            return True
        else:
            return False

    N = int(input())
    L = [list(map(int, input().split())) for _ in range(N)]

    answer = 'Yes'
    for i in range(N):
        for j in range(N):
            if i != j:
                if is_same(L[i], L[j]):
                    answer = 'No'
        
        
    print(answer)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int n, m;
	cin >> n >> m;
	vector<int> c(m);
	REP(i, m) {
		cin >> c[i];
	}
	SORT(c);
	vector<int> dp(n + 1, n);
	dp[0] = 0;
	REP(i, m) {
		for (int j = c[i]; j <= n; ++j) {
			dp[j] = min(dp[j], dp[j - c[i]] + 1);
		}
	}
	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 3164
n=int(input())

x=[[int(i) for i in input().split()] for i in range(n)]
#print(x)
cnt=0
for m in range(n):
  if x[m][2]>0:
    cnt+=1
    ii=m
    
#print(ii,cnt)

def hight(a,b,x,y,z):
  h=z+abs(x-a)+abs(y-b)
  return h

for i in range(101):
  for j in range(101):
    flag=0
    for k in range(n):
      if x[k][2]>0:
        if hight(i,j,x[ii][0],x[ii][1],x[ii][2])==hight(i,j,x[k][0],x[k][1],x[k][2]):
          flag+=1
      else:
        if hight(i,j,x[ii][0],x[ii][1],x[ii][2]) > hight(i,j,x[k][0],x[k][1],x[k][2]):
          flag=0
     
    if flag==cnt:
      ans1=i
      ans2=j
      ans3=hight(i,j,x[ii][0],x[ii][1],x[ii][2])
      
print(ans1,ans2,ans3)
#print(flag)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;

struct edge{
	llint to, cap, rev;
	edge(llint a, llint b, llint c){
		to = a, cap = b, rev = c;
	}
};

int n;
llint p[100005], q[100005];
llint a[100005], b[100005];

vector<edge> G[100005];
int S, T;
llint level[100005], iter[100005];


void bfs(llint s)
{
	for(int i = 1; i <= T; i++) level[i] = inf;
	level[s] = 0;
	
	queue<int> Q;
	Q.push(s);
	while(Q.size()){
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < G[v].size(); i++){
			int u = G[v][i].to;
			if(G[v][i].cap <= 0 || level[u] < inf) continue;
			level[u] = level[v] + 1;
			Q.push(u);
		}
	}
}

llint dfs(int v, llint f)
{
	if(v == T) return f;
	
	llint ret;
	for(llint &i = iter[v]; i < G[v].size(); i++){
		if(level[v] >= level[G[v][i].to] || G[v][i].cap <= 0) continue;
		ret = dfs(G[v][i].to, min(f, G[v][i].cap));
		if(ret > 0){
			G[v][i].cap -= ret;
			G[G[v][i].to][G[v][i].rev].cap += ret;
			return ret;
		}
	}
	return 0;
}

void add_edge(int s, int t, llint cap)
{
	G[s].push_back(edge(t, cap, G[t].size()));
	G[t].push_back(edge(s, 0, G[s].size()-1));
}

llint calc(llint p[], llint a[])
{
	llint ret = 1;
	for(int i = 1; i <= n; i++){
		if(a[i]) continue;
		int v = i;
		do{
			a[v] = ret;
			v = p[v];
		}while(!a[v]);
		ret++;
	}
	return ret-1;
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> p[i], p[i]++;
	for(int i = 1; i <= n; i++) cin >> q[i], q[i]++;
	
	llint P = calc(p, a), Q = calc(q, b);
	S = P+Q+1, T = P+Q+2;
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(p[i] == i && q[i] == i) ans++;
		else if(p[i] == i) add_edge(P+b[i], T, 1);
		else if(q[i] == i) add_edge(S, a[i], 1);
		else{
			add_edge(P+b[i], a[i], 1);
			if(p[i] == q[i]) add_edge(a[i], P+b[i], 1);
		}
	}
		
	llint flow;
	while(1){
		bfs(S);
		if(level[T] >= inf) break;
		for(int i = 1; i <= T; i++) iter[i] = 0;
		while(1){
			flow = dfs(S, inf);
			if(flow <= 0) break;
			ans += flow;
		}
	}
	cout << n-ans << endl;
	
	return 0;
}

Measured memory_bytes: 18304
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define LL long long
LL x,y;
LL Abs(LL m)
{
	if(m>=0) return m;
	return -m;
}
int main()
{
	scanf("%lld %lld",&x,&y);
	if(Abs(x-y)<=1)
		printf("Brown\n");
	else printf("Alice\n");
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1e5;
const ll WALLET = 1e15;
const ll INF = 1e18;

int n, m, s, t;
vector<pii> conn[2][N];
ll cost[2][N], tot[N];

void dijkstra(int start, int cur) {
	rep(i, 0, n) cost[cur][i] = INF;
	cost[cur][start] = 0;
	
	set<pair<ll, ll>> q;
	q.insert({0, start});
	
	while (!q.empty()) {
		int v = q.begin()->second;
		q.erase(q.begin());
		for (auto u : conn[cur][v]) {
			ll to = u.first, price = u.second;
			if (cost[cur][v] + price < cost[cur][to]) {
				q.erase({cost[cur][to], to});
				cost[cur][to] = cost[cur][v] + price;
				q.insert({cost[cur][to], to});
			}
		}
	}
}

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m >> s >> t;
	--s, --t;
	rep(i, 0, m) {
		ll u, v, a, b;
		cin >> u >> v >> a >> b;
		--u, -- v;
		conn[0][u].push_back({v, a});
		conn[1][u].push_back({v, b});
		conn[0][v].push_back({u, a});
		conn[1][v].push_back({u, b});
	}
	
	dijkstra(s, 0);
	dijkstra(t, 1);
	
	set<pair<ll, ll>> best;
	rep(i, 0, n) {
		tot[i] = cost[0][i] + cost[1][i];
		best.insert({tot[i], i});
	}
	
	rep(i, 0, n) {
		cout << WALLET - best.begin()->first << '\n';
		best.erase({tot[i], i});
	}
}


Measured memory_bytes: 24096
using System;
using System.Linq;

class Abc
{
    static void Main()
    {
        string N = Console.ReadLine();
        int a = int.Parse(N.Substring(0, 1));
        int b = int.Parse(N.Substring(1, 1));
        int c = int.Parse(N.Substring(2, 1));
        int d = int.Parse(N.Substring(3, 1));
        if (a - b - c - d == 7) Console.WriteLine("{0}-{1}-{2}-{3}=7", a, b, c, d);
        else if (a - b - c + d == 7) Console.WriteLine("{0}-{1}-{2}+{3}=7", a, b, c, d);
        else if (a - b + c - d == 7) Console.WriteLine("{0}-{1}+{2}-{3}=7", a, b, c, d);
        else if (a - b + c + d == 7) Console.WriteLine("{0}-{1}+{2}+{3}=7", a, b, c, d);
        else if (a + b - c - d == 7) Console.WriteLine("{0}+{1}-{2}-{3}=7", a, b, c, d);
        else if (a + b - c + d == 7) Console.WriteLine("{0}+{1}-{2}+{3}=7", a, b, c, d);
        else if (a + b + c - d == 7) Console.WriteLine("{0}+{1}+{2}-{3}=7", a, b, c, d);
        else if (a + b + c + d == 7) Console.WriteLine("{0}+{1}+{2}+{3}=7", a, b, c, d);


    }
}

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

int main() {
  int N;
  
  cin >> N;
  
  int thousand = N/1000;
  int handred = N/100-thousand*10;
  int ten = N/10-thousand*100-handred*10;
  int one = N%10;
  
  //cout << thousand << endl << handred << endl << ten << endl << one << endl; 
  
  if( handred == ten && (thousand == handred || ten == one) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

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

	int ans = 100000;
	for(int i = 0; i < n; i++) {
		double tmp = ans * 1.05;
		if((int)tmp % 1000 > 0) tmp += 1000;
		ans = tmp / 1000;
		ans *= 1000;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;

int solve();
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int w, h, tx, ty, kx, ky;
int maps[52][52];
int memo[52][52][52][52];

struct Data{
    P pt, pk;
    int cnt;
    Data(P pt_, P pk_, int cnt_){
        pt = pt_;
        pk = pk_;
        cnt = cnt_;
    }
    Data(){}
};

int main(void){
    while(cin >> w >> h, w){
        cin >> tx >> ty;
        cin >> kx >> ky;
        fill_n(*maps, 52*52, 1);
        FOR(i, h)FOR(j, w){
            cin >> maps[i+1][j+1];
        }
        int a = solve();
        if(a == -1 || a >= 100)FIN("NA");
        else FIN(a);
    }
    return 0;    
}


int solve(){
    int ans = -1;
    fill_n(***memo, 52*52*52*52, INF);
    queue<Data> que;
    que.push(Data(P(tx,ty), P(kx, ky), 0));
    while(que.size()){
        Data data = que.front();
        que.pop();
        int x1 = data.pt.first;
        int y1 = data.pt.second;
        int x2 = data.pk.first;
        int y2 = data.pk.second;
        int cost = data.cnt;
        if(cost > 100)break;
        if(memo[x1][y1][x2][y2] <= cost)continue;
        memo[x1][y1][x2][y2] = cost;
        if(x1 == x2 && y1 == y2){ans = cost;break;};
        FOR(i, 4){
            int nx1 = x1 + dx[i];
            int ny1 = y1 + dy[i];
            int nx2 = x2 - dx[i];
            int ny2 = y2 - dy[i];
            if(maps[ny1][nx1] == 1){nx1 = x1;ny1 = y1;};
            if(maps[ny2][nx2] == 1){nx2 = x2;ny2 = y2;};
            que.push(Data(P(nx1,ny1), P(nx2, ny2), cost+1));
        }
    }

    return ans;
}

Measured memory_bytes: 30968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
const int N = 105 , mod = 998244353;
map<lll , int > f,vis;
int n,a[N],b[N];char s[N];
lll get(lll x,int l,int r){return x>>l&(((lll)1<<(r-l+1))-1);}
int DP(lll x)
{
	if(vis[x])return f[x]; vis[x]=1;
	int ret=0,k=x>>n; if(!k)return f[x] = 1;
	lll S = get(x,0,n-1);
	for(int i=0;i<k;i++) if(S>>i&1) ret++; ret = b[ret];
	int cnt=0;
	for(int i=0;i<k;i++)
	{
		for(int j=i;j<k;j++)
		{
			int len = j-i+1; if(j+len>k-1)break;
			lll v = get(S,i,j);
			for(int t=i+len;t+len-1<k;t+=len)
				v&=get(S,t,t+len-1),ret=(ret+(ll)b[cnt]*DP(v|(lll)len<<n)%mod*
					DP(get(S,t+len,k-1)|(lll)(k-(t+len))<<n))%mod;
		}
		if(S>>i&1) cnt++;
	}
	// printf("%lld %d\n",x,ret);
	return f[x] = ret;
}
int main()
{
	scanf("%s",s),n=strlen(s); b[0] = 1;
	for(int i=1;i<=n;i++)b[i]=(b[i-1]<<1)%mod;
	for(int i=0;i<n;i++)a[i] = s[i]-'0';
	lll S = 0;
	for(int i=0;i<n;i++)if(a[i])S|=(lll)1<<i; S|=(lll)n<<n;
	printf("%d\n",DP(S));
}

Measured memory_bytes: 6528
N = int( input())
X = list( map( int, input().split()))
 
v_min = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1):
  v = 0
  for x in X:
    v += ( i - x ) ** 2
  v_min = min( v, v_min )
print( v_min )

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i,  e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	arr := make([]int, 0)
	q := nextInt()
	for i := 0; i < q; i++ {
		switch nextInt() {
		case 0:
			x := nextInt()
			arr = append(arr, x)
		case 1:
			p := nextInt()
			fmt.Println(arr[p])
		case 2:
			// fmt.Printf("before: %+v\n", arr)
			arr = arr[:len(arr)-1]
			// fmt.Printf("after: %+v\n", arr)
		default:
			println("no such operation!")
		}
	}
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  sort(v.begin(), v.end());
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    double y = v[i];
    ans = (ans + y) / 2;
  }
  printf("%0.10f\n", ans);
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BPath {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] d = new int[5];
            for (int i = 0; i < 6; i++) {
                int x = in.nextInt();
                d[x]++;
            }
            int odd = 0;
            for (int i = 1; i <= 4; i++) {
                if (d[i] % 2 == 1) odd++;
            }
            if (odd == 2) out.println("YES");
            else out.println("NO");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22484
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static final Scanner sc = new Scanner(System.in);
        
    static WeightedUnionFind uf;
    static int n, m;
    static int l, r, d;


    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();

        uf = new WeightedUnionFind(n + 1);

        for (int i = 0; i < m; i++) {
            l = sc.nextInt();
            r = sc.nextInt();
            d = sc.nextInt();

            if (uf.isSameGroup(l, r) &&
                uf.diff(l, r) != d) {
                System.out.println("No");
                return;
            }
            else {
                uf.unite(l, r, d);
            }
        }

        System.out.println("Yes");
    }
}


/**
 * 重み付きUnionFind木.
 * アーベル群まで拡張したいけどパフォが気になるので保留
 * ArrayList\<Integer\>がint[]よりだいぶ遅い
 */
class WeightedUnionFind {
    /** 親を示す 自身が根の場合は -(集合の大きさ) を持つ */
    private int[] parent;
    
    /** ノードの重み (親との差分) */
    private int[] diff_weight;

    public WeightedUnionFind(int nmemb) {
        parent = new int[nmemb];
        diff_weight = new int[nmemb];

        Arrays.fill(parent, -1);
        Arrays.fill(diff_weight, 0);
    }

    /** 根を求める */
    private int root(int x) {
        if (parent[x] < 0) {
            return x;
        }

        // 累積和的に重みを再計算
        int r = root(parent[x]);
        diff_weight[x] += diff_weight[parent[x]];
        parent[x] = r;

        return parent[x];
    }

    private int weight(int x) {
        root(x);
        return diff_weight[x];
    }

    public int diff(int x, int y) {
        return weight(y) - weight(x);
    }
    
    public boolean isSameGroup(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * x->yの重みをwとして併合.
     * 即ち, weight(y) = weight(x) + w が成り立つ
     * x, yが既に同じグループのときは何もしない
     */
    public void unite(int x, int y, int w) {
        if (isSameGroup(x, y)) {
            return;
        }

        w += weight(x);
        w -= weight(y);
        x = root(x);
        y = root(y);
    
        parent[y] = x;
        diff_weight[y] = w;
    }

    public int groubSize(int x) {
        return -parent[root(x)];
    }
}


Measured memory_bytes: 150964
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,sum=0;
    cin>>a>>b;
    int x[b];
    for(int i=0;i<b;i++)
    {
        cin>>x[i];
        sum+=x[i];
    }
    if(sum>=a)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 18;

void solve()
{
	char t[4];
	scanf ("%s", t);
	
	printf("%s\n", (t[0] == t[1] and t[1] == t[2]) ? "No" :"Yes");
} 

 
int main()
{
    int t;
    t=1;//scanf ("%d", &t);
    while (t--)
    	solve();
    return 0;    
}


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

#define N 10

int dp[10][N];

void out(int i, int j, long* k) {
    if (*k <= 0) {
        return;
    }
    if (dp[i][j] < *k) {
        *k -= dp[i][j];
        return;
    }

    cout << i;
    if (dp[i][j] == 1) {
        *k -= 1;
        return;
    }

    if (i == 0) {
        out(0, j-1, k);
        out(1, j-1, k);
        return;
    }
    if (i == 9) {
        out(8, j-1, k);
        out(9, j-1, k);
        return;
    }
    out(i-1, j-1, k);
    out(i, j-1, k);
    out(i+1, j-1, k);
}

int main()
{
    long k;
    cin >> k;
    for (int i = 0; i < 10; i++) {
        dp[i][0] = 1;
    }
    for (int j = 1; j < N; j++) {
        dp[0][j] = dp[0][j-1] + dp[1][j-1];
        for (int i = 1; i < 9; i++) {
            dp[i][j] = dp[i-1][j-1] + dp[i][j-1] + dp[i+1][j-1];
        }
        dp[9][j] = dp[8][j-1] + dp[9][j-1];
    }
    for (int j = 0; j < N; j++) {
        for (int i = 1; i < 10; i++) {
            if (dp[i][j] >= k) {
                out(i, j, &k);
                cout << endl;
                return 0;
            }
            k -= dp[i][j];
        }
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a <= b){
            for(int i=0; i<b; i++){
                System.out.print(a);
            }
        } else {
            for(int i=0; i<a; i++){
                System.out.print(b);
            }
        }
    }
}

Measured memory_bytes: 21716
import itertools
 
N = int(input())
coord = [list(map(int, input().split())) for _ in range(N)]
dis = 0

for order in itertools.permutations(range(N)):
  for i in range(1, N):
    dis += ((coord[order[i]][0]-coord[order[i-1]][0])**2 + (coord[order[i]][1]-coord[order[i-1]][1])**2)**0.5
 
ave = dis / len(list(itertools.permutations(range(N))))
print(ave)

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  int N;
  cin>>N;
  vector<int> s(N);

  for(int i=0;i<N;i++){
    cin>>s[i];
  }

  int dp[101][10001]={false};
  dp[0][0]=true;
  for(int i=0;i<N;i++){
    for(int j=0;j<10001;j++){
      if(dp[i][j]) {
        dp[i+1][j]=true;
        dp[i+1][j+s[i]]=true;
      }
    }
  }

  int ans=0;
  for(int i=10000;i>=0;i--){
    if(i%10!=0&&dp[N][i]){
      ans=i;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 4224
import itertools
N = int(input())
L = [int(_) for _ in input().split()]
ans = 0
for i, j, k in itertools.combinations(range(N), 3):
    a, b, c = sorted([L[i], L[j], L[k]])
    if a + b > c and a != b and b != c:
        ans += 1
print(ans)


Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int k=a/d+(a%d==0?0:1);int l=c/b+(c%b==0?0:1);
	if(k>=l)
	cout<<"Yes";
	else
	cout<<"No";
}



Measured memory_bytes: 3644
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    s = input()

    print(s.replace("7", "8", 1))

    pass


if __name__ == "__main__":
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll A, B, C;
    cin >> A >> B >> C;
    cout << max(C - (A-B), 0ll) << endl;
    return 0;
}

Measured memory_bytes: 256
m,d = map(int,input().split())

count = 0
for i in range(1,d+1):
    i1 = i % 10
    i2 = i // 10
    if i1 >= 2 and i2 >= 2 and i1 * i2 <= m and i1 * i2 >= 1:
        count += 1

print(count)


Measured memory_bytes: 2940
s=input()
a=int(s[:2])
b=int(s[2:])
if 0<a<13 and 0<b<13:
    print("AMBIGUOUS")
elif 0<=a and 0<b<13:
    print("YYMM")
elif 0<=b and 0<a<13:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3060
def count(n, x):
    b1 = 1<<n
    b2 = b1<<1
    return 1 if n == 0 else \
           0 if x == 1 else \
           count(n-1, x-1) if x <b2-1 else \
           b1 if x == b2-1 else \
           count(n-1, x+1-b2)+b1 \

N, X = map(int, input().split())
print(count(N, X))


Measured memory_bytes: 38256
a = list(input())

su = 0
dd = 0
co = 0
for i in range(len(a)-1,-1,-1):
	if a[i] == 'W':
		co += 1
	if co >= 1:
		if a[i] == 'B':
			su += (len(a)-1 - i) - dd
	if a[i] == 'B':
		dd += 1

print(su)


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
    string t;
    cin >> t;
    
    for (int i = 0; i < t.size(); i++) {
        if (t[i] == 'P' || t[i] == 'D') {
            cout << t[i];
            continue;
        }
        cout << 'D';
    }
    cout << endl;
    
    return 0;
}

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

using namespace std;
int main()
{
    long long n,m,a,b,sum=0;
    cin>>n>>m;
    vector<pair<long long,long long int>>v;
    for(int i=0; i<n; i++)
    {
        cin >>a>>b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    for(int i = 0; i < n; i++)
    {
        sum+=min(v[i].second,m)*v[i].first;
        m-=min(v[i].second,m);
    }
    cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 2420
#include <stdint.h>

#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int64_t N;
  cin >> N;
  vector<string> si(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> si[i];
  }

  map<int64_t, int64_t> m;
  for (const auto &s : si) {
    vector<int> cnt(26, 0);
    for (const auto c : s) {
      cnt[c - 'a']++;
    }
    int64_t h = 0;
    int64_t k = 1;
    for (auto c : cnt) {
      h += k * c;
      k *= 11;
    }
    m[h]++;
  }

  int64_t ans = 0;
  for (auto k : m) {
    if (k.second > 1) {
      ans += k.second * (k.second - 1) / 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 12600
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<int, int, int>;

long long MOD = 1000000007;
long long dp[100005][4];

long long dist[200][200];

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int N, M, R;
	cin >> N >> M >> R;

	vector<int>visit(R);
	for (int i = 0; i < R; ++i) {
		int v;
		cin >> v;
		visit[i] = --v;
	}
	
	for (int i = 0; i < N; ++i)for (int j = 0; j < N; ++j)dist[i][j] = 10000000000;

	for (int i = 0; i < M;++i) {
		long long a, b, c;
		cin >> a >> b >> c;
		dist[a - 1][b - 1] = c;
		dist[b - 1][a - 1] = c;
	}

	for (int k = 0; k < N;++k) {
		for (int i = 0; i < N;++i) {
			for (int j = 0; j < N;++j) {
				dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}

	long long ans = 9223372036854775807;
	for (int i = 0; i < R;++i) {
		for (int j = 0; j < R; ++j) {
			if (i == j)continue;
			if (R == 2) {
				ans = min(ans,dist[visit[i]][visit[j]]);
				continue;
			}
			for (int k = 0; k < R; ++k) {
				if (i == k || j==k)continue;
				if (R == 3) {
					ans = min(ans, dist[visit[i]][visit[j]]+dist[visit[j]][visit[k]]);
					continue;
				}
				for (int l = 0; l < R; ++l) {
					if (i == l || j == l || k == l)continue;
					if (R == 4) {
						ans = min(ans, dist[visit[i]][visit[j]] + dist[visit[j]][visit[k]] + dist[visit[k]][visit[l]]);
						continue;
					}
					for (int m = 0; m < R; ++m) {
						if (i == m || j == m || k == m || l == m)continue;
						if (R == 5) {
							ans = min(ans, dist[visit[i]][visit[j]] + dist[visit[j]][visit[k]] + dist[visit[k]][visit[l]] + dist[visit[l]][visit[m]]);
							continue;
						}
						for (int n = 0; n < R; ++n) {
							if (i == n || j == n || k == n || l == n || m == n)continue;
							if (R == 6) {
								ans = min(ans, dist[visit[i]][visit[j]] + dist[visit[j]][visit[k]] + dist[visit[k]][visit[l]] + dist[visit[l]][visit[m]] + dist[visit[m]][visit[n]]);
								continue;
							}
							for (int o = 0; o < R; ++o) {
								if (i == o || j == o || k == o || l == o || m == o || n == o)continue;
								if (R == 7) {
									ans = min(ans, dist[visit[i]][visit[j]] + dist[visit[j]][visit[k]] + dist[visit[k]][visit[l]] + dist[visit[l]][visit[m]] + dist[visit[m]][visit[n]] + dist[visit[n]][visit[o]]);
									continue;
								}
								for (int p = 0; p < R; ++p) {
									if (i == p || j == p || k == p || l == p || m == p || n == p || o == p)continue;
									ans = min(ans, dist[visit[i]][visit[j]] + dist[visit[j]][visit[k]] + dist[visit[k]][visit[l]] + dist[visit[l]][visit[m]] + dist[visit[m]][visit[n]] + dist[visit[n]][visit[o]] + dist[visit[o]][visit[p]]);
								}
							}
						}
					}
				}
			}
		}
	}

	cout << ans << endl;
}


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

string judge(int x,int y){
  if(x == 2 || y == 2)return"No";
  int mi = min(x,y), ma = max(x,y);
  if(mi == 4 && ma == 6)return "Yes";
  if(mi == 4 && ma == 9)return "Yes";
  if(mi == 4 && ma == 11)return "Yes";
  if(mi == 6 && ma == 9)return "Yes";
  if(mi == 6 && ma == 11)return "Yes";
  if(mi == 9 && ma == 11)return "Yes";


  if(mi == 4)return "No";
  if(mi == 6)return "No";
  if(mi == 9)return "No";
  if(mi == 11)return "No";
  if(ma == 4)return "No";
  if(ma == 6)return "No";
  if(ma == 9)return "No";
  if(ma == 11)return "No";

  return"Yes";
}
int main(void){
  int x,y;
  cin>>x>>y;
  cout<<judge(x,y)<<endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b

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

# 累積和，和の候補
cA = [0] * (N + 1)
for i in range(N):
    cA[i + 1] = cA[i] + A[i]
nums = []
for i in range(N + 1):
    for j in range(i + 1, N + 1):
        nums.append(cA[j] - cA[i])

# 解は和のandのmax
# 解xは，x ∧ Ai = x を満たすiが少なくともK個存在する

# 解の計算 2⁴⁰ ~ 2⁰
now = 0
for d in range(40, -1, -1):
    count = 0
    # 今の解(上位から構築)が成り立ち，考えている桁でK以上1が
    # 立てられるなら，この桁を採用して良い
    for s in nums:
        if s & (now | (1 << d)) == now | (1 << d):
            count += 1
    if count >= K:
        now = now | (1 << d)
print(now)


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

const long long MOD = 998244353;

int main(){
	int N;
	cin >> N;
	vector<int> D(N);
	for(int i=0;i<N;i++)	cin >> D.at(i);
	
	if(D.at(0)!=0){
		cout << 0 << endl;
		return 0;
	}
	
	vector<long long> count(N,0);
	for(int i=1;i<N;i++)	count.at(D.at(i))++;
	if(count.at(0)!=0){
		cout << 0 << endl;
		return 0;
	}
	int x;
	for(x=1;x<N;x++)	if(count.at(x)==0)	break;
	for(;x<N;x++){
		if(count.at(x)!=0){
			cout << 0 << endl;
			return 0;
		}
	}
	
	long long ans=1;
	count.at(0)=1;
	for(int i=1;i<N;i++){
		if(count.at(i)==0)	break;
		for(int j=0;j<count.at(i);j++){
			ans*=count.at(i-1);
			ans%=MOD;
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

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

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int cumgcd= data.at(0);
  for(int i=0; i<N; i++){
    cumgcd= gcd(cumgcd, data.at(i));
  }

  if(cumgcd != 1){
    cout << "not coprime" << endl;
  }
  else{
    constexpr int Pmax= 1000;
    vector<int> primes;
    bitset<Pmax> sieve;
    sieve.set(); sieve.reset(0); sieve.reset(1);
    for(int p=2; p<Pmax; p++){
      if(sieve.test(p)){
        primes.emplace_back(p);
        for(int m= 2*p; m< Pmax; m+=p){
          sieve.reset(m);
        }
      }
    }

    bool pairwise_coprime= true;
    set<int> factors;
    for(auto num:data){
      for(auto p:primes){
        if(num%p==0){
          if(factors.count(p)){
            pairwise_coprime= false;
            break;
          }
          else{
            factors.insert(p);
            while(num%p==0){
              num/= p;
            }
          }
        }
      }
      if(num > 1){
        if(factors.count(num)){
          pairwise_coprime= false;
        }
        else{
          factors.insert(num);
        }
      }
      
      if(!pairwise_coprime){ break; }
    }

    string ans= pairwise_coprime ? "pairwise coprime"
                                 : "setwise coprime";
    cout << ans << endl;
  }
}

Measured memory_bytes: 7244
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;  //このネームスペースを使う
int main(){
  int r,D,x[11] ;
  cin >> r >> D >> x[0] ;
  
  int i;
  for(i=1;i<11;i++){
    x[i]=x[i-1]*r-D;
    cout << x[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios	      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
      
      ios
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      int i=1;
      while(i){
            
            if(i%2!=0){
                  c = c-b;
                  if(c<=0){
                        cout << "Yes" <<"\n";
                        break;
                  }      
            }
            else{
                  a=a-d;
                  if(a<=0){
                        cout << "No" <<"\n";
                        break;
                  }      
            }
            i++;
      }

      return 0;
}


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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b!=c) cout<<"Yes"<<endl;
    else if(b==c && c!=a) cout<<"Yes"<<endl;
    else if(c==a && a!=b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

const ll INF = LONG_LONG_MAX / 2;

struct Edge {
    int from;
    int to;
    int score;
};

vector<struct Edge> edges;
vector<vector<int>> edges_from_start;
vector<vector<int>> edges_from_goal;

vector<bool> reachable;
vector<bool> reachable_from_start;
vector<bool> reachable_to_goal;

vector<ll> scores;

ll bellman_ford(const int N) {
    for (int i = 0; i < N; i++) {
        for (auto &edge : edges) {
            int u = edge.from;
            int v = edge.to;
            int c = edge.score;

            if (!reachable[u]) continue;
            if (!reachable[v]) continue;

            if (scores[v] > scores[u] + c) {
                scores[v] = scores[u] + c;
            }
        }
    }

    for (auto &edge : edges) {
        int u = edge.from;
        int v = edge.to;
        int c = edge.score;

        if (!reachable[u]) continue;
        if (!reachable[v]) continue;

        if (scores[v] > scores[u] + c) {
            return -INF;
        }
    }

    return scores[N - 1];
}

void dfs(const int cur, vector<bool> &my_reachable, const vector<vector<int>> &my_edges) {
    if (my_reachable[cur]) {
        return;
    }
    my_reachable[cur] = true;
    for (auto &next : my_edges[cur]) {
        dfs(next, my_reachable, my_edges);
    }
}

void check_reachable(const int N) {
    dfs(0, reachable_from_start, edges_from_start);
    dfs(N - 1, reachable_to_goal, edges_from_goal);
    for (int i = 0; i < N; i++) {
        reachable[i] = reachable_from_start[i] && reachable_to_goal[i];
    }
}

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

    edges.resize(N);
    edges_from_start.resize(N);
    edges_from_goal.resize(N);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;

        c -= P;
        c *= -1;
        edges.push_back({a, b, c});

        edges_from_start[a].push_back(b);
        edges_from_goal[b].push_back(a);
    }

    reachable.resize(N, false);
    reachable_from_start.resize(N, false);
    reachable_to_goal.resize(N, false);
    check_reachable(N);

    scores.resize(N, INF);
    scores[0] = 0;
    ll ans = bellman_ford(N);
    if (ans == -INF) {
        cout << -1 << endl;
    } else if (ans <= 0) {
        cout << -1 * ans << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 896
n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] != l[j] != l[k]:
                if l[i] + l[j] > l[k]:
                    ans += 1
print(ans)

Measured memory_bytes: 9184
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=305;

int n,k,Mo,f[N][N],C[N][N],s[N][N];

int main() {
	scanf("%d%d%d",&n,&k,&Mo);
	fo(i,0,n) {
		C[i][0]=1;
		fo(j,1,i) C[i][j]=(C[i-1][j]+C[i-1][j-1])%Mo;
	}
	fo(i,0,k) f[1][i]=1,s[1][i]=k-i+1;
	fo(i,2,n+1) {
		fo(j,0,k)
			fo(l,1,i-1)
				(f[i][j]+=(ll)f[i-l][j]*s[l][j+1]%Mo*C[i-2][l-1]%Mo)%=Mo;
		fd(j,k,0) s[i][j]=(s[i][j+1]+f[i][j])%Mo;
	}
	printf("%d\n",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 1280
from collections import deque
N,M=map(int,input().split())
ab=[tuple(map(int,input().split())) for _ in range(M)]
ans=0
for i in range(M):
    tab=ab[:]
    tab.pop(i)
    r=[[] for _ in range(N)]
    for a,b in tab:
        r[a-1].append(b-1)
        r[b-1].append(a-1)
    l=[True]*N
    l[0]=False
    q=deque(r[0])
    while q:
        t=q.popleft()
        if l[t]:
            l[t]=False
            for j in r[t]:
                if r[j]:
                    q.append(j)
    ans+=any(l)
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MOD 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define P pair<ll, ll>
#define VII vector<P>
#define P_B push_back

int n, k;
int n_l;
int v[100];
vector<int> g[(int)(2e5)];
vector<bool> visited((int)(1e5+1), false) ;
vector<int> DP((int)(1e5+1), -1); 

int backtrack(int node) {

	// cout<<node<<" ";
	int answer = 0;
	if(DP[node] != -1) return DP[node];	
	for (auto nd : g[node]) {
		answer = max(answer, 1 + backtrack(nd));
	}
	return DP[node] = answer;
	// return DP[node];
}

int main() {
	
	// ll T; cin>>T; while(T--) 
	{
		
		cin>>n>>k;
		for (int i = 0; i < k; i++) {
			int u, v;
			cin>>u>>v;
			g[u].P_B(v);
		}

		int answer = 0;
		for (int i = 1; i <= n; i++) {
			answer = max(answer, backtrack(i));
		}
		
		// for (int i = 1; i <= n; i++) cout<<DP[i]<<" ";	
		cout<<answer;
	}	
	return 0;
}

Measured memory_bytes: 13392
import sys
import collections

while True:
    n, w = map(int, sys.stdin.readline().split())
    
    if n == 0:
        break
    
    count = collections.Counter()
    for i in xrange(n):
        count[int(raw_input()) / w] += 1
    largest_value = count.most_common(1)[0][1]
    largest_key = max(count.keys())
    ink = 0
    for i, v in count.iteritems():
        if i >= largest_key:
            continue
        ink += (largest_key - float(i)) / (largest_key) * v / largest_value
    print ink + 0.01

Measured memory_bytes: 4656
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    a,b,c=map(int, input().split())
    x=abs(a-b)+abs(b-c)
    y=abs(a-c)+abs(b-c)
    z=abs(a-b)+abs(a-c)
    print(min(x,y,z))
resolve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
bitset<4000005> B;
int n,v,sum;
int main(){
    scanf("%d",&n);
    B[0]=1;
    for(int i=1;i<=n;i++){
        scanf("%d",&v);
        B|=B<<v;
        sum+=v;
    }
    for(int i=(sum+1)/2;i<=sum;i++)
        if(B[i]){
            printf("%d\n",i);
            return 0;
        }
    cout<<"peace & love.";
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String op;
      String[] words;
      Tree tree = new Tree();

      for(int i=0,k=0; i<n; i++,k=0){
        words = br.readLine().split(" ");
        op  = words[k++];
        if ( op.equals("insert") ) { 
          tree.insert(Integer.parseInt(words[k++]));
        }
        else {
          tree.dispRoundPath();
        }
      }

    }
    catch(IOException e) {
      System.out.println("IOException!");
    }
  }
}

class Tree {

  static final BTreeNode NIL = new BTreeNode(-1);
  BTreeNode root;
  StringBuilder buf;

  public Tree() {
    root = NIL;
    buf = new StringBuilder();
  }

  public void insert(int val) {
    BTreeNode y = NIL;
    BTreeNode x = root;
    BTreeNode z = new BTreeNode(val);

    while( !x.equals(NIL) ) {
      y = x;
      if( z.key < x.key )
        x = x.left;
      else
        x = x.right;
    }
    z.parent = y;

    if( y.equals(NIL) ){
      root = z;
    }
    else if( z.key < y.key )
      y.left = z;
    else
      y.right = z;
  } 
  void preParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      buf.append(" ").append(u.key);
      preParse(u.left);
      preParse(u.right);
    }
  }
  void inParse(BTreeNode u) {
    if( !u.equals(NIL) ) {
      inParse(u.left);
      buf.append(" ").append(u.key);
      inParse(u.right);
    }
  }

  void dispRoundPath() {

    inParse(root);
    buf.append("\n");
    preParse(root);
    buf.append("\n");

    System.out.print(buf);
    buf.setLength(0);
  }
}

class BTreeNode {
  int key;
  BTreeNode parent,left,right;

  public BTreeNode(int key) {
    this.key = key;
    this.parent =
    this.left =
    this.right = Tree.NIL;
  }

  @Override
  public boolean equals(Object o) {
    if(o == this) return true;
    if(o == null) return false;
    if(!(o instanceof BTreeNode)) return false;

    BTreeNode node = (BTreeNode)o;
    if(!(this.key == node.key)) return false;

    return true;
  }
}


Measured memory_bytes: 126560
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

int main(){
    int k,s;
    cin >> k >> s;
    int count = 0;
    for(int x =0; x<k+1;x++){
        for(int y=0; y<k+1;y++){
            if(s>=x+y && s-x-y<=k){
                count ++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))

int main() {
    string s;cin>>s;
    bool a=false;

    rep(i,s.size()) {
        if ((i+1)%2==1 && s[i]=='L') {
            a=true;
            break;
        }
        if ((i+1)%2==0 && s[i]=='R') {
            a=true;
            break;
        }
    }

    if (a) {
        cout<<"No"<<endl;
    }
    else {
        cout<<"Yes"<<endl;
    }

}

Measured memory_bytes: 256
n=int(input())
nn=[]
for i in range(n):
    nn.append(input())
m=int(input())
mm=[]
for i in range(m):
    mm.append(input())
ans=0
nns=set(nn)
for i in nns:
    tmp = nn.count(i)- mm.count(i) 
    ans=max(ans,tmp)

print(ans)

Measured memory_bytes: 3060
z=-1e8;
n,i;main(a,s){
  for(;scanf("%d",
             !n?
             s=a-1&&!printf("%d\n",a),i=a=z,&n:&i),
      (i-z?(a=a<(s+=i)?s:a),n--:n)
      ;s*=s>0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n;
    cin >> n;
    vector <long long> a(n);
    rep(i,n) cin >> a[i];

    if(n == 2){
        cout << max(a[0], a[1]) << endl;
        return 0;
    }

    sort(all(a));
    reverse(all(a));

    long long ans = a[0];

    int set = (n-2)/2;
    int rem = (n-2)%2;
    for(int i=1; i<=set; i++){
        ans += 2 * a[i];
    }

    if(rem == 0);
    else{
        ans += a[set+1];
    }

    cout << ans << endl; 

}

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

void Main()
{
    int n, q;
    cin >> n >> q;
    atcoder::fenwick_tree<long> g(n);
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        g.add(i, a);
    }
    for (int i = 0; i < q; i++)
    {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 0) g.add(a, b);
        if (t == 1) cout << g.sum(a, b) << endl;
    }
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 8240
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

lenA = len(A)
BC.sort(reverse = True, key = lambda x:x[1])

i = 0
cnt = 0
while cnt < lenA and i < M:
  A.extend([BC[i][1] for _ in range(BC[i][0])])
  cnt += BC[i][0]
  i += 1
A.sort(reverse = True)
l = A[0:lenA]

print(sum(l))

Measured memory_bytes: 34880
from collections import defaultdict
import bisect

s = input()
t = input()
#%%
ls = len(s)-1
cnt = 0
num = -1
di = defaultdict(list)
for ind,i in enumerate(s):
    di[i].append(ind)

for i in t:
    if(i not in di):
        print(-1)
        break
    if(di[i][-1]<=num):
        cnt += ls-num+di[i][0]+1
    else:
        x = bisect.bisect_left(di[i],num+1)
        if(num==-1):
            cnt += di[i][x]
        else:
            cnt += di[i][x]-num
    num = cnt%(ls+1)
    #print(i,cnt)

else:
    print(cnt+1)


Measured memory_bytes: 7924
N, M = map(int, input().split())
A = list(map(int, input().split()))

dp = [[1<<60]*(N+1) for _ in range(M+1)]
dp[0][0] = 0

for i in range(M):
    for j in range(N+1):
        if A[i] <= j:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-A[i]] + 1)
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[M][N])


Measured memory_bytes: 43736