akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n){
    d.resize(n,-1);
  }
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return;
  }
  int size(int x){return -d[find(x)];}
};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for(int i=0; i<m; ++i){
    int x, y, z;
    cin >> x >> y >> z;
    --x; --y;
    uf.unite(x,y);
  }
  map<int, bool> mp;
  int ans = 0;
  for(int i=0; i<n; ++i){
    if(mp[uf.find(i)]) continue;
    else{
      mp[uf.find(i)] = true;
      ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8256
#include <iostream>

using namespace std;

int main() {
	long long n, a, b;
	cin >> n >> a >> b;

	long long ans;

	if (n == 1) {
		ans = a == b ? 1 : 0;
	} else if (a > b) {
		ans = 0;
	} else {
		long long diff = b - a;

		long long maxi = a + b * (n - 1);
		long long mini = a * (n - 1) + b;

		ans = maxi - mini + 1;
	}


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


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

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(int i = a; i < b; i++)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define oset tree < int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update >


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

    int t = 1;
    // cin>>t;
    while(t--){
      ll a,b,c,k;
      cin>>a>>b>>c>>k;
      ll mx = 0;
      if(k <= a){
        cout<<k<<"\n";
        continue;
      }
      else {
        mx+=a; k-=a;
      }
      if(k <= b){
        cout<<mx<<"\n";
        continue;
      }
      else{
        k -= b;
      }
      if(k <= c){
        mx -= k;
        cout<<mx<<"\n";
        continue;
      }
      
    }
    return 0;
  }


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOREACH(x, a) for(auto x : a)

/* exchange */
#define CHMIN(a, b) (a) = min((ll)(a), (ll)(b))
#define CHMAX(a, b) (a) = max((ll)(a), (ll)(b))

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define LN() cerr << "\n"
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

struct Student {
  ll i;
  ll ai;
};

ll N = 0;
ll t;
ll ret = 0;
priority_queue<Student> que;

bool operator< (Student s1, Student s2) {
  return s1.ai > s2.ai;
}



void input() {
  IN(N);
  REP(i, N) {
    IN(t);
    Student s = {i: i+1, ai: t};
    que.push(s);
  }
}

void solve() {
  REP(i, N) {
    Student s = que.top();
    que.pop();
    cout << s.i << " ";
  }
  cout << endl;
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 2544
fun main(args: Array<String>) {
    val (N, X) = readLine()!!.split(" ").map { Integer.parseInt(it) }
    val LList = readLine()!!.split(" ").map { Integer.parseInt(it) }
    var result = 0
    for (i in 0 until N + 1) {
        if (LList.subList(0, i).sum() <= X) {
            result++
        }
    }
    print(result)

}


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

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

  	int N; cin >> N;
    if (N <= 999) cout << "ABC" << endl;
    else cout << "ABD" << endl;
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	else return 0;
}

long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++)
	{
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) { return key%M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++) {
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0 ) return 1;
		else if (strlen(H[h]) == 0) return 0;
	}
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);
	for (i = 0; ; i++)
	{
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0) return 1;
		else if (strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main()
{
	int i, n, h;
	char str[L], com[9];
	for (i = 0; i < M; i++) H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%s %s", com, str);

		if (com[0] == 'i') {
			insert(str);
		}
		else {
			if (find(str)) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}
	return 0;
}


Measured memory_bytes: 16036
#include <iostream>

using namespace std;

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int max=0;
    int ans=0;

    cin >> a >> b >> c;

    max=a;
    if(max<=b)max=b;
    if(max<=c)max=c;

    if(max==a){
        ans=a*10+b+c;
    }else if(max==b){
        ans=b*10+a+c;
    }else if(max==c){
        ans=c*10+a+b;
    }

    cout << ans << endl;

    return 0;
}

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

public class Main {

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

		ArrayList<String> lines = new ArrayList<String>();

		String string = "";
		int cn = 0;
		while (true) {
			string = sc.nextLine();
			lines.add(string);
			cn++;
			if (string.contains("?")) {
				break;
			}
		}

		int[] in = new int[2];

		for (int i = 0; i < cn - 1; i++) {
			String[] st = lines.get(i).split(" ");
			in[0] = Integer.parseInt(st[0]);
			in[1] = Integer.parseInt(st[2]);

			if (st[1].equals("+")) {
				System.out.println(in[0] + in[1]);
			} else if (st[1].equals("-")) {
				System.out.println(in[0] - in[1]);
			} else if (st[1].equals("*")) {
				System.out.println(in[0] * in[1]);
			} else if (st[1].equals("/")) {
				System.out.println(in[0] / in[1]);
			}

		}

	}
}

