akhauriyash/Code-Regression huggingface dataset:
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	x := make([]int, 100)
	y := make([]int, 100)
	r := make([]int, 100)
	for scanner.Scan() {
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		for i := 0; i < a; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmpx, _ := strconv.Atoi(input[0])
			tmpy, _ := strconv.Atoi(input[1])
			tmpr, _ := strconv.Atoi(input[2])
			x[i], y[i], r[i] = tmpx, tmpy, tmpr
		}
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			c, _ := strconv.Atoi(input[0])
			d, _ := strconv.Atoi(input[1])
			e, _ := strconv.Atoi(input[2])
			f, _ := strconv.Atoi(input[3])
			ok := false
			for j := 0; j < a; j++ {
				if (c-x[j])*(c-x[j])+(d-y[j])*(d-y[j]) >= r[j]*r[j] || (e-x[j])*(e-x[j])+(f-y[j])*(f-y[j]) >= r[j]*r[j] {
					if (e-c)*(x[j]-c)+(f-d)*(y[j]-d) < 0 {
						if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d) <= r[j]*r[j] {
							ok = true
						}
					} else {
						if (e-c)*(x[j]-c)+(f-d)*(y[j]-d)>(e-c)*(e-c)+(f-d)*(f-d) {
							if (x[j]-e)*(x[j]-e)+(y[j]-f)*(y[j]-f)<=r[j]*r[j] {
								ok = true
							}
						} else {
							if (x[j]-c)*(x[j]-c)+(y[j]-d)*(y[j]-d)-((e-c)*(x[j]-c)+(f-d)*(y[j]-d))*((e-c)*(x[j]-c)+(f-d)*(y[j]-d))/((e-c)*(e-c)+(f-d)*(f-d))<=r[j]*r[j] {
								ok = true
							}
						}
					}

				}
			}
			if ok {
				fmt.Println("Safe")
			} else {
				fmt.Println("Danger")
			}
		}
	}
}



Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

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

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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

