akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Student[] a = new Student[n];
        for (int i = 0; i < n; i++) {
            a[i] = new Student(i + 1, sc.nextInt());
        }
        System.out.println(Stream.of(a).sorted().map(s -> String.valueOf(s.num)).collect(Collectors.joining(" ")));
    }
    private static class Student implements Comparable<Student> {
        int num;
        int order;
        private Student(int num, int order) {
            this.num = num;
            this.order = order;
        }
        @Override
        public int compareTo(Student o) {
            return Integer.compare(this.order, o.order);
        }
    }
}

Measured memory_bytes: 62992
#include <cstdio>
using namespace std;
 
int p[110], q[110], cnt;
long long N;
     
void solve(long long n){
    if(n<1)	return;
   	if(!(n&1)){
   		q[++q[0]]=cnt++;
   		solve(n-1);
   	}
   	else{
   		p[++p[0]]=cnt++;
   		solve(n>>1);
 	}
}
    
int main(){
  	scanf("%lld", &N);
  	solve(N);
  	printf("%d\n", cnt+100);
  	for(int i=1; i<=q[0]; i++)	printf("%d ", cnt-q[i]);
  	for(int i=p[0]; i; i--)		printf("%d ", cnt-p[i]);
   	for(int i=1; i<=100; i++)	printf("%d ", i);
 	return 0;
}

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

int main() {
    int32_t a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int32_t answer = 2147483647;
    for (int32_t i = 0; i <= (x > y ? x : y) * 2; i += 2) {
        int32_t temp = 0;
        temp += a * (x - i / 2 > 0 ? x - i / 2 : 0);
        temp += b * (y - i / 2 > 0 ? y - i / 2 : 0);
        temp += c * i;
        if (temp < answer) {
            answer = temp;
        }
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,a;
    cin>>n;
    std::deque<int> deq;
    int flag=0;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (flag==0) {
            deq.emplace_back(a);
            flag=1;
        } else {
            deq.emplace_front(a);
            flag=0;
        }
    }
    if (flag==0) {
        for (int j=0;j<n;j++) {
            if (j!=n-1) {
                cout<<deq[j]<<" ";
            } else {
                cout<<deq[j]<<endl;
            }
        }
    } else {
        for (int k=n-1;k>=0;k--) {
            if (k!=0) {
                cout<<deq[k]<<" ";
            } else {
                cout<<deq[k]<<endl;
            }
        }
    }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;
    //cout << dx << " " << dy << endl;
    cout << x2 - dy << " " << y2 + dx << " " << x1 - dy << " " << y1 + dx << " " << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

const int MAXN = 2e5 + 10;
const int pwpw = 443664157;
int t[MAXN << 2];
int u[MAXN << 2];
int pw[MAXN];
int n, q;

int binpow(int a, int n) {
    int res = 1;
    while(n) {
        if(n & 1) res = res * 1ll * a % MOD2;
        a = a * 1ll * a % MOD2;
        n >>= 1;
    }
    return res;
}

int calc(int l, int r) {
    l = n - l;
    r = n - r;
    swap(l, r);
    return (pw[r + 1] - pw[l] + MOD2) % MOD2 * 1ll * pwpw % MOD2;
}

void push(int v, int tl, int tr) {
    if(u[v]) {
        int tm = tl + tr >> 1;
        t[v << 1] = u[v] * 1ll * calc(tl, tm) % MOD2;
        t[v << 1 | 1] = u[v] * 1ll * calc(tm + 1, tr) % MOD2;
        u[v << 1] = u[v];
        u[v << 1 | 1] = u[v];
        u[v] = 0;
    }
}

void upd(int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
    if(l <= tl && tr <= r) {
        t[v] = val * 1ll * calc(tl, tr) % MOD2;
        u[v] = val;
        return;
    }
    if(l > tr || r < tl) return;
    push(v, tl, tr);
    int tm = tl + tr >> 1;
    upd(l, r, val, v << 1, tl, tm);
    upd(l, r, val, v << 1 | 1, tm + 1, tr);
    t[v] = (t[v << 1] + t[v << 1 | 1]) % MOD2;
}

void build(int v = 1, int tl = 1, int tr = n) {
    if(tl == tr) {
        t[v] = pw[n - tl];
        return;
    }
    int tm = tl + tr >> 1;
    build(v << 1, tl, tm);
    build(v << 1 | 1, tm + 1, tr);
    t[v] = (t[v << 1] + t[v << 1 | 1]) % MOD2;
}

void solve() {
    pw[0] = 1;
    for(int i = 1; i < MAXN; ++i) pw[i] = pw[i - 1] * 10ll % MOD2;
    cin >> n >> q;
    build();
    while(q--) {
        int l, r, x;
        cin >> l >> r >> x;
        upd(l, r, x);
        cout << t[1] << '\n';
    }
}


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 8552
N = int(input())
S = input()
A = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ''
for i in range(len(S)):
    for j in range(len(A)):
        if S[i] == A[j]:
            ans += A[j+N]
            break
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  int ans = 1;
  
  for(int i = 1; i < n; i++) {
    if(a[i] <= a[i - 1]) ans++;
  }
  
  cout << ans << endl;
  cout << n << endl;
  return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

int dp[100001];

void solve()
{
	int n;
	cin>>n;
	vector<int>h(n);
	rep(i,n){
		cin>>h[i];
	}
	rep(i,n){
		dp[i]=1e9+2;
	}
	dp[0]=0;
	dp[1]=abs(h[0]-h[1]);
	FOR(i,2,n){
		chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
		chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1]<<endl;

}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int a[m];
  for(int i=0;i<m;i++) cin >> a[i];
  long long dp[n];
  for(int i=0;i<n+1;i++){
    dp[i] = 0;
  }
  dp[0] = 1;
  for(int i=0;i<m;i++) dp[a[i]] = -1;
  if(a[0] != 1){
    dp[1] = 1;
  }
  else{
    dp[1] = 0;
  }
  for(int i=2;i<n+1;i++){
    if(dp[i] < 0) dp[i] = 0;
    else{
      dp[i] = dp[i-1]%1000000007 + dp[i-2]%1000000007;
    }
  }
  cout << dp[n] %1000000007<< endl;

  return 0;
}