Measured memory_bytes: 26020
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int i = 0;
    string a,b;
    cin >> a >> b;
    for(;i < min(a.size(),b.size());i++)
    {
        cout << a[i] << b[i];
    }
    if(a.size() != b.size()){cout << a[i] << endl;}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	for(int i=0;i<y2-y1;i++)
		cout<<"U";
	for(int i=0;i<x2-x1;i++)
		cout<<"R";
	for(int i=0;i<y2-y1;i++)
		cout<<"D";
	for(int i=0;i<x2-x1;i++)
		cout<<"L";
	cout<<"L";
	for(int i=0;i<y2-y1+1;i++)
		cout<<"U";
	for(int i=0;i<x2-x1+1;i++)
		cout<<"R";
	cout<<"DR";
	for(int i=0;i<y2-y1+1;i++)
		cout<<"D";
	for(int i=0;i<x2-x1+1;i++)
		cout<<"L";
	cout<<"U";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
//#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
int kk=0;vector<vector<int>>v;vector<bool>vis;
void dfs(int root)
{
  vis[root]=1;kk++;
  for(int i=0;i<v[root].size();i++)
  {
    if(!vis[v[root][i]])
    {
      dfs(v[root][i]);
    }
  }
}
int32_t main()
{
    io
 int n,m;cin>>n>>m;
 v.resize(n+1);kk=0;
 vis.assign(n+1,0);
 int x,y;int ans=0;
 while(m--)
 {
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
 }
for(int i=1;i<=n;i++)
{
  if(!vis[i])
  {
    dfs(i);
    ans=max(ans,kk);
    kk=0;
  }
}
cout<<ans<<endl;


    
}

Measured memory_bytes: 23396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  cout << 32*n << endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }

int main() {
	int t;
	//cin >> t;
	t = 1;
	while(t--) {
		char n;
		cin >> n;
      
      	if(n >= 'a' && n <= 'z')
            cout << 'a' << endl;
        else if(n >= 'A' && n <= 'Z')
            cout << 'A' << endl;
	}

	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#define NUM 1000000
using namespace std;

int Prime[NUM];

int main(){

	for( int i=0;i<NUM;i++ ){
		Prime[i]=1;
	}
	Prime[0]=Prime[1]=0;
	for( int i=2;i<NUM;i++ ){
		if( Prime[i] ){
			for( int j=i*2;j<NUM;j+=i ){
				Prime[j]=0;
			}
		}
	}
	int n;
	while( cin>>n ){
		int primenum=0;
		for( int i=0;i<=n;i++ ){
			primenum+=Prime[i];
		}
		cout<<primenum<<endl;
	}

	return 0;
}

Measured memory_bytes: 5068
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;


int main(){
	double w,h,x,y;
	cin>>w>>h>>x>>y;
	cout<<(w*h/2)<<endl;
	if(abs(x-w/2)<EPS&&abs(y-h/2)<EPS){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.array, std.string;
import std.algorithm;
import std.container;
import std.range;
import std.bitmanip;
import std.math;
import std.regex;

class Key {
  public int price;
  public int canOpen;

  this(int price, int[] boxNumbers, int maxBoxSize) {
    this.price = price;
    foreach(i; 1..maxBoxSize+1) if (boxNumbers.canFind(i)) canOpen += 2.pow(i - 1);
  }
}

void main() {
  int N, M; readf("%d %d\n", &N, &M);
  Key[] keys;
  foreach(z; 0..M) {
    int price, canOpenCount; readf("%d %d\n", &price, &canOpenCount);
    keys ~= new Key(price, readln.split.to!(int[]), N);
  }
  
  uint[int] dp;
  int[] updated = [0];
  dp[updated[0]] = 0;

  while(true) {
    int[] nextUpdated;
    foreach(current; updated) {
      foreach(key; keys) {
        int next = current | key.canOpen;
        if (next == current) continue;
        if (next in dp && dp[next] <= dp[current] + key.price) continue;

        dp[next] = dp[current] + key.price;
        nextUpdated ~= next;
      }
    }
    debug nextUpdated.writeln;
    debug dp.writeln;
    if (nextUpdated.empty) break;
    updated = nextUpdated;
  }

  int allOpened = 0;
  N.iota.each!(n => allOpened += 2.pow(n));
  writeln(allOpened in dp ? dp[allOpened].to!string : "-1");
}


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

ans = []
for i in range(n):
    if i == 0:
        ans.append(a[n-1] - a[i])
        continue
    ans.append((a[i-1]+k)-a[i])
#print(ans)
print(min(ans))


Measured memory_bytes: 86140
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
fn main() {
    let x: String = read();
    let lower_x = x.to_ascii_lowercase();
    if x != lower_x {
        println!("A");
    } else {
        println!("a");
    }
}

Measured memory_bytes: 2052
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int gcd(int x, int y){
    if (y == 0) return x;
    return gcd(y, x % y);
}

VI primes(int n){
    vector<bool> a(n+1, 1);
    VI p;
    FOR(x,2,n){
        if (!a[x]) continue;
        p.push_back(x);
        for (int y = 2 * x; y <= n; y += x) a[y] = 0;
    }
    return p;
}

bool check_pair(VI a){
    int n = a.size();
    VI ps = primes(1000);
    set<int> st;
    for (int x : a){
        for (int p : ps){
            if (x % p == 0){
                if (st.count(p)) return false;
                st.insert(p);
                while (x % p == 0) x /= p;
            }
        }
        if (x > 1){
            if (st.count(x)) return false;
            st.insert(x);
        }
    }
    return true;
}

int main(void){
    int n;
    cin >> n;
    VI a(n);
    REP(i,n) a[i] = in();
    if (check_pair(a)){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    int d = a[0];
    REP(i,n) d = gcd(a[i], d);
    if (d == 1){
        cout << "setwise coprime" << endl;
    }else{
        cout << "not coprime" << endl;
    }
    return 0;
}


Measured memory_bytes: 11232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> a(5);
  int k;
  for(int i=0;i<5;i++)
    cin >> a.at(i);
  cin >> k;

  bool flag = true;
  for(int i=0;i<4;i++){
    for(int j=i+1;j<5;j++){
      if(a.at(j) - a.at(i) > k)
        flag = false;
    }
  }
  
  cout << std::setprecision(20);

  if(flag)
    cout << "Yay!" << endl;
  else
    cout << ":(" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

 
using namespace std;
 
int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,m,k,i;
    cin>>n>>m>>k;
    vi a(n+1),b(m+1);
    vi suma(n+1),sumb(m+1);
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        suma[i]=suma[i-1]+a[i];

    }
    for(i=1;i<=m;i++)
    {
        cin>>b[i];
        sumb[i]=sumb[i-1]+b[i];
    }
    int ans=0;
    for(i=0;i<=n;i++)
    {
        if(suma[i]>k) break;
        else
        {
            int x=k-suma[i];
        auto it=upper_bound(sumb.begin(),sumb.end(),x);
        int pos=it-sumb.begin()-1;
        if(pos<0) pos=0;
        ans=max(ans,i+pos);
        }
    }
    cout<<ans;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1000000007;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	priority_queue<int> que;
	int n,m;
	int sum = 0;
	int a;
	cin >> n >> m;
	rep(i,n){
		cin >> a;
		que.emplace(a);
		sum += a;
	}
	while(true){
		if(m == 0){
			break;
		}
		int x = que.top();
		sum -= (x + 2 - 1) / 2;
		x /= 2;
		que.pop();
		que.emplace(x);
		--m;
	}
	cout << sum << '\n';
	return 0;
}



Measured memory_bytes: 1400
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    int n;
    double sum = 0.0;
    cin >> n;

    double x;
    string unit;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        cin >> unit;
        if (unit == "JPY") {
            sum += x;
        } else {
            sum += x * 380000.0;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,k,a[100005]={},ans=inf;
  cin >> n >> k;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-k+1; i++) {
    if(a[i+k-1]<=0) {
      ans=min(ans,abs(a[i]));
    }
    else if(a[i]>=0) {
      //ans=min({ans,abs(a[i])*2+a[i+k-1],abs(a[i])*a[i+k-1]});
      ans=min(ans,a[i+k-1]);
    }
    else {
      //ans=min(ans,a[i+k-1]);
      ans=min({ans,abs(a[i])*2+a[i+k-1],abs(a[i])+a[i+k-1]*2});
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>A(N);
  
  rep(i,N){
    cin>>A[i];
  }
  sort(all(A));
  bool flag=true;
  if(N%2==1){
    rep(i,N){
      if(A[0]!=0){
flag=false;
        break;
      }
      else if(i%2==1){
if(A[i]!=i+1){
flag=false;
  break;
}
      }
else{
if(A[i]!=i){
flag=false;
  break;
}
}
    }
  }
else{
rep(i,N){
  if(i%2==0){
if(A[i]!=i+1){
  flag=false;
  break;
}
  }
  else{
    if(A[i]!=i){
      flag=false;
      break;
    }
  }
}
}
  
  if(flag){
   ll ans=1;
    
    for(ll i=1;i<=N/2;i++){
      ans*=2;
      ans%=mod;
     
  }
    
    cout<<ans<<endl;
  }

  else{
    cout<<0<<endl;
  }
}
    

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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




int main(){
    int n, q; cin >> n >> q;
    queue<pair<string, int>> que;
    REP(i, n){
        string name; cin >> name;
        int time; cin >> time;
        que.push(MP(name, time));
    }
    int t = 0;
    while(!que.empty()){
        pair<string, int> cur = que.front();
        que.pop();
        int prctime = min(cur.second, q);
        cur.second -= prctime; t += prctime;
        if(cur.second > 0)
            que.push(cur);
        else cout << cur.first << " " << t << "\n";
    }
    return 0;
}



Measured memory_bytes: 6332
#include <stdio.h>

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

  if(b % a == 0) {
    a += b;
    printf("%d", a);
  }
  else {
    b -= a;
    printf("%d", b);
  }
  return 0;
}

Measured memory_bytes: 1736
#include <iostream>
 
using namespace std;
 
int GCD(int a, int b)
{
    if(a % b == 0) { return b; }
 
    if(b % a == 0) { return a; }
 
    if(a > b) { return GCD(a % b, b); }
 
    if(a < b) { return GCD(a, b % a); }
}
 
int LCM(int a, int b)
{
    return a / GCD(a, b) * b;
}
 
int main()
{
    int a, b;
 
    while(cin >> a >> b)
    {
int n=GCD(a,b);
        cout << n << ' ' << a/n*b << endl;
    }
 
    return 0;
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
using vi = vector <int>;
using vvi = vector <vi>;

class Warshall_Floyd{
private:
	vector <vector <int>> G;

public:
	Warshall_Floyd(int v){
		G = vector <vector <int>> (v, vector <int> (v));
		for(int i = 0; i < G.size(); i++)
			for(int j = 0; j < G.size(); j++)
				G[i][j] = i == j ? 0 : INF;
	}

	void addEdge(int start, int end, int cost){
		G[start][end] = cost;
	}

	int dist(int start, int end){
		return G[start][end];
	}

	bool checkNegativeCircle(){
		bool flag = false;
		for (int i = 0; i < G.size(); i++)
			if(G[i][i] < 0)
				flag = true;
		return flag;
	}

	void execute(){
		for(int k = 0; k < G.size(); k++)
			for(int i = 0; i < G.size(); i++)
				for(int j = 0; j < G.size(); j++)
					if(G[i][k] != INF && G[k][j] != INF)
						G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
	}

};

signed main(){
	int v, e;
	cin >> v >> e;

	Warshall_Floyd wf(v);

	rep(i, e){
		int s, t, d;
		cin >> s >> t >> d;
		wf.addEdge(s, t, d);
	}

	wf.execute();

	if(wf.checkNegativeCircle()){
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}

	rep(i, v){
		rep(j, v){
			if(wf.dist(i, j) == INF)
				cout << "INF";
			else
				cout << wf.dist(i, j);
			if(j != v - 1)
				cout << " ";
			else
				cout << endl;
		}
	}
}

Measured memory_bytes: 3248
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int a[1000000];
int n;
vector<int> G;

//間隔g を指定した挿入ソート（シェルソート）
void insertionSort(int a[], int n, int g){
    for(int i = g; i < n; i++){
        int v = a[i];
        int j = i - g;
        while(j >= 0 && a[j] > v){
          a[j + g] = a[j];
          j -= g;
          cnt++;
        }
        a[j + g] = v;
    }
}

void shellSort(int a[], int n){
    //数列G = {1, 4, 13, 40, 121, 364, 1093・・・}を生成 g(n+!) = 3g(n) + 1 の漸化式によって表される数列
    for(int h = 1; ;){
        if(h > n) break;
        G.push_back(h);
        h = 3 * h + 1;
    }

    for(int i = G.size()-1; i >= 0; i--){//逆順にG[i] = gを指定
        insertionSort(a, n, G[i]);
    }
}

int main(){
    cin >> n;
    //より速い入力scanf関数を使用
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    cnt = 0;

    shellSort(a, n);

    cout << G.size() << endl;
    for(int i = G.size()-1; i>=0; i--){
        printf("%d", G[i]);
        if(i) printf(" ");
    }
    printf("\n");
    printf("%lld\n", cnt);
    for(int i = 0; i < n; i++)
        printf("%d\n", a[i]);

    return 0;
}




Measured memory_bytes: 7208
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template<class T> inline vector<pair<T, int>> factoring(T n) {
	using p = pair<T, int>;
	using vp = vector<p>;
	vp res;
	T k = n;
	if (n % 2 == 0) {
		res.push_back(p(2, 1));
		n /= 2;
		while (n % 2 == 0) {
			res[0].second++;
			n /= 2;
		}
	}
	for (T i = 3; i <= n && i * i <= k; i += 2) {
		if (n % i == 0) {
			res.push_back(p(i, 1));
			n /= i;
			while (n % i == 0) {
				res.back().second++;
				n /= i;
			}
		}
	}
	if (n != 1) {
		res.push_back(p(n, 1));
	}
	return res;
}

namespace {
	template<typename T, typename U>
	inline T pow(T x, U exp) {
		if (exp <= 0) {
			return 1;
		}
		if (exp % 2 == 0) {
			T d = pow(x, exp / 2);
			return d * d;
		} else {
			return (x * pow(x, exp - 1));
		}
	}

	template<typename T> inline T phi(T n) {
		vector<pair<T, int>> fact = factoring(n);
		T res = 1;
		const int l = (int)fact.size();
		for (int i = 0; i < l; ++i) {
			T tmp = pow<T>(fact[i].first, fact[i].second - 1);
			res *= (tmp * fact[i].first - tmp);
		}
		return res;
	}
}

int main() {
	IOS;
	int n;
	cin >> n;
	put(phi(n));
	return 0;
}




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

int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
vector<long long int> adj[200001];
bool vis[200001];
#define ll long long int
#define ull unsigned long long int
#define MAX 1000000007
#define MOD 998244353

#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
ll arr[201];
ll sizes[201];
vector<pair<ll,pll> > edge;
ll power(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1) ans=ans*a;
        b/=2;
        a=a*a;
    }
    return(ans);
}

int main(){
    IO
    int n;
    cin>>n;
    n=n%10;
    if(n==2 || n==4 || n==5 || n==7 || n==9) cout<<"hon";
    else if(n==0 || n==1 || n==6 || n==8) cout<<"pon";
    else cout<<"bon";
    return(0);
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
signed main(){
    IOS;
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size();i++){
      c+=s[i]-'0';
    }
    if(c%9)cout<<"No";
    else cout<<"Yes";
}

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

#define rep(i,n) for(int i=0;i<n;i++)
///1<<3シフト演算子 とは　0001の1を三つずらして1000にする, これは8を表しておりつまりbitは0から7まで
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
int main(){

   int n;
   cin >> n;
   vector<bool> exist(8,false);
   int cnt = 0;
    rep(i,n){
        int rate;
        cin >> rate;
        if(rate < 3200) {
            exist.at(rate/400) = true;
            cnt++;
        }
    }
    int va = count(all(exist),true);
    int ma,mi;
    if(cnt == 0){
        ma = n;
        mi = 1;
    } 
    else{
        mi = va;
        ma = va+n-cnt;
    }
    cout << mi sp ma << endl;


   
}

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

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1 << 29)
#define LLINF (1LL << 60)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

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

