akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1e9+7
#define oo 1000006
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n,k;
int a[oo];
int f[oo];
void ReadInPut()
{
    n=read();
    k=read();
    F(i,1,n){a[i]=read();}
}
void Solve()
{
    FD(i,n-1,1)
    {
        f[i]=1e9;
        F(j,1,k)
        {
            if((i+j)<=n)MIN(f[i],f[i+j]+abs(a[i]-a[i+j]));
        }
    }
    cout<<f[1];
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}


Measured memory_bytes: 4736
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n, m = None, read = 0):
        self.n = n
        self.parents = [-1] * n
        if read:
            if m is None:
                exit(print("Warning: What is M"))
            for i in range(m):
                a, b = map(int, input().split())
                self.union(a - 1, b - 1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

n, m = map(int, input().split())
*p, = map(int, input().split())
UF = UnionFind(n, m, read = 1)

a = 0
for i in range(n):
    P = p[i] - 1
    if UF.same(P, i):
        a += 1
print(a)


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

ll i,j,k;
const ll MOD = 1000000000 + 7;

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main(){
    int n,m;
    cin>>n>>m;
    int ans=0;
    int h[n];
    bool good[n];
    int a[m],b[m];
    REP(i,n){
        cin>>h[i];
        good[i]=true;
    }
    REP(i,m){
        cin>>a[i]>>b[i];
        if(h[a[i]-1]<=h[b[i]-1]){
            good[a[i]-1]=false;
        }
        if(h[b[i]-1]<=h[a[i]-1]){
            good[b[i]-1]=false;
        }
    }
    

    REP(i,n){
        if(good[i])ans++;
    }
    cout<<ans<<'\n';

    return 0;
}



Measured memory_bytes: 4908
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string s,t;
    cin >> s;
    t = "CODEFESTIVAL2016";
    int ans = 0;
    REP(i,16){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] l=new int[n+1];
		for(int i=1;i<=n;i++)
			l[i]=i;
		int m=sc.nextInt();
		for(int i=0;i<m;i++){
			String[] s=sc.next().split(",");
			int a=Integer.parseInt(s[0]);
			int b=Integer.parseInt(s[1]);
			for(int k=1;k<=n;k++){
				if(l[k]==a)
					l[k]=b;
				else if(l[k]==b)
					l[k]=a;
			}
		}
		int[] ans=new int[n+1];
		for(int i=1;i<=n;i++)
			ans[l[i]]=i;
		for(int i=1;i<=n;i++)
			println(""+ans[i]);
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

int main()
{
  int h,a;
  cin>>h>>a;
  int t[a];
  for(int i=0;i<a;i++)
  {
    cin>>t[i];
  }
  for(int i=0;i<a;i++)
  {
    h=h-t[i];
  }
  if(h<=0)
  {
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    int main() {
        ll ans = 0;
        int D = 40;
        ll N,K,a;
        cin >> N >> K;
        vector<ll> b(D);
        for (int i=0;i<N;i++) {
            cin >> a;
            int j = 0;
            while(a > 0) {
                b[j] += a & 1;
                a >>= 1;
                j++;
            }
        }
        bool flipped = false;
        for (int i=D-1; i>=0; i--) {
            if (N - b[i] > b[i]) {
                if (flipped) {
                    ans += (N - b[i]) << i;
                } else if ((K >> i) & 1 == 1) {
                    ans += (N - b[i]) << i;
                } else {
                    ans += b[i] << i;
                }
            } else {
                ans += b[i] << i;
                flipped = flipped || ((K >> i) & 1 == 1);
            }
        }
        cout << ans << '\n';
        return 0;
    }

Measured memory_bytes: 256
N=int(input())
a = list(map(int,input().split()))
# N = 2*10**5
# a = [0 for i in range(N)]

fail = False
r = [0 for i in range(N)]
for i in range(N)[::-1]:
  tmpsum = 0
  for t in range(2,(N//(i+1))+1):
#     print(f"  {t*(i+1)}")
    tmpsum += r[(i+1)*t-1]
  diff = (a[i]-tmpsum)%2
#   print(diff)
  if diff == 1:
    r[i] = 1
  elif diff == 0:
    r[i] = 0
  else:
    fail = True
    break

if fail:
  print(-1)
else:
  print(sum(r))
#   print(" ".join(map(str,r)))

  result = []
  for i in range(N):
    if r[i]==1:
      result.append(i+1)
  if len(result) > 0:
    print(" ".join(map(str,result)))

Measured memory_bytes: 82160
#include<bits/stdc++.h>
#include <sstream>
#define ll long long
#define M 1000000000000000000
using namespace std;
/*ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0) {

        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}*/
void solve( )
{
    ll n,a,i,s=0;
    cin>>n;
    map<ll, ll> m;
    while(n--)
    {
        cin>>a;
        m[a]++;
    }
    for(auto it=m.begin();it!=m.end();++it)
    {
        if(it->first>it->second)
            s+=it->second;
        else if(it->first<it->second)
            s+=(it->second-it->first);
    }
    cout<<s;
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  ll t,y=0;
    //cin>>t;
    t=1;
   while(t--)
    {
        y++;
      solve();
      cout<<endl;
    }
    return 0;
}


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

#define ll long long

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin>>n;
	int a[n];
	cin>>a[0];
	int s=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		s^=a[i];
	}
	cout<<(a[0]^s);
	for(int i=1;i<n;i++)
		cout<<" "<<(a[i]^s);
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){


    ll n;
    cin>>n;

    ll cnt=0;

    for (ll i=1;i<=n-1;i++){
        cnt+=(n-1)/i;
    }

    cout<<cnt<<endl;








}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
	bool ok[200005];
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	char cc;
	for(int i=1;i<=n;i++)
	{
		cin>>cc;
		if(cc=='.')
		{
			ok[i]=true;
		}
	}
	for(int i=a;i<=max(c,d);i++)
	{
		if(!ok[i] && !ok[i+1])
		{
			cout<<"No";
			return 0;
		}
	}
	if(c>d)
	{
		bool t=false;
		for(int i=b-1;i+2<=d+1;i++)
		{
			if(ok[i] && ok[i+1] && ok[i+2])
			{
				t=true;
			}
		}
		if(!t)
		{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 384
package main

import "fmt"

func isOK(s string) bool {
	ok := true
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-1-i] {
			ok = false
			break
		}
	}
	return ok
}

func main() {
	var s string
	fmt.Scan(&s)
	N := len(s)
	if isOK(s) && isOK(s[:(N-1)/2]) && isOK(s[N/2+1:]) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll factorial[2010000];
ll invfactorial[2010000];

ll extGCD(ll a, ll b, ll &x, ll &y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
 
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll nCrM(ll n, ll r){
	ll ret = factorial[n];
	ret *= invfactorial[n - r];
	ret %= MOD;
	ret *= invfactorial[r];
	ret %= MOD; 
	return ret;
}

int main(void){
    factorial[0] = 1;
    for (int i = 1; i < 2010000; i++){
        factorial[i] = (factorial[i - 1] * i) % MOD;
    }
    for (int i = 0; i < 2010000; i++){
        ll x, y;
        ll g = extGCD(factorial[i], MOD, x, y);
        while (x < 0) x += MOD;
        x %= MOD;
        invfactorial[i] = x;
    }
    ll n, m, k;
    cin >> n >> m >> k;
    ll ans = 0;
    for(ll i = n - 1; i >= 1; i--){
        ll tmpans = 0;
        tmpans += i * (n - i);
        tmpans %= MOD;
        tmpans *= nCrM(n * m - 2, k - 2);
        tmpans %= MOD;
        tmpans *= m * m;
        tmpans %= MOD;
        ans += tmpans;
        ans %= MOD;
    }



    for(ll i = m - 1; i >= 1; i--){
        ll tmpans = 0;
        tmpans += i * (m - i);
        tmpans %= MOD;
        tmpans *= nCrM(n * m - 2, k - 2);
        tmpans %= MOD;
        tmpans *= n * n;
        tmpans %= MOD;
        ans += tmpans;
        ans %= MOD;
    }

    cout << ans << endl;


}


Measured memory_bytes: 31616
N = gets.to_i
C = gets.chomp

i = 0
j = N - 1
ans = 0

while i < j
  while i < N && C[i] == 'R'
    i += 1
  end

  while j >= 0 && C[j] == 'W'
    j -= 1
  end

  if i < j
    C[i], C[j] = C[j], C[i]
    ans += 1
  end
end

puts ans


Measured memory_bytes: 14756
// 解説見た
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
// 4/2 = 
// 4/4 = 1/2 + 1/4 + 1/4
// 4/6 = 
void solve() {
    lint N; cin >> N;
    for (int h=1; h<=3500; h++) {
        for (int n=h; n<=3500; n++) {
            double w = double(N*h*n) / double(4*h*n-N*n-N*h);
            if (w != INFINITY && floor(w) == w && w > 0) {
                cout << h << ' ' << n << ' ' << lint(w) << endl;
                return;
            }
        }
    }
}
int main() {
    // 12/3N = 
    solve();
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int cnt[1000001] = { 0 };
	bool mult[1000001] = { 0 };
	for (int i = 0; i < n; i++) {
		int a = ri();
		if (!cnt[a]++) for (int j = a + a; j <= 1000000; j += a) mult[j] = true;
	}
	int res = 0;
	for (int i = 0; i <= 1000000; i++) if (cnt[i] == 1 && !mult[i]) res++;
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 8680
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
    }

    a.sort();
    a.reverse();
    let v = a[0];
    a[1..].sort_by_key(|&x| (v as i64 - 2 * x as i64).abs());
    println!("{} {}", a[0], a[1]);
}


Measured memory_bytes: 6396
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
  char c[1211];
  int cl;
  fgets(c,sizeof(c),stdin);
  cl=strlen(c);
  c[cl-1]='\0';
  for(int i=0;i<cl;i++){
    if('A'<=c[i]&&c[i]<='Z'){
      c[i]=(int)c[i]+32;
    }else if('a'<=c[i]&&c[i]<='z'){
      c[i]=c[i]-32;
    }
  }
  cout << c << endl;
  return(0);
}



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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int s=0;
    for(int i=1;i<=n;i++){
        s+=i;
    }
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()

    n = 1

    while N >= 2 ** n:
        n += 1
    print((2 ** n) - 1)


main()


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

int main() {
 int n;
 cin>>n;
 
 int t,x,y;
 int currentt = 0;
 int currentx = 0;
 int currenty = 0;
 bool a = true;
 
 for(int i = 0;i<n;i++) {
 cin >>t>>x>>y;
   if(t - currentt < abs(x - currentx) + abs(y - currenty) || (t-currentt)%2 != abs(x - currentx + y - currenty)%2) {
   a = false;
   break;
    }
  currentt = t;
  currentx = x;
  currenty = y;
  }
 
 if(a) {
  cout << "Yes" << endl;
  } else {
   cout << "No" << endl;
   }
   
}

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

#define F first
#define S second

using ll = long long;
using ld = double;
using pii = pair <int, int>;

const int oo = 1e9 + 4;
const int SZ = 2e5 + 4;

ld n;

void read() {
    cin >> n;
}

void solve() {
    printf("%.6f", pow(n / 3., 3));
}

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

    read();
    solve();
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main() {
	int N;
	int d[50];
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0;i < N-1;i++) {
		for (int q = i+1;q < N;q++) {
			ans += d[i] * d[q];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int h=in(),w=in(),d=in();
    vector<vec> a(h,vec(w));
    vector<vector<pair<int,int>>> p(d,vector<pair<int,int>>((h*w+d-1)/d));
    rep(i,h)rep(j,w){
        int x=in()-1;
        p[x%d][x/d]=make_pair(i,j);
    }
    vector<vecll> s(d,vecll((h*w+d-1)/d));
    rep(i,d)rep(j,(h*w-1)/d)s[i][j+1]=s[i][j]+abs(p[i][j+1].first-p[i][j].first)+abs(p[i][j+1].second-p[i][j].second);
    int q=in();
    rep(i,q){
        int l=in()-1,r=in()-1;
        cout<<s[r%d][r/d]-s[l%d][l/d]<<endl;
    }
}


Measured memory_bytes: 10624
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)

ll N,Q;
string s;
char t[200010];
char d[200010];
map<ll,char> Move;

bool checkleft(ll a){
    if (a < 0 || a > N-1) return false;
    ll active = a;
    rep(i,Q){
        if (Move[active] == t[i]){
            if (d[i] == 'R'){
                active++;
            }
            else active--;
            if (active > N-1) return false;
            if (active < 0) return true;
        }
    }
    return false;
}

bool checkright(ll a){
    if (a < 0 || a > N-1) return false;
    ll active = a;
    rep(i,Q){
        if (Move[active] == t[i]){
            if (d[i] == 'R'){
                active++;
            }
            else active--;
            if (active < 0) return false;
            if (active > N-1) return true;
        }
    }
    return false;
}

int main() {
    cin >> N >> Q;
    cin >> s;
    rep(i,Q) cin >> t[i] >> d[i];
    rep(i,N){
        Move[i] = s[i];
    }
    ll left = -1;
    ll right = N;
    
    ll le1=0;
    ll ri1 = N;
    while(le1+1<ri1){
        ll mid = (le1+ri1)/2;
        if (checkleft(mid)){
            le1 = mid;
        }
        else ri1 = mid;
    }
    if (checkleft(ri1)) left = ri1;
    else if(checkleft(le1)) left = le1;
    
    ll le2=0;
    ll ri2 = N;
    while(le2+1<ri2){
        ll mid = (le2+ri2)/2;
        if (checkright(mid)){
            ri2 = mid;
        }
        else le2 = mid;
    }
    if (checkright(le2)) right = le2;
    else if(checkright(ri2)) right = ri2;
    ll ans = right-left-1;
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int place;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int n;
	cin >> n;
	int dp[100001];
	fn(dp, 100001, inf);
	dp[0] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= i; j *= 9){
			dp[i] = min(dp[i], dp[i-j] + 1);
		}
		for(int j = 1; j <= i; j *= 6){
			dp[i] = min(dp[i], dp[i-j] + 1);
		}
	}
	// for(int i = 0; i <= n; i++){
	// 	cout << dp[i] << " ";
	// }

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
    string str;
    cin >>str;
    long long n = str.size();
    long long np=0,ng=0;

    for(long long i=0;i<n;i++){
        if(str[i]=='g')
            ng++;
        if(str[i]=='p')
            np++;
    }
    cout << (ng-np)/2 <<endl;
}


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

long long n,m,a=1,c;
string s;
bool b;

int main(){
    cin>>n;
    vector<int>v(100,0);
    for (int i=1; i<10; i++){
        for (int j=1; j<10; j++){
            v[i*j]++;
        }
    }
    if (v[n]>0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


Measured memory_bytes: 3572
/*input
3 3 1
2 1 2 3
.@.
.@.
.@.
*/

#include <bits/stdc++.h>
#include <unistd.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e9
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(all((x)))))

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(ll* a,ll n,ll val){
    for(ll i=0;i<n;i++)
        a[i]=val;
}

ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

void solve(){
    ll i,j,_;
    ll h,w,k;
    cin>>h>>w>>k;
    char ch;
    ll x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2,--x1,--x2,--y1,--y2;
    ll a[h][w];
    ld b[h][w][4];
    rep(i,0,h){
        rep(j,0,w){
            cin>>ch;
            a[i][j]=(ch=='.');
            rep(_,0,4)b[i][j][_]=inf;
        }
    }
    if(!a[x1][y1]||!a[x2][y2]){
        cout<<-1<<endl;
        return;
    }
    rep(i,0,4)b[x1][y1][i]=0;
    set<pair<pair<ld,ll>,pll>> st;
    st.insert({{0,0},{x1,y1}});
    pll z;
    ld tmp,tmp2;
    ll x,y,dir;
    while(st.size()){
        auto it = st.begin();
        z=(*it).S,dir=(*it).F.S,tmp=(*it).F.F,tmp2=tmp;
        st.erase(it);
        rep(i,0,4){
            tmp=tmp2;
            x=z.F+dx[i],y=z.S+dy[i];
            if(x<0||y<0||x>h-1||y>w-1||!a[x][y])continue;
            if(dir==i){
                tmp+=1/(ld)k;
            }else{
                tmp=ceil(tmp);
                tmp+=1/(ld)k;
            }
            if(tmp>=b[x][y][i])continue;
            b[x][y][i]=tmp;
            st.insert({{tmp,i},{x,y}});
        }
    }
    ll ans=inf;
    rep(i,0,4)ans=min(ans,(ll)ceil(b[x2][y2][i]));
    if(ans==inf)ans=-1;
    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T=1;
   // cin>>T;
    while(T--){
        solve();
    }
    return 0;
}




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

#define ll long long
#define pb push_back

void solve()
{
    ll n,res=0;
    cin >> n;
    ll cnt[n];
    for(int i=0;i<n;i++)
    {
        cin >> cnt[i];
        res=res^cnt[i];
    }
    for(int i=0;i<n-1;i++)
        cout << (res^cnt[i]) << " ";
    cout << (res^cnt[n-1]) << "\n";
}

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

    int tt=1;
    ///cin >> tt;
    while(tt--)
    {
        solve();
    }
}


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

