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

int main(){
  int N,M;
  int i;
  int t,u;
  
  cin >> N >> M;
  vector<int> num(N);

  for(i=0;i<M;++i){
    cin >> t >> u;
    if(t == 1 && u == 0 && N != 1){
      cout << -1 << endl;
      return 0;
    }
    if(num.at(t-1) == 0 || num.at(t-1) == u){
      num.at(t-1) = u;
    }else{
      cout << -1 << endl;
      return 0;
    }
  }

  if(num.at(0) == 0 && N != 1){
    num.at(0) = 1;
  }
  for(i=0;i<N;++i){
    cout << num.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      
      int ac = 0;
      int wa = 0;
      int tle = 0;
      int re = 0;
      
      for(int i=0; i<n; i++){
      	String s = sc.next();
        
        if("AC".equals(s))
          ac++;
        if("WA".equals(s))
          wa++;
        if("TLE".equals(s))
          tle++;
        if("RE".equals(s))
          re++;
      }
      
      
      	System.out.println("AC x " + ac);
      	System.out.println("WA x " + wa);
      	System.out.println("TLE x " + tle);
      	System.out.println("RE x " + re);
    }
}

Measured memory_bytes: 48420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_031
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            long mask = 1000000000 + 7;
            long n = ReadLong();
            string s = Read();
            long[] cnts = new long[26];
            for (int i = 0; i < 26; i++) cnts[i] = 1;
            for(int i = 0; i < n; i++)
            {
                cnts[s[i] - 'a']++;
            }
            long res = 1;
            for(int i = 0; i < 26; i++)
            {
                res *= cnts[i];
                res %= mask;
            }
            WriteLine(res - 1);
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11232
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long unsigned int ll;
using namespace std;
int main()
{
  ll N, A, B;
  cin >> N >> A >> B;
  if((B - A) %2 == 0){
    cout << (B - A)/2 << endl;
  }else{
    ll c = A + (B - A - 1)/2;
    ll d = (N - B) + (B - A + 1)/2;
    ll e = B - 1;
    ll f = N - A;
    cout << min(c,min(d,min(e,f))) << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve(int tc)
{
	int n;
	cin >> n;
	v32 arr(n, 0);
	v32 left(n, 0), right(n, 0);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			left[i] = arr[i];
			right[n - i - 1] = arr[n - i - 1];
		}
		else
		{
			left[i] = __gcd(left[i - 1], arr[i]);
			right[n - i - 1] = __gcd(right[n - i], arr[n - i - 1]);
		}
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
			ans = max(ans, right[i + 1]);
		else if (i == n - 1)
			ans = max(ans, left[i - 1]);
		else
			ans = max(ans, __gcd(left[i - 1], right[i + 1]));
	}
	cout << ans << ln;
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve(tc);
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 1408
<?php /*atcoder.php*/

$t = new temp();

$t->stdin(fgets(STDIN));
$t->main();

unset($t);

class temp{
	private $stdin = array();
	private $map = 0;
	private $apos = 0;
	private $bpos = 0;
	
	public function __construct(){
	}

	public function stdin($data = null){
		$this->stdin = explode(" ", $data);
		$this->map = $this->stdin[0];
		$this->apos = $this->stdin[1];
		$this->bpos = $this->stdin[2];
	}
	
	public function main(){
		$buf = $this->apos + $this->bpos;
		if(0 == ($buf % 2)){
			echo "Alice\n";
		}else{
			echo "Borys\n";
		}
	}
}

?>


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

using namespace std;
 
const int MOD=1e9+7;




//const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long ans=0;
    int n;
    cin>>n;
    int mx;
    cin>>mx;
    for(int i=1; i<n; i++){
        int x;
        cin>>x;
        if(x<=mx) ans+=(mx-x);
        else mx=x;
        
    }
    cout<<ans;
    
    return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define Ans(s) cout << s << endl

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> inv;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	vector<int> c(n);
	vector<int> s(n);
	vector<int> f(n);

	rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];

	for (int i = 0; i < n; i++)
	{
		int t = c[i] + s[i];

		for(int j = i + 1; j < n - 1; j++)
		{
			if (s[j] > t) t = s[j];
			else if (t % f[j] == 0);
			else t += f[j] - t % f[j];

			t += c[j];
		}
		
		Ans(t);
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		int i = 0;
		int j = 0;
		int sa = 0;

		int x = 0;
		int y = 0;

		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[m];
		int d[] = new int[m];

		i = 0;
		for (i = 0; i < n; i++) {
			a[i] = s.nextInt();
			b[i] = s.nextInt();
			//System.out.println(a[i]);
			//System.out.println(b[i]);

		}

		for (i = 0; i < m; i++) {
			c[i] = s.nextInt();
			d[i] = s.nextInt();
			//System.out.println(c[i]);
			//System.out.println(d[i]);

		}
		int ary[][] = new int[n][m];

		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) {
				if (a[i] > c[j]) {
					x = a[i] - c[j];
				} else if (a[i] <= c[j]) {
					x = c[j] - a[i];
				}

				if (b[i] > d[j]) {
					y = b[i] - d[j];
				} else if (b[i] <= d[j]) {
					y = d[j] - b[i];
				}

				sa = x + y;

				ary[i][j] = sa;


				//System.out.println(ary[i][j]);

			}

		}
		int ans[] = new int[n];

		for (i = 0; i < n; i++) {
			ans[i] = 1;
			int min = ary[i][0];
			for (j = 1; j < m; j++) {
				if (min > ary[i][j]) {
					min = ary[i][j];
					ans[i]=j+1;
				}
			}

			System.out.println(ans[i]);
		}

	}

}