string to_string(string s) { return s; }
template <class S>
string to_string(unordered_set<S> s);
template <class S>
string to_string(set<S> s);
template <class S, class T>
string to_string(map<S, T> m);
template <class T>
string to_string(vector<T> v);

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S>
string to_string(set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x) + ",";
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x) + ",";
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  cin.tie(0);
  string S;
  cin >> S;
  char c = S[0];
  if (S == "SUN") {
    print(7);
  } else if (S == "SAT") {
    print(1);
  } else if (c == 'M') {
    print(6);
  } else if (S == "TUE") {
    print(5);
  } else if (c == 'W') {
    print(4);
  } else if (S == "THU") {
    print(3);
  } else if (c == 'F') {
    print(2);
  }
  return 0;
}

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

def bubbleSort(num_list):
    flag = True
    length = len(num_list)
    count = 0
    while flag:
        flag = False
        for j in range(length-1, 0, -1):
            if num_list[j] < num_list[j-1]:
                num_list[j], num_list[j-1] = num_list[j-1], num_list[j]
                flag = True
                count += 1
    return num_list, count


input_num = int(input())
num_list = [int(i) for i in input().split()]

bubble_list, swap_num = bubbleSort(num_list)
for i in range(len(num_list)):
    if i > 0:
        print(" ", end="")
    print(num_list[i], end="")