int main() {
  int N,A,f,j;
  cin >> N >> A >>f>>j;
  if (N+A>f+j) {
    cout <<"Left"<< endl;
  }
  else if(N+A==f+j)cout<<"Balanced"<<endl;
  else cout<<"Right"<<endl;
}

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

string prime(int n){
  int i,j;
  string p="001";
  while(p.size()<=n)p+="10";
  i=3;
  while(i*i<n){
    for(j=3*i;j<n;j+=2*i)p[j]='0';
    do{i+=2;}while(p[i]-'1');
  }
  return p;
}

int main(){
  int n,ans;
  string p = prime(50000);

  while(1){
    cin >> n;
    if(!n)break;

    ans = 0;
    for(int i=0;i<=n/2;i++){
      if(p[i]-'0' && p[n-i]-'0')ans++;
    }
    cout << ans << endl;
  }
}

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
  
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21732
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	string ans = "";
	for (int i = 0; i < n; i++)
	{
		ans += a.at(i);
		ans += b.at(i);
	}
	cout << ans << endl;
}


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());
		int paint = Integer.parseInt(br.readLine());
		int disp = num * num - paint;
		System.out.println(disp);

	}
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
bool mp[105][105];
int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    a--;b--;
    for(int i=0;i<50;i++)
        for(int j=0;j<100;j++)
            mp[i][j]=1;
    int x=0,y=0;
    while(a){
        mp[x][y]=0;
        a--;y+=2;
        if(y>=100){
            x+=2;
            y=0;
        }
    }
    x=99;y=0;
    while(b){
        mp[x][y]=1;
        y+=2;b--;
        if(y>=100){
            x-=2;
            y=0;
        }
    }
    puts("100 100");
    for (int i=0;i<100;i++){
        for(int j=0;j<100;j++)
            if(mp[i][j])printf("#");
            else printf(".");
        puts("");
    }
}