Measured memory_bytes: 21844
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    N = NI()
    CMAX = 2*10**5
    A = [0 for _ in range(CMAX+1)]
    S = [1 for _ in range(CMAX+1)]
    C = [NI() for _ in range(N)]
    P = 1
    A[C[0]] = 1
    for i in range(1,N):
        if C[i] != C[i-1] and A[C[i]] > 0:
            S[C[i]] = S[C[i]] + P
        else:
            S[C[i]] = P
        A[C[i]] = 1
        P = S[C[i]] % MOD
    print(P)


if __name__ == '__main__':
    main()

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

int main()
{
  int n;
  cin >> n;
  int arare[n][2] = {
    {'P',0},
    {'W',0},
    {'G',0},
    {'Y',0}
  }; 
  char c;
  rep(i, n) 
  {
    cin >> c;
    rep(j, 4){
    if(c == arare[j][0]){
       arare[j][1]++;
     } 
    }      
  }
  int count = 0;
  rep(i, n) {
    if(arare[i][1] > 0) count++;
  }
  if(count == 3)
    cout << "Three" << endl;
  if(count == 4)
    cout << "Four" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
 
using namespace std;
 
//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<vector<int>>vvi;
typedef vector<vector<ll>>vvl;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back
 
const int mod = 998244353;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
bool check(vl &vals, ll m, int v, int p, int pos)
{
	//cerr << endl;
	//cerr << pos << vals[pos]<<endl;
	if (pos < 0)
	{
		return false;
	}
	int n = vals.size();
	if (vals[pos] >= vals[n - p])
	{
	//	cerr << "Case 1" << endl;
		return true;
	}
	if (vals[pos] + m < vals[n - p])
	{
	//	cerr << "Case 2" << endl;
		return false;
	}
	vector<ll> nes;
	ll mv = (pos + p - 1);
	mv = v - mv;
	if (mv <= 0)
	{
		return true;
	}
	ll sum = 0;
	ll dif=n-v;
	for (int i = n - p; i > pos; i--)
	{
		sum += m - (vals[i]- vals[pos]);
	//	cerr << sum << ' ' << dif << ' ' << endl;
		if (sum < (n - p - i - dif + 1)*m)
		{
		//	cerr << i << endl;
			return false;
		}
	}
//	cerr << "True" << endl;
	return true;
}
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	ll n, m, v, p;
	vl pr;
	cin >> n >> m >> v >> p;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		pr.push_back(x);
	}
	sort(pr.begin(), pr.end());
	int lb = -1, rb = n - 1;
	for (int turn = 0; turn < 30; turn++)
	{
		int mid = (lb + rb + turn % 2) / 2;
		if (!check(pr, m, v, p, mid))
		{
			lb = mid;
		}
		else
		{
			rb = mid;
		}
	}
	cout << n - rb<< endl;
 
}
int main()
{
	solve();
	int n;
	cin >> n;
}

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

