akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    int k;
    string s;
    cin >> k >> s;
    if (s.size() > k)
    {
        rep(i, k)
        {
            cout << s.at(i);
        }
        cout <<"..."<< endl;
    }
    else
    {
        cout << s << endl;
    }

    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int w;
  int n;
  int a;
  int b;
  int a1;
  int b1;
  int c[50]={0};
  int i,j;
  char x;

  cin>>w>>n;
  for(i=1;i<=w;i++){
    c[i]=i;
  }
  for(i=1;i<=n;i++){
    cin>>a>>x>>b;
    swap(c[a],c[b]);
  }
  for(i=1;i<=w;i++){
    cout<<c[i]<<endl;
  }

  return 0;
}
  
  
  
  

Measured memory_bytes: 1160
def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

n, a, b = map(int, input().split())
p = 10 ** 9 + 7
ans = pow(2, n, p) - comb(n, a, p) - comb(n, b, p) - 1
print(ans % p)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    const double unit = 0.1;
    int L;
    cin >> L;
    double ans = L/3.0 * L/3.0 * L/3.0;
    cout << ans << endl;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
)

type Dice struct{
	/*
	こういう感じ
  		 ___
	____|_1_|_______
	|_4_|_2_|_3_|_5_|
		|_6_|
	*/
	Surface []int
}

func (d *Dice)Move(dir string){
	switch dir{
	case "W":
		d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[2], d.Surface[5], d.Surface[3], d.Surface[0]
	case "E":
		d.Surface[0], d.Surface[2], d.Surface[5], d.Surface[3] = d.Surface[3], d.Surface[0], d.Surface[2], d.Surface[5]
	case "N":
		d.Surface[0], d.Surface[4], d.Surface[5], d.Surface[1] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]
	case "S":
		d.Surface[5], d.Surface[1], d.Surface[0], d.Surface[4] = d.Surface[1], d.Surface[0],d.Surface[4], d.Surface[5]	
	}
}

func (d *Dice)Roll(dir string){
	switch dir{
	case "R":
		d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4] = d.Surface[1], d.Surface[2], d.Surface[4], d.Surface[3]
	case "L":
		d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4] = d.Surface[4], d.Surface[3], d.Surface[1], d.Surface[2]
	}
}

func (d *Dice)GetStatus(){
	doc := `              ____
 	 ____|_%02d_|_________
	|_%02d_|_%02d_|_%02d_|_%02d_|
	     |_%02d_|`
	fmt.Printf(doc, d.Surface[0], d.Surface[3], d.Surface[1], d.Surface[2], d.Surface[4], d.Surface[5])
	fmt.Println()
}

func main(){
	d := Dice{
		make([]int, 6),
	}
	for i:=0; i<6; i++{
		var n int
		fmt.Scan(&n)
		d.Surface[i] = n
	}
	var n int
	fmt.Scan(&n)
	for i:=0; i<n; i++{
		var up, front int
		fmt.Scan(&up, &front)
		u := getIndex(d.Surface, up)
		switch u{
			case 0:
				// 何もしなくていい
				break
			case 1:
				d.Move("N")
			case 2:
				d.Move("W")
			case 3:
				d.Move("E")
			case 4:
				d.Move("S")
			default:
				// 適当に2回同じ方向に回す
				d.Move("N")
				d.Move("N")
		}
		// d.GetStatus()
		f := getIndex(d.Surface, front)
			switch f{
				//4通りしかないはず
			case 3:
				d.Roll("L")
			case 1:
				break
			case 2:
				d.Roll("R")
			case 4:
				// 適当に同じ方向に2回回す
				d.Roll("R")
				d.Roll("R")
			default:
				fmt.Println("fuckkkkkkkkk")
		}
		// d.GetStatus()
		fmt.Println(d.Surface[2])
	}
}

func getIndex(ns []int, key int)(id int){
	for idx, v := range ns{
		if v==key{
			id = idx
			break
		}
	}
	return
}


Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a<400)
      mp[0]++;
    else if(a<800)
      mp[1]++;
    else if(a<1200)
      mp[2]++;
    else if(a<1600)
      mp[3]++;
    else if(a<2000)
      mp[4]++;
    else if(a<2400)
      mp[5]++;
    else if(a<2800)
      mp[6]++;
    else if(a<3200)
      mp[7]++;
    else
      mp[8]++;
  }
  int c=0;
  for(int i=0;i<8;i++){
    if(mp[i]>0)
      c++;
  }
  if(c>0)
    cout<<c<<" "<<c+mp[8];
  else
    cout<<1<<" "<<mp[8];
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long result=0;
		long l[] =new long[N];
		long r[]= new long[N];
		for(int i=0;i<N;i++) {
			l[i]=sc.nextLong();
			r[i]=sc.nextLong();
			long max=Math.max(l[i], r[i]);
			long min=Math.min(l[i], r[i]);
			result+=(max-min+1);
		}
		System.out.println(result);
		
		
	}

	
}
		