Measured memory_bytes: 1408
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

namespace Util {
    template<typename INT>
    INT gcd_with_coef(INT x, INT y, INT* outCX, INT* outCY);
};    // namespace Util

template<typename INT>
INT Util::gcd_with_coef(INT x, INT y, INT* outCX, INT* outCY) {
    if (x < 0) {
        INT d = gcd_with_coef(-x, y, outCX, outCY);
        *outCX *= -1;
        return d;
    }
    if (y < 0) {
        INT d = gcd_with_coef(x, -y, outCX, outCY);
        *outCY *= -1;
        return d;
    }
    if (x > y) {
        return gcd_with_coef(y, x, outCY, outCX);
    }
    if (x == 0) {
        if (outCX != nullptr && outCY != nullptr) {
            *outCX = 0;
            *outCY = 1;
        }
        return y;
    }
    INT q = y / x;
    INT r = y % x;
    INT d = gcd_with_coef(r, x, outCY, outCX);
    if (outCX != nullptr && outCY != nullptr) {
        *outCX -= q * *outCY;
    }
    return d;
}

int main() {
    ll A, B;
    cin >> A >> B;
    ll gcd = Util::gcd_with_coef<ll>(A, B, nullptr, nullptr);
    ll ans = 1;
    constexpr ll P_MAX = 1000000;
    vector<bool> furui(P_MAX + 1, true);
    for (ll p = 2; p <= P_MAX; p++) {
        if (furui[p]) {
            if (gcd % p == 0) {
                ans++;
                while (gcd % p == 0) {
                    gcd = gcd / p;
                }
            }
        }
    }
    if (gcd >= 2) {
        ans++;
    }
    cout << ans << endl;
}



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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

void solve(int N, int Y) {
    map<ii,ii> m;
    for (int a=0;a<=N;++a) {
        for (int ab=a;ab<=N;++ab) {
            int z = 1000*a + 5000*(ab-a);
            m[ii(ab,z)] = ii(a,ab-a);
        }
    }
    for(int c=0;c<=N;++c) {
        int z = Y - 10000*c;
        if (z<0) break;
        ii k(N-c, z);
        if (found(m,k)) {
            ii p = m[k];
            printf("%d %d %d\n", c, p.second, p.first);
            return;
        }
    }
    printf("-1 -1 -1\n");
}

int main() {
    int N,Y; cin>>N>>Y;
    solve(N,Y);
    return 0;
}


Measured memory_bytes: 125440
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var dp = new int[n + 4];
            dp[1] = 1; dp[2] = 2; dp[3] = 4;
            if (n <= 3) goto next;
            for (int i = 1; i <= n; i++)
                dp[i + 3] = dp[i + 2] + dp[i + 1] + dp[i]; 
            next:;
            var ans = dp[n];
            int ans2;
            if (ans % 3650 == 0) ans2 = ans / 3650;
            else ans2 = ans / 3650 + 1;
            Console.WriteLine(ans2);
        }
    }
}

Measured memory_bytes: 9112
#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N];
long long b[N];
bool ok[N];
int n,k,tot,x;
long long y,ans;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%lld",&x,&y);
		if(x<=k) a[++tot]=x,b[tot]=y,ok[tot]=1;
	}
	n=tot;
	for(int i=30;i>=0;i--)
	  if(k&(1<<i))
	  {
	  	long long tmp=0;
		for(int j=1;j<=n;j++)
		  if(~a[j]&(1<<i)&&ok[j]) tmp+=b[j];
		ans=max(ans,tmp);
	  }
	  else
	  {
		for(int j=1;j<=n;j++)
		  if(a[j]&(1<<i)&&ok[j]) ok[j]=0;
	  }
	long long tmp=0;
	for(int i=1;i<=n;i++)
	  if(ok[i]) tmp+=b[i];
	printf("%lld",max(ans,tmp));
	return 0;
}

