akhauriyash/Code-Regression huggingface dataset:
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define ei else if
#define all(a) a.begin(),a.end()
#define size(s) ((LL)s.size())
#define F first
#define S second
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define int_INF 1<<29
#define ll_INF 1LL<<60
#define MOD 1000000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<LL>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using mcl = map<char, LL>;
using vpi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50  //グラフの最大位数　適宜変更
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b,m) f(i,0,m){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

void _yn(bool p) {
	p ? _y() : _n();
}

void _YN(bool p) {
	p ? _Y() : _N();
}


LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		ret %= MOD;
	}
	return ret;
}

#pragma endregion 



/*****************************************************************************/

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

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if (k % 2 == 0) {
		ans += (a - b);
	}
	else {
		ans += (b - a);
	}
	if (ans > 1e18) {
		cout << "Unfair";
	}
	else {
		cout << ans;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    Scanner in = new Scanner(System.in);
    public void solve() {
        int a = in.nextInt(), b = in.nextInt();
        if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
        		System.out.println("Possible");
        }else {
        		System.out.println("Impossible");
        }

    }

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

Measured memory_bytes: 23764
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int n,x,buf;
	vector<int> m;
	cin >> n >> x ;
	REP(i, n) {
		cin >> buf;
		x -= buf;
		m.push_back(buf);
	}
	sort(m.begin(), m.end());
	cout << x/m[0] + m.size();
	return(0);
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

func solve(lev, num int, nums, p []int) int {
	if lev == 0 {
		if num == 1 {
			return 1
		} else {
			return 0
		}
	} else {
		if num == 1 {
			return 0
		} else if num <= nums[lev-1]+1 {
			return solve(lev-1, num-1, nums, p)
		} else if num == nums[lev-1]+2 {
			return p[lev-1] + 1
		} else if num <= nums[lev-1]*2+2 {
			return solve(lev-1, num-(nums[lev-1]+2), nums, p) + p[lev-1] + 1
		} else {
			return p[lev-1]*2 + 1
		}
	}
}

func rec(N, X int, t, p []int) int {
	if N == 0 {
		if X == 0 {
			return 1
		}
		return 0
	} else {
		if X == 1 {
			return 0
		} else if X <= t[N-1]+1 {
			return rec(N-1, X-1, t, p)
		} else if X == t[N-1]+2 {
			return p[N-1] + 1
		} else if X <= t[N-1]*2+2 {
			return rec(N-1, X-(t[N-1]+2), t, p) + p[N-1] + 1
		} else {
			return p[N-1]*2 + 1
		}
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)

	N, X := getInt(), getInt()

	p := make([]int, 51)
	t := make([]int, 51)

	p[0] = 1
	t[0] = 1

	for i := 1; i <= N; i++ {
		t[i] = t[i-1]*2 + 3
		p[i] = p[i-1]*2 + 1
	}

	ans := solve(N, X, t, p)
	out(ans)
}