print()
print(swap_num)

Measured memory_bytes: 7788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>
#include<map>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long
#define all(x) (x).begin(), (x).end()

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

int main(){
    map<string, int> H = {
        {"SUN", 0}, {"MON", 1}, {"TUE", 2}, {"WED", 3}, {"THU", 4}, {"FRI", 5}, {"SAT", 6}
    };
    string wd; cin>>wd; int d = H[wd];
    d = (d == 0) ? 7 : 7-d;
    cout << d << endl;
}

Measured memory_bytes: 256
//e4 - e5 - f4
//#include <boost/multiprecision/cpp_int.hpp> 
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
typedef long long int ll;
typedef double db;
// __int128 s128;
// __uint128_t u128;
typedef unsigned long long u64;
#define int long long int
#define P 1000000007
#define Q 1000000006
#define sz(a) (ll)a.size()
#define lt(a) (ll)a.length()
#define pll pair<ll,ll>
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define bac(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define mt make_tuple
#define eb emplace_back
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define teevra_gati ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define N 100005
#define PI 3.14159265359
#define inf LLONG_MAX
//using namespace boost::multiprecision; 
using namespace __gnu_pbds;
using namespace std;

void solve(){
    ll x,y;
    cin>>x>>y;
    ll c2 = 4*x - y, t2 = y-2*x;
    if(c2>=0 && t2>=0 && c2%2==0 && t2%2==0) cout<<"Yes";
    else cout<<"No";
}

signed main() {
    teevra_gati
        
    solve();

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int x;
int main() {
	scanf("%d",&x);
	if (x<1200) puts("ABC"); else puts("ARC");
}


Measured memory_bytes: 128
// A. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, char *argv[])
{
	int N, dir = 0, prev, ans = 1;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		if (i) {
			if (a > prev) {
				if (!dir) {
					dir = 1;
				} else if (dir < 0) {
					++ans;
					dir = 0;
				}
			} else if (a < prev) {
				if (!dir) {
					dir = -1;
				} else if (dir > 0) {
					++ans;
					dir = 0;
				}
			}
		}
		prev = a;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// Aizu 0244: Hot Spring Trip
// 2017.9.10 bal4u@uu

#include <stdio.h>
#include <string.h>

#define INF 0x7fffffff
#define MAX 5000
#define min(a,b) ((a)<=(b)?(a):(b))
typedef struct { int t, k, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
  int l, r;
  int smallest;

  l = LEFT(i), r = RIGHT(i);
  if (l < qsize && que[l].t < que[i].t) smallest = l; else smallest = i;
  if (r < qsize && que[r].t < que[smallest].t) smallest = r;
  if (smallest != i) {
    QUE t = que[i]; que[i] = que[smallest]; que[smallest] = t;
    min_heapify(smallest);
  }
}

int deq(int *k, int *c)
{
  if (qsize == 0) return 0;
  *k = que[0].k, *c = que[0].c;
  que[0] = que[--qsize];
  min_heapify(0);
  return 1;
}

void enq(int k, int t, int c)
{
  int i, ii;

  i = qsize++;
  que[i].t = t, que[i].k = k, que[i].c = c;
  while (i > 0 && que[ii = PARENT(i)].t > que[i].t) {
    QUE tt = que[i]; que[i] = que[ii]; que[ii] = tt;
    i = ii;
  }
}

typedef struct { int len, to[102], c[102]; } TBL;
TBL tbl[102];
int node[102][3]; int size;
int start, goal;

int search()
{
	int s, i, c, s2, f2, c2, k;
	TBL *p;

	qsize = 0;
	memset(node, -1, sizeof(node));
	node[start][2] = 0;
	enq(start, 0, 2);
	while(deq(&s, &c)) {
		if (s == goal) {
			if (c != 1) break;
		}
		for (p = tbl+s, i = 0; i < p->len; i++) {
			s2 = p->to[i], f2 = p->c[i];
			k = node[s][c] + f2;
			if (c != 1) {
				if (node[s2][c] < 0 || k < node[s2][c]) node[s2][c] = k, enq(s2, k, c);
			}
			if (c > 0) {
				c2 = c-1;
				k = node[s][c];
				if (node[s2][c2] < 0 || k < node[s2][c2]) node[s2][c2] = k, enq(s2, k, c2);
			}
		}
	}
	if (node[goal][0] >= 0 && node[goal][2] >= 0) return min(node[goal][0], node[goal][2]);
	if (node[goal][0] >= 0) return node[goal][0];
	return node[goal][2];
}

int main()
{
	int m, a, b, c;
	TBL *p;

	while (scanf("%d%d", &size, &m) && size) {
		memset(tbl, 0, sizeof(TBL)*size);
		start = 0, goal = size-1;
		while (m-- > 0) {
			scanf("%d%d%d", &a, &b, &c), a--, b--;
			p = tbl + a, p->to[p->len] = b, p->c[p->len] = c, p->len++;
			p = tbl + b, p->to[p->len] = a, p->c[p->len] = c, p->len++;
		}
		printf("%d\n", search());
	}
	return 0;
}

Measured memory_bytes: 1856
#include <iostream>
#include <cmath>
#include <cstdio>
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main(){
    string n;
    cin>>n;
    for(int i=0;i<3;++i){
        if(n[i]=='1'){
            n[i]='9';
        }else{
            n[i]='1';
        }
    }
    cout<<n<<endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            String[] s = sc.nextLine().split(" ");
            int n = s.length;
            int[] l = new int[n];
            for (int i = 0; i < n; i++) 
                l[i] = Integer.parseInt(s[i]);
            if (l[0] == 0)
                break;
            Arrays.sort(l);
            int sum = 0;
            while (n-- > 0)
                sum+=l[n]!=1?Math.min(10,l[n]):sum+n<=10?11:1;
            System.out.println(sum>21?0:sum);
        }
    }
}


Measured memory_bytes: 26420
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int r = stdIn.nextInt(); //現在のレーティング
		int g = stdIn.nextInt(); //とりたいレーティング
		
		System.out.println(2*g-r);
		
		
		
	}

}