using namespace std;

typedef int64_t ll;

template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> void generatePrimes(T n);
template <class T> void factorize(T n);

vector<ll> primes;
int listedPrimesUpto = 1;
ll ans = 1;


int main()
{
	ll a, b; cin >> a >> b;
	ll g = gcd(a, b);

	if (g == 1)
	{
		cout << 1 << endl;
		return 0;
	}

	factorize(g);

	cout << ans << endl;
}

template <class T> void factorize(T n)
{
	if (n < 2)
		return;

	T rt = (T)ceil(sqrt(n));

	if (listedPrimesUpto < rt)
		generatePrimes(rt);

	for (T d : primes)
	{
		if (rt < d) break;

		if (!(n % d))
		{
			++ans;
			while (!(n % d))
				n /= d;
		}
	}

	if (n != 1)
		++ans;
}

template <class T> void generatePrimes(T n)
{
	if (n <= listedPrimesUpto) return;
	if (primes.empty()) primes.push_back(2);
	if (primes.back() == 2 && n > 2) primes.push_back(3);

	bool isPrime;

	for (T k = primes.back() + 2; k <= n; k += 2)
	{
		if (!(k % 3)) continue;

		isPrime = true;
		T lim = (T)ceil(sqrt(k));

		for (T p : primes)
		{
			if (p > lim) break;
			if (!(k % p)) { isPrime = false; break; }
		}

		if (isPrime) primes.push_back(k);
	}
	listedPrimesUpto = n;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  COMinit();
  
  int h,w,a,b;
  cin >> h >> w >> a >> b;
  
  ll ans = 0;
  rep(i,h-a){
    ll res = COM(i+b-1,b-1)*COM(h-i-1+w-b-1,w-b-1);
    res %= MOD;
    ans += res;
    ans %= MOD;
  }
  cout << ans << endl;
 
  return 0;
}


Measured memory_bytes: 12160
x1,y1,x2,y2 = map(int, input().split())
dx = x2 - x1
dy = y2 - y1
x3 = x2 - dy
y3 = y2 + dx
x4 = x3 - dx
y4 = y3 - dy
print("{} {} {} {}".format(x3,y3,x4,y4))

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

