akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().split())
s = [0]*m
c = [0]*m
for i in range(m):
    s[i], c[i] = map(int, input().split())

if n == 1:
    start = 0
elif n == 2:
    start = 10
else:
    start = 100
for i in range(start,10**n):
    num = str(i)
    for j in range(m):
        if num[s[j]-1] != str(c[j]):
            break
    else:
        break
else:
    print(-1)
    exit()
print(num)

Measured memory_bytes: 9028
kn=list(map(int, input().split()))
a=list(map(int, input().split()))
k=kn[0]
n=kn[1]
maxdis=k-a[n-1]+a[0]
#print(maxdis)
for i in range(n-1):
    if maxdis<(a[i+1]-a[i]):
        maxdis=(a[i+1]-a[i])
        #print(i)
        #print(maxdis)
print(k-maxdis)

Measured memory_bytes: 26444
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    string s; cin>>s;
    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3]) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());



signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  int ma = 0;
  int ans = 0;
  rep(i, n) {
    int a; cin >> a;
    if (a >= ma) {
      ans++;
      chmax(ma, a);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 02.09.2017 15:07:12       
**/
#include <bits/stdc++.h>

using namespace std;

const int md = 998244353;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) {
    a -= md;
  }
}

inline int mul(int a, int b) {
  return (long long) a * b % md;
}

inline int power(int a, int b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int x) {
  return power(x, md - 2);
}

const int N = 12345;

int x[N], y[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", x + i, y + i);
  }
  int ans = power(2, n);
  add(ans, md - 1);
  add(ans, md - n);
  add(ans, md - n * (n - 1) / 2);
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int a = y[j] - y[i];
      int b = x[i] - x[j];
      int c = -a * x[i] - b * y[i];
      int cnt = 2;
      for (int k = 0; k < n; k++) {
        if (k == i || k == j) {
          continue;
        }
        int z = a * x[k] + b * y[k] + c;
        if (z != 0) {
          continue;
        }
        if (k < j) {
          break;
        }
        cnt++;
      }
      add(ans, md - power(2, cnt));
      add(ans, 1);
      add(ans, cnt);
      add(ans, cnt * (cnt - 1) / 2);
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