Measured memory_bytes: 640
function Main(input) {
  input = input.split("\n");
  var a = parseInt(input[0].split(" ")[0]);
  var b = parseInt(input[0].split(" ")[1]);
  var ans ="Yes";
  if(a%2==0||b%2==0){
    ans="No";
  }

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>


using namespace std;

int main()
{
    int L, N;
    cin >> N >> L;
    vector<string> s(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end(), [](string s1, string s2) {
        return strcmp(s1.c_str(), s2.c_str()) < 0;
    });

    for (auto &_s : s)
    {
        cout << _s;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int dx[4]={1, 0, 0,-1};
int dy[4]={0, 1,-1, 0};

struct info{
	int y;
	int x;
	int dist;
	info(int y, int x, int d): y(y),x(x),dist(d){}
};

int main(){
	int h,w;
	cin >> h >> w;
	vector<vector<char> > map(h+2, vector<char>(w+2, '#'));
	int sy, sx;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			cin >> map[i][j];
			if(map[i][j]=='%'){
				sy = i;
				sx = j;
			}
		}
	}
	
	queue<info> q;
	q.push(info(sy, sx, 0));
	map[sy][sx] = '#';
	int princess=-1, soldier=-1;
	while(!q.empty()){
		int y=q.front().y;
		int x=q.front().x;
		int d=q.front().dist;
		q.pop();
		for(int i=0; i<4; i++){
			int ny=y+dy[i], nx=x+dx[i];
			if(map[ny][nx] != '#'){
				if(map[ny][nx]=='@'){
					princess=d;
				}
				if(map[ny][nx]=='$' && soldier==-1){
					soldier=d;
				}
				q.push(info(ny, nx, d+1));
				map[ny][nx] = '#';
			}
		}
	}
	
	if(soldier==-1 || princess < soldier){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

const int N = 200005;

int n;
char s[N];

int solve() {
  scanf("%d", &n);
  scanf("%s", s);

  int l = 0, r = n-1;
  int ans = 0;
  while (l <= r) {
    while (l < n && s[l] == 'R') ++l;
    while (r >= 0 && s[r] == 'W') --r;

    if (l <= r) ++ans;
    ++l, --r;
  }

  printf("%d\n", ans);
  return 0;
}

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


Measured memory_bytes: 3992
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    n, k = map(int,input().split())
    x = 1
    y = 0
    while n:
        n //= k
        y += 1
    print(y)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
from collections import Counter
N, P = map(int, input().split())
pr = P
c = Counter()
i = 2
while i*i<=P:
  while pr%i == 0:
    c[i] += 1
    pr //= i
  i += 1
if pr>1:
  c[pr] += 1
r = 1
for p in c:
  while c[p]>=N:
    r *= p
    c[p] -= N
print(r)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pair<int, int> x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

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

const ll MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e7;
const int MX = 100001; //check the limits, dummy

ll p(ll n, ll x) {
    ll ans = 1, cur = n;
    while(x) {
        if(x & 1) ans = (cur * ans) % MOD;
        cur = (cur * cur) % MOD;
        x >>= 1;
    }
    return ans;
}

struct Res {
    ll g, x, y;
};

Res modinv(ll a, ll b) {
    if(b == 0) return {a, 1, 0};
    Res prev = modinv(b, a % b);
    return {prev.g, prev.y, prev.x - a / b * prev.y};
}

ll ncr(ll n, ll r) {
    ll ans = 1, den = 1;
    for(int i = n; i > n - r; i--) ans = (ans * i) % MOD;
    for(int i = 2; i <= r; i++) den = (den * i) % MOD;
    ll inv = modinv(den, MOD).x;
    return (ans * inv + MOD) % MOD;
}

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

    ll n, a, b;
    cin >> n >> a >> b;
    ll x = p(2, n);
    ll y = ncr(n, a);
    ll z = ncr(n, b);
    cout << (x - y - z - 1 + MOD) % MOD << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,a[201],i,cnt=-1,flag=1;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	while(flag==1){
		for(i=0;i<n;i++){
			if(a[i]%2==1)flag=0;
			a[i]/=2;
		}
	cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}
	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
//typedef long long float;
#define int long long
typedef pair<int, int> pii;
//#define float unsigned long long
typedef pair<int, int> pii;
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 
#define pi pair<int,int> 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y) 
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b) 
{
	return (long long) a * b % MOD2;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

int isPalindrome(string a)
{
    string rev=a;
    reverse(a.begin(),a.end());
    if(a==rev)
    return 1;
    else
    return 0;
}


int32_t main()
{
    FAST
    cout << fixed << setprecision(2);
 
    int n,m;
    cin>>n>>m;
    int a=(n*(n-1))/2;
    int b=(m*(m-1))/2;
    cout<<a+b<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long long  N,A,B,sum=0;
	scanf("%lld %lld %lld",&N,&A,&B);
	sum+=N/(A+B)*A;
	sum+=min(N%(A+B),A);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll  long long int
#define pb push_back
#define IO ios::sync_with_stdio(false);
typedef vector<int> vi;
#define H return 0;
#define C continue;
#define B break;
#define sec second
int countDivisors(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
int main()
{IO
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++)
  {
      if(countDivisors(i)==8&&i%2==1)
        ans++;
  }
  cout<<ans;
}


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

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

using namespace std;

string reversStr(string s){
    string r = "";
    for(int i = s.length()-1;i >= 0;i--){
        r += s[i];
    }
    return r;
}

int main(){

    int n;
    string s;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> s;
        set<string> slist;
        for(int j = 1;j < s.length();j++){
            string ls = s.substr(0,j);
            string rs = s.substr(j,s.length()-j);
            slist.insert(ls+rs);
            slist.insert(rs+ls);
            slist.insert(reversStr(ls)+rs);
            slist.insert(reversStr(rs)+ls);
            slist.insert(rs+reversStr(ls));
            slist.insert(ls+reversStr(rs));
            slist.insert(reversStr(ls)+reversStr(rs));
            slist.insert(reversStr(rs)+reversStr(ls));
        }
        cout << slist.size() << endl;
    }

	return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
int main(void)
{
	int i, n, m;

	for (i = 1;; i++) {
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0) {
			break;
		}
		if (n > m) {
			printf("%d %d\n", m, n);
		}
		else {
			printf("%d %d\n", n, m);
		}
	}

	return(0);
}


Measured memory_bytes: 2140
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

bool is_bigger(int x, int y, int h, int w) {
    int ar = x*x + y*y;
    int br = h*h + w*w;
    if(ar != br) return ar > br;
    return x > h;
}

void solve(int H, int W) {
    int ax = 300, ay = 300;
    for(int x=1; x<=150; x++) {
        for(int y=x+1; y<=150; y++) {
            if(is_bigger(x, y, H, W)) {
                if(is_bigger(ax, ay, x, y)) {
                    ax = x;
                    ay = y;
                }
            }
        }
    }
    cout << ax << " " << ay << endl;
}

int main() {
    int H, W;
    while(cin >> H >> W, H || W) solve(H, W);
    return 0;
}



Measured memory_bytes: 3036
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();	
		int C = 0;
		if(A <= B || A <= B*2) {
			C = 0;
		}else {
			C = A - B*2;
		}
		
		System.out.println(C);
		
		sc.close();
	}
}

Measured memory_bytes: 22996
#include<stdio.h>

int main(){
  int a, b;
  char op;
  int res;

  while(1){
    scanf("%d %c %d", &a, &op, &b);

    if(op == '?') break;

    if(op == '+'){
      res = a + b;
    }
    else if(op == '-'){
      res = a - b;
    }
    else if(op == '*'){
      res = a * b;
    }
    else if(op == '/'){
      res = a / b;
    }

    printf("%d\n", res);
  }
  
  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<int> vs,vw;
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int w=0;
    int sw=f/(100+e)*(e+1);
    for(int i=0;i*100*a<=f;++i){
        for(int j=0;j*100*b<=f;++j){
            if(i*100*a+j*100*b<=f&&(i!=0||j!=0)){
                vw.pb(i*100*a+j*100*b);
            }
        }
    }
    for(int i=0;i*c<=sw;++i){
        for(int j=0;j*d<=sw;++j){
            if(i*c+j*d<=sw){
                vs.pb(i*c+j*d);
            }
        }
    }
    int fw,s;
    double con=-1;
    rep(i,vw.size())rep(j,vs.size()){
        if(vw[i]+vs[j]<=f){
            if(con*(vw[i]+vs[j])<100*vs[j]&&(double)vw[i]/100*e>=vs[j]){
                con=(double)(100*vs[j])/(vw[i]+vs[j]);
                fw=vw[i]+vs[j];s=vs[j];
            }
        }
    }
    cout<<fw<<" "<<s<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 8;
bool vis[N][N];
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};
int ans;

void countup(int r,int c,int y,int x,int &cnt,int tar,
             int m[N][N]){
  if (vis[y][x])return;
  vis[y][x]=true;
  cnt++;
  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (nex == -1 || nex == c || ney == -1 || ney == r ||
        m[ney][nex] != tar)continue;
    countup(r,c,ney,nex,cnt,tar,m);
  }
}