Measured memory_bytes: 24024
// abc179_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    if (S.back() == 's'){
        S += "es";
    } else {
        S += "s";
    }
    print(S);

    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int days(int y, int m, int d)
{
	int out = 0;

	if (y > 1){
		out = (y - 1) * 195 + (y - 1) / 3 * 5;
	}
	
	if (m > 1){
		out += (m - 1) * 20;
		if (y % 3 != 0){
			out -= (m - 1) / 2;
		}
	}
	
	out += d;

	return (out);
}


int main(void)
{
	int n;
	int Y, M, D;
	int i;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d%d%d", &Y, &M, &D);

		printf("%d\n", days(1000, 1 , 1) - days(Y, M, D));

	}
	
	return (0);
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    double a, b;
    cin >> a >> b;
    cout << ceil((a + b) / 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

int main() {
    string s; cin >> s;
    if(s[0]==s[1] && s[3]==s[2] && s[1]!=s[2]) cout << "Yes";
    else if(s[0]==s[2] && s[1]!=s[2] && s[1]==s[3]) cout << "Yes";
    else if(s[0]==s[3] && s[1]!=s[3] && s[1]==s[2]) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
n = int(input())
a = [0] * n
b = [0] * n

for i in range(n):
    a[i],b[i] = map(int,input().split())

ans = 0
for i in range(n-1,-1,-1):
    ans += (b[i] - ((a[i]+ans)%b[i])) % b[i]

print(ans)


Measured memory_bytes: 10868
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    if (A < 10 && B < 10) {
      Console.WriteLine(A*B);
    } else {
      Console.WriteLine(-1);
    }
  }
}

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

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

  string ans = "";

  for(int i=0;i<s.size();i++) {
    if(s[i] == '0') ans += '0';
    else if(s[i] == '1') ans += '1';
    else {
      if(ans.size()==0) continue;
      else ans.pop_back();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  queue<string> que;
  string state;
  state.push_back('a');
  que.push(state);
  char maxchr;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(state.size()==N) {
      cout<<state<<endl;
      continue;
    }
    maxchr = 'a';
    for(int i=0;i<state.size();++i) {
      if(maxchr<state[i]) maxchr = state[i];
    }
    maxchr++;
    for(char j='a';j<=maxchr;++j) {
      state.push_back(j);
      que.push(state);
      state.pop_back();
    }
  }
}



Measured memory_bytes: 7352
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] cou = new int[5];
		for(int i = 0; i < 6; i++){
			cou[sc.nextInt()]++;
		}
		boolean flag = false;
		for(int i = 1; i < 5; i++){
			if(cou[i] == 0 || cou[i] > 2){
				flag = true;
			}
		}

		if(!flag){
			System.out.print("YES");
		}else{
			System.out.print("NO");
		}
	}
}


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL n;
    string s;
    cin >> n >> s;

    LL x = 0, mx = 0;
    for(LL i = 0; i < n; i++){
        if(s[i] == 'I')
            x++;
        if(s[i] == 'D')
            x--;
        mx = max(mx, x);
    }

    cout << mx << '\n';
    return 0;
}



Measured memory_bytes: 256
var GET = (function () {
    function f(s) {
        return new g(s);
    }

    function g(s) {
        this._s = s.trim().split("\n");
    }

    g.prototype.getValue = function (n) {
        return this.stox(this._s[n]);
    };
    g.prototype.getArray = function (n) {
        return this.stoa(this._s[n]);
    };
    g.prototype.slice = function (s, limit) {
        return this._s.slice(s, +limit + s || undefined).map(v => this.stox(v));
    };
    g.prototype.sliceArray = function (s, limit) {
        return this._s.slice(s, +limit + s || undefined).map(v => this.stoa(v));
    };
    g.prototype.stoa = function (s) {
        return s.split(" ").map(v => this.stox(v));
    };
    g.prototype.stox = function (v) {
        var i = +v;
        return (i === i) ? i : v;
    };
    return f;
})();
var o = GET(require("fs").readFileSync("/dev/stdin", "utf8"));

console.log(main());
function main(){
    var N = o.getValue(0);
    var S = o.getValue(1);

    var alphabet = [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "I",
        "J",
        "K",
        "L",
        "M",
        "N",
        "O",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "U",
        "V",
        "W",
        "X",
        "Y",
        "Z"
    ];

    var ans = "";
    for(var i = 0; S.length > i; i++) {
        var index = alphabet.findIndex((v) => S[i] === v);
        ans += alphabet[(N + index) % 26]
    }

    return ans;
}