Measured memory_bytes: 21716
s = input()

y,m,d = s.split("/")
y = int(y)
m = int(m)
d = int(d)

if y < 2019 :
    print("Heisei")
elif y > 2019 :
    print("TBD")
else :
    if m <= 4 :
        print("Heisei")
    else :
        print("TBD")

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

#define ll long long
#define vi vector<int>
#define pi pair<int, int>
#define pb push_back
#define ppb pop_back

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int N = 1e5 + 667;
vi v;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    v.pb(1);
    v.pb(1);
    v.pb(1);
    v.pb(2);
    v.pb(1);
    v.pb(2);
    v.pb(1);
    v.pb(5);
    v.pb(2);
    v.pb(2);
    v.pb(1);
    v.pb(5);
    v.pb(1);
    v.pb(2);
    v.pb(1);
    v.pb(14);
    v.pb(1);
    v.pb(5);
    v.pb(1);
    v.pb(5);
    v.pb(2);
    v.pb(2);
    v.pb(1);
    v.pb(15);
    v.pb(2);
    v.pb(2);
    v.pb(5);
    v.pb(4);
    v.pb(1);
    v.pb(4);
    v.pb(1);
    v.pb(51);
    
    int k;
    cin >> k;
    cout << v[k-1];
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int a=0, z=0;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'Z') z = i;
  }
  reverse(s.begin(), s.end());

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'A') a = s.length() - i - 1;
  }

  cout << z - a + 1 <<endl;

}