void coloring(int r,int c,int y,int x,int tar,int prev,int m[N][N]){
  if (vis[y][x])return;
  vis[y][x]=true;
  rep(i,4){
    int nex=x+dx[i],ney=y+dy[i];
    if (nex == -1 || nex == c || ney == -1 || ney == r)continue;
    if (m[ney][nex] != prev)continue;
    m[ney][nex]=tar;
    coloring(r,c,ney,nex,tar,prev,m);
  }
}


void search(int r,int c,int now,int tar,int m[N][N]){
  if (now == 5){
    //cout << m[0][0] <<" " << tar << endl;
    if (m[0][0] != tar)return;
    /*
    rep(i,r){
      rep(j,c){
        cout << m[i][j]<<" ";
      }
    }
    cout << endl;
    */
    int cnt=0;
    rep(ii,r)rep(jj,c)vis[ii][jj]=false;
    countup(r,c,0,0,cnt,tar,m);
    ans=max(ans,cnt);
    return;
  }
  REP(i,1,7){
    int tmp[N][N];
    rep(ii,r)rep(jj,c)tmp[ii][jj]=m[ii][jj];
    rep(ii,r)rep(jj,c)vis[ii][jj]=false;
    tmp[0][0]=i;
    coloring(r,c,0,0,i,m[0][0],tmp);
    search(r,c,now+1,tar,tmp);
  }
}