class MainClass : Scanner
{
    static void Main()
    {
        var (x, y, z) = ReadTuple<int,int,int>();
        WriteLine($"{z} {x} {y}");
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


Measured memory_bytes: 27476
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
res = 0
(0...n).each do |i|
  d = [a[i], b[i]].min
  res += d
  b[i] -= d
  if b[i] > 0
    d = [a[i + 1], b[i]].min
    res += d
    a[i + 1] -= d
  end
end
puts res

Measured memory_bytes: 21788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,ans=0,a,b;cin>>n>>m;
  vector<lvector> jobs(m);
  rep(i,n) {
    cin>>a>>b;
    if(a>m) continue;
    jobs[m-a].emplace_back(b);
  }
  lpque que;
  for(ll i=m-1;i>-1;--i) {
    for(ll job:jobs[i]) que.push(job);
    if(que.size()) {ans+=que.top();que.pop();}
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
const int N = 100000+5;
int p[N];
int f[N];
int find(int x)
{
    return f[x] == x ? f[x] : f[x] = find(f[x]);
}
int main()
{
   int n,m;
   while(cin >> n >> m)
   {
       for(int i = 1;i <= n; i++) f[i] = i;
       for(int i = 1; i <= n; i++)
       {
           scanf("%d",&p[i]);
       }
       for(int i = 0; i < m; i++)
       {
           int a,b;
           scanf("%d%d",&a,&b);
           int fa = find(a);
           int fb = find(b);
           f[fb] = fa;
       }
       int ans = 0;
       for(int i = 1; i <= n; i++)
       {
           if(p[i] == i) ans ++;
           else if(find(i) == find(p[i])) ans ++;
       }
       printf("%d\n",ans);
   }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
   
int main(void){
    int n,a[100] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
       
    cout << a[n-1];
    for(int i = n-2; i >= 0; i--){
        cout << " " << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int n,a[N];
void Put(int p) {p&1?puts("First"):puts("Second");exit(0);}
void dfs(int p)
{
	int od=0,ov=0,g=0,mn=1e9;
	for(int i=1;i<=n;i++) a[i]&1?od++:ov++,mn=min(mn,a[i]);
	if(ov&1) Put(p);
	if(od>1||mn==1) Put(p^1);
	for(int i=1;i<=n;g=__gcd(g,a[i]),i++) if(a[i]&1) a[i]--;
	for(int i=1;i<=n;i++) a[i]/=g;
	dfs(p^1);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(n==1) Put(a[1]-1);dfs(1);
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {

	int n,k = 0;
	int i = 0;
	int num = 1;

	scanf("%d", &n);
	scanf("%d", &k);

	while(i < n) {
		if (num < k) {
			num = 2*num;
		}
		else {
			num = num + k;
		}
		i++;
	}
	printf("%d\n", num);
	return 0;
}


Measured memory_bytes: 128
#coding:utf-8
submit=True
MOD=(10**9)+7
if submit:
    L=raw_input()
    #dp[i][0]:=Lを絶対超えない
    #dp[i][1]:=Lを超えるかも
    dp=[[0,0] for _ in range(len(L))]

    dp[0][0]=1 #(0,0)
    dp[0][1]=2 #(1,0),(0,1)

    for i,c in enumerate(L):
        if i==0:continue
        if c=='1':
            dp[i][0]=dp[i-1][0]*3 #(1,0),(0,1),(0,0)
            dp[i][0]+=dp[i-1][1]*1 #(0,0)
            dp[i][1]=dp[i-1][1]*2 #(1,0),(0,1)
        else:
            dp[i][0]=dp[i-1][0]*3 #(1,0),(0,1),(0,0)
            #dp[i][0]=dp[i-1][1]*1#(0,0)
            dp[i][1]=dp[i-1][1]*1#(0,0)
        dp[i][0]%=MOD
        dp[i][1]%=MOD
    print((dp[len(L)-1][0]+dp[len(L)-1][1])%MOD)
else:
    ans=0
    L=0b1010
    for a in range(1000):
        for b in range(1000):
            if a+b<=L and a+b==a^b:
                ans+=1
    print(ans)

Measured memory_bytes: 41500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {
	// 2020/2/24 Beginner
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String[] strArray = br.readLine().split(" ");
	int N = Integer.parseInt(strArray[0]);
	int R = Integer.parseInt(strArray[1]);
	if (N >= 10)
	    System.out.println(R);
	else
	    System.out.println(100 * (10 - N) + R);
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    double a, b;
    cin >> a >> b;
    cout << fixed << setprecision(10) << a / b << endl;
    return 0;
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

cout.precision(17);
  ll n,k;cin>>n>>k;
  ld ans=0;
  for(ll i=1;i<=n;i++){
    ll t=i;
    ld p=(ld)1.0/n;
    while(t<k){
      p *= 0.5;
      t *= 2;
    }
    ans+=p;
  }
  cout<<ans<<endl;
    return 0;
}


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

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

    vector<int> d(N);
    rep(i, N){
        cin >> d.at(i);
    }

    int sum = 0;
    rep(i, N){
        repi(j,i+1,N){
            sum += d.at(i) * d.at(j);
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

ll getNum(int a){
  ll n = (ll)a;
  return n*n*n*n*n;
}

void solve(){	
  ll x; cin>>x;
  for(int i = -1000; i <= 1000; i++){
    for(int j = -1000; j <= 1000; j++){
      if(getNum(i) - getNum(j) == x){
        cout<<i<< " "<<j<<endl;
        return;
      }
    }
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N;
  for (int i=0; i< N; i++) {
    cin >> S;
    if (S == "Y") {
      cout << "Four" << endl;
      break;
    }
    else if (i == N-1) {
      cout << "Three" << endl;
    }
  }

  // ここにプログラムを追記
}


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

int main()
{
 bool flag1 = true ;
 bool flag2 = true ;
 int N;
 cin >> N ;
 int arr[N];
 for (int i=0 ; i<N ; i++)
    cin >> arr[i];
 int counter = 0 ;
 for (int i=1 ; i<=N ; i++)
    {
      if (i%2 == 0)
        flag1=false ;
      else if (arr[i-1]%2 == 0)
        flag2 = false ;
      if (flag1 && flag2)
        counter++ ;
        flag1 = true ;
        flag2 = true ;

    }
      cout << counter << endl ;
}


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

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

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

    int ans = 0;
    for(int mid = N-2;mid>0;mid--){
        for(int low = mid-1;low>=0;low--){
        auto itr = lower_bound(A.begin(),A.end(),A[mid]+A[low]);
        int ng = distance(itr,A.end());
        ans += N-1 - mid - ng;
        }
    }
    cout << ans << endl;
}



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


#define	ll_int	long long int
#define	SIZE	32


void Init(int *box)
{
	int i;

	for(i = 0; i < SIZE; i++)
		box[i]  = 0;
}


void To_bit(int *box, ll_int x)
{
	ll_int tmp;
	int i = 0;

	while( (tmp = x / 2) >= 1){
		box[(SIZE - 1) - i] = x % 2;
		x = tmp;
		i++;
	}
	box[(SIZE - 1) - i] = x;
}


// 引数：表示する配列、反転するか否か
void Disp(int *box, int inversion)
{
	int i;

	for(i = 0; i < SIZE; i++){
		if(inversion){
			if(box[i])
				printf("0");
			else
				printf("1");
		}else
			printf("%d", box[i]);
	}
	printf("\n");
}


int main()
{
	ll_int a, b;
	int bit_box[SIZE];
	int i;

	scanf("%lld %lld", &a, &b);


	/* 表示 */
	// AND
	Init(bit_box);
	To_bit(bit_box, a & b);
	Disp(bit_box, 0);

	// OR
	Init(bit_box);
	To_bit(bit_box, a | b);
	Disp(bit_box, 0);

	// XOR
	Init(bit_box);
	To_bit(bit_box, a ^ b);
	Disp(bit_box, 0);

	return 0;
}


Measured memory_bytes: 1996
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n,1);
    vector<int> b(n);
    b[0]=1;
    rep(i,m) {
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        if(b[x]>0) {
            b[x]--;
            b[y]=a[y]+1;
        }else if(b[y]>0) {
            b[y]++;
        }
        a[x]--; a[y]++;
    }
    int ans = 0;
    rep(i,n) if(b[i]>0) ans += 1;
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 4728
#include<cstdio>

int S[1000000],n,q;

int binary(int x){
	int l=1;
	int r=n+1;
	int mid;
	while(l<r){
		mid = (l + r) / 2;
		if(x==S[mid]) return 1;
		else if(x < S[mid]) r=mid;
		else if(x > S[mid]) l=mid+1;
	}
	return 0;
}



int main(){
	int x,cnt;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&S[i]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		scanf("%d",&x);
		cnt+=binary(x);
	}
	printf("%d\n",cnt);
	return 0;
}


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

struct Edge {
    int to;
    ll distance;
};
struct Data {
    int from;
    int index;
    ll distanceFromK;
};
//
int N;
//経路
vector<vector<Edge>> edgeMap(100001);
//Kからの距離
ll minD[100001];

//全都市のKからの距離を計算
//K,およびその先から伸びるすべての辺を探索。最大でも100000回ですむはず
void calcFromK(int from, int curr, ll distance) {
    minD[curr] = distance;

    //都市 d.curr から伸びている辺を全部あさる。ただし来た道は除外
    auto arr = edgeMap[curr];
    for (auto e: arr) {
        if (e.to != from) {
            calcFromK(curr, e.to, distance + e.distance);
        }
    }
}
//x -> k -> yな距離を計算
ll solve(int x, int y, int k) {
    return minD[x] + minD[y];
}

int main()
{
    cin >> N;
    rep(i, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        edgeMap[a].push_back({b, c});
        edgeMap[b].push_back({a, c});
    }
    int Q, K;
    cin >> Q >> K;
    vector<ll> ans;
    calcFromK(-1, K, 0);
    rep(i, Q) {
        int x, y;
        cin >> x >> y;
        ans.push_back(solve(x, y, K));
    }

    for (auto a : ans) {
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 18944
n , m = map(int , input().split())
a =[]
b=[]
for i in range(n):
	a.append(list(map(int , input().split())))
for i in range(m):
	b.append(list(map(int, input().split())))
for i in range(n):
	now =10**9+90000
	idx=0
	for j in range(m):
		d=abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])
		if(d<now):
			now=d
			idx=j+1
	print(idx)

Measured memory_bytes: 68136
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define mod 1000000007
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int fact[1000001];
bool ok = false;

void f(int x){
    if(ok) return;
    for(int i = 1; i*i<=x;i++){
        if(x%i==0){
            int a = i;
            int b = x/i;
            if(a==b){
                a= i;
                b=1;
            }
            if(a!=1){
                if(fact[a]){
                    ok = true;
                    return;
                }
                fact[a]++;
            }
            if(b!=1){
                if(fact[b]){
                    ok = true;
                    return;
                }
            fact[b]++;
            }
        }
    }
}
int main()
{ int n;
    cin>>n;
    int a[n];
    for(int i = 0 ;i <n;i++) cin>>a[i];
    int gc = a[0];
    f(a[0]);
    for(int i = 1;i<n;i++){
        f(a[i]);
        gc = __gcd(gc,a[i]);
    }

    if(!ok) cout<<"pairwise coprime"<<endl;
    else if(gc==1) cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
 
 
return 0;
   
}

Measured memory_bytes: 7812
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if(s.size() == 2) {
    cout << s << endl;
  }
  else if(s.size() == 3) {
    for(int i = 2; i > -1; i--) {
      cout << s[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = input()
if len(N) >= 3:
    A = int(N[-3])*100 + int(N[-2])*10 + int(N[-1])
    if A == 0:
        print(0)
    else:
        print(1000 - A)
elif len(N) == 2:
    A = int(N[-2])*10 + int(N[-1])
    print(1000 - A)
elif len(N) == 1:
    A = int(N[-1])
    print(1000 - A)

Measured memory_bytes: 9196
a,b,c=map(int,input().split())
if a>b:
    a,b=b,a
    if b>c:
        b,c=c,b
        if a>b:
            a,b=b,a
    else:
        pass
elif b>c:
    b,c=c,b
    if a>b:
        a,b=b,a
        
else:
    pass

print(f'{a} {b} {c}')


Measured memory_bytes: 5612
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{	
    public static void Main()
	{
	    int[] n = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        if(n[0] <= n[1]) Console.WriteLine(n[0]);
        else Console.WriteLine(n[0]-1);
	} 
}

Measured memory_bytes: 11220
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N,H,W;
  cin >> N >> H >> W;
  int ans = (N - H + 1) * (N - W + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    
    long n,a[100000],b[100000];
    
    scanf("%ld",&n);
    for(int i=1;i<=n;i++) scanf("%ld",&a[i]);
    
    for(int i=1;i<=n;i++){
        b[a[a[i]]]=a[i];
    }
    
    for(int i=1;i<=n;i++) printf("%ld ",b[i]);
    
    return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  for(auto &i : a) cin >> i;
  sort(a.begin(), a.end());
  int ans = unique(a.begin(), a.end()) - a.begin();
  cout << ans << endl;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int cnt[100000] = {},ma = 0;
		for(int i = 0;i < n;i++){
			int a,b,c,d,e,f;
			scanf("%d:%d:%d %d:%d:%d",&a,&b,&c,&d,&e,&f);
			cnt[a * 3600 + b * 60 + c + 1]++;
			cnt[d * 3600 + e * 60 + f + 1]--;
		}
		for(int i = 1;i <= 86400;i++){
			cnt[i] += cnt[i - 1];
			ma = max(ma,cnt[i]);
		}
		cout << ma << endl;
	}
}

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long 
#define f(z) for(int i=1;i<=z;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
int cl(int n ,int m) { if(n%m)return n/m + 1 ;else return n/m ;}
int pw(int a,int b){int r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
#define mod  1000000007
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1e6 + 5 ;
vector <P > a[20] ;
signed main(){
	int n , ans = 0, k;
	cin >> n; 
	f(n){
		cin >> k ;
		for (int j = 1 ; j<=k ;j++){
			int x , y ;
			cin >> x >> y ;
			a[i].pb({x,y}) ;
		}
	}

	for ( int mask = 0 ; mask<(1<<n) ; mask++){
		si s , t ;
		int ok = 0 , cnt = 0  ;
		for ( int i = 0 ; i<n ; i++){
			if( mask&(1<<i) ) {
				cnt++ ;
				for ( auto it : a[i+1] ){
					
					if(it.second == 0 ){
						if( (mask&(1<<(it.first-1)) ) ) ok = 1 ;
					}
					else {
						if( (mask&(1<<(it.first-1)) ) == 0) ok = 1; 
					}
				}
			}
		}

		if( ok == 0 )  ans = max( ans , cnt ) ;
	}
	cout << ans ;
}







Measured memory_bytes: 256
import java.util.Scanner;

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

		if ((a == b && a != c)||(b == c && b != a)||(c == a && c !=b)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}

}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

string s, t;

vector <int> poss[1005];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> s >> t;

    for(int i = 0; i < s.size(); i++) {
        poss[s[i]].push_back(i);
    }

    long long ans = 0;

    int last = -1;
    for(int i = 0; i < t.size(); i++) {
        if(poss[t[i]].empty()) {
            cout << -1;
            return 0;
        }
        auto it = lower_bound(poss[t[i]].begin(), poss[t[i]].end(), last + 1);
        if(it == poss[t[i]].end()) {
            ans += s.size();
            last = poss[t[i]][0];
        } else {
            last = *it;
        }
    }
    cout << ans + last + 1;
}

Measured memory_bytes: 1228
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		while (s.hasNext()) {
			String str = s.next();
			if (str.equals("-")) return;
			int n = Integer.parseInt(s.next());
			for (int i = 0; i < n; ++i) {
				int h = Integer.parseInt(s.next());
				str = str.substring(h, str.length()) + str.substring(0, h);
			}
			System.out.println(str);
		}
	}
}

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

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

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int m = 0, x = INF;
    rep(i, n){
        int a, b;
        cin >> a >> b;
        m = max(a, m);
        x = min(x, b);
    }

    int ans = m + x;
    cout << ans << "\n";

    return 0;
}


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

from fractions import gcd

def main():
    n = int(raw_input())
    l = map(int, raw_input().split())

    pr = 1
    for e in l:
        pr *= e

    denum = 0

    for e in l:
        denum += pr / e

    g = gcd(pr, denum)
    pr /= g
    denum /= g

    print 1.0 * pr / denum

if __name__ == "__main__":
    main()


Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'




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

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

	int a[n];
	for(auto &it:a)
	{
		int val;
		cin>>val;
		it = val;
	}

	int ans = 0;
	int sum =0;
	for(int i=0;i<k;i++)
	{
		sum+=(a[i]+1);


	}
	ans = max(ans,sum);
	for(int i=k;i<n;i++)
	{
		// watch(sum);
		sum-=(a[i-k]+1);
		sum+=(a[i]+1);
		ans = max(ans,sum);
	}

	// long double  res = (long double)ans / 2;
	// cout<<res<<endl;


  cout << fixed << setprecision(9) << (double)ans/2 << endl;

	
	
	
	



}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		List<Integer> C = new ArrayList<Integer>();
		List<Integer> S = new ArrayList<Integer>();
		List<Integer> F = new ArrayList<Integer>();

		for (int i = 0; i < N - 1; i++) {
			String[] get = br.readLine().split(" ");
			C.add(Integer.parseInt(get[0]));
			S.add(Integer.parseInt(get[1]));
			F.add(Integer.parseInt(get[2]));
		}

		Stack time = new Stack();
		time.push(0);

		int now = 0;
		for (int n = 0; n < N ; n++) {
			now = 0;
			for (int i = n; i < N - 1; i++) {
				if (now < S.get(i))
					now = S.get(i);

				while (now % F.get(i) != 0) {
					now++;
				}

				now += C.get(i);

			}
			System.out.println(now);
		}

	}
}

Measured memory_bytes: 24020
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,*aaa = get_all_int()

for a in aaa:
    if a%2 == 0 and (a%3!=0 and a%5!= 0):
        print("DENIED")
        exit()
print("APPROVED")

Measured memory_bytes: 38704
#include <stdio.h>
int main(void) {
	char s[110];
	int i;
	int bool = 1;

	for (i = 0; i < 110; i++)
		s[i] = 0;

	scanf("%s", s);

	i = 0;
	while (s[i] != 0) {
		if (s[i] == 'L') {
			bool = 0;
			printf("No");
			break;
		}
		i += 2;
	}

	if (bool == 0)
		return 0;

	i = 1;
	while (bool&& s[i] != 0) {
		if (s[i] == 'R') {
			printf("No");
			break;
		}
		i += 2;
	}

	if (s[i] == 0)
		printf("Yes");

	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
int SY,SX,GY,GX;
string S[1010];
int D[1010][1010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>SY>>SX>>GY>>GX;
	SY--,SX--,GY--,GX--;
	FOR(y,H) {
		cin>>S[y];
		FOR(x,W) D[y][x]=1010101;
	}
	
	deque<int> Q;
	D[SY][SX]=0;
	Q.push_front(SY*1000+SX);
	while(Q.size()) {
		int cy=Q.front()/1000;
		int cx=Q.front()%1000;
		Q.pop_front();
		
		if(cy==GY&&cx==GX) {
			cout<<D[cy][cx]<<endl;
			return;
		}
		
		FOR(i,4) {
			int dd[4]={1,0,-1,0};
			int ty=cy+dd[i];
			int tx=cx+dd[i^1];
			if(ty<0||ty>=H||tx<0||tx>=W||S[ty][tx]=='#') continue;
			if(D[ty][tx]>D[cy][cx]) {
				D[ty][tx]=D[cy][cx];
				Q.push_front(ty*1000+tx);
			}
		}
		for(int ty=max(0,cy-2);ty<=min(H-1,cy+2);ty++) {
			for(int tx=max(0,cx-2);tx<=min(W-1,cx+2);tx++) {
				if(S[ty][tx]=='.'&&D[ty][tx]>D[cy][cx]+1) {
					D[ty][tx]=D[cy][cx]+1;
					Q.push_back(ty*1000+tx);
				}
			}
		}
		
		
	}
	cout<<-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 8740
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jcg
 */

#include <iostream>

#include <iostream>

class ARedOrNot
{
public:
    void solve(std::istream& in, std::ostream& out)
    {
        int n;
        std::string s;
        in >> n >> s;

        out << (n >= 3200 ? s : "red") << '\n';
    }
};


int main()
{
    std::ios_base::sync_with_stdio(0);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    in.tie(0);
    ARedOrNot solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）
//制約をよく読め！

const ll INF=1e18;
set<string> que;
int n;
void f(string s,int k){
    if(k==n){
        que.insert(s);
        return;
    }
    set<char> st;
    rep(i,k) st.insert(s[i]);
    int c=*rbegin(st)-'a';
    rep(i,26){
        if(i<=c+1){
            string u=s;
            u+=i+'a';
            f(u,k+1);
        }
    }
}

void solve(){
    
    string s="a";
    
    f(s,1);
}

signed main(){
    cin>>n;
    
    // que.push(s);
    // rep(i,n-1){
    //     string t;
    //     rep(j,i) t+='a';
    //     rep(j,n-i) t+='b';
    //     que.push(t);
    // }
    
    solve();
    while(!que.empty()){
        string t=*begin(que);
        cout<<t<<'\n';
        que.erase(t);
    }
}


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


void solve(long long H, long long W, std::vector<std::vector<long long>> A, std::vector<std::vector<long long>> B){
    vector<vector<int>> C(H);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            C[i].emplace_back(abs(A[i][j]-B[i][j]));
        }
    }


    int max = 80 *80 * 2;
    bool dp[H+1][W+1][max];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<max;k++){
                dp[i][j][k] = false;
            }
        }
    }
   