signed main(){

	int A, B;
	cin >> A >> B;
	int g[100][100];

	for (int i = 0; i < 100; i++)
		for (int j = 0; j < 100; j++){
			if (j < 50) g[i][j] = 1;
			else g[i][j] = 0;
		}

	A--; B--;
	int x = 0, y = 0;
	while (A > 0){
		g[x][y] = 0;
		A--;
		x += 2;
		if (x >= 100){ y += 2; x = 0; }
	}

	x = 0, y = 99;
	while (B > 0){
		g[x][y] = 1;
		B--;
		x += 2;
		if (x >= 100){ y -= 2; x = 0; }
	}

	cout << "100 100" << endl;
	for (int i = 0; i < 100; i++){
		for (int j = 0; j < 100; j++){
			cout << (g[i][j] == 0 ? "." : "#");
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  int a,sum,tmp,ans1,ans2;
  cin >> a;
  vi num(a+1,0);
  rep(i,a){
    cin >> tmp;
    sum += tmp;
    num.at(i+1) = tmp + num.at(i);
  }
  ans1 = sum;
  rep(i,a+1){
    tmp = num.at(i)*2;
    ans1 = min(ans1,abs(tmp-sum));
    ans2 = ans1;
  }
  cout << ans2;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const double eps = 1e-9;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ")
{ if (!v.size()) puts(""); rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

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

lint lcm(lint a, lint b) {
  return a / gcd(a, b) * b;
}

signed main() {
  lint n = in(), k = in();
  vi a;

  rep(i, n) a.pb(in());

  lint d = a[0];
  for (int i = 1; i < n; ++i) {
    d = gcd(d, a[i]);
  }
  //
  // print(d);

  sort(all(a));

  bool f = false;
  for (int i = 0; i < n; ++i) {
    lint x = a[i] - k;
    if (x < 0) continue;
    if (x % d == 0) f = true;
  }

  cout << (f ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

long long gcd(long long a, long long b) {
    while (b) {
        long long c = a % b;
        a = b;
        b = c;
    }
    return a;
}

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

void _main() {
    int N;
    cin >> N;
    int ans = 1;
    REP(i, N) {
        int T;
        cin >> T;
        ans = lcm(ans, T);
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int N;
vector<int> arr;

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

    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }

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

    int v, cnt = 0, ans = 0;
    for(int i = 0; i < N; i++) {
        v = arr[i];
        cnt++;
        if(i == N - 1 || arr[i] != arr[i + 1]) {
            if(v <= cnt) ans += cnt - v;
            else ans += cnt;

            cnt = 0;
        }
    }

    printf("%d", ans);
}


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

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        int[] arr = nextIntArr(5);
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 0) {
                outln(i + 1);
                return;
            }
        }
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 32852
#include <stdio.h>

#define N 100

int main() {
	static int xx[N], yy[N];
	int n, m, x, y, i, j, max, min;

	scanf("%d%d%d%d", &n, &m, &x, &y);
	for (i = 0; i < n; i++)
		scanf("%d", &xx[i]);
	for (j = 0; j < m; j++)
		scanf("%d", &yy[j]);
	max = x;
	for (i = 0; i < n; i++)
		if (max < xx[i])
			max = xx[i];
	min = y;
	for (j = 0; j < m; j++)
		if (min > yy[j])
			min = yy[j];
	printf(max < min ? "No War\n" : "War\n");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <cmath>

using namespace std;

int main(){
	int n;
	double x[100] = {0},y[100] = {0},p_1 = 0,p_2 = 0,p_3 = 0,p_infinity = -1;
	scanf("%d",&n);
	for(int i = 0; i < n; i++) scanf("%lf",&x[i]);
	for(int i = 0; i < n; i++) scanf("%lf",&y[i]);

	for(int i = 0; i < n; i++){
		p_1 += abs(x[i] - y[i]);
		p_2 += (x[i] - y[i])*(x[i] - y[i]);
		p_3 += abs((x[i] - y[i])*(x[i] - y[i])*(x[i] - y[i]));
		p_infinity = (p_infinity >= abs(x[i] - y[i]))? p_infinity:abs(x[i] - y[i]);
 	}
	printf("%.6lf\n",p_1);
	printf("%.6lf\n",sqrt(p_2));
	printf("%.6f\n",cbrt(p_3));
	printf("%.6lf\n",p_infinity);

}


Measured memory_bytes: 2908
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,ans=0,i,j,k;
  string s;
  cin>>n;
  map<string,long long>m;
  for(i=0;i<n;i++)
  {
    cin>>s;
    sort(s.begin(),s.end());
    ans+=m[s];
    m[s]++;

  }
  cout<<ans<<endl;

}


Measured memory_bytes: 11136
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << (a + b == c + d ? "Balanced" : a + b > c + d ? "Left" : "Right") << endl;
    // if (a + b > c + d)      cout << "Left" << endl;
    // else if (a + b < c + d) cout << "Right" << endl;
    // else                    cout << "Balanced" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> nums=new ArrayList<Integer>(N);
		for(int i=0;i<N;i++) {
			nums.add(Integer.parseInt(sc.next()));
		}
		int ans=0;
		while(true)
		{
			
			int max=Collections.max(nums);
			if(max==0) {
				break;
			}
			int index=nums.indexOf(max);
			while(true) {
				nums.set(index, max-1);
				if(index==N-1) {
					break;
				}else if(nums.get(index)==nums.get(index+1)-1) {
					index+=1;
				}else {
					break;
				}
			}
			ans++;
			
		}
		System.out.println(ans);
		sc.close();
	}
	
}


Measured memory_bytes: 22996
#include <stdio.h>
#include <string.h>
#include <list>

using namespace std;

int main()
{
    int n;
    char s[16];
    int d;
    list<int> l;
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	scanf("%s", s);
	if ( !strcmp( s, "insert" ) ) {
	    scanf("%d", &d);
	    l.push_front(d);
	}
	else if ( !strcmp( s, "delete" ) ) {
	    scanf("%d", &d);
	    
	    for ( list<int>::iterator it = l.begin(); it != l.end(); it++ ) {
		if ( *it == d ) {
		    l.erase( it );
		    break;
		}
	    }
	}
	else if ( !strcmp( s, "deleteFirst" ) ) {
	    l.pop_front();
	}
	else if ( !strcmp( s, "deleteLast" ) ) {
	    l.pop_back();
	}
    }

    for ( list<int>::iterator it = l.begin(); it != l.end(); it++ ) {
	if ( it != l.begin() ) {
	    printf(" ");
	}
	printf("%d", *it);
    }
    printf("\n");
    
    return 0;
}

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

void solve(){
    
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    vector<ll> vec;
    while(n > 0){
        n--;
        vec.push_back(n%26);
        n /= 26;
    }
    for(ll i=vec.size() - 1; i>=0; i--){
        cout<<string(1, 'a' + vec.at(i));
    }



   
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x, y;
	cin >> x >> y;

	if(x == 0 or y == 0) {
		if(x <= y) {
			cout << y - x << endl;
			return 0;
		} else {
			ll rsl = 1 + x - y;
			cout << rsl << endl;
			return 0;
		}
	}
	if(x <= y) {
		if(x >= 0 and y >= 0) {
			cout << y - x << endl;
			return 0;
		}
		if(x <= 0 and y >= 0) {
			if(abs(x) <= abs(y)) {
				ll rsl = 1 + y - abs(x);
				cout << rsl << endl;
				return 0;
			} else {
				ll rsl = abs(x) - y + 1;
				cout << rsl << endl;
				return 0;
			}
		}
		if(x <= 0 and y <= 0) {
			ll rsl = abs(x) - abs(y);
			cout << rsl << endl;
			return 0;
		}
	}

	if(x >= 0 and y >= 0) {
		ll rsl = 2 + x - y ;
		cout << rsl << endl;
		return 0;
	}

	if(x >= 0 and y <= 0) {
		if(abs(x) >= abs(y)) {
			ll rsl = 1 + x - abs(y);
			cout << rsl << endl;
			return 0;
		} else {
			ll rsl = 1 + abs(y) - x;
			cout << rsl << endl;
			return 0;
		}
	}

	if(x <= 0 and y <= 0) {
		ll rsl = 2 + abs(y) - abs(x);
		cout << rsl << endl;
		return 0;
	}

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

        int x = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        
        int res = x - a;
        int cnt = (int) Math.floor(res / b);
        res -= (cnt*b);

        System.out.println(res);

        scan.close();
    
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define eb emplace_back
#define mod (1000000007)
 
long int vis[100002] = {0};
   vector<long int> g[100002];


void dfs(int u,long int x,long int &value)
{
  // vis[u] = 1;

    value = max(value,x);
   for(auto v : g[u])
   {
      if(vis[v] == 0){
        x++;
       dfs(v,x,value);
      }
        x = 0;
   }
}
int main() {
 
  long long int t = 1;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
 
 //cin >> t;
  while(t--){
 
   long int n,m,x = 0,y = 0,start = 0,end = 0,index = 0,z;

      cin >> n >> m;

      long long int arr[n][m];

      char ch[n][m];

      for(int i = 0;i<n;i++)
       for(int j = 0;j<m;j++)
        cin >> ch[i][j];

        start = 1;
        for(int i = 1;i<m;i++)
        {
          if(start && ch[0][i] != '#')
              arr[0][i] = 1;
          else{
            start = 0;
            arr[0][i] = 0;
          } 

        }
        start = 1;
        for(int i = 1;i<n;i++)
        {
          if(start && ch[i][0] != '#')
              arr[i][0] = 1;
          else{
            start = 0;
            arr[i][0] = 0;
          } 
        }

      arr[0][0] = 0;

      for(int i = 1;i<n;i++)
      {
        for(int j = 1;j<m;j++)
        {
          if(ch[i][j] == '#')
             arr[i][j] = 0;
             else
            arr[i][j] = (arr[i-1][j]%mod + arr[i][j-1]%mod)%mod;
        }
      }
         
      cout << arr[n-1][m-1];
  } 
}


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

#define MAX 100

int n[MAX], top = 0; 

void push(int x)
{
    n[top] = x;
    top++;
}

int pop()
{
    top--;
    return n[top];
}

int main(void)
{
    int x, y;
    char str[10];
    
    while (scanf("%s", str) != EOF) {
        switch (str[0]) {
            case '+':
                y = pop();
                x = pop();
                push(x + y);
                break;
            case '-':
                y = pop();
                x = pop();
                push(x - y);
                break;
            case '*':
                y = pop();
                x = pop();
                push(x * y);
                break;
            default:
                push(atoi(str));
                break;
        }
    }
    printf("%d\n", n[0]);
    return 0;
}

Measured memory_bytes: 548
# 2019/07/13
# Union-Find
# Disjoint-Set

import sys
from collections import Counter
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

class union_find():
    def __init__(self,n):
        self.par=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def is_same(self,x,y):
        return self.find(x)==self.find(y)
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if self.rank[x]<self.rank[y]:
            self.par[x]=y
        else:
            self.par[y]=x
            if self.rank[x]==self.rank[y]:
                self.rank[x]+=1


n,k,l=map(int,input().split())
res=[1]*(n+1)
uf1=union_find(n)
for i in range(k):
    p,q=map(int,input().split())
    uf1.unite(p,q)

uf2=union_find(n)
for i in range(l):
    r,s=map(int,input().split())
    uf2.unite(r,s)

res=[]
for i in range(n+1):
    res.append((uf1.find(i),uf2.find(i)))
c=Counter(res)

ans=[]

for i in range(n+1):
    ans.append(c[res[i]])
print(*ans[1:])

Measured memory_bytes: 60316
#include <stdio.h>
int main(void)
{
	int H,W,i,j;
	while(1)
	{
		scanf("%d %d", &H, &W);
		if (H == 0 && W == 0)
		{
			break;
		}
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				if (i == 0 || i == H - 1)
				{
					printf("#");
				}
				else if (j == 0 || j == W - 1)
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	} 

	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char s[2001];
    cin>>s;
    int n=strlen(s);
    cout<<s;
    if(s[n-1]=='s')cout<<"es";
    else cout<<"s";
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int dx[] = {0, 1, 1, 0, -1, -1};
const int dy[] = {1, 1, 0, -1, -1, 0};
const int base = 100;

class state {
public:
    int x, y, t;
    state(int a, int b, int c) { x = a; y = b; t = c; }
};

int main()
{
    int t, n;

    while (cin >> t >> n, t || n) {
        int map[200][200]; // 0: 未到達   1: 敵    2: 到達済み
        int t_x, t_y, s_x, s_y;
        int ans = 0;
        
        memset(map, 0, sizeof(map));
        for (int i = 0; i < n; i++) {
            cin >> t_x >> t_y;
            map[t_y + base][t_x + base] = 1;
        }
        cin >> s_x >> s_y;

        queue<state> q;
        q.push(state(s_x + base, s_y + base, 0));
        map[s_y + base][s_x + base] = 2;
        ans++;

        while (!q.empty()) {
            state now = q.front();
            q.pop();

            for (int i = 0; i < 6; i++) {
                int nx = now.x + dx[i];
                int ny = now.y + dy[i];

                if (map[ny][nx] == 1 || map[ny][nx] == 2)
                    continue;
                if (now.t + 1 > t)
                    continue;
                map[ny][nx] = 2;
                ans++;
                q.push(state(nx, ny, now.t + 1));
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1376
require 'set'
io = STDIN
def expand(current_pool,cnt)
  pool=Set.new
  current_pool.each do |n|
    pool.add(n+cnt)
    pool.add(n-cnt)
  end
  pool
end
acts=io.gets.chomp.chars
      .chunk_while{|x,y|x==y}
      .map{|str|[str[0],str.size]}
x,y=io.gets.split.map(&:to_i)
ct=1
id,cnt=acts.shift
xpool=Set[((id=="F") ? cnt : 0)]
ypool=Set[0]
ct+=cnt if (id=="T")
acts.each do |act|
  id,cnt=act
  if id=="F"
    if ct.odd?
      xpool=expand(xpool,cnt)
    else
      ypool=expand(ypool,cnt)
    end
  else
    ct+=cnt
  end
end
puts xpool.include?(x) && ypool.include?(y) ? 'Yes' : 'No'


Measured memory_bytes: 90776
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

int main(){
  ll N;
  cin >> N;
  cout << ((2*N)/__gcd(2LL,N)) << endl;



  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;
using P = pair<int, int>;

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 int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  int n, k;
  cin >> n >> k;

  int mx = (n-1) * (n-2) / 2;
  if (k > mx) {
    puts("-1");
    return 0;
  }

  cout << n - 1 + mx - k << endl;

  // 頂点1とその他を全て繋ぐ
  for (int i = 2; i <= n; i++) {
    cout << 1 << " " << i << endl;
  }

  vector<P> edges;
  for (int i = 2; i < n; i++) {
    for (int j = i+1; j <= n; j++) {
      edges.push_back(P(i, j));
    }
  }

  rep(i, mx - k) {
    cout << edges[i].first << " " << edges[i].second << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define N 10
#define ll long long
int n, d;
ll x[N+1][N+1];

ll dist(int i, int j)
{
	ll tot = 0;
	for(int k = 0; k < d; k++)
	{
		tot += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
	}
	return tot;
}

int main() {
	cin >> n >> d;
	for(int i = 0; i < n; i ++)
	{
		for(int j = 0; j < d; j ++)
		{
			cin >> x[i][j];
		}
	}
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		for(int j = i+1; j < n; j++)
		{
			ll dd = dist(i,j);
			ll sqt = sqrt(dd);
			if(sqt * sqt == dd)
			{
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
typedef long long ll;
int main()
{
    ll a, b, c, n=0;
    ll i;
    scanf("%lld %lld %lld",&a,&b,&c);
    for(i=0; c>0 && b>0; i++) {
        b--;
        c--;
        n += 2;
    }
    for(i=0; a>0 && c>0; i++) {
        c--;
        a--;
        n += 1;
    }
    if(c>0) {
        c--;
        n++;
    }
    n += b;
    printf("%lld",n);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <string>
 
using namespace std;
 
int main(void){
    int n;
    scanf("%d",&n);
    int* a = new int[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << a[n - 1];
    for (int i = 1; i < n; i++) {
        cout << " " << a[n - i - 1];
    }
    cout << endl;
    delete[] a;
    return 0;
}

Measured memory_bytes: 1240
use proconio::input;
 
fn main() {
  input! {
    A: f64,
    B: usize,
  }
  
  let original = B * 10;
  for v in 0..10 {
    if ((original + v) as f64 * 0.08f64).floor() == A {
      println!("{}", original + v);
      return
    }
  }
  println!("{}", -1);
}

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

int main()
{
	int N;
	string str;
	
	cin >> N >> str;
	
	string ans[4];
	string end[4];
	
	ans[0]="S";end[0]="S";
	ans[1]="S";end[1]="W";
	ans[2]="W";end[2]="S";
	ans[3]="W";end[3]="W";
	
	for(int i=0;i<N-2;i++)
	{
		for(int j=0;j<4;j++)
		{
			if(i==0)
			{
				if((ans[j][i]=='S' && str[i]=='o') || (ans[j][i]=='W' && str[i]=='x'))
					ans[j]+=end[j];
				else if(end[j][0]=='S')
					ans[j]+="W";
				else
					ans[j]+="S";
			}
			else
			{
				if((ans[j][i]=='S' && str[i]=='o') || (ans[j][i]=='W' && str[i]=='x'))
					ans[j]+=ans[j][i-1];
				else if(ans[j][i-1]=='S')
					ans[j]+="W";
				else
					ans[j]+="S";
			}
		}
	}
	
	for(int i=0;i<4;i++)
	{
		ans[i]+=end[i];
		ans[i]+=ans[i][0];
		ans[i]=end[i]+ans[i];
	}
		
	
	for(int i=0;i<4;i++)
	{
		bool isok=true;
		for(int j=1;j<ans[i].size()-1;j++)
		{
			if((ans[i][j]=='S' && str[j-1]=='o') || (ans[i][j]=='W' && str[j-1]=='x'))
			{
				if(ans[i][j-1]!=ans[i][j+1])
				{
					isok=false;
					break;
				}
			}
			else
			{
				if(ans[i][j-1]==ans[i][j+1])
				{
					isok=false;
					break;
				}
			}
		}
		if(isok)
		{
			for(int j=1;j<ans[i].size()-1;j++)
				cout << ans[i][j];
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1152
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      String s = sc.next();
      int n = s.length();
      Deque<Integer> st = new ArrayDeque<Integer>();

      for (int i = 0; i < n; i++) {
        int c = s.charAt(i);
        if (st.isEmpty() || st.peek() == c) {
          st.push(c);
        } else {
          st.pop();
        }
      }
      System.out.println(n - st.size());
    } finally {
      sc.close();
    }
  }
}

Measured memory_bytes: 40416
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> in(n, 0);
	vector<vector<int> > out(n);
	for(int i = 0; i < n + m - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		in[b]++;
		out[a].push_back(b);
	}

	queue<int> qu;
	vector<int> ans(n);
	for(int i = 0; i < n; i++){
		if(in[i] == 0){
			qu.push(i);
			ans[i] = 0;
			break;
		}
	}

	while(!qu.empty()){
		int now = qu.front();
		qu.pop();
		for(int i = 0; i < out[now].size(); i++){
			int next = out[now][i];
			in[next]--;
			if(in[next] == 0){
				ans[next] = now + 1;
				qu.push(next);
			}
		}
	}

	for(int i = 0; i < n; i++){
		cout << ans[i] << endl;
	}
	return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    vector<int>v(3);
    cin >> v[0] >> v[1] >> v[2];
    int five = 0, seven = 0;
    for(int i=0; i<3; ++i)
    {
        if(v[i] == 5) five++;
        else if(v[i] == 7) seven++;
    }
    if(five == 2 && seven == 1) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 3608
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

n=ri()
a=rl()
a.sort()


import bisect

p = a[-1]
p2 = p/2
q_i = bisect.bisect_left(a,p2)
if ((a[q_i]-p2) > (p2 - a[q_i-1]) or p==a[q_i]) and q_i != 0:
    q_i -= 1
q = a[q_i]

print(p,q)

Measured memory_bytes: 14648
#include <cstdio>
#include <algorithm>

using namespace std;

int main(void){
    int num[2];
    
    for (int i = 0; ; i++){
        scanf("%d %d", &num[0], &num[1]);
        if (num[0] == 0 && num[1] == 0){
            break;
        }
        sort(num, num+2);
        printf("%d %d\n", num[0], num[1]);
    }

    return 0;
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using  P = pair<int,int>;
using LL = long long;
int n,in[M];
vector<P> s;
set<int> sp;
int main()
{
    while (~scanf("%d", &n)) {
        s.clear();
        sp.clear();
        REP(i,1,n) {
            scanf("%d", &in[i]);
            s.push_back(make_pair(in[i], i));
        }
        sort(s.begin(), s.end(), greater<P>());

        auto find_less = [&](int x) {
            auto it = sp.lower_bound(x);
            if (it==sp.begin()) return 0;
            it--;
            return *it;
        };
        auto find_more = [&](int x) {
            auto it = sp.upper_bound(x);
            if (it==sp.end()) return n+1;
            return *it;
        };

        LL ans = 0;
        for (auto itt: s) {
            int num = itt.first;
            int pos = itt.second;

            int l = find_less(pos);
            int r = find_more(pos);
            if (l!=0) {
                int ll = find_less(l);
                ans += (LL)(l-ll) * (r-pos) * num;
            }
            if (r!=n+1) {
                int rr = find_more(r);
                ans += (LL)(pos-l) * (rr-r) * num;
            }

            sp.insert(pos);
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define Phuong ios_base::sync_with_stdio(0); cin.tie(0);
typedef unsigned long long ll;
using namespace std;
typedef pair<int,int> pii;
#define mpp make_pair
#define pb push_back
const int MAXN = 1e5+5;
int a[6] = {100, 101, 102, 103, 104, 105};
bool dp[MAXN];

void init()
{
    memset(dp,false,sizeof(dp));
    dp[0]=true;
    for(int i=0; i<6; ++i)
    {
        for(int j=0; j<=MAXN-a[i]; ++j)
         if (dp[j]) dp[j+a[i]] = true;
    }
}

int main()
{
#ifndef RICARDO
    //freopen("input.inp", "r", stdin);
#endif // RICARDO
    Phuong;
    init();
    int n;
    cin >> n;
    if (dp[n]) cout << 1; else cout << 0;
    return 0;
}


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

int main() {
  
  int N;
  cin >> N;
  
  vector<pair<pair<string, int>, int>> p(N);
  
  for(int i=0; i<N; i++){ 
  	string S;
    int P;
    cin >> S >> P;
    
    p[i]=make_pair(make_pair(S, -P), i+1);
  }
  
  sort(p.begin(), p.end());
  
  for (int i=0; i<N; i++){
  	cout << p[i].second << endl;
  }

}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    Ds = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += Ds[i]*Ds[j]
    print(ans)

if __name__ == "__main__":
    solve()


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

int main(){
    int n,m;
    cin >> n;
    vector<string> s(n);
    vector<string> t(m);
    for (int i = 0;i < n;i++){
        cin >> s.at(i);
    }
    cin >> m;
    for (int i = 0;i < m;i++){
        cin >> t.at(i);
    }
    map<string,int> mp;
    for (int i = 0;i < n;i++){
        mp[s.at(i)]++;
    }
    for (int i = 0;i < m;i++){
        mp[t.at(i)]--;
    }

    int ans = 0;
    for (int i = 0;i < n;i++){
        if (ans < mp[s.at(i)]){
            ans = mp[s.at(i)];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import sys
from heapq import heappush,heappop
sys.setrecursionlimit(10**9)
INF = 10**18


def input():
    return sys.stdin.readline().rstrip()


def main():
    N,K=map(int,input().split())
    S=list(map(int,list(input())))
    f=S[0]
    left1=0
    for i,x in enumerate(S):
        if x==0:
            break
        else:
            left1+=1
    l=[left1]
    tmp=0
    pre=1
    for i,x in enumerate(S[left1:]):
        if pre!=x:
                l.append(tmp)
                tmp=0
        tmp+=1
        pre=x
    l.append(tmp)
    A=[0]*(len(l)+1)
    for i in range(len(l)):
        A[i+1]=A[i]+l[i]
    ans=0
    for i in range(len(l)+1):
        if i%2:
            ans=max(ans,A[i]-A[max(0,i-K*2)])
        else:
            ans=max(ans,A[i]-A[max(0,i-K*2-1)])
    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 53880
#include <bits/stdc++.h>
#define pb push_back 
#define x first 
#define y second 
#define MOD 998244353LL

#if 1
#define pi(x) printf("%s = %i; ", #x, x)
#define ps(x) printf("%s = %s; ", #x, x.c_str())
#define pn printf("\n");
#else  
#define pi(x)
#define ps(x)
#define pn
#endif

using namespace std;
typedef unsigned long long ll;
typedef pair< int , int > PII;
const int dirx[] = {0,1,0,-1};
const int diry[] = {1,0,-1,0};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

int n, a[100100], m;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    int rs = (m * 1900 + (n - m) * 100) * (1 << m);
    cout << rs;
	return 0;
}


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

// コンテスト中のみ
//#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
ll INF = (1LL << 60);
int MOD = 1000000007;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, Q; cin >> N >> Q;
	vector<ll>a(N); rep(i, N)cin >> a[i];
	rep(_, Q) {
		ll x; cin >> x;
		ll right = 0;
		ll now = 0;
		ll ans = 0;
		for (ll left = 0; left < N; left++) {
			while (right < N && now + a[right] <= x) {
				now += a[right]; right++;
			}
			ans += right - left;
			if (left == right)right++;
			else now -= a[left];
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3520
#include<bits/stdc++.h>
using namespace std;
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
int main(){
  string S;
  cin >> S;
  
  int val= ctoi(S[0])*100 + ctoi(S[1])*10 + ctoi(S[2]);
  int min = abs(753-val);
  
  for(int i=1; i<(S.size()-2); i++){
    val= ctoi(S[i])*100 + ctoi(S[i+1])*10 + ctoi(S[i+2]);
    if(min > abs(753-val)) min = abs(753-val);
  }

  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace I_am_an_idiot
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            string[] s;
            s = Console.ReadLine().Split(' ');
            a = Convert.ToInt32(s[0]);
            b = Convert.ToInt32(s[1]);
            c = Convert.ToInt32(s[2]);
            d = Convert.ToInt32(s[3]);
            while (true)
            {
                c -= b;
                if (c <= 0)
                {
                    Console.WriteLine("Yes");break;
                }
                a -= d;
                if (a <= 0)
                {
                    Console.WriteLine("No");break;
                }
            }
            return;
        }
    }
}

Measured memory_bytes: 17936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll psum[300005];
const int INF=1e9+7;
int main()
{
    string s;
    cin>>s;
    string s1[8]={" ","SAT","FRI","THU","WED","TUE","MON","SUN"};
    for(int i=1;i<=7;i++)
        if(s1[i]==s) cout<<i;
}


Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        p: [(i64, i64); n],
    }
    let mut p: Vec<(i64, i64)> = p.into_iter().map(|p| (p.0 - p.1, p.0 + p.1)).collect();
    p.sort_by_key(|p| p.1);
    let mut ans = 1;
    let mut r = p[0].1;
    for p in p[1..].iter() {
        if p.0 >= r {
            ans += 1;
            r = p.1;
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define vi std::vector<int>
#define pi std::pair<int, int>
#define mp std::make_pair
#define stdabs std::abs
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
#define Yes std::cout << "Yes" << std::endl
#define No std::cout << "No" << std::endl
#define YES std::cout << "YES" << std::endl
#define NO std::cout << "NO" << std::endl
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
unsigned long long modpow(int x__, int n__, long long mod__);
template <typename T> void debug(const T& t);
constexpr ll mod10_9p7 = 1000000000 + 7;

/**************************************************************/
int main()
{
    stat();
    int n, k;
    cin>>n>>k;
    vec<int>x(n);
    rep(i,n){
cin>>x[i];
    }
    ull ans=0;
    rep(i,n){
	    ans+=(2*min(x[i],abs(k-x[i])));
    }
cout<<ans<<endl;

    return 0;
}
/**************************************************************/
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}

unsigned long long modpow(int x__, int n__, long long mod__)
{
    long long ret__ = 1;
    for (long long i__ = 0; i__ < n__; ++i__) {
        ret__ = ret__ * x__ % mod__;
    }
    return ret__;
}

template <typename T> void debug(const T& t)
{
#ifdef local
    dbg(t);
#endif
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int INF=100000000;
int N, A, B, C;
int l[1001];

int dfs(int cur, int a, int b, int c) {
  if(cur == N) {
    int tmp = min(a,b);
    tmp = min(tmp, c);
    if(tmp > 0) {
      return abs(a-A) + abs(b-B) + abs(c-C) - 30;
    } else {
      return INF;
    }
  }
  int ans;
  int ret0 = dfs(cur+1, a, b, c);
  int ret1 = dfs(cur+1, a+l[cur], b, c) + 10;
  ans = min(ret0, ret1);
  int ret2 = dfs(cur+1, a, b+l[cur], c) + 10;
  ans = min(ans, ret2);
  int ret3 = dfs(cur+1, a, b, c+l[cur]) + 10;
  ans = min(ans, ret3);
  return ans;
}

int main() {
  cin >> N >> A >> B >> C;
  for(int i = 0; i < N; ++i) cin >> l[i];
  cout << dfs(0,0,0,0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <pair<string, int>, int> P;
const ll MOD=1000000007;
int N;
vector<P> v;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    v.resize(N);
    rep(i,0,N){
        string s;
        int p;
        cin>>s>>p;
        v[i].fr.fr=s;
        v[i].fr.sc=-p;
        v[i].sc=i;
    }
    sor(v);
    rep(i,0,N){
        cout <<v[i].sc+1<<"\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int n, k;
	cin >> n >> k;
	int p[200005];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	double ans = 0;
	for (int i = 0; i < n; i++) {
		ans = (double)(((1 + p[i]) * p[i]) / 2)/p[i];
		q[i] = ans;
	}
	
	double sum = 0;
	for (int i = 0; i < k; i++) {
		sum += q[i];
	}
	double max = sum;
	double kai = 0;
	for (int i = k; i < n; i++) {
		kai = (sum - q[i - k]) + q[i];
		if (max < kai) {
			max = kai;
		}
		sum = kai;
	}
	printf("%.12f", max);
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main()
{   
    int x,y,z=0;
    int t=300000;
    int s=200000;
    int q=100000;
    int r=400000;
    scanf("%d", &x);
    scanf("%d", &y);
    if(x==1 && y==1)
    {
        z=t+t+r;
        //printf("%d",z);
    }
    else if(x==2 && y==2)
    {
        z=s+s;
        //printf("%d",z);
    }
    else if(x==3 && y==3)
    {
        z=q+q;
        //printf("%d",z);
    }
     else if((x==1 && y==2) || (x==2 && y==1))
    {
        z=s+t;
    }
       else if((x==1 && y==3) || (x==3 && y==1))
    {
        z=q+t;
    }
       else if((x==3 && y==2) || (x==2 && y==3))
    {
        z=s+q;
    }
    else if(x==1 || y==1)
    {
        z=t;
    }
     else if(x==2 || y==2)
    {
        z=s;
    }
     else if(x==3 || y==3)
    {
        z=q;
    }
     printf("%d",z);
    return 0;    
}


Measured memory_bytes: 128
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b=gsmi
putsend(-1) if a>=10 || b>=10
puts a*b


Measured memory_bytes: 1788