main(){
  int r,c,tar;
  while(cin>>r>>c>> tar && r){
    int in[8][8];
    rep(i,r){
      rep(j,c){
        cin>>in[i][j];
      }
    }
    ans=0;
    search(r,c,0,tar,in);
    cout << ans << endl;
  }
  return false;
}

Measured memory_bytes: 872
/*
３つの整数を読み込み、それらを値が小さい順に並べて出力するプログラムを作成して下さい。
 */

#include <stdio.h>

void swap(int *a, int *b)
{
    int temp;

    temp = *a;
    *a = *b;
    *b = temp;
}

int main(void)
{
    int array[3];
    int i, j;

    for(i = 0; i < 3; i++)
    {
        scanf("%d", &array[i]);
    }

    // sorting
    for(i = 0; i < 2; i++)
    {
        for(j = i + 1; j < 3; j++)
        {
            if (array[i] > array[j])
            {
                swap(&array[i], &array[j]);
            }
        }
    }
    printf("%d %d %d\n", array[0], array[1], array[2]);
    return (0);
}


Measured memory_bytes: 2060
s = int(input())
if s == 2:
    print(4)
    quit()
if s == 1:
    print(4)
    quit()
count = 1
c4 = 0
while True:
    if s == 4:
        print(count+3)
        break
    if s%2==0:
        s = s//2
    else:
        s = s*3+1
    count += 1

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define CHOR 100001

int arr[CHOR];
int sze[CHOR];
 
class dsu
{
	public: int root(int x)
			{
				while(x != arr[x])
				x = arr[arr[x]];
				return x;	
			}
 
			void find_union(int x, int y)
			{
				int rx = root(x);
				int ry = root(y);
				if(rx == ry)
				return;
				if(sze[rx] > sze[ry])
				{
					arr[ry] = rx;
					sze[rx] += sze[ry];
				}	
				else
				{
					arr[rx] = ry;
					sze[ry] += sze[rx];
				}	
				return;
			}
};