Measured memory_bytes: 3772
sx,sy,tx,ty = map(int, input().split())
x = tx-sx
y = ty-sy
ans = ('R'*x + 'U'*y + 'L'*x + 'D'*y)+'D' + 'R'*(x+1) + 'U'*(y+1)+'L'+'U' + 'L'*(x+1) + 'D'*(y+1)+'R'
print(ans)

Measured memory_bytes: 3060
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i in range(N):
  ans += B[A[i]-1]
  if i < N-1:
    if A[i]+1==A[i+1]:
      ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) { printf("Yes\n");
	} else { printf("No\n"); }
	return;
}

int A[200001] = {0};
int ans[200001] = {0};

int main()
{
	int N = 0, i = 0;
	scanf("%d", &N);

	for (i = 0; i < (N-1); i++) {
		scanf("%d", &A[i]);
		ans[A[i]]++;
	}

	for (i = 1; i <= N; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  long long acc[n+1];
  acc[0] = 0;
  for (int i=1; i<=n; i++) acc[i] = acc[i-1] + a[i-1];
  long long ans = 1e15;
  for (int i=2; i<n-1; i++) {
    vector<pair<long long, long long>> l;
    long long l_acc = acc[i];
    int l_idx = lower_bound(acc, acc + i + 1, l_acc / 2) - acc;
    for (int d=-1; d<=1; d++) {
      if (l_idx + d >= 0 && l_idx + d <= i) {
        l.emplace_back(acc[l_idx+d], l_acc - acc[l_idx+d]);
      }
    }
    vector<pair<long long, long long>> r;
    long long r_acc = acc[n] - acc[i];
    int r_idx = lower_bound(acc + i + 1, acc + n + 1, acc[i] + r_acc / 2) - acc;
    for (int d=-1; d<=1; d++) {
      if (r_idx + d >= 0 && r_idx + d <= n) {
        r.emplace_back(acc[r_idx+d] - acc[i], acc[n] - acc[r_idx+d]);
      }
    }
    for (auto li: l) {
      for (auto ri: r) {
        long long v[4];
        v[0] = li.first;
        v[1] = li.second;
        v[2] = ri.first;
        v[3] = ri.second;
        sort(v, v + 4);
        ans = min(v[3] - v[0], ans);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {

	private static Scanner sc;

	public static void main(String[] args) {
		sc = new Scanner(System.in);
		String w =sc.next();
		for(int i=0;i<w.length();i++) {
			int sum=0;
			for(int j=0;j<w.length();j++) {
				if(w.charAt(i)==w.charAt(j)) sum=sum+1;
			}
			if(sum%2!=0) {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");

	}

}

Measured memory_bytes: 23380
N, A, B, C = map(int, input().split())
INF = 10**18
L = []
for i in range(N):
    l = int(input())
    L.append(l)

    
def dfs(i, a, b, c):
    if i == N:
        if (a == 0) or (b == 0) or (c == 0):
            return INF
        return abs(a-A) + abs(b-B) + abs(c-C)
    p = 0 if a == 0 else 10
    q = 0 if b == 0 else 10
    r = 0 if c == 0 else 10
    res1 = dfs(i+1, a, b, c)
    res2 = dfs(i+1, a+L[i], b, c) + p
    res3 = dfs(i+1, a, b+L[i], c) + q
    res4 = dfs(i+1, a, b, c+L[i]) + r
    return min(res1, res2, res3, res4)


print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
        checked {
#if DEBUG
            MyDebugger.Test(process, "../TextFile1.txt");
            //TestCaseMaker.MakeTestCase1("../TextFile2.txt");
            //MyDebugger.Test(process, "../TextFile2.txt");
#else
            object ret = process(new StreamReader(Console.OpenStandardInput()));
            //Console.WriteLine(ret);
#endif
        }
    }

    public const int QN = 26;

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var cc = ToIntArray(input.ReadLine(), QN);
        var ss = new int[n][];
        for (int i = 0; i < ss.Length; i++) {
            ss[i] = ToIntArray(input.ReadLine(), QN);
        }

        var lasts = new int[QN];
        List<int> ans = new List<int>();

        for(int day=1; day<=n; day++) {
            long max = long.MinValue;
            int maxJ = 0;

            for(int j=0; j<QN; j++) {
                var x = UpVal(day, ss, cc, lasts, j);
                if(x > max || (x==max && cc[j] > cc[maxJ])){
                    max = x;
                    maxJ = j;
                }
            }

            lasts[maxJ] = day;
            ans.Add(maxJ);
        }

        foreach(var x in ans) {
            Console.WriteLine(x+1);
        }

        return n;
    }

    static long UpVal(int day, int[][] ss, int[] cc, int[] lasts, int si) {
        long up = ss[day-1][si];

        var prev = lasts[si];
        lasts[si] = day;
        var down = DownVal(day, cc, lasts);
        lasts[si] = prev;
        
        return up - down;
    }

    static long DownVal(int day, int[] cc, int[] lasts) {
        long y = 0;
        for(int i=0; i < QN; i++) {
            y += cc[i] * (day - lasts[i]);
        }
        return y;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        if (n == 0) return ret;
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 28420
//D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int raw[maxn];
int main(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++)cin >> raw[i];
	sort(raw+1,raw+n+1);
	reverse(raw+1,raw+n+1);
	ll ans = raw[1];
	int res = n-2,idx = 2,flip = 0;
	while(res--){
		ans += raw[idx];
		flip = !flip;
		if(!flip)idx++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
 using namespace std;
int main(){
  int n, t, a, h[1200];
  cin >> n >> t >> a;
  int res, cc;
  cc = 1 << 30;
  for (size_t i = 0; i < n; i++) {
    cin >> h[i];
    h[i] = abs(a*1000 - (t*1000 - h[i]* 6));
    if (h[i] < cc) {
      res = i+1;
      cc = h[i];
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
from collections import Counter
s = input()
t = input()
#文字の順番入れ替えは可能
#文字の個数は増やせない
#結局はaabbbなら2,3になる
#abcdbならa:1,b:2,c:1,d:1
s_dict = Counter(s)
t_dict = Counter(t)
s_val = list(s_dict.values())
t_val = list(t_dict.values())
s_val.sort()
t_val.sort()
if s_val == t_val:
    print('Yes')
else:
    print('No')



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

const int INF = 1e9 + 1;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] *= -1;
  }
  vector<int> dp(n + 1, INF);
  for (int i = 0; i < n; i++) {
    *upper_bound(begin(dp), end(dp), a[i]) = a[i];
  }
  cout << lower_bound(begin(dp), end(dp), INF) - begin(dp) << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
void ABC170C()
{
	int X, N;
	cin >> X >> N;
	vi p(N);
	for (auto& x : p)
		cin >> x;
	if (N == 0)
	{
		cout << X << endl;
		return;
	}
	sort(p.begin(), p.end());
	auto q = lower_bound(p.begin(), p.end(), X);
	int k = distance(p.begin(), q);
	if (q == p.cend() || *q != X)
	{
		cout << X << endl;
		return;
	}
	for (int i = 0; i <= N; ++i)
	{
		auto r1 = k + i;
		auto r2 = k - i;
		if (r2 < 0 || p[r2] != X - i)
		{
			cout << X - i;
			return;
		}
		else if (r1 > N-1 || p[r1] != X + i)
		{
			cout << X + i;
			return;
		}
	}
}
int main()
{
	ABC170C();
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  
  int sum=0;
  int a=0,b=0;
  scanf("%d %d", &a,&b);
  if (a == b){
    printf("Draw");
  }else if((a>b || a==1) && b!=1){
    printf("Alice");
  }else if(b>a || b==1){
    printf("Bob");
  }
  
 return 0; 
}

Measured memory_bytes: 1660
#167
N,M,X = map(int,input().split())
cost_performances = []
for i in range(N):
  book = list(map(int,input().split()))
  cost_performances.append(book)
  for j in range(len(cost_performances)-1):
    cost_performances.append([book[k]+cost_performances[j][k] for k in range(M+1)])
candidate = []
for cost_performance in cost_performances:
  judge = [cost_performance[i+1]>=X for i in range(M)]
  if(False in judge):
    continue
  else:
    candidate.append(cost_performance)
if(len(candidate)==0):
  print(-1)
else:
  cost = [candidate[i][0] for i in range(len(candidate))]
  print(min(cost))

Measured memory_bytes: 11172
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int A,B,C,D;cin>>A>>B>>C>>D;
  P(min(A,B)+min(C,D));
  return 0;
}


Measured memory_bytes: 256
s = input()
# print(s)
s_list = list(s)
# print(s_list)

ans  = 0
number_of_consecutive_times = 0
for ss in s_list:
    if ss == 'R':
        number_of_consecutive_times += 1
    else:
        number_of_consecutive_times = 0
    ans = max(ans, number_of_consecutive_times)
print(ans)

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    set<int> st;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        st.insert(A[i]);
    }

    if (N % 2 == 0) {
        if (st.size() % 2 == 0) cout << st.size() << endl;
        else cout << st.size() - 1 << endl;
    }
    else {
        if (st.size() % 2 == 0) cout << st.size() - 1 << endl;
        else cout << st.size() << endl;
    }
}

Measured memory_bytes: 5376
def main():

    x,k,d = tuple([int(t)for t in input().split()])

    if k*d>abs(x):
        ax = abs(x)
        steps = k-ax//d
        if steps%2==0:
            print(ax%d)

        else:
            print(d-ax%d)
    else:
        print(abs(x)-k*d)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9140
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int main()
{
    long int n,a,b,cnt,bnt;
    char str[100005];

    while(scanf("%ld %ld %ld",&n,&a,&b)==3)
    {
        scanf("%s",str);

        cnt=0;
        bnt=0;

        for(int i=0; i<n; i++)
        {
            if(str[i]=='c')
                printf("No\n");

            else if(str[i]=='a')
            {
                if(cnt<(a+b))
                {
                    printf("Yes\n");

                    cnt++;
                }

                else
                    printf("No\n");
            }

            else if(str[i]=='b')
            {
                if((cnt<(a+b))&&(bnt<b))
                {
                    printf("Yes\n");

                    cnt++;

                    bnt++;
                }

                else
                    printf("No\n");
            }
        }
    }

    return (0);
}


Measured memory_bytes: 768
import java.util.Scanner;

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(C >= B/A){
			System.out.println(B/A);
		}else{
			System.out.println(C);
		}

		
	}
	
	
}



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

int main(void){
    int N, A;

    scanf("%d", &N);

    int *out = (int *) malloc(sizeof(int) * N);

    for(int i = 0; i < N; i ++){
        scanf("%d", &A);
        out[A - 1] = i + 1;
    }
    for(int i = 0; i < N; i ++){
        printf("%d ", out[i]);
    }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define y_n(ans) cout<<(ans?"Yes":"No")<<endl;

int main() {
    int x;
    cin >> x;
    if (x == 0) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll X[N];
    for(int i = 0; i < N; i++) cin >> X[i];

    ll ans = 0;
    for(int i = 1; i < N; i++) {
        if(A * (X[i] - X[i - 1]) > B)
            ans += B;
        else
            ans += A * (X[i] - X[i - 1]);
    }

    cout << ans << "\n";
    return 0;
}


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

int main() {
  int n, x;
  while (true) {
    cin >> n >> x;
    if (!n && !x) break;
    int ans{};
    for (int i{1}; i <= n; ++i) {
      for (int j{i+1}; j <= n; ++j) {
        int k{x - i - j};
        if (j < k && k <= n) ++ans;
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

int main(){
    ios::sync_with_stdio(false);
    int n;
    for(cin>>n;n--;){
        int k=0;
        string a,b;
        cin >> a;
        cin >> b;
        if(a.size() < b.size()) swap(a,b);//????????????a>b?????????
        while(b.size() < a.size()) b = '0' + b;//????????????a==b?????????
        for(int i=a.size()-1;i>=0;i--){//???????????????????????????
            a[i] += b[i] - '0' + k;
            if(a[i] > '9'){
                a[i]-=10;
                k = 1;
            }
            else k = 0;
        }
        if(k)   a="1"+a;//??°??????????????????????????????????¶?????????¨???
        if(a.size() > 80)   cout << "overflow" << "\n";
        else    cout << a << "\n";
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007

int dp[105][100005];

int main(){
    rep(i,100005) rep(j,105)  dp[j][i] = 0;
    int n,k; cin >> n >> k;
    vector<int> a(n); rep(i,n) cin >> a[i];
    rep(j,k+1){
        if(j <= a[0]) dp[0][j] = 1;
        else  dp[0][j] = 0;
    }
    for(int i=1;i<n;i++){
        int sum = 0;
        for(int j=0;j<=a[i];j++){
            sum = (sum + dp[i-1][j]) % MOD;
            dp[i][j] = sum;
        }
        for(int j=a[i]+1; j <= k; j++){
            sum = (sum - dp[i-1][j - a[i] - 1] + MOD) % MOD;
            sum = (sum + dp[i-1][j]) % MOD; 
            dp[i][j] = sum;
        }
        //cout << i <<  ":" << dp[i][0] <<  endl;
    }
    
    
    cout << dp[n-1][k] << endl;
    return 0;
}

Measured memory_bytes: 41848
# ARC081C - Make a Rectangle (ABC071C)
from collections import Counter


def main():
    n = int(input())
    cnt = sorted(
        {
            k: v
            for k, v in Counter(map(int, input().rstrip().split())).items()
            if v >= 2
        }.items(),
        reverse=True,
    )
    if cnt == []:
        print(0)
    elif cnt[0][1] >= 4:
        print(cnt[0][0] ** 2)
    else:
        print(cnt[0][0] * cnt[1][0])


if __name__ == "__main__":
    main()

Measured memory_bytes: 24104