Measured memory_bytes: 1536
//
// C - Write and Erase
//

#include <iostream>
#include <unordered_map>

using namespace std;

int main() {

    int N;
    cin >> N;

    unordered_map<int, int> nums;

    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (nums.find(A) == nums.end()) {
            nums[A] = 1;
        } else {
            nums[A]++;
        }
    }

    //
    int ans = 0;

    for (auto num:nums) {
        if (num.second % 2) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4128
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<numeric>
using namespace std;
#define INF (1<<29)
	
int main(){
	int n,m;
	int s[100],t[100];
	while(cin>>n>>m,n||m){
		for(int i=0;i<n;i++)cin>>s[i];
		for(int i=0;i<m;i++)cin>>t[i];
		int x,y;
		x = accumulate(s,s+n,0);
		y = accumulate(t,t+m,0);
		int ans1=-1,ans2;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(x-s[i]+t[j] == y-t[j]+s[i]){
					if(ans1==-1 || s[i]+t[j]<ans1+ans2){
						ans1=s[i];
						ans2=t[j];
					}
				}
			}
		}
		if(ans1==-1)cout<<-1<<endl;
		else cout<<ans1<<' '<<ans2<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > vec(n , vector<int>(m));
    vector<int> b(m);

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> vec[i][j];
        }
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
    }

    for(int i = 0; i < n; i++) {
        int sum = 0;
        for(int j = 0; j < m; j++) {
            sum += vec[i][j] * b[j];
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3172
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
q = int(input())
oper = [list(map(int, input().split())) for _ in range(q)]
dic = {}
for i in range(n):
    if a[i] in dic:
        dic[a[i]] += 1
    else:
        dic[a[i]] = 1
        
res = sum(a)

for i in range(q):
    b, c = oper[i]
    if b in dic:
        bCount = dic[b]
        del(dic[b])
        if c in dic:
            dic[c] += bCount
        else:
            dic[c] = bCount

        dif = c-b

        res += dif*bCount

    print(res)

Measured memory_bytes: 37340
#include <iostream>
#include <math.h>
#define PI 3.141592
using namespace std;

int main() {
double r,th=0,x=0,y=0,kaku=0;
char d;
while(1){
	cin>>r>>d>>th;
	if(r==0&&th==0){
		break;
	}
	x=x+r*sin(kaku*PI/180);
	y=y+r*cos(kaku*PI/180);
	kaku=th+kaku;
}
int xx,yy;
xx=x;
yy=y;
cout<<xx<<endl;
cout<<yy<<endl;
	return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;


// 147_b
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        int len = s.length();
        int half = len / 2;

        int count = 0;

        for (int i = 0; i < half; i++) {
            if (!(s.charAt(i) == s.charAt(s.length() - i - 1))) {
                count++;
            }
        }

        out(count);

    }

    /*
     * 以下メソッド集
     */

    static long lcm(long m, long n) {

        return m * n / gcd(m, n);
    }

    static int lcm(int m, int n) {

        return m * n / gcd(m, n);
    }

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 21844
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val D = rd.readIntArray()
    val M = rd.readInt()
    val T = rd.readIntArray()

    val dm = mutableMapOf<Int, Int>()
    for (i in 0 until N) {
        dm[D[i]] = (dm[D[i]] ?: 0) + 1
    }
    val tm = mutableMapOf<Int, Int>()
    for (i in 0 until M) {
        tm[T[i]] = (tm[T[i]] ?: 0) + 1
    }

    for (t in tm) {
        val k = t.key
        if (dm.containsKey(k) && t.value <= dm[k]!!) continue
        println("NO")
        return
    }

    println("YES")
}


//val rd = debug.Reader("etc", "code-festival-2017-qualb", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 102924
#include <stdio.h>
#include <math.h>

int main(){
	int N, D, X[10][10];
	int i, j, k, cnt=0;
	double ans;


	scanf("%d %d", &N, &D);
	for(i=0; i<N; i++){
		for(j=0; j<D; j++){
			scanf("%d", &X[i][j]);
		}
	}

	for(i=0; i<N; i++){
		for(j=0; j<i; j++){
			ans = 0;

			for(k=0; k<D; k++)
				ans += pow((double)X[i][k] - (double)X[j][k], 2);

			ans = sqrt(ans);
			if(ceil(ans) == floor(ans))
				cnt++;
		}
	}

	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
 
public class Main {
   public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
      
      int N = sc.nextInt();
	  double[] X = new double[N];
      double[] Y = new double[N];
      double D = sc.nextDouble();
      int cnt = 0;
     
      for(int i=0; i<N; i++) {
        X[i]=sc.nextDouble();
        Y[i]=sc.nextDouble();
      }
      
      for(int i=0; i<N; i++) {
        double dis = Math.sqrt(X[i]*X[i]+Y[i]*Y[i]);
        if(dis <= D) {
          cnt ++;
        } else {
          //cnt += 0;
          continue;
        }
      }
      System.out.println(cnt);
    }
}

Measured memory_bytes: 67916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define all(s) s.begin(),s.end()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

//#define DEBUG
ll power(ll x,ll y){
  ll t=1;
  while(y>0){
    if(y%2) y-=1,t=t*x%mod;
    else y/=2,x=x*x%mod;
  }
  return t;
}
#ifdef DEBUG
#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#else
#define dprintf(fmt,...)
#endif

int a[4];
char s[N];
int main(){
	int n;
	scanf("%s",s);
	n=strlen(s);
	REP(i,n) if(s[i]=='N') a[0]++; else if(s[i]=='E') a[1]++; else if(s[i]=='S') a[2]++; else a[3]++;
	REP(i,4) if(a[i]>1) a[i]=1;
	if((a[0]^a[2])||(a[1]^a[3])) printf("No\n"); else printf("Yes\n");
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

ll modAdd(ll a, ll b) {
	return a+b >= MOD ? a+b-MOD : a+b;
}
ll modSub(ll a, ll b) {
	return a < b ? a-b+MOD : a-b;
}
ll modPow(ll a, ll b) {
	if (b & 1) return a * modPow(a, b-1) % MOD;
	if (b == 0) return 1;
	return modPow(a*a % MOD, b / 2);
}

// res[k] = \sum_{i,j : i^j == k} a[i] b[j]
// overflows if n res[i] overflows
void xorTF(vector<ll>& v) {
	for (int b = 1; b < v.size(); b *= 2) {
		for (int i = 0; i < v.size(); ++i) {
			if (i & b) continue;
			ll ri = v[i^b];
			v[i^b] = modSub(v[i], ri);
			v[i] = modAdd(v[i], ri);
		}
	}
}
vector<ll> xorConv(vector<ll> a, vector<ll> b) {
	xorTF(a); xorTF(b);
	for (int i = 0; i < a.size(); ++i) a[i] = (a[i] * b[i]) % MOD;
	xorTF(a);

	ll inv = modPow(a.size(), MOD-2);
	for (int i = 0; i < a.size(); ++i) a[i] = (a[i] * inv) % MOD;
	return a;
}

const int N = 1e5;
vector<int> conns[3][N];
int grundy[3][N];
vector<ll> vals[3];

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

	int n;
	cin >> n;

	for (int j = 0; j < 3; ++j) {
		int m;
		cin >> m;
		for (int i = 0; i < m; ++i) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			conns[j][a].push_back(b);
			conns[j][b].push_back(a);
		}
		for (int i = n-1; i >= 0; --i) {
			vector<int> hits;
			for (auto t : conns[j][i]) {
				if (t > i) hits.push_back(grundy[j][t]);
			}
			sort(hits.begin(), hits.end());

			for (auto v : hits) {
				if (grundy[j][i] == v) ++grundy[j][i];
			}
		}
	}

	int h = 1;
	while(h < n) h <<= 1;
	for (int j = 0; j < 3; ++j) vals[j].resize(h, 0);

	ll base = modPow(10, 18);
	ll cur = base;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) {
			vals[j][grundy[j][i]] = modAdd(vals[j][grundy[j][i]], cur);
		}
		cur = (cur * base) % MOD;
	}

	vector<ll> aux = xorConv(vals[0], xorConv(vals[1], vals[2]));
	cout << aux[0] << '\n';
}