int main(void)
{
	int n,m;
	std::cin>>n>>m;
	for(int i=1;i<CHOR;i++)
	{
		arr[i] = i;
		sze[i] = 1;
	}	
	int a[n];
	for(int i=0;i<n;i++)
	std::cin>>a[i];
	dsu T;
	for(int i=0;i<m;i++)
	{
		int x,y;
		std::cin>>x>>y;
		T.find_union(a[x-1], a[y-1]);
	}	
	int ctr = 0;
	for(int i=1;i<=n;i++)
	{
		if(T.root(i) == T.root(a[i-1]))
		ctr++;	
	}	
	std::cout<<ctr<<"\n";
	return 0;	
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string S;
    cin >> S;
    bool a = false, b = false;
    for(int i = 0; i < 3; i++){
        if(S[i] == 'A') a = true;
        else b = true;
    }
    if(a&&b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
#define LENGTH 100

int main(){
  
  vector<int> Digit(LENGTH, 0);
  
  
  int tmp;
  int cnt=0;
  while(cin >> tmp){
    cnt++;
    Digit[tmp]++;
  }
  int max = 0;
  vector<int> maxDigits;
  for(int i=0;i<cnt;i++){
    if(Digit[i]>max){
      //      vector<int>().swap(maxDigits); //
      maxDigits.clear();
      maxDigits.push_back(i);
      max = Digit[i];
      //      cout << i << ">:" << endl; 
    }else{
      if(Digit[i]==max){
	maxDigits.push_back(i);
	//	cout << i << "==:" << endl;
      }
    }
  }

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

  for(int i=0;i<maxDigits.size();i++){
    cout << maxDigits[i] << endl;
  }
    
  
}

Measured memory_bytes: 1216
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ps = readLine()!!.split(' ').map { it.toInt() }
    var ans = 0
    for (i in (1 until n - 1)) {
        val xs = listOf(ps[i - 1], ps[i], ps[i + 1]).sorted()
        if (ps[i] == xs[1]) {
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 36388
xy = list(map(int, input().split()))
A = [2]
B =[4,6,9,11]
C = [1,3,5,7,8,10,12]

if (xy[0]in B and xy[1] in B) or (xy[0]in C and xy[1] in C):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w;
  cin >> h >> w;
  vector<string> sv(h);
  REP(i,h) cin >> sv[i];
  
  REP(i,w+2) cout << '#';
  cout << '\n';
  REP(i,h) cout << '#' << sv[i] << "#\n";
  REP(i,w+2) cout << '#';
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
import numpy as np
import math
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()

a, b, x = imap()
ans = (b//x) - (a//x)
if a % x == 0: ans += 1
print(ans)

Measured memory_bytes: 13232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin>>s;
	ll ans=1e9;
	for(char c='a';c<='z';c++){
		ll num=0,cnt=0;
		for(int i=0;i<s.size();i++){
			if(s[i]==c){
				num=max(num,cnt);
				cnt=0;
			}else cnt++;
		}
		num=max(num,cnt);
		ans=min(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILL(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  string s;
  cin >> s;
  if(s == "Sunny")cout << "Cloudy";
  if(s == "Cloudy")cout << "Rainy";
  if(s == "Rainy")cout << "Sunny";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
  int x,a;
  cin >> x >> a;
  if(x<a){
    cout << "0" << endl;
  }else{
    cout<< "10" << endl;
  }
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        int h; cin >> h;

        if (h >= k) ++ans;
    }

    cout << ans << endl;
}

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

int main(){
    int x;
    int sat=0;
    scanf("%d",&x);
    sat = x/500;
    sat *=1000;
    x = x%500;
    int temp;
    temp = x/5 ;
    temp *=5;

    sat = sat +temp;

    printf("%d",sat);
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int s;
    cin>>s;
    int ans=0;
    init_fact(10000);
    for(int n=1;3*n<=s;n++){
        int t=s-3*n;
        ans+=comb(t+n-1,t);
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3780
#include<stdio.h>

int dp[50];

int fib(int n){
	if(n == 0 || n == 1){
		return dp[n] = 1;
	}
	if(dp[n] != -1){
		return dp[n];
	}
	
	return dp[n] = fib(n - 1) + fib(n - 2);
}

int main(void){
	int n;
	for(int i = 0; i < 50; i++){
		dp[i] = -1;
	}
	
	scanf("%d", &n);
	printf("%d\n", fib(n));
	
	return 0;
}


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

int main() {
  
  ll a, b, k;
  cin >> a >> b >> k;
  
  ll ia = a, ib = b;
  
  a -= min(ia,k);
  k -= min(ia,k);
  b -= min(ib,k);
  k -= min(ib,k);
  
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 10000000000000000
int main() {
    long long int N, W;
    cin >> N >> W;
    long long int weight[N], value[N];
    for(int i = 0; i < N; i++) {
        cin >> weight[i] >> value[i];
    }
    long long int dp[N+1][100100];
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j < 100100; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int sum_v = 0; sum_v < 100100; sum_v++) {
            if(sum_v - value[i] >= 0) {
                dp[i+1][sum_v] = min(dp[i+1][sum_v],
                 dp[i][sum_v - value[i]] + weight[i]);
            }
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    long long int result = 0;
    for(int sum_v = 0; sum_v < 100100; sum_v++) {
        if(dp[N][sum_v] <= W) {
            result = sum_v;
        }
    }
    cout << result << endl;
    return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    long long int a, b, r = 1;
    while (cin >> a >> b)
    {
        if (a < b)
        {
            long long int temp;
            temp = b;
            b = a;
            a = temp;
        }
        long long int tempa = a, tempb = b;
        r = b;
        b = a;
        while (r != 0)
        {
            a = b;
            b = r;
            r = a % b;
        }
        long long ans = tempa * tempb / b;
        cout << b << " " << ans << endl;
    }
    return 0;
}

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

#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

string s;

int a[300000];

vector<string> poti;
vvi lobada;

string temp;
int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
	cin>>s;
	int ind = 0;
	while(ind<s.length())
	{
		temp.clear();
		while(ind<s.length())
		{
			temp.pb(s[ind]);
			if(s[ind]=='L'&&s[ind+1]=='R')
			{
				ind++;
				break;
			}
			ind++;
		}
		poti.pb(temp);
	}
	for(int i=0;i<poti.size();i++)
	{
		vi temp;
		//cout<<"poti.length()= "<<poti[i].length()<<endl;
		for(int j=0;j<poti[i].length();j++)
		{
			temp.pb(0);
		}
		lobada.pb(temp);
	}
	//cout<<lobada.size()<<endl;
	for(int i=0;i<poti.size();i++)
	{
		//cout<<"i = "<<i<<endl;
		int total = poti[i].length();
		int tepo = 0;
		while(poti[i][tepo]=='R')
			tepo++;
		//cout<<"tepo = "<<tepo<<endl;
		int R = tepo;
		int L = total - R;
		int Rpe = (R+1)/2 + L/2;
		int Lpe = total - Rpe;
		lobada[i][tepo] = Lpe;
		lobada[i][tepo-1]=Rpe;
	}
	//cout<<"lobada = "<<endl;
	for(int i=0;i<lobada.size();i++)
	{
	//	cout<<"i = "<<i<<endl;
		for(int j=0;j<lobada[i].size();j++)
			cout<<lobada[i][j]<<" ";
	}
	return 0;
}

Measured memory_bytes: 6080
class Dice
  def initialize(n)
    @dice = n
  end

  def rot_W
    @dice = [@dice[2], @dice[1], @dice[5], @dice[0], @dice[4], @dice[3]]
  end
  def rot_S
    @dice = [@dice[4], @dice[0], @dice[2], @dice[3], @dice[5], @dice[1]]
  end
  def rot_E
    @dice = [@dice[3], @dice[1], @dice[0], @dice[5], @dice[4], @dice[2]]
  end
  def rot_N
    @dice = [@dice[1], @dice[5], @dice[2], @dice[3], @dice[0], @dice[4]]
  end

  def dice_top
    @dice[0]
  end
end

dice = Dice.new(gets.split(" ").map(&:to_i))
s = gets
for i in 1..s.length
  if s[i-1] == "W"
    dice.rot_W
  elsif s[i-1] == "S"
    dice.rot_S
  elsif s[i-1] == "E"
    dice.rot_E
  elsif s[i-1] == "N"
    dice.rot_N
  else
  end
end
puts dice.dice_top



Measured memory_bytes: 6880
fn main() {
    let (a, b, c, k) = read();
    let ans = solve(a, b, c, k);
    write(ans);
}
 
fn read() -> (u64, u64, u64, u64) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let mut iter = s.split_whitespace();
    let a = iter.next().unwrap().parse::<u64>().unwrap();
    let b = iter.next().unwrap().parse::<u64>().unwrap();
    let c = iter.next().unwrap().parse::<u64>().unwrap();
    let k = iter.next().unwrap().parse::<u64>().unwrap();
 
    (a, b, c, k)
}
 
fn write(x: i64) {
    println!("{}", x);
}
 
fn solve(a: u64, b: u64, c: u64, k: u64) -> i64 {
    let mut r = k;
    let x = 
        if r >= a {
            a
        } else {
            r
        };
        r -= x;
 
        let y =
        if r >= b {
            b
        } else {
            r
        };
        if r > 0 {
            r -= y;
        }
        let z =
        if r >= c {
            c
        } else {
            r
        };
        //r -= z;
    
        (x as i64) - (z as i64)
}


Measured memory_bytes: 2092
while True:
    try:
        w = float(raw_input())
        if w <= 48.0:
            print  "light fly"
        elif w <= 51.0:
            print "fly"
        elif w <= 54.0:
            print "bantam"
        elif w <= 57.0:
            print "feather"
        elif w <= 60:
            print "light"
        elif w <= 64.0:
            print "light welter"
        elif w <= 69.0:
            print "welter"
        elif w <= 75.0:
            print "light middle"
        elif w <= 81.0:
            print "middle"
        elif w <= 91.0:
            print "light heavy"
        else:
            print "heavy"
    except:
        break

Measured memory_bytes: 4224
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

int n,d[200],cnt[401];
set<vi> ans; vi tmp;
void rec(int c,int right){
	//cerr<<c<<" "<<right<<endl;
	//rep(i,tmp[0]+1)if(cnt[i])rep(j,cnt[i])cerr<<i<<" "; cerr<<endl;
	if(c==n){
		vi d,e=tmp; sort(all(e));
		rep(i,n-1)d.pb(e[i+1]-e[i]);
		if(!ans.count(d))ans.insert(d);
		return;
	}
	int mx=right;
	for(;mx>=0&&cnt[mx]==0;mx--);
	if(mx<0)return;
	
	rep(it,2){
		tmp.pb(mx);
		bool ok=1;
		rep(i,c)if(--cnt[abs(tmp[i]-mx)]<0)ok=0;
		if(ok)rec(c+1,it?tmp[0]-mx:mx);
		rep(i,c)cnt[abs(tmp[i]-mx)]++;
		tmp.erase(tmp.begin()+c);
		
		if(mx==tmp[0]-mx)break;
		mx=tmp[0]-mx;
	}
}

int main()
{
	while(cin>>n,n){
		ans.clear();
		rep(i,401)cnt[i]=0;
		rep(i,n*(n-1)/2)cin>>d[i],cnt[d[i]]++;
		
		int mx=*max_element(d,d+n*(n-1)/2);
		tmp.clear(); tmp.pb(mx); tmp.pb(0); cnt[mx]--;
		rec(2,mx);
		fr(i,ans)rep(j,n-1)cout<<(*i)[j]<<(j==n-2?"\n":" ");
		cout<<"-----"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
x = int(input())
if x <= 6:
	print(1)
elif  x <= 11:
	print(2)
else:
	a,b = divmod(x,11)
	if b == 0:
		print(a*2)
	elif 1 <= b <= 6:
		print(a*2+1)
	else:
		print(a*2+2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,c=0,d=0,e=0,result=0;
	cin>>a>>b;
	c=a+b;
	d=a-b;
	e=a*b;
	if(c<d)
	{
		if(e<d)
		{
			result=d;
		}
		else
		{
			result=e;
		}
	}
	else
	{
		if(c<e)
		{
			result=e;
		}
		else
		{
			result=c;
		}
	}
	cout<<result;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>

const int MAXN=1e5+5;

int n;
int a[MAXN];

int main()
{
	int i;scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",a+i);
	int ans=0;
	for(i=1;i<=n+1;i++) ans+=abs(a[i]-a[i-1]);
	for(i=1;i<=n;i++)
	{
		int det=-abs(a[i-1]-a[i])-abs(a[i+1]-a[i])+abs(a[i-1]-a[i+1]);
		printf("%d\n",ans+det);
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase
#include <ctime>    // clock

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

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


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

#define int long long

using namespace std;

const int maxn = 20;
int a[maxn][maxn], dp[1 << maxn], p[1 << maxn], n;

signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;

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

    for (int mask = 1; mask < (1 << n); mask++)
    {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < i; j++)
                if ((mask >> i & 1) && (mask >> j) & 1)
                    p[mask] += a[i][j];
        dp[mask] = p[mask];
        for (int sub = mask; sub; sub = (sub - 1) & mask)
            dp[mask] = max(dp[mask], dp[mask ^ sub] + p[sub]);
    }

    cout << dp[(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define N 200005
using namespace std;
int n;
long long ans;
char a[N];
int main(){
	scanf("%s",a+1);
	n=strlen(a+1);
	int cnt=0;
	for(int i=n;i;i--){
		if(a[i]=='B') ans+=cnt;
		else cnt++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	int ans = inf;
	for (int i = -101; i <= 101; ++i) {
		int tmp = 0;
		rep(j, n) tmp += abs(a[j] - i) * abs(a[j] - i);
		mins(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
int main(){
  int n,m,p,i,s,x[101];
  while(1){
    memset(x,0,sizeof(x));s=0;
    scanf("%d%d%d",&n,&m,&p);p=100-p;
    if(!n&&!m)return 0;
    for(i=1;i<=n;i++){
      scanf("%d",x+i);
      s+=x[i];
    }
    printf("%d\n",x[m]?p*s/x[m]:0);
  }
}

Measured memory_bytes: 600
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long 
#define PI 3.14159265358979323846
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(x,n) for(ll x=1;x<(ll)n+1;x++)
using namespace std;

int main() {
	ll N;
	string ans;
	cin >> N;
	while (N > 0) {
		N--;
		ll m = N % 26;
		char a = 'a' + m;
		ans.push_back(a);
        N/=26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3560
import java.util.*;
import java.awt.geom.*;

public class Main{
	double EPS = 1.0e-08;
	
	//1755 start
	//1831 sample match
	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			ArrayList<Point2D> polygon = new ArrayList<Point2D>();
			for(int i = 0; i < n; i++){
				polygon.add(new Point2D.Double(sc.nextDouble(), sc.nextDouble()));
			}
			Line2D [] lineList = new Line2D[n];
			for(int i = 0; i < n; i++){
				Point2D from = polygon.get(i), to = polygon.get((i+1) % n);
				Line2D nowSegment = new Line2D.Double(from, to);
				lineList[i] = segmentToLine(nowSegment);
			}
			
			boolean ansflg = true;
			for(int i = 0; i < n; i++){
				polygon = polygoncut(polygon, lineList[i]);
				if(polygon.size() < 3){
					ansflg = false;
					break;
				}
			}
			System.out.println(ansflg ? 1:0);
		}

	}
	private ArrayList<Point2D> polygoncut(ArrayList<Point2D> polygon, Line2D l) {
		ArrayList<Point2D> res = new ArrayList<Point2D>();
		int n = polygon.size();
		for(int i = 0; i < n; i++){
			Point2D from = polygon.get(i), to = polygon.get((i+1) % n);
			if(l.relativeCCW(from) <= 0){
				res.add(from);
			}
			
			int temp1 = l.relativeCCW(from);
			int temp2 = l.relativeCCW(to);
			if(temp1 * temp2 < 0){
				Line2D l2 = new Line2D.Double(from, to);
				Point2D intersectpt = intersectPtSS(l,l2);
				res.add(intersectpt);
			}
		}
		
		return res;
	}
	private Point2D intersectPtSS(Line2D l, Line2D m) {
		Point2D lV = sub(l.getP2(), l.getP1());
		Point2D mV = sub(m.getP2(), m.getP1());
		Point2D m1l1V = sub(m.getP1(), l.getP1());
		double a = cross(m1l1V, lV);
		double b = cross(lV, mV);
		if(Math.abs(a) < EPS && Math.abs(b) < EPS){
			return l.getP1();
		}
		double t = a / b;
		double x = m.getX1() + t * mV.getX();
		double y = m.getY1() + t * mV.getY();
		return new Point2D.Double(x, y);
	}
	private double cross(Point2D p1, Point2D p2) {
		double res = p1.getX() * p2.getY() - p1.getY() * p2.getX();
		return res;
	}
	private Line2D segmentToLine(Line2D l) {
		final int K = 10000;
		Point2D Vec = sub(l.getP2(), l.getP1());
		Point2D p1 = new Point2D.Double(K * Vec.getX() + l.getX1(), K * Vec.getY() + l.getY1());
		Point2D p2 = new Point2D.Double(-K * Vec.getX() + l.getX1(), -K * Vec.getY() + l.getY1());
		return new Line2D.Double(p2, p1);
	}
	private Point2D sub(Point2D p1, Point2D p2) {
		double x = p1.getX() - p2.getX();
		double y = p1.getY() - p2.getY();
		return new Point2D.Double(x, y);
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

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

using namespace std;

int main () {

  int P, Q, R;
  cin >> P >> Q >> R;

  int arr[] = { P + Q, Q + P, Q + R, R + Q, P + R, R + P };
  int n = sizeof(arr) / sizeof(arr[0]); 

  int min = *min_element(arr, arr + n);

  cout << min << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
import math
#a,b= map(int,input().split())
#li= [int(x) for x in input().split()]
ans=0
a=int(input())
li= [int(x) for x in input().split()]
for i in range(a):
  if li[i]%2==1:
    continue;
  elif (li[i]%3==0 or li[i]%5==0):
    continue;
  else:
    ans=1
if ans==1:
  print("DENIED")
else:
  print("APPROVED")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  cout<<a[n/2]-a[n/2-1];
}

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

ansn = max(a)
b = list(map(lambda x: abs(x-ansn/2), a))

minu = 10**9+1
ind = 0

for i in range(n):
  if b[i] <= minu:
    minu = b[i]
    ind = i
    
print(str(ansn)+" "+str(a[ind]))

Measured memory_bytes: 14428
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	// Atcoder用のサンプルプログラム
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			//line = br.readLine();
			String N= br.readLine();

			int temp = Integer.parseInt(N);
			List memory = new ArrayList();
			for (int i = 0;i < 1000000;i++) {
				if (memory.contains(temp)) {
					System.out.println(i+1);
					break;
				} else {
					memory.add(temp);
					//System.out.println("temp:" + temp);
				}
              
				if (temp % 2 == 1) {
				    temp=3*temp+1;	
				} else {
					temp=temp/2;
				}
				

			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N;
vector<ll> A;

map<ll,ll> mp;

void factorize(ll X,ll V){
  for(ll i=2;i*i<=X;i++){
    if(X%i==0){
      while(X%i==0) X/=i;
      mp[i]+=V;
    }
  }

  if(X!=1) mp[X]+=V;
}

int main(){
  cin>>N;
  A.resize(N);
  for(int i=0;i<N;i++) cin>>A[i];

  for(int i=0;i<N;i++) factorize(A[i],A[i]);

  ll ans=0;
  for(auto m:mp){
    ans=max(ans,m.second);
  }
  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3176
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int t = in(); t; t--) {
		int n = in() - 1, k = in() - 1, p = in(), r = 0;
		vector<int> v;
		while (n--) {
			int c = in(), d = c - p;
			r += d;
			v.push_back(d);
			p = c;
		}
		sort(v.rbegin(), v.rend());
		for (int i = 0; i < (int) v.size() && i < k; i++)
			r -= v[i];
		outl(r);
	}
}


Measured memory_bytes: 3060