int main(){
  int N; cin >> N;
  vector<double> p(N);
  for(int i = 0; i < N; i++) cin >> p[i];
  vector<vector<double> > dp(N + 1, vector<double> (N + 1, 0));
  dp[0][0] = 1.0;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j <= N; j++){
      if(j == 0) dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]);
      else dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1];
    }
  }
  double ans = 0;
  for(int j = (N + 1)/2; j <= N; j++) ans += dp[N][j];
  cout << setprecision(10) <<  ans << endl;
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int hp(ivec x, int p){
    int s=0, n=x.size();
    REP(i, n){
        s+=(x[i]-p)*(x[i]-p);
    }
    return s;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ivec x(n);
    VIN(x);
    ll m=0;
    REP(i, n){
        m+=x[i];
    }
    m /= n;



    cout << min(hp(x, m), hp(x,m+1)) << endl;
}


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

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
 int n;
 int m;
 int work = 0;
 cin >> n >> m;
 vector<int> vec(m);
 for (int i = 0; i < m; ++i){
	 cin >> vec[i];
	 work += vec[i];
 }
 if (n < work){
	 cout << -1;
 }
 else{
	 cout << n - work;
 }
} 

Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int N;
	cin >> N;

	cout << N / 2 + N % 2;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
 	int k,n;
 	cin>>k>>n;
 	int a[n];
 	for(int i=0;i<n;i++) cin>>a[i];
 	sort(a,a+n);
 	int ans=(a[n-1]-a[0]);
 	for(int i=1;i<n;i++){
 		if(i!=0){
 			int res=(a[n-1]-a[i])+(a[i-1]-a[0])+(k-a[n-1])+(a[0]);
 			ans=min(res,ans);
 		}
 	}  
 	cout<<ans<<endl;
}

Measured memory_bytes: 1792
def count_div(num):
    res = 0
    while num % 2 == 0:
        num //= 2
        res += 1
    return res

n = int(input())

ans = 1
max_cnt = 0
if n >= 2:
    for i in range(2, n+1, 2):
        cnt = count_div(i)
        if cnt > max_cnt:
            max_cnt = cnt
            ans = i

print(ans)

Measured memory_bytes: 3060
<?php

// define('DEBUG', true);
define('DEBUG', false);

// define('MOD', 1000000007);

fscanf(STDIN, "%d", $N);

for ($h = 1; $h <= 3500; $h++) {
    for ($n = 1; $n <= 3500; $n++) {
        $base = 4 * $h * $n - $N * $n - $N * $h;
        if ($base == 0) continue;
        $w = ($N * $h * $n) / $base;

        if ($w == intval($w) && $w > 0) {
            echo "{$h} {$n} {$w}\n";
            exit;
        }
    }
}


Measured memory_bytes: 4728
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



vector <long long> enumrate_digit(long long N) {
    vector <long long> res;
    while (N > 0) {
        res.push_back(N % 10);
        N /= 10;
    }
    Reverse(res);
    return res;
}





int main(void) {

    ll N; cin >> N;
    vector <ll> a = enumrate_digit(N);
    ll sum = 0;
    rep(i,a.size()) sum += a[i];
    if (N % sum == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    
    
    return 0;
}











Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    a, b, c, d = map(int, input().split())
    tt = (c - 1) // b
    at = (a - 1) // d
    r = "Yes" if tt <= at else "No"
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include <iostream>
#include <cmath>
using namespace std;
int main(){

  long long int n,result,n8,blank,i;

  while(cin>>n,n){
    
    result=0;
    for(i=20;i!=-1;i--){
      
      n8=pow(8,i);
      blank=n/n8;
      if(blank>=4) blank++;
      if(blank>=6) blank++;
      result+=blank*pow(10,i);
      n=n%n8;
      
    }
    
    cout<<result<<endl;

  }
  
  return 0;

}
      
    
    

Measured memory_bytes: 3220
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;


int main()
{
	char c; cin >> c;
	cout << (char)(c + 1) << endl;
}

Measured memory_bytes: 256
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())
          


n = 0
for i in range(N):
    if x[i] == y[i]:
        n = n+1
    elif n >=3:
        break
    elif x[i] != y[i]:
        n = 0

if n >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)44e15;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int L;cin>>L;
	string s,t;cin>>s>>t;
	llint lc=lcm(s.size(),t.size());
	//s,t,lcmの何か
	string ssss;
	string tttt;
	while(ssss.size()<min((llint)L,lc)){ssss+=s;}
	while(tttt.size()<min((llint)L,lc)){tttt+=t;}
	if(ssss>tttt){swap(s,t);}
	string ans;
	while(!((L-ans.size())<lc&&(L-ans.size())%t.size()==0)){ans+=s;}
	while(ans.size()<L){ans+=t;}
	cout<<ans<<endl;
}

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