Measured memory_bytes: 23040
#include <cstdio>
using namespace std;
char s[5][5];
int main(){
	scanf("%s %s", s[1]+1, s[2]+1);
	for(int i=1; i<=3; i++)
		if(s[1][i]^s[2][3-i+1]){
			printf("NO");
			return 0;
		}
	printf("YES");
	return 0;
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)

int main(){
    ll N,K;
    cin>>N>>K;
    N-=(N/K)*K;
     ll ans=N;
    vector<int>v;
    bool ok=true;
    while(ok){
        
        if(ans<=llabs(N-K))ok=false;
        ans=min(ans,llabs(N-K));
        N=llabs(N-K);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3596
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                for(int i = 0; i < n; i++){
                        ArrayList<Integer> a = new ArrayList<Integer>();
                        for(int j = 0; j < 10; j++){
                                a.add(sc.nextInt());
                        }   
                        ArrayList<Integer> b = new ArrayList<Integer>();
                        ArrayList<Integer> c = new ArrayList<Integer>();
                        b.add(0);
                        c.add(0);
                        boolean flag = true;
                        while(flag && !a.isEmpty()){
                                int ball = a.remove(0);
                                ArrayList<Integer> bigger = b.get(b.size()-1) < c.get(c.size()-1) ? c: b;
                                ArrayList<Integer> smaller = b.get(b.size()-1) < c.get(c.size()-1) ? b: c;
                                if(bigger.get(bigger.size()-1) < ball){
                                        bigger.add(ball);
                                }else if(smaller.get(smaller.size()-1) < ball){
                                        smaller.add(ball);
                                }else{
                                        flag = false;
                                }   
                        }   
                        String s = flag ? "YES": "NO";
                        System.out.println(s);
                }   
                sc.close();
        }   
}