Measured memory_bytes: 640
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int q = Integer.parseInt(sc.next());
        String s = sc.next();
        Integer[] l = new Integer[q];
        Integer[] r = new Integer[q];
        for (int i = 0; i < q; i++) {
            l[i] = Integer.parseInt(sc.next());
            r[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        int[] arr = new int[n];
        for (int i = 1; i < n; i++) {
            arr[i] = arr[i - 1];
            if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
                arr[i]++;
            }
        }

        // 出力
        for (int i = 0; i < q; i++) {
            int result = arr[r[i] - 1] - arr[l[i] - 1];
            System.out.println(result);
        }
    }
}


Measured memory_bytes: 66340
#include<stdio.h>
int main()
{
    long long int N,K;
    scanf("%lld%lld",&N ,&K);
    N=N%K;
    if(N< K-N)
    {
        printf("%lld\n",N);
    }
     else
     {
         printf("%lld\n",K-N);
     }
     return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;
int N,M,Q;

vector<vector<long long int> >A(550,vector<long long int>(550,0));

int main(void){
 int N,M,Q;
 int L,R;
 cin>>N>>M>>Q;

 for(int i=0; i<M; i++){
  cin>>L>>R;
  A[L][R]++;
 }
 
 //buildSumTable;
 for(int i=1; i<=N; i++)
  for(int j=1; j<=N; j++){
   A[i][j]+=A[i][j-1];
   A[i][j]+=A[i-1][j];
   A[i][j]-=A[i-1][j-1];
  }
  
  for(int i=0; i<Q; i++){
   cin>>L>>R;
   std::cout<<A[R][R]-A[R][L-1]-A[L-1][R]+A[L-1][L-1]<<std::endl;
  }
 return 0;
}

Measured memory_bytes: 3328
import sys
n=int(input())
a=map(int,input().split())
num=[0,0,0]
for i in a:
  if(i%4==0):num[0]+=1
  elif(i%2==0):num[1]+=1
  else:num[2]+=1
if(num[2]==0):print("Yes")
elif(num[2]==1):
  if(num[0]!=0):print("Yes")
  else:print("No")
else:
  if(num[2]>num[0]+1):print("No")
  else:
    if(num[2]==num[0]+1):
      if(num[1]==0):print("Yes")
      else:print("No")
    elif(num[2]==num[0]):print("Yes")
    else:print("No")


Measured memory_bytes: 11100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll x;
    cin >> x;

    ll ans = 0;
    ans = x / 11 * 2;
    if(x % 11 != 0){
        if(x % 11 <= 6){
            ans++;
        }else{
            ans += 2;
        }
    }

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


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <vector>
using namespace std;

// 問題名："Circle and Points"
// https://onlinejudge.u-aizu.ac.jp/problems/1132
// 所要時間… 考察：10分程度 実装：20分程度

/*
***方針***
最大数囲む半径1の円の囲み方が有るときに、囲む点を変えずに少なくとも2点を同時に円周上に持ってくることができる。したがって、周上に2点が存在するような円のみを考えれば良い。周上に置く2点を決めた時、考えられる半径1の円の囲み方は最大2通り存在する（2点間の距離が2より大きいと存在しない）。この2点の選び方はNC2=O(N^2)通りなので、それぞれについて円で囲まれる点を一つづつ数えると、計算量はO(N^3)となりN<=300で間に合いそうである。

***学んだこと***
complex型によって、平面上の点の操作が容易となる（複素平面的扱いにより変数の数を減らすことが可能）。
*/

int main() {
  int n;
  while (cin >> n, n > 0) {
    // 入力
    vector<complex<double>> p(n);
    double xt, yt;
    for (int i = 0; i < n; i++) {
      cin >> xt >> yt;
      p[i].real(xt);
      p[i].imag(yt);
    }

    int ret =
        1;  // 1<=Nなので答えは必ず1以上（0とすると、下のループに入らない場合にバグる）
    for (int i = 0; i < n; i++) {  // 円周に来る2点の組でループ
      for (int j = i + 1; j < n; j++) {
        if (abs(p[i] - p[j]) > 2)
          continue;  // 2点間の距離が2より大きかったら無視

        // 回転操作と実数倍で、2つの点p[i],p[j]から円の中心を二つ求める（c+pmとc-pm）
        complex<double> pm = (p[i] + p[j]) / 2.0;
        complex<double> c = p[i] - pm;
        double d = abs(c);
        c *= sqrt(1 - d * d) / d * 1.0i;
        int cntp = 0, cntm = 0;

        // できる2つの円について、含まれる点の個数を数える
        // ちょうど周上に来る2点を確実に入れるために、ボーダーを少し広めに設定（制約上、外の点を含むことはない）
        for (int k = 0; k < n; k++) {
          if (abs(p[k] - (c + pm)) < 1.00005) cntp++;
          if (abs(p[k] - (-c + pm)) < 1.00005) cntm++;
        }
        ret = max({ret, cntp, cntm});  // 大きいものを採用
      }
    }
    cout << ret << endl;
  }
}


Measured memory_bytes: 3224