void MakePrimeArray(bool A[],int n){
	A[0] = A[1] = false;
	for(int i=2;i<n;i++){
		A[i] = true;
	}

	for(int	i=2;i*i<n;i++){
		if(A[i]){
			for(int j=i*i;j<n;j+=i){
				A[j] = false;
			}
		}
	}
}



int main(){
  /*
  long int n=10000000;

  bool *primearray = new bool[n];

	MakePrimeArray(primearray,n);
*/
	int num;
  cin >> num;
  int input=0;
  int solve=0;
	for(int i=0;i<num;i++){
    cin >> input;
    /*if(primearray[input]){
      solve++;
    }*/
    if(input!=1){
      for(int j=2;j*j<=input;j++){
        if(input%j==0){
          solve--;
          break;
        }
      }
      solve++;
    }
  }
	cout << solve << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <bits/stdc++.h>
#include <string>
#include <stdlib.h>
#include <vector>
#include <sstream>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
int main(){
	long long n, cal = 0;
    cin >> n;
    long long a[n+1], b[n];
    for (int i = 0; i<=n; i++){
    	cin >> a[i];
	}
	for (int i = 0; i<n; i++){
		cin >> b[i];
	}
    for (int i = 0; i<n; i++){
    	if (b[i]<=a[i]) cal+=b[i];
    	else if (b[i]>=a[i]+a[i+1]){
    		cal+=(a[i]+a[i+1]);
    		a[i+1]=0;
		} 
		else{
			cal+=b[i];
			a[i+1]-=(b[i]-a[i]);
		} 
	}
	cout << cal;
	return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[][] a = new int[h][w];

		int count = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = sc.nextInt();
			}
		}

		List<int[]> answer = new ArrayList<>();

		boolean carrying = false;
		for (int i = 0; i < h; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < w; j++) {
					if (a[i][j] % 2 == 1) {
						if (carrying) {
							if (j == 0) {
								answer.add(new int[]{i, 1, i + 1, 1});
							} else {
								answer.add(new int[]{i + 1, j, i + 1, j + 1});
							}
							carrying = false;
						} else {
							carrying = true;
						}
					} else {
						if (carrying) {
							if (j == 0) {
								answer.add(new int[]{i, 1, i + 1, 1});
							} else {
								answer.add(new int[]{i + 1, j, i + 1, j + 1});
							}
						}
					}

				}
			} else {
				for (int j = w - 1; j >= 0; j--) {
					if (a[i][j] % 2 == 1) {
						if (carrying) {
							if (j == w - 1) {
								answer.add(new int[]{i, w, i + 1, w});
							} else {
								answer.add(new int[]{i + 1, j + 2, i + 1, j + 1});
							}
							carrying = false;
						} else {
							carrying = true;
						}
					} else {
						if (carrying) {
							if (j == w - 1) {
								answer.add(new int[]{i, w, i + 1, w});
							} else {
								answer.add(new int[]{i + 1, j + 2, i + 1, j + 1});
							}
						}
					}
				}
			}
		}
		System.out.println(answer.size());
		StringBuilder sb = new StringBuilder();
		for (int[] x : answer) {
			sb.append(x[0]);
			sb.append(" ");
			sb.append(x[1]);
			sb.append(" ");
			sb.append(x[2]);
			sb.append(" ");
			sb.append(x[3]);
			sb.append("\n");
		}
		System.out.print(sb.toString());
	}
}


Measured memory_bytes: 97532
/* ex 9_1
   アカウント名 */

#include <stdio.h>
#include <stdlib.h>
#define SIZE 11


typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}