Measured memory_bytes: 11964
l, r = gets.split.map(&:to_i)
mark = 2020
for i in l..r - 1
  for j in i+1..r
    if i * j % 2019 < mark
      mark = i * j % 2019     
    end
    break if mark == 0
  end
  break if mark == 0
end
puts mark


Measured memory_bytes: 1788
n = gets.chomp.to_i
arr = gets.chomp.split(" ").map(&:to_i)

ret = 0

while arr.max >= n
  s = arr.map{|x| x / n}.inject(:+)
  arr.map!{|x| x + s - (n+1)*(x / n)}
  ret += s
end

puts ret

Measured memory_bytes: 3836
#include <iostream>

long int sum_area(int d){
	long int sum;
	for(int i = d;i <= 600 - d;i += d){
		sum += i*i*d;
	}
	return sum;
}

int main(){
	int d;
	while(std::cin >> d)
		std::cout << sum_area(d) << std::endl;
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
    int N, fN = 0, n;
    cin >> N;
    n = N;
    while(n > 0){
        fN += n % 10;
        n /= 10;

    }
  
    if(N % fN) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3596
$queen_poss = [nil] * 8

def valid?(new_i, new_j)

  if $queen_poss[new_i] != nil
    return false
  end

  # Check column
  $queen_poss.each{|j|
    if j == new_j
      return false
    end
  }

  i = new_i
  j = new_j
  while 0 <= i-1 && 0 <= j-1
    i -= 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while i+1 < 8 && j+1 < 8
    i += 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while 0 <= i-1 && j+1 < 8
    i -= 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  i = new_i
  j = new_j
  while i+1 < 8 && 0 <= j-1
    i += 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  return true
end

def print_queens()
  $queen_poss.each{|j|
    row = ['.'] * 8
    row[j] = 'Q'
    puts(row.join)
  }
end


$fixed_ijs = []

# Input values
_ = gets
while line = gets
  i, j = line.split(' ').map(&:to_i)
  $queen_poss[i] = j
  $fixed_ijs.push([i, j])
end


def solve(i)

  if i == 8
    print_queens()
    return
  end

  (0...8).each{|j|
    if $fixed_ijs.include?([i,j])
      solve(i+1)
    end
    if valid?(i, j)
      $queen_poss[i] = j
      solve(i+1)
      $queen_poss[i] = nil
    end
  }
end


solve(0)



Measured memory_bytes: 6880
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 9 && b <= 9) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
#define intmax 2147483647
#define intmin -2147483647
#define llmax 9223372036854775807
using namespace std;

int a, b, c, d, e, f;
bool w[31], s[1501];
int wmx, smx;


int main(){
	cin >> a >> b >> c >> d >> e >> f;
	lp(31)
		w[i] = false;
	lp(1501)
		s[i] = false;
	w[0] = true;
	lp(31) {
		if (i - a >= 0) {
			if (w[i - a])
				w[i] = true;
		}
		if (i - b >= 0) {
			if (w[i - b])
				w[i] = true;
		}
	}
	s[0] = true;
	lp(1501) {
		if (i - c >= 0) {
			if (s[i - c])
				s[i] = true;
		}
		if (i - d >= 0) {
			if (s[i - d])
				s[i] = true;
		}
	}
	wmx = 100 * a;
	smx = 0;
	lp(31) {
		if (i * 100 > f)break;
		if (w[i]) {
			for (int j = i*e; i >= 0; j--) {
				if (s[j]&&i*100+j<=f) {
					if (smx*i * 100 < wmx*j) {
						wmx = i * 100;
						smx = j;
					}
					break;
				}
			}
		}
	}
	cout << wmx + smx << sp << smx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define inf 1000000000

using namespace std;

struct state{
	int coin, cost;
	state(){}
	state(int c, int s){
		coin = c, cost = s;
	}
	bool operator<(const state& ope)const{
		return coin < ope.coin || (coin == ope.coin && cost > ope.cost);
	}
};

int n;
int p[105];
state dp[105][250005];

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		for(int i = 1; i <= n; i++) cin >> p[i];
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j < 250005; j++){
				dp[i][j] = state(-inf, inf);
			}
		}
		dp[0][0] = state(0, 0);
		
		int pay, ret;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 250005; j++){
				dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
				
				pay = (p[i+1] + 999) / 1000 * 1000;
				ret = pay - p[i+1];
				if(ret >= 500) dp[i+1][j+ret-500] = max(dp[i+1][j+ret-500], state(dp[i][j].coin+1, dp[i][j].cost+p[i+1]));
				else dp[i+1][j+ret] = max(dp[i+1][j+ret], state(dp[i][j].coin, dp[i][j].cost+p[i+1]));
				
				ret = (p[i+1] + 500) % 1000;
				if(ret <= j){
					dp[i+1][j-ret] = max(dp[i+1][j-ret], state(dp[i][j].coin+1, dp[i][j].cost+p[i+1]));
				}
			}
		}
		
		state ans = state(-inf, inf);
		for(int i = 0; i < 250005; i++){
			ans = max(ans, dp[n][i]);
		}
		
		cout << ans.coin << " " << ans.cost << endl;
	}
	
	return 0;
}