Measured memory_bytes: 11000
#include <iostream>
using namespace std;
int main() {
	int N;
	int max = 0;
	int ans = 1;
	cin >> N;

	for (int i = 1; i <= N; i++)
	{
		int tmp = i;
		int cnt = 0;
		while (tmp > 0) {
			if (tmp % 2 == 0) {
				tmp /= 2;
				cnt++;
			}
			else
			{
				break;
			}
		}

		if (max < cnt) {
			max = cnt;
			ans = i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	void doIt() {
		Scanner sc = new Scanner(System.in);
		int i, k, under;
		Person[][] PersonArray = new Person[3][8];
		Person[] chance = new Person[6];	
		for(i = 0; i < 3; i++){
			for(k = 0; k < 8; k++){
				PersonArray[i][k] = new Person(sc.nextInt(), sc.next());	
			}
			Arrays.sort(PersonArray[i]);
			for(k = i*2, under = 2; k < 2*(i+1); k++, under++){
				chance[k] = PersonArray[i][under];
			}
		}
		Arrays.sort(chance);
		for(i = 0; i < 3; i++){
			for(k = 0; k < 2; k++){
				System.out.println (PersonArray[i][k]);
			}
		}
		for(i = 0; i < 2; i++){
			System.out.println (chance[i]);
		}
	}
	
	public static void main(String[] args){
		new Main().doIt();
	}
	
	class Person implements Comparable<Person>{
		int num;
		String time;
		Person(int num, String time){
			this.num = num;
			this.time = time;
		}
		public String toString(){
			return num +" "+ time;
		}
		@Override
		public int compareTo(Person o) {
			return time.compareTo(o.time);
		}
	}	
}

Measured memory_bytes: 25932
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
int main()
{
    ///"In the name of Allah,most gracious and most merciful"///

        ll i,j,x,y,z,count=0,sum=0,n,ans=0;
        string a,b,c;
        cin>>a>>b;
        c=a+b;
        ll k=stoi(c);

        bool ok = true;

        for(i=1;i*i<=k;i++)
        {
            if((i*i)==k)
            {
                ok=false;
                break;
            }
        }

    if(!ok)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}





Measured memory_bytes: 3636
#include <cstdio>
#include <cstring>
#include <algorithm>

const int Inf = 0x3f3f3f3f;
const int MN = 2005;

int N;
char s[MN], t[MN];

int A[MN], B[MN], L[MN], R[MN], dl[MN], dr[MN], p[MN], suf[MN];
inline int Solve(int r) {
	int ret = 0, lb = 0, rb = 0, K = 0;
	if (r >= 0) ret = r, rb = r;
	else ret = -r, lb = r;
	for (int i = 1; i <= N; ++i) {
		if (A[i] == B[(((i + r) % N + N - 1) % N) + 1]) continue;
		++ret;
		if (lb <= L[i] || R[i] <= rb) continue;
		dl[++K] = lb - L[i], dr[K] = R[i] - rb, p[K] = K;
	}
	std::sort(p + 1, p + K + 1, [](int i, int j) { return dl[i] < dl[j]; });
	suf[K + 1] = 0;
	for (int i = K; i >= 1; --i) suf[i] = std::max(suf[i + 1], dr[p[i]]);
	int mnv = suf[1];
	for (int i = 1, val = 0; i <= K; ++i)
		val = std::max(val, dl[p[i]]),
		mnv = std::min(mnv, val + suf[i + 1]);
	return ret + 2 * mnv;
}

int main() {
	scanf("%s%s", s + 1, t + 1), N = strlen(s + 1);
	int ok = 0;
	for (int i = 1; i <= N; ++i) if (t[i] == '1') ok = 1;
	if (!ok) {
		for (int i = 1; i <= N; ++i) if (s[i] == '1') return puts("-1"), 0;
		return puts("0"), 0;
	}
	for (int i = 1; i <= N; ++i)
		A[i] = s[i] - '0', B[i] = t[i] - '0';
	for (int i = 1, x, y; i <= N; ++i) {
		x = y = i;
		while (!B[x]) --L[i], x = x > 1 ? x - 1 : N;
		while (!B[y]) ++R[i], y = y < N ? y + 1 : 1;
	}
	int Ans = Inf;
	for (int r = 1 - 2 * N; r <= 2 * N - 1; ++r)
		Ans = std::min(Ans, Solve(r));
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 1784
class Pair
	attr_accessor :first, :second
	def initialize(a, b)
		@first  = a
		@second = b
	end
end

s1 = []
s2 = []
sum = 0

input = STDIN.gets
input.each_char.with_index do |c, i|
	if c == "\\"
		s1.push i
	elsif c == "/" && s1.size > 0
		j = s1.pop
		sum += i - j
		a = i -j
		while s2.size > 0 && s2.last.first > j
			a += s2.pop.second
		end
		s2.push(Pair.new(j, a))
	end
end

ans = []
until s2.empty?
	ans << s2.pop.second
end
puts sum
print ans.size
ans.reverse_each do |n|
	printf " #{n}"
end
print "\n"

Measured memory_bytes: 6284
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
long long p[200000], q[200000], n, k;
int main() {
	cin >> n >> k;
	for (long long i = 1; i <= n; i++) {
		long long a; cin >> a;
		if (a > 0)p[i] += a;
		q[i] += a;
	}
	for (long long i = 1; i < 200000; i++)p[i] += p[i - 1];
	for (long long i = 1; i < 200000; i++)q[i] += q[i - 1];
	long long maxn = 0;
	for (long long i = 1; i <= n; i++) {
		long long L = i, R = i + k - 1;//区間[L, R]は制限される
		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない
		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない
		if (R > n)continue;
		long long w1 = q[R] - q[L - 1];
		long long w2 = p[R1] - p[L1 - 1];
		long long w3 = p[R2] - p[L2 - 1];
		maxn = max(maxn, w1 + w2 + w3);
	}
	for (long long i = 1; i <= n; i++) {
		long long L = i, R = i + k - 1;//区間[L, R]は制限される
		long long L1 = 1, R1 = L - 1;//区間[1, L-1]は制限されない
		long long L2 = R + 1, R2 = n;//区間[R+1, n]は制限されない
		if (R > n)continue;
		long long w1 = 0;
		long long w2 = p[R1] - p[L1 - 1];
		long long w3 = p[R2] - p[L2 - 1];
		maxn = max(maxn, w1 + w2 + w3);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3456
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int max = (n - 1) * (n - 2) / 2;
        if (k > max) { 
            System.out.println(-1);
            return;
        }
        int count = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 2; i <= n; i++) {
            sb.append(1).append(" ").append(i).append("\n");
            count++;
        }
        for (int i = 2; i <= n - 1 && k < max; i++) {
            for (int j = i + 1; j <= n && k < max; j++) {
                sb.append(i).append(" ").append(j).append("\n");
                count++;
                max--;
            }
        }
        System.out.println(count);
        System.out.print(sb);
   }
}

Measured memory_bytes: 23124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * 0066 Tic Tac Toe
 */
public class Main {

	public static void main(String[] args) throws IOException {
		List<TicTacToe> ticTacToeList = readTicTacToe();
		for (TicTacToe ticTacToe : ticTacToeList) {
			// System.out.println(ticTacToe);
			System.out.println(ticTacToe.judge());
		}
	}

	private static List<TicTacToe> readTicTacToe() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		List<TicTacToe> ticTacToeList = new ArrayList<>();
		String line = null;
		while ((line = reader.readLine()) != null) {
			ticTacToeList.add(new TicTacToe(line));
		}
		return ticTacToeList;
	}

	// Tic Tac Toe
	private static class TicTacToe {

		// Win pattern
		Pattern[] WIN_PATTERN = { Pattern.compile(".*1.*4.*7.*"), Pattern.compile(".*2.*5.*8.*"),
				Pattern.compile(".*3.*6.*9.*"), Pattern.compile(".*1.*2.*3.*"), Pattern.compile(".*4.*5.*6.*"),
				Pattern.compile(".*7.*8.*9.*"), Pattern.compile(".*1.*5.*9.*"), Pattern.compile(".*3.*5.*7.*") };

		// position
		private String o = "";
		private String x = "";

		// Constructor
		public TicTacToe(String input) {
			for (int i = 0; i < input.length(); i++) {
				if (input.charAt(i) == 'o') {
					o = o + (i + 1);
				} else if (input.charAt(i) == 'x') {
					x = x + (i + 1);
				}
			}
		}

		// Judge
		private char judge() {
			// Check o
			for (Pattern p : WIN_PATTERN) {
				if (p.matcher(o).matches()) {
					return 'o';
				}
			}
			// Check x
			for (Pattern p : WIN_PATTERN) {
				if (p.matcher(x).matches()) {
					return 'x';
				}
			}
			return 'd';
		}

		@Override
		public String toString() {
			return "o: " + o + ", x: " + x;
		}
	}
}

Measured memory_bytes: 26156
//package Hotdays;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int I = sc.nextInt(); int N = sc.nextInt();
		int[] forecast = new int[I];
		int[][] data = new int[N][3];
		//[0] = ???????°???? [1] = ???????°???? [2] = ?´???????
		int[][] costtable = new int[N][I];
		int max = 0;
		for(int i = 0; i < I; i++) forecast[i] = sc.nextInt();
		for(int i = 0; i < N; i++) {
			data[i][0] = sc.nextInt();
			data[i][1] = sc.nextInt();
			data[i][2] = sc.nextInt();
		}
		for(int i = 0; i < I; i++) {
			for(int j = 0; j < N; j++) {
				if(data[j][0] > forecast[i] || data[j][1] < forecast[i]) { 
					costtable[j][i] = -1; //???????????????????????????
				}
			}
		}
		for(int i = 1; i < I; i++) {
			for(int j = 0; j < N; j++) {
				if(costtable[j][i] != -1) {
					for(int k = 0; k < N; k++) { 
						if(costtable[k][i - 1] != -1) {
							if(costtable[j][i] < costtable[k][i - 1] + Math.abs(data[j][2] - data[k][2])) {
								costtable[j][i] = costtable[k][i - 1] + Math.abs(data[j][2] - data[k][2]);
							}
						}
					}
				}
			}
		}
		for(int i = 0; i < N; i++) {
			if(max < costtable[i][I - 1]) max = costtable[i][I - 1];
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n, m;
    cin >> n >> m;
    map<ll, ll> mp;
    rep(i,m){
        ll a, b;
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    bool flag = true;
    for(auto e : mp){
        if(e.second%2==1){
            flag = false;
            break;
        }
    }
    printf("%s", flag?"YES":"NO");
}

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

l = 0
r = max(a)

while r - l > 1:
    cnt = 0
    mid = (r + l) // 2
    for i in range(n):
        d = (a[i] - 1) // mid
        if d > 0: cnt += d
    if cnt <= k: r = mid
    else: l = mid 

print(r)

Measured memory_bytes: 30784
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
const int d = 365;
//const int d = 5;
int c[26];
int s[d][26];
int last[26] = {0};


int score(vector<int> t){
    vector<int> last(26,0);
    int ans = 0;
    rep(i,d){
        ans += s[i][t[i]];
        last[t[i]] = i+1;
        rep(j,26) ans -= c[j] * (i+1-last[j]);
        //cout << ans << endl;
    }
    return ans;
}

//day 1-index i_day 's contest is k
int nowscore(int i,int k){
    int res = s[i][k];
    int before = last[k];
    last[k] = i+1;
    rep(j,26) res -= c[j] * (i+1-last[j]);
    last[k] = before;
    return res;
}

int main(){
    int tmp;
    cin >> tmp;
    rep(i,26) cin >> c[i];
    rep(i,d)rep(j,26) cin >> s[i][j];

    vector<int> ans(d,-1);
    for(int i=0;i<d;i++){
        int id = -1;
        int mx = -INF;
        for(int j=0;j<26;j++){
            int res = nowscore(i,j);
            if(mx < res){
                id = j;
                mx = res;
            }
            ans[i] = id;
            last[id] = i+1; 
        }
    }

    rep(i,d) cout << ans[i]+1 << endl;
    //cout << score(ans) << endl;

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 3e5+5;

int h[sz];
bitset <sz> bst;

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) scanf("%d", &h[i]);

    while(m--) {
        int u, v;
        scanf("%d %d", &u, &v);
        if(h[u] > h[v]) bst[v] = 1;
        else if(h[v] > h[u]) bst[u] = 1;
        else bst[u] = bst[v] = 1;
    }

    int ans = 0;
    for(int i=1; i<=n; i++) if(!bst[i]) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 4024
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 42
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
int N,Ma,Mb;
int A[MaxN],B[MaxN],C[MaxN];
int DP[MaxM][MaxM];
void solve()
{
    MST(DP,INF);
    DP[0][0] = 0;
    for(int i=0;i<N;i++)
    {
        for(int j=400;j>=1;j--)
        {
            for(int k=400;k>=1;k--)
            {
                if(j>=A[i] && k>=B[i])
                {
                    DP[j][k] = min(DP[j-A[i]][k-B[i]]+C[i], DP[j][k]);
                }
                else break;
            }
        }
    }
    int ans = INF;
    for(int j=1;j<=400;j++)
    {
        for(int k=1;k<=400;k++)
        {
            if(j*Mb == k*Ma)
            {
                //cout << j << " " << k  << " " << DP[j][k] << endl;
                ans = min(ans, DP[j][k]);
            }
        }
    }
    if(ans==INF) ans = -1;
    printf("%d\n", ans);
}
int main()
{
    //std::ios::sync_with_stdio(false);
    scanf("%d%d%d", &N, &Ma, &Mb);
    for(int i=0;i<N;i++)
    {
        scanf("%d%d%d", &A[i], &B[i], &C[i]);
    }
    solve();
    //system("pause");
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include<stack>
#include<string>
#include<algorithm> 
#include <set>
#include<list>
#include <bit>
#include <bitset>
#include <cstdint>
#include <initializer_list>
typedef long long int ll;
using namespace std;
const int MOD = 1000000007;


int main() {
	string str;
	cin >> str;
	int ans = 0;
	int temp;
	for (int i = 0; i < 3; i++) {
		temp = 0;
		while (str[i] == 'R'&&i<3) {
			temp++;
			i++;
		}
		if (temp >= ans)ans = temp;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3148
using System;


namespace ALDS_1_11_B
{
    class Program
    {
        const int N = 100;
        const int white = 0;
        const int gray = 1;
        const int black = 2;
        static int n,tt;
        static int[,] M = new int[N,N];
        static int[] color = new int[N];
        static int[] d = new int[N];
        static int[] f = new int[N];

        static void dfs_visit(int u)
        {
            color[u] = gray;
            d[u] = ++tt;
            for (int v = 0; v < n; v++)
            {
                if (M[u, v] == 0) continue;
                if (color[v] == white) dfs_visit(v);
            }
            color[u] = black;
            f[u] = ++tt;
        }
        static void dfs()
        {
            for (int u = 0; u < n; u++) if (color[u] == white) dfs_visit(u);
            for (int u = 0; u < n; u++) Console.WriteLine(u+1+" "+d[u]+" "+f[u]);
        }
        static void Main(string[] args)
        {
            n = scan()[0];
            for (int i = 0; i < n; i++)
            {
                var t = scan();
                for (int j = 0; j < t[1]; j++)
                {
                    M[t[0] - 1, t[j + 2] - 1] = 1;
                }
            }
            dfs();

        }
        static int[] scan()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
    }
}

Measured memory_bytes: 9348
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n,x,y;
	int maxn=-1e11,maxx=1e11,minx=-1e11,minn=1e11;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x>>y,maxn=max(x+y,maxn),maxx=min(x+y,maxx),minx=max(x-y,minx),minn=min(x-y,minn);
	cout<<max(maxn-maxx,minx-minn)<<endl;	
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

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

        int r = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();

        //        for (int i = 1; i <= n; i++) {
        //
        //        }

        sc.close();

        long num = r * x - d;

        System.out.println(num);

        for (int i = 0; i < 9; i++) {
            num = r * num - d;

            System.out.println(num);
        }

        //        System.out.println(b);

    }
}

Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
int sum = 0;
int temp = 0;
int main(){
    int n,time;
    int t[200005];
    scanf("%d %d",&n,&time);
    for(int i = 1;i <= n;i++){
        scanf("%d",&t[i]);
    }
    for(int i = 1;i < n;i++){
         temp = t[i + 1] - t[i];
         if(temp <= time)
            sum = sum + temp;
         else
            sum = sum + time;
    }
    sum = sum + time;
    printf("%d",sum);
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()

int main() {
		int N, K;
		cin >> N >> K;
		vector<bool> D(10, false);
		for (int i = 0; i < K; i++) {
				int t;
				cin >> t;
				D[t] = true;
		}

		for (int i = N; i <= 10 * N; i++) {
				bool flg = true;
				string S = to_string(i);
				for (int j = 0; j < S.size(); j++) {
						if (D[S[j]-'0'] == true) {
								flg = false;
								break;
						}
				}

				if (flg) {
						cout << i << endl;
						return 0;
				}
		}
		return 0;
}


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

const int maxn = 11111;
string s;
int front_b, back_a, both, n;

int main() {
    scanf("%d", &n);
    int ans = 0;
    rep(i, n) {
        cin >> s;
        int fb = false, ba = false;
        if(s[0] == 'B') fb = true;
        if(s.back() == 'A') ba = true;
        bool hasa = false;
        for(auto g : s) {
            if(g == 'A') {
                hasa = true;
            } else {
                if(g == 'B') {
                    if(hasa) ans++;
                }
                hasa = false;
            }
        }
        if(fb) {
            if(ba) both++;
            else front_b++;
        } else if(ba) back_a++;
    }
    // printf("fb = %d, ba = %d, both = %d\n", front_b, back_a, both);
    ans += both + min(front_b, back_a);
    if(front_b == 0 && back_a == 0 && both) ans--;
    printf("%d\n", ans);
    
    
    return 0;
}

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

int main(){
  int m,d;
  string w[7] = {
    "Thursday","Friday","Saturday","Sunday",
    "Monday","Tuesday","Wednesday",
 };
  int p[12] = { 
    31,29,31,30,31,30,
    31,31,30,31,30,31 };


  while( cin>>m>>d && (m) ){
    --d;
    for( int i=0;i+1<m;i++ )
      d += p[i];
    //    cout << "d="<<d<<endl;

    cout << w[ d%7 ] << endl;
  }

  return 0;
}

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

#define LL long long
#define int long long
#define MIN LLONG_MIN
#define MAX LLONG_MAX
#define PB push_back
#define N 200001
#define MX 262144
#define LG 17
#define M 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define LD long double
#define F first
#define S second
#define endl "\n"

int32_t main()
{
    LL i,j,lt,d,z,v,c,r,l,t1,k,h,u,q,ts,te,x,y,n,m;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    LL a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    x=n/2;
    cout<<a[x]-a[x-1];
}   

Measured memory_bytes: 1024