    dp[0][0][C[0][0]] = true;
    // cout << dp[0][0][C[0][0]]<< endl;

    // if(dp[H][W][0]){
    //     cout << "a" << endl;
    // }


    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<max;k++){
                if(dp[i][j][k]){
                    if(i < H-1){
                        dp[i+1][j][k+C[i+1][j]] = true;
                        dp[i+1][j][abs(k-C[i+1][j])] = true;
                    }
                    if(j < W-1){
                        dp[i][j+1][k+C[i][j+1]] = true;
                        dp[i][j+1][abs(k-C[i][j+1])] = true;
                    }
                }
            }
        }
    }

    for(int k=0;k<=max;k++){
        if(dp[H-1][W-1][k]){
            cout << k << endl;
            return;
        }
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    cin >> H;
    long long W;
    cin >> W;
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            int a;
            cin >> a;
            A[i][j] = a;
        }
    }
    std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            int b;
            cin >> b;
            B[i][j] = b;
        }
    }
    solve(H, W, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 82048
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = [0]
for i in range(1, n+1):
    d.append(d[i-1] + l[i-1])
    if d[i] > x :
        print(len(d) - 1)
        exit()
print(len(d))

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100


int global_A[1000];
int top;
void push(int);
int pop(void);
;
int main(){
  char A[N];
  int i =0;
  int x;
  int a,b;

  while(scanf("%s",A) != EOF){
   
    
    if(A[0]=='+'){
      a = pop();
      b=pop();
      push(a+b);
    }

    else if(A[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }

    else if(A[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    
  
  else{
    push(atoi(A));
  }
 }printf("%d\n",pop());

  
  return 0;
}



void push(x){
  
 
  
    top++;
   global_A[top]=x;
  
}
int  pop(){
 
    top--;
    return global_A[top+1];
  
}



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

long n,March[5]={0};

long solve(int i,int j)
{
  	if(j==0) 
    	return 1;
  	if(i==5)
    	return 0;
  	return March[i]*solve(i+1,j-1)+solve(i+1,j);
}

int main() 
{
	int i,j;
  	cin>>n;
  	for(i=0;i<n;i++) 
	{
   	 	char s[11];
    	cin>>s;
    	switch(s[0]) 
		{
    		case 'M':
      			March[0]++;
      			break;
    		case 'A':
      			March[1]++;
      			break;
    		case 'R':
				March[2]++;
      			break;
    		case 'C':
      			March[3]++;
      			break;
    		case 'H':
      			March[4]++;
      			break;
    	}   
  	}
  	cout<<solve(0,3);
  	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		
		Map<String, Integer> rest = new TreeMap<String, Integer>();
		
		for(int i=1; i< N+1; i++){
			String s  = keyboard.next();
			int k  = keyboard.nextInt();
			rest.put(s+(200-k), i);
		}
		
        for(String key : rest.keySet()){
				System.out.println(rest.get(key));
			}
		keyboard.close();	
	}
}


Measured memory_bytes: 20820
import bisect
import sys


sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


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


def main():
    N, M = map(int, input().split())
    d = [[] for _ in range(N + 1)]
    PY = []
    for _ in range(M):
        p, y = map(int, input().split())
        d[p].append(y)
        PY.append((p, y))

    for i in range(N + 1):
        if not d[i]:
            continue
        d[i] = sorted(set(d[i]))

    for p, y in PY:
        order = bisect.bisect_left(d[p], y)
        print(str(p).zfill(6) + str(order + 1).zfill(6))


if __name__ == "__main__":
    main()


Measured memory_bytes: 30692
#include<stdio.h>
int main (void)
{
	int a,b,c;
	for(a=1;a<10;a++){
		for(b=1 ; b<10 ; b++){
			c=a*b;
			printf("%dx%d=%d\n",a,b,c);
					}
			}
	return 0;
}

Measured memory_bytes: 924
def dec_bin(num, n):
    ret = ""
    while num > 0:
        ret += str(num%2)
        num //= 2
    curr_len = len(ret)
    for i in range(0, n-curr_len):
        ret += '0'
    return ret[::-1]

min_cost = 100000000
nmx = [int(s) for s in input().split()]
n, m, x = nmx[0], nmx[1], nmx[2]
data = []
for i in range(n):
    row = [int(s) for s in input().split()]
    data.append(row)
for num in range(0, (1<<n)):
    dec = dec_bin(num, n)
    tot_cost = [0 for x in range(m)]
    price = 0
    for j in range(n):
        if dec[j] == '1':
            price += data[j][0]
            for i in range(m):
                tot_cost[i] += data[j][i+1]
    good = True
    for cost in tot_cost:
        if cost < x:
            good = False
            break
    #print(dec, tot_cost, price)
    if good:
        min_cost = min(price, min_cost)
if min_cost == 100000000:
    print(-1)
else:
    print(min_cost)


Measured memory_bytes: 9240
<?php
fscanf(STDIN, "%d", $N);
$p = explode(" ", trim(fgets(STDIN)));
$count = 0;
for($i=1;$i<$N-1;$i++){
 if($p[$i-1]<$p[$i]&&$p[$i]<$p[$i+1]){
   $count++;
 }
   if($p[$i-1]>$p[$i]&&$p[$i]>$p[$i+1]){
   $count++;
 }
}
  echo  $count."\n";
?>


Measured memory_bytes: 4604
fs = require('fs');
buf = fs.readFileSync('/dev/stdin');
str = buf.toString();
S = parseInt(str);
util = require('util');
f = Math.floor;
h = f(S/3600);
m = f((S%3600)/60);
s = f(S%60);
console.log(util.format("%d:%d:%d", h, m, s));

Measured memory_bytes: 15580
#include <stdio.h>
#define N 100
int main()
{
  int cnt=0,i,mini,a,A[N],n,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  scanf("%d",&A[i]);
  for(i=0;i<=n-1;i++)
  {
    mini = i;
    for(j=i;j<=n-1;j++)
    {
      if(A[j] < A[mini])
        {
          mini = j;
        }
    }
      if(A[i] != A[mini])
        cnt++;
      a = A[i];
      A[i] = A[mini];
      A[mini] = a;
  }
  for(i=0;i<n;i++)
  {
    printf("%d",A[i]);
    if(i!=n-1)
      printf(" ");
  }
  printf("\n%d\n",cnt);
}


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

int main(){
	
	long long int X, K, D, tmp, kaisuu, res = 0;
	vector<long long int> L;
	
	cin >> X >> K >> D;

	if(abs(X)/D > K){
		if(X < 0){
			res = abs(X + D*K);
		}else{
			res = abs(X - D*K);
		}
	}else{
		kaisuu = K - abs(X)/D;
		if(X < 0){
			tmp = X + (abs(X)/D) * D;
		}else{
			tmp = X - (abs(X)/D) * D;
		}
		
		if(kaisuu%2 == 1){
			res = min(abs(tmp + D), abs(tmp - D));
		}else{
			res = min(min(abs(tmp), abs(tmp + D*2)), abs(tmp - D*2));
		}
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;


int main(){
    int N;
    cin >> N;
    cout << (1 + N) * N / 2 << endl;
}

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

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b push_back
#define m_p make_pair

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll c,w;
};
vector<Node>v;

ll we[1003],co[1003];
ll dp[1003][10004];
ll n,h;


bool cmp(Node a,Node b){
    if(a.w==b.w){
        return a.c>=b.c;
    }
    return a.w<=b.w;
}

ll KS(ll pos,ll w){
    if(pos>n){
        if(w>h) return 0;
        else return INT_MAX;
    }

    if(w>=h) return 0;

    if(dp[pos][w]) return dp[pos][w];

    ll x=co[pos]+ KS(pos,w+we[pos]);
    ll y=KS(pos+1,w);

    return dp[pos][w]=min(x,y);
}

int main(){
    _fastio
    cin>>h>>n;
    for(ll i=1;i<=n;i++){
        cin>>we[i]>>co[i];
        Node x;
        x.w=we[i];
        x.c=co[i];
        v.push_back(x);
    }

    sort(v.begin(),v.end(),cmp);

    for(ll i=1;i<=n;i++){
        we[i]=v[i-1].w;
        co[i]=v[i-1].c;
    }

    ll ans=KS(1,0);

    cout<<ans<<endl;



    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
    	var sc = new Scanner();
    	int n = sc.NextInt();
    	int m = sc.NextInt();
    	var dic = new Dictionary<int, List<int>>();
    	var pairs = new List<Tuple<int, int>>();
    	for (int i = 0; i < m; i++)
    	{
    		int p = sc.NextInt();
    		if (!dic.ContainsKey(p)) dic.Add(p, new List<int>());
    		int y = sc.NextInt();
    		dic[p].Add(y);
    		pairs.Add(Tuple.Create(p, y));
    	}
    	var res = new Dictionary<Tuple<int, int>, string>();
    	foreach (var item in dic.OrderBy(p => p.Key))
    	{
    		item.Value.Sort();
    		for (int i = 0; i < item.Value.Count;i++)
    		    res.Add(Tuple.Create(item.Key, item.Value[i]), string.Format("{0:D6}{1:D6}", item.Key, i + 1));
    	}
    	
    	foreach (var item in pairs)
    	    Console.WriteLine(res[item]);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }
        
    public long NextLong()
    {
    	CheckNext();
    	return long.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}

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

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    for (; b != 0; )
    {
        if(a < b)
        {
            swap(a, b);
        }
        int c = a % b;
        a = b;
        b = c;
    }
    printf("%d\n", a);
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(){
  int x=1,y=1;
  while(1){
    scanf("%d%d", &x, &y);

    if(x == 0 && y == 0)
      break;
    if(x > y)
      printf("%d %d\n", y, x);
    else
      printf("%d %d\n", x, y);
  }
  
  return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        long a = in.nl(), V = in.nl();
        long b = in.nl(), W = in.nl();
        long dist = Math.abs(a-b);
        long v = V-W;
        long t = in.nl();
        if(v*t>=dist) out.println("YES");
        else out.println("NO");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 32776
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  	string s,t;
  	cin >> s >> t;
  	int l1=s.length();
  	int l2=t.length();
  	int ans = INT32_MAX;
  	for(int i=0;i<l1;i++){
      if(i+t.size() > s.size()) break;
  	    int count = 0;
  	    for(int j=0;j<l2;j++)
  	        if(s[i+j]!=t[j])
  	            count++;
  	 ans = min(ans,count);
  	}
  	 
 
    cout << ans <<"\n";
      
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  long long a,b,c,k;
  cin >> a >> b >> c >> k;
  if (k <= a + b && k >= a){
    cout << a << '\n';
    return 0;
  }
  if (k < a){
    cout << k << '\n';
    return 0;
  }
  
  cout << a - (k - (a + b)) << '\n';
  return 0;
}

Measured memory_bytes: 3644
import java.util.*;

public class Main {

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

        long N = scanner.nextLong();

        ArrayList<Integer> cards = new ArrayList<>();

        for(int i=0; i<N; i++){
            cards.add(scanner.nextInt());
        }

        Collections.sort(cards, Collections.reverseOrder());

        int acc = 0;
        for(int i=0; i<N; i++){
            if(i%2 == 0){
                acc += cards.get(i);
            }else{
                acc -= cards.get(i);
            }
        }

        System.out.println(acc);

    }

    static List<Integer> primeList(int n) {
        List<Integer> list = new ArrayList<>();
        boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        prime[0] = false;
        prime[1] = false;
        for (int i = 2; i < Math.sqrt(n); i++) {
            if (!prime[i]) continue;
            for (int j = 2; i * j <= n; j++) {
                prime[i * j] = false;
            }
        }
        for (int i = 0; i < prime.length; i++) {
            if (prime[i]) list.add(i);
        }

        return list;
    }
}


Measured memory_bytes: 21716