Measured memory_bytes: 200344
//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define pi 3.14159265358979
const ll MOD = 1000000007;
const ll N=200005;
ll dp[1005][1005];
int main()
{
    IOS
    ll n,m,i,j;
    cin>>n>>m;
    char pa[n][m];
    for(i=0; i<n; i++)
        for(j=0; j<m; j++)
        cin>>pa[i][j];
    dp[0][0]=1;
    for(i=1; i<m; i++)
    {
        if(pa[0][i]=='.')
            dp[0][i]=1;
        else
            break;
    }
    for(i=1; i<n; i++)
    {
        if(pa[i][0]=='.')
            dp[i][0]=1;
        else
            break;
    }
    for(i=1; i<n; i++)
    {
        for(j=1; j<m; j++)
        {
            if(pa[i][j]=='.')
            {
                dp[i][j]=dp[i-1][j]+dp[i][j-1];
                dp[i][j]%=MOD;
            }
            else
                continue;
        }
    }
    cout<<dp[n-1][m-1];
    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int L = A + B;
    int R = C + D;
    if (L > R) cout << "Left";
    else if (L < R) cout << "Right";
    else cout << "Balanced";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll t,n,i,j,k,l,c,f,x,d;
	cin>>x>>k>>d;
	ll cnt=llabs(x/d);
	if(cnt>k)
	{
	    if(x>0)x-=k*d;
	    else x+=k*d;
	}
	else
	{
	    if(x>0)x-=cnt*d;
	    else x+=cnt*d;
	    if((k-cnt)&1)
	    {
	        x=min(llabs(x-d),llabs(x+d));
	    }
	}
	cout<<llabs(x);
	return 0;
}


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

#define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf = (ll)1e14;
const ll N = (ll)1e3+77;
const ll mod = (ll)1e9+7;

int n,a[11],ans;

void go(int p, int v[]) {
    if (p == n) {
        ll pp = 1;
        forn(i, n) pp *= v[i];
        if (pp % 2 == 0) ans++;
        return;
    }
    go(p + 1, v);
    v[p]++;
    go(p + 1, v);
    v[p]--;
    v[p]--;
    go(p + 1, v);
    v[p]++;
}

int main() {
    fast;
    cin >> n;
    forn(i, n) cin >> a[i];
    go(0, a);
    cout << ans << endl;
    return 0;
}

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

int main(){
	int N,M,C,ans=0,d,e;
  	
  	cin >> N >> M >> C;
  	vector<int> B(M,0);
  	for(int j=0;j<M;j++)cin >> B[j];
  	for(int i=0;i<N;i++){
      	d=C;
    	for(int j=0;j<M;j++){
          cin >> e;
          d+=e*B[j];
        }
    	if(d>0)ans++;
    }
  	cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <functional>
#include<stdio.h>
using namespace std;
#define ll       	long long int
#define dd      	long double
#define pb          push_back
#define pf          push_front
#define pi         pair<ll,ll>
#define vi          vector<ll>
#define vpi        vector<pi>
#define mi          map<ll,ll>
#define vvi         vector<vector<ll>>
#define mpi         map<pi,ll>
#define pipi        pair<ll,pair<ll,ll> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x         first
#define y         second
#define sz(x)       (ll)x.size()
#define u        	'\n'
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define rf(s)       for(auto &c : s)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++) //use Iterator
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define ef          else if
#define yes       cout<<"YES"<<'\n';
#define no        cout<<"NO"<<'\n';
#define C         continue;
#define wa(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#define debug(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<'\n'
#define debugp(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i.x<<","<<i.y<<" | "; cout<<'\n'
#include <ext/pb_ds/tree_policy.hpp>     
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>     
using namespace __gnu_pbds;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define fbo find_by_order
#define ook order_of_key
const ll N = 350;
 
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); } 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) 
    { 
        if (y & 1) 
        res = res*x; 
        y = y>>1; 
        x = x*x;  
    } 
    return res; 
}