int main(void){
    stack stk;
    int i;
    char input_seq[SIZE];
    char tmp, *ptr;
    scanf("%s", input_seq);
    ptr = input_seq;
    initialize_stack(&stk);
    while(*ptr != '\0'){
        if(*ptr != 'B'){
            push(&stk, *ptr);
        }
        else if(stk.count > 0){
            tmp = pop(&stk);
        }
        ptr++;
    }
    for(i = 0; i < stk.count+1; i++){
        if(stk.data[SIZE - i] != '\0'){
            printf("%c", stk.data[SIZE - i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1620
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



long long ways(int n){
    return (long long) n*(n-1)/2;
}
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    long long ans = 0LL;
    map<int,int> m;
    rep(i,n){
        m[a[i]]++;
    }
    for(auto e: m){
        ans += ways(e.second);
    }
    rep(i,n){
        int c = m[a[i]];
        cout << ans - (c-1)<< endl;
    }
    
    
}



Measured memory_bytes: 8320
s_a = list(input())
s_b = list(input())
s_c = list(input())
x=s_a[0]

while True:
    if x=='a':
        if len(s_a)==0:
            print('A')
            exit()

        x=s_a[0]
        s_a.remove(x)


    elif x=='b':
        if len(s_b)==0:
            print('B')
            exit()
        x=s_b[0]
        s_b.remove(x)
        

    elif x=='c':
        if len(s_c)==0:
            print('C')
            exit()
        x=s_c[0]
        s_c.remove(x)




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

char s[2][2001];
int dp[2002][2002][2], n[2];
int main() {
	scanf("%d%d%s%s", &n[0], &n[1], s[0], s[1]);
	int Max = 0;
	for (int i = n[0]; i >= 0; i--)for (int j = n[1]; j >= 0; j--)rep(t, 2)rep(k, 2) {
		int a = (k ? dp[i][j + 1][!t] : dp[i + 1][j][!t]), b = (k ? j : i);
		if (b == n[k] || a % 2 == t)continue;
		if (t != (s[k][b] == 'I' ? 0 : 1))dp[i][j][t] = max(dp[i][j][t], a + 1);
		if (dp[i][j][t] % 2)Max = max(Max, dp[i][j][t]);
	}
	printf("%d\n", Max);
}

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

int main(){
	ll n;
  	cin>>n;
  	string s;
  	map<string,ll>m;
  	while(n--){
    	cin>>s;
      	m[s]++;
    }
  	//map<string,ll>::iterator i;
    ll count=m.size();
    cout<<count;
}

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

#define LL long long
const int N = 50;
int d, x = 0;
int FF[N], FN[N];
int del[N];
LL ans = 0;
int main()
{
    cin >> d;
    while (d)
    {
        FF[x ++] = d % 10;
        d /= 10;
    }
    for (int X = 1; X < 15; ++ X)
        for (int Y = 0; Y <= 1; ++ Y)
            for (int i = 0; i < (1 << X); ++ i)
            {
                memset(del, 0, sizeof del);
                for (int j = 0, z = 0; j < X; ++ j)
                {
                    if (i & (1 << j))
                    {
                        del[j] = FF[j] + z;
                        del[X * 2 + Y - 1 - j] = -del[j];
                        z = 0;
                    }
                    else
                    {
                        del[j] = FF[j] - 10 + z;
                        del[X * 2 + Y - 1 - j] = -del[j];
                        z = 1;
                    }
                }

                memset(FN, 0, sizeof FN);
                int z = 0;
                for (int j = 0; j < X * 2 + Y; ++ j)
                {
                    FN[j] = del[j] + z; z = 0;
                    if (FN[j] < 0) FN[j] += 10, z = -1;
                }
                for (int j = 0; j < N; ++ j)
                    if (FN[j] != FF[j]) z = -1;
                if (z == -1) continue;

                LL tmp = 1;
                for (int j = 0; j < X; ++ j)
                    tmp *= (10 - abs(del[j]) - (j == 0));
                if (tmp < 0) tmp = 0;
                if (Y) tmp *= 10;
                ans += tmp;
            }
    cout << ans;
}


Measured memory_bytes: 256
const main = (input: string) => {
  const lines = input.trim().split("\n")
  const [N, T] = lines[0].split(" ").map(str => parseInt(str));
  const CT = lines.slice(1);
  const CTNumberList: number[][] = [];
  let minCost = 0;
  let answer: number | string;

  CT.forEach(ct => {
    CTNumberList.push(ct.split(" ").map(str => parseInt(str)))
  })

  CTNumberList.forEach(ct => {
    if(T >= ct[1] && (ct[0] < minCost || minCost === 0)) {
      minCost = ct[0]
    }
  })

  answer = minCost === 0 ? "TLE" : minCost
  console.log(answer)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;






int main() {

	
	int n, m;
	cin >> n >> m;
	string s;
	cin >> s;
	reverse(ALL(s));

	VI v;
	int cur = 0;
	int i = 0;
	while (i < n) {
		bool b = true;
		for (int j = min(m, n - i); j > 0; j--) {
			if (s[i + j] == '0') {
				v.push_back(j);
				b = false;
				i = i + j;
				break;
			}
		}
		if (b) {
			cout << -1 << endl;
			return 0;
		}
	}
	reverse(ALL(v));

	for (int i : v) {
		cout << i << ' ';
	}
	

}

Measured memory_bytes: 1144
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = Console.ReadLine();
            var N = S.Split('/');
            N[0] = "2018";
            Console.WriteLine(N[0] + "/" + N[1] + "/" + N[2]);
            
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}

Measured memory_bytes: 13268
{-# LANGUAGE OverloadedStrings, ViewPatterns #-}
import Data.List
import qualified Data.ByteString.Char8 as B

main = breads >>= main'
    where
        main' [n, a, b] = B.getLine >>= mapM_ B.putStrLn . solve (a + b) b 0 0

solve :: Int -> Int -> Int -> Int -> B.ByteString -> [B.ByteString]
solve ab b tn n (B.uncons -> Just (x, xs))
    | x == 'a' && tn < ab = "Yes" : solve ab b (tn + 1) n xs
    | x == 'b' && tn < ab && n < b = "Yes" : solve ab b (tn + 1) (n + 1) xs
    | otherwise = "No" : solve ab b tn n xs
solve _ _ _ _ _ = []

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 1532
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int M = 1e9 + 9;
int B = 63;
int n;
char g[601][601];
int down[601][601];
int R[601][601];
int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j) {
			scanf(" %c", &g[i][j]);
			for (int dx = 0; dx < 2; ++dx)
				for (int dy = 0; dy < 2; ++dy)
					g[i + n*dx][j + dy*n] = g[i][j];
		}
	for (int i = 0; i + n <= n * 2; ++i)
		for (int j = 0; j < 2 * n; ++j) {
			int &x = down[i][j];
			for (int k = 0; k < n; ++k)
				x = ((ll)x*B + g[i + k][j] - 'a' + 1) % M;
		}
	for (int i = 0; i < n * 2; ++i)
		for (int j = 0; j + n <= 2 * n; ++j) {
			int &x = R[i][j];
			for (int k = 0; k < n; ++k)
				x = ((ll)x*B + g[i][j + k] - 'a' + 1) % M;
		}
	int res = 0;
	for (int A = 0; A < n; ++A)
		for (int B = 0; B < n; ++B) {
			bool ok = true;
			for (int j = 0; j < n; ++j) {
				if (down[A][B + j] != R[A + j][B]) {
					ok = false;
					break;
				}
			}
			if (ok)
				++res;
		}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    if(x < 0) {
        x *= -1;
    }

    ll a = x/d;
    ll b = x%d;

    if(k < a) {
        out(x - d*k);
    }
    else {
        if(k%2 == a%2) {
            out(b);
        }
        else {
            out(abs(b - d));
        }
    }
    
    re0;
}

Measured memory_bytes: 3636
{-# LANGUAGE FlexibleContexts, BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf


readInt :: IO Double
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-' || c == '.'
                then (c :) <$> input
                else return []

prints :: [Double] -> IO ()
prints as = putStr $ concat $ intersperse "\n" $ map (printf "%.7f") as

main = prints . f =<< replicateM 3 readInt

f [a,b,c] = let co = cos (c * pi / 180)
                si = sin (c * pi / 180)
            in [a * b * si / 2, a + b + sqrt (a^2 + b^2 - 2*a*b*co), b * si]


Measured memory_bytes: 4252
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> s(N,0);
    for(int i=0; i<N; i++){
        cin >> s[i];
    }
    int cnt=1;
    int tmp=-1;
    int flag=0;
    for(int i=0; i<N; i++){
        if(flag == 1 && s[i]<tmp){
            cnt++;
            flag=0;
        }else if(flag == -1 && s[i]>tmp){
            cnt++;
            flag=0;
        }else if(flag==0 && tmp>=0){
            if(s[i]>tmp){
                flag=1;
            }else if(s[i]<tmp){
                flag=-1;
            }
        }
        tmp=s[i];
    }
    cout << cnt << endl;
}

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

int main()
{
    int N,tmp;
    cin >> N;
    set<int> v;
    rep(i, N)
    {
        cin >> tmp;
      v.insert(tmp);
    }
    cout << v.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	    //  #ifndef ONLINE_JUDGE
	    //  // for getting input from input.txt
	    //  freopen("input.txt", "r", stdin);
	    //  // for writing output to output.txt
	    //  freopen("output.txt", "w", stdout);
	    // #endif
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n,k;
	    cin>>n>>k;
	    string s;
	    cin>>s;

	   	s[k-1] = s[k-1]+32;
	   	cout<<s;
	    return 0;
	  }


Measured memory_bytes: 3620
# 全縦線と全横線を全探索するとO(N^5)
# 50 ** 5 = 312500000
# 縦線の選び方は50 C 2だから2分の1になるのを考慮しても、78125000
# いや無理だろ……と思ったら公式がこの解法だった。衝撃。
# 二次元累積和を使うと各回の計算がO(1)になるので、O(N^4)となる。

# まず O(N^5)解法を作ってみよう。通るのかこれ?


n, k = list(map(int, input().split()))
coords = [list(map(int, input().split())) for _ in range(n)]

ans = (3 * 10 ** 9) ** 2
for ix1, x1 in enumerate(coords):
    for ix2, x2 in enumerate(coords[ix1+1:]):
        for iy1, y1 in enumerate(coords):
            for iy2, y2 in enumerate(coords[iy1+1:]):
                point_in_rect = 0
                for c in coords:
                    # ソートしてない。
                    if (c[0] - x1[0]) * (c[0] - x2[0]) <= 0 and (c[1] - y1[1]) * (c[1] - y2[1]) <= 0:
                        point_in_rect += 1
                if point_in_rect >= k:
                    ans = min(ans, abs((x1[0] - x2[0]) * (y1[1] - y2[1])))

print(ans)


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

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

	string r = s.substr(0, n/2);
	string l = s.substr(n/2, n/2);

	if (n%2)
	{
		cout << "No\n"; return 0;
	}

	if (r == l) cout << "Yes\n";
	else cout << "No\n";
	return (0);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static int[] f = new int[1000001];
	static long ans = 0;

	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int h = sc.nextInt(), w = sc.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++)
			a[i] = sc.next();
		boolean[] row = new boolean[h], col = new boolean[w];
		Arrays.fill(row, false);
		Arrays.fill(row, false);
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				if (a[i].charAt(j) == '#') {
					row[i]=true;
					col[j]=true;
				}
		for(int i=0;i<h;i++){
			if(row[i]){
				for(int j=0;j<w;j++){
					if(col[j]){
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}

}


Measured memory_bytes: 28116