vector<vi>v;
ll t1[100005][2];
vi vis;
void dfs(ll n)
{
	vis[n]=1;
	for(auto i:v[n])
	{
		if(vis[i]==0)
		{
			dfs(i);
			t1[n][0]=(t1[n][0]*t1[i][1])%M;
			t1[n][1]=(t1[n][1]*(t1[i][0]+t1[i][1])%M)%M;
		}	
	}	
}
signed main()
{
	tezz
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll n,i,j;
		cin>>n;
		v=vector<vi>(n+1);
		vis=vi(n+1);
		fo(i,0,n-1)
		{
			ll a,b;
			cin>>a>>b;
			v[a].pb(b);
			v[b].pb(a);
		}
		fo(i,0,100005)
		{
		    fo(j,0,2)
		    t1[i][j]=1;
		}
		dfs(1);
		cout<<(t1[1][0]+t1[1][1])%M<<u;
	}
	return 0;
} 

Measured memory_bytes: 16544
<?php
//??????????????¬???????????????????????°????????\????????¨????????°
$rightCard = 0;
$leftCard = 0;
//?????????????¨??????\???????????°
$rightAns = 0;
$leftAns = 0;
while(true){
//??\?????????????????????
    $stdin=trim(fgets(STDIN));
    //??????????????°???0??????break
    if($stdin == 0){
        break;
    }
    //??????????????°???10000??\????????????????????????
    if($stdin <= 10000){
        //??\????????°???????????????????????????
        for($i = 0;$i<$stdin;$i++){
            //??\??????????????§??????
            $cardin=trim(fgets(STDIN));
            $cards = explode(" ", $cardin);
            //??????????????°????????\???
            $leftCard = $cards[0];
            $rightCard = $cards[1];
            //??????????¨????
            if($leftCard > $rightCard){
                $leftAns += $leftCard + $rightCard;
            }
            else if($leftCard < $rightCard){
                $rightAns += $leftCard + $rightCard;
            }
            else if($leftCard == $rightCard){
                $leftAns += $leftCard;
                $rightAns += $rightCard;
            }
        }
        //????????????
        echo $leftAns." ".$rightAns."\n";
        //??????????????????
        $rightAns = 0;
        $leftAns = 0;
    }
}

Measured memory_bytes: 15156
#include<bits/stdc++.h>
using namespace std;
const int N=110;
typedef long long ll;
int dp[N][4],a[N],k;
char s[N];
int dfs(int pos,bool lead,bool lim,int now)
{
	if(pos==0)return now==0;
	if(now<0)return 0;
	if(~dp[pos][now] && !lead && !lim)return dp[pos][now];
	int ret=0;
	int up=lim?a[pos]:9;
	for(int i=0;i<=up;++i)
	{
		if(i==0)ret+=dfs(pos-1,lead,lim&&(i==up),now);
		else ret+=dfs(pos-1,0,lim&&(i==up),now-1);
	}
	return !lim?dp[pos][now]=ret:ret;//注意到方案数只受非lim限制不受前导0限制 
}
 
int part(char s[])
{
	int len=0;
	int l=strlen(s);
	for(int i=l-1;i>=0;--i)
		a[++len]=s[i]-'0';
	memset(dp,-1,sizeof dp);
	return dfs(len,1,1,k); 
}
 
int main()
{
	scanf("%s",s);
	scanf("%d",&k);
	printf("%d\n",part(s));
}

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

int main() {
  double a;
  cin >> a;
  double p = 3.14159265359,c,k;
  c = a * a * p;
  k = (a + a) * p;
  cout << fixed << setprecision(6) << c << " " << k << endl;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

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



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

int main(void){
    int n,y;
    scanf("%d %d",&n,&y);
    y/=1000;
    int bill[3];
    for (size_t i = 0; i <= n; i++)
    {
        for (size_t j = 0; j <= n-i; j++)
        {
            if(10*i+5*j+n-i-j==y){
                printf("%d %d %d",i,j,n-i-j);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
vector<int> ans;
map<int,int> mp;
int n,a,b,c,d;
const int INF = 1001002003004005006ll;

int dfs(int now){
    if(mp.find(now) != mp.end())return mp[now];
    int res = INF;

    if(INF/d > now)res =  now*d;
    
    
    //res = min(res,dfs((now-m2)/2)+m2*d +a);
    //res = min(res,dfs((now+2-m2)/2)+(2-m2)*d+a);
    //res = min(res,dfs((now-m3)/3)+m3*d+b);
    //res = min(res,dfs((now+3-m3)/3)+(3-m3)*d+b);
    //res = min(res,dfs((now-m5)/5)+m5*d+c);
    //res = min(res,dfs((now+5-m5)/5)+(5-m5)*d+c);
    auto f = [&](int x){
        if(x >= now)return INF;
        return dfs(x);
    };
    {
        int l = now/2*2,r = l+2;
        res = min(res,f(l/2) + a + (now - l)*d);
        res = min(res,f(r/2) + a + (r - now)*d);
    }
    {
        int l = now/3*3,r = l+3;
        res = min(res,f(l/3) + b + (now - l)*d);
        res = min(res,f(r/3) + b + (r - now)*d);
    }
    {
        int l = now/5*5,r = l+5;
        res = min(res,f(l/5) + c + (now - l)*d);
        res = min(res,f(r/5) + c + (r - now)*d);
    }
    return mp[now] = res;
    

}

void solve(){
    cin >> n >> a >> b >> c >>  d;
    mp = map<int,int> ();
    mp[0] = 0;
    mp[1] = d;
    ans.push_back(dfs(n));
    
}
signed main(){
    int t;cin >> t;
    while(t--)solve();
    for(auto p:ans)cout << p << endl;
    return 0;
}

Measured memory_bytes: 4756
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(M)]
Lmax = max([lr[0] for lr in LR])
Rmin = min([lr[1] for lr in LR])
if Rmin >= Lmax:
    print(Rmin - Lmax + 1)
else:
    print(0)


Measured memory_bytes: 101304
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

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

	int ans = 0;
	while(N > ans){
		ans += 1000;
	}	

	cout << ans - N << "\n";

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, C;
vector<pii> v[30];
int cum[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    v[c - 1].emplace_back(s, t);
  }
  for (int i = 0; i < C; i++) {
    sort(v[i].begin(), v[i].end());
    int l = 0, r = 0;
    while (l < v[i].size()) {
      while (r + 1 < v[i].size() && v[i][r].second == v[i][r + 1].first) r++;
      cum[v[i][l].first * 2 - 1]++;
      cum[v[i][r].second * 2]--;
      l = ++r;
    }
  }
  int ans = cum[0];
  for (int i = 1; i < 200010; i++) {
    cum[i] += cum[i - 1];
    ans = max(ans, cum[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2304
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int MAXN=1e5+5;
int n;
vector<int>G[2];
map<int,int>R[2];
struct node {
	int num,pl;
	node() {};
	node(int X,int Y) {
		num=X,pl=Y;
	}
}x1,x2,y1,y2;
int main()
{
	scanf("%d",&n);
	int x;
	for(int i=1;i<=n;i++) {
		scanf("%d",&x);
		int p=i%2;
		if(R[p][x]==0)
			G[p].push_back(x);
		R[p][x]++;
	}
	for(int i=0;i<G[0].size();i++) {
		if(R[0][G[0][i]]>x1.pl)
			x2=x1,x1=node(G[0][i],R[0][G[0][i]]);
		else if(R[0][G[0][i]]>x2.pl)
			x2=node(G[0][i],R[0][G[0][i]]);
	}
	for(int i=0;i<G[1].size();i++) {
		if(R[1][G[1][i]]>y1.pl)
			y2=y1,y1=node(G[1][i],R[1][G[1][i]]);
		else if(R[1][G[1][i]]>y2.pl)
			y2=node(G[1][i],R[1][G[1][i]]);
	}
	int Max=0;
	if(x1.num!=y1.num)
		Max=x1.pl+y1.pl;
	if(x1.num!=y2.num)
		Max=max(Max,x1.pl+y2.pl);
	if(x2.num!=y1.num)
		Max=max(Max,x2.pl+y1.pl);
	if(x2.num!=y2.num)
		Max=max(Max,x1.pl+y2.pl);
	printf("%d",n-Max);
}

Measured memory_bytes: 5368
X,N = map(int, input().split())
p = list(map(int, input().split()))
dif = 1

if(X not in p):
    print(X)
else:
    while True:
        if(X-dif not in p):
            dif = dif*(-1)
            break
        elif(X+dif not in p):
            break
        else:
            dif=dif+1
    print(X+dif)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
#define mod 1000000007
/****************************/
using namespace std;
ll n,m;
int main()
{
	cin>>n;
	ll ans=0;
	for(int i=1;i<n;i++)
	{
		ans+=(n/i);
		if(n%i==0) ans--;
	}
	cout<<ans;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    if (s[s.size()-1] == 's') {
        cout << s << "es" << "\n";
    } else {
        cout << s << "s" << "\n";
    }
    return 0;
}


Measured memory_bytes: 3620
S = input()
N = len(S)
S1 = S[0:((N-1)//2)]
S2 = S[(((N+3)//2)-1):N]
if S == S[::-1] and  S1 == S1[::-1] and  S2 == S2[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void){

	int a,b,c;
	int N;
	cin >> N;

	for(int i=0;i<N;i++){
		
		cin >> a >> b >> c;

		if(a*a + b*b == c*c
		  || c*c + a*a == b*b
		  || b*b + c*c == a*a){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 1152
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
# my functions here!
def pin(type=int):
    return map(type,input().split())
#input
H,=pin()
#solution 
def crcl(num):
    if num == 1:
        return 1
        #print(0)
    else:
        #print(num)
        return 1+crcl(num//2)*2
#print(ans)
print(crcl(H))

Measured memory_bytes: 64364
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
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; }

int main() {
    int N; cin >> N;
    int a[2][N];
    rep(i, 2){
        rep(j, N) cin >> a[i][j];
    }
    int ans = 0;
    rep(i, N){
        int tmp = 0;
        for(int j=0; j<=i; j++) tmp += a[0][j];
        for(int j=i; j<N; j++) tmp += a[1][j];
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 0;
		for(int i=0;i<N;i++) {
			if(sc.nextInt()>=K) {
				ans++;
			}
		}
		sc.close();
		System.out.println(ans);

	}
}

Measured memory_bytes: 48280
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    bool isFst = true;
    FOR(i, x-k+1, x+k){
        if(isFst){
            cout << i;
            isFst = false;
        }
        else {
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    int A,B;cin>>A>>B;
    int x=0;
    while(x<=10010){
        double c=(double)x*0.08,d=(double)x*0.1;
        int C=c,D=d;
        if(A==C && B==D){
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> h(n+1);
  rep1(i,n) cin >> h[i];
  vector<vector<int>> to(n+1,vector<int>(0));
  rep(i,m){
    int a,b;
    cin >> a >> b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  int ans = 0;
  rep1(i,n){
    //cout << i << "...";
    bool fail_at_least = 0;
    for(int j : to[i]){
      //cout << j << " ";
      if(h[j] >= h[i]) fail_at_least = 1;
    }
    if(!fail_at_least) ans ++;
    //cout << endl;
  }
  cout << ans << endl;
}

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

#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, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    string s, t;
    cin>>s;

    int i, j;
    int c=0;
    for(i=0; i<s.length(); i++){
        if(i==0){
            if(s[i]!='A'){
                cout<<"WA"<<endl;
                return 0;
            }
        }
        else if(i>1 && i<s.length()-1){
            if(s[i]=='C'){
                c++;
                if(c==2){
                    cout<<"WA"<<endl;
                    return 0;
                }
            }
            else{
                if(s[i]>'z'||s[i]<'a'){
                    cout<<"WA"<<endl;
                    return 0;
                }
            
            }
        }
        else{
            if(s[i]>'z' || s[i]<'a'){
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(c==1){
        cout<<"AC"<<endl;
    }
    else{
        cout<<"WA"<<endl;
    }

    return 0;
}

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

typedef struct {
    int h;
    int w;
} RECT;

int comp(const void *a, const void *b)
{
    int x;
    
    x = (*(RECT *)a).w - (*(RECT *)b).w;
    if (x != 0){
        return (x);
    }
    return ((*(RECT *)a).h - (*(RECT *)b).h);
}


int main(void)
{
    RECT rect[6];
    int i;
    int h, w, t;
    int flag;
    
    flag = 1;
    for (i = 0; i < 6; i++){
        scanf("%d%d", &w, &h);
        
        if (w > h){
            t = w;
            w = h;
            h = t;
        }
        
        rect[i].w = w;
        rect[i].h = h;
    }
    
    qsort(rect, 6, sizeof(RECT), comp);

    for (i = 0; i < 6; i++){
//        printf("%d:%d %d\n", i, rect[i].w, rect[i].h);
    }


    
    for (i = 0; i <= 4; i += 2){
        if (rect[i].w != rect[i + 1].w || rect[i].h != rect[i + 1].h){

// printf("<1>");
            flag = 0;
            break;
        }
    }
    if (rect[0].w != rect[2].w || rect[2].h != rect[4].h || rect[0].h != rect[4].w){
// printf("<2>");
        flag = 0;
    }

    if (flag == 1){
        printf("yes\n");
    }
    else {
        printf("no\n");
    }

    
    return (0);
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define REP(i, n) for(int i=1; i<=(int)(n); i++)

using namespace std;

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A) {
    if (A.size() == N+1) {
        int now = 0;
        rep(i, Q) {
            if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= M) {
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> N >> M >> Q;
    a = b = c = d = vector<int>(Q);

    rep(i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1, 1));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll INF=1e15;
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
const double pi = acos(-1.0);
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

long long binpows(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)  //impar
            res = res * a;
        a = a * a;
        b >>= 1;  // /2
    }
    return res;
}
const int mod=1e9+7;
int binpow(int a, int b, int m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//CHECAR SE PRECISA DE LONG LONG
vector<int> adj[123456];
int dp[123456];
int resolve(int pos){
	int &x=dp[pos];
	if(x!=-1){
		return x;
	}
	x=0;
	for(int &i: adj[pos]){
		x=max(x,resolve(i)+1);
	}
	return x;
}
void solve(){
	memset(dp,-1,sizeof(dp));
	int n,m;
	cin>>n>>m;
	for(int i=0; i<m; i++){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
	}
	int mai=0;
	for(int i=1; i<=n; i++){
		mai=max(mai,resolve(i));
	}
	cout<<mai<<endl;
}
//revise as variaveis e a ordem nas funções
signed main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}

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


public class Main {

    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);


        String s = in.next();
        char [] c = s.toCharArray();
        char first = c[0];
        char second = c[1];
        char last = c[2];
        int num =  Integer.parseInt(Character.toString(first));
        if(second > first) {
            num++;
        }
        else if(second == first) {
            if(last > second) {
                num++;
            }
        }
        out.println(num+""+num+""+num);

        out.flush();

    }
    static boolean check(char [] ca,char [] cb) {
        for (char c = 'a';c<='z';c++) {
            HashSet<Character> set = new HashSet<>();
            for (int i = 0; i < ca.length; i++) {
                if(ca[i] == c) {
                    set.add(cb[i]);
                }
                if(set.size() > 1) {
                    return false;
                }
            }
        }
        return  true;
    }
}

class Envelope {
    private int width;
    private int height;

    public int getHeight() {
        return height;
    }

    public int getWidth() {
        return width;
    }

    public Envelope(int width,int height) {
        this.width = width;
        this.height = height;
    }

    @Override
    public String toString() {
        return width + " " + height;
    }
}

class InputReader extends BufferedReader {
    StringTokenizer tokenizer;

    public InputReader(InputStream inputStream) {
        super(new InputStreamReader(inputStream), 32768);
    }

    public InputReader(String filename) {
        super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(readLine());
            } catch (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public Integer nextInt() {return Integer.valueOf(next());}
    public Long nextLong() {return  Long.valueOf(next());}
    public Double nextDouble() {return Double.valueOf(next());}

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }
    }
}

Measured memory_bytes: 20820
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
	int n,i,now=1,ans=0;;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	i=0;
	while(now!=2){
		now = a[now-1];
		ans++;
		if(ans==n+1){ans=-1;break;}
	}
	
	
	printf("%d",ans);
	return 0;
}

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

bool is_prime(ll n) {
  for(ll i=2;i*i<=n;i++) {
    if(n%i==0) {
      return false;
    }
  }
  return n!=1;
}

int main() {
  vector<bool> p(1e5+1,false);
  for(ll i=2;i<1e5+1;i++) {
    p[i]=is_prime(i);
  }
  vector<ll> like(1e5+1);
  for(ll i=3;i<1e5+1;i++) {
    like[i]=like[i-1];
    if(p[i]&&p[(i+1)/2]) {
      like[i]++;
    }
  }
  ll q;
  cin >> q;
  for(ll i=0;i<q;i++) {
    ll l,r;
    cin >> l >> r;
    cout << like[r]-like[l-1] << endl;
  }
}

Measured memory_bytes: 1536
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int d, n;
  scanf("%d%d", &d, &n);
  int ans;
  ans = n;
  if (ans == 100) ans++;
  for (int i=0; i<d; i++) ans *= 100;
  printf("%d\n", ans);
  return 0;
}


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

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

int opr(string& S) {
	if (S[0] == 't')  {
		S = S.substr(4);
		return 0;
	}
	
	S = S.substr(5);
	return 1;
}

int main() {
	string S;
	
	while (cin >> S, S != "#") {
		reverse(S.begin(), S.end());
		
		int ans1 = (opr(S)) ? 0 : 90, ans2 = 1;
		
		while (!S.empty()) {
			if (opr(S)) ans1 = 2 * ans1 - 90;
			else ans1 = 2 * ans1 + 90;
			ans2 *= 2;
		}
		
		int dv = gcd(ans1, ans2);
		cout << ans1 / dv;
		if (ans2 / dv != 1) cout << "/" << ans2 / dv;
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1200