akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    ll n; cin >> n;
    map<ll,ll> mp1;
    int a[n];
    rep(i,n){
        ll x; cin >> x;
        mp1[x-i+1]++;
        a[i]=-x-i+1;
    }
    ll ans=0;
    rep(i,n){
        ans+=mp1[a[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 27072
import scala.io.StdIn.readLine

object Main {
  def calc(c:Char,a:Int,b:Int) = c match { case '+' => a+b;case '-'=> a-b;case '*'=>a*b }
  def loop2(a:Int,b:Int,c:Int,d:Int,ops:List[List[Char]]):Boolean = ops match {
    case Nil => false
    case op::tl =>
      if(calc(op(2),calc(op(1),calc(op(0),a,b),c),d)==10) {
        printf("(((%d %c %d) %c %d) %c %d)\n",a,op(0),b,op(1),c,op(2),d);true
      }
      else if(calc(op(1),calc(op(0),a,b),calc(op(2),c,d))==10) {
        printf("((%d %c %d) %c (%d %c %d))\n",a,op(0),b,op(1),c,op(2),d);true
      } else loop2(a,b,c,d,tl)
  }

  def loop(l:Iterator[Array[Int]],ops:List[List[Char]]):Unit = {
    if(l.isEmpty) println(0)
    else {
      val Array(a,b,c,d):Array[Int] = l.next
      if(loop2(a,b,c,d,ops)) return
      else loop(l,ops)
    }
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile ( s => s != "0 0 0 0").foreach { s =>
      val l = s.split(" ").map(_.toInt).permutations
      val op = List('+','-','*')
      val ops = { for(i<-op;j<-op;k<-op) yield List(i,j,k) }.toList
      loop(l,ops)
    }
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	stack<int> S;
	int n;
	while ( cin >> n ) {
		if (n == 0) {
			cout << S.top() << endl;
			S.pop();
		}
		else {
			S.push(n);
		}
	}
}

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

class Dice{
  public:
    int face[6];
    int temp;

  Dice(){
  }

  void north(){
    temp = face[0];
    face[0] = face[1];
    face[1] = face[5];
    face[5] = face[4];
    face[4] = temp;
  }

  void south(){
    temp = face[0];
    face[0] = face[4];
    face[4] = face[5];
    face[5] = face[1];
    face[1] = temp;
  }

  void west(){
    temp = face[0];
    face[0] = face[2];
    face[2] = face[5];
    face[5] = face[3];
    face[3] = temp;
  }

  void east(){
    temp = face[0];
    face[0] = face[3];
    face[3] = face[5];
    face[5] = face[2];
    face[2] = temp;
  }

  void roll(char order){
    if(order == 'N') north();
    if(order == 'S') south();
    if(order == 'W') west();
    if(order == 'E') east();
  }

  void spin(){
    temp = face[1];
    face[1] = face[2];
    face[2] = face[4];
    face[4] = face[3];
    face[3] = temp;
  }

  void findTop(int top){
    string order = "NNNWNNN";
    for(int i = 0; i < 7; i++){
      if(face[0] == top) break;
      roll(order[i]);
    }
  };

  void findFront(int front){
    for(int i = 0; i < 4; i++){
      if(face[1] == front) break;
      spin();
    }
  }

  void rightSide(int top, int front){
    findTop(top);
    findFront(front);
    cout << face[2] << endl;
  }

  bool isSame(Dice dice1){
    string order = "NNNWNNN";
    for(int i = 0; i < 7; i++){
      for(int j = 0; j < 4; j++){
        if(face[0] == dice1.face[0] && face[1] == dice1.face[1] && face[2] == dice1.face[2] && face[3] == dice1.face[3] && face[4] == dice1.face[4] && face[5] == dice1.face[5]){
          return true;
        }
        spin();
      }
      roll(order[i]);
    }

    return false;
  }
};

int main(){
  int input[6], n, count = 0;
  Dice dice[100];

  cin >> n;

  for(int i = 0; n > i; i++){
    for(int j = 0; j < 6; j++){
      cin >> dice[i].face[j];
    }
  }

  for(int i = 1; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == j) continue;
      if(dice[i].isSame(dice[j])){
        count++;
        break;
      }
    }
  }

  string res = count < 1 ? "Yes" : "No";
  cout << res << endl;
}

Measured memory_bytes: 3204
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <regex>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define pq priority_queue
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define INF 9999999999
#define F first
#define S second
//#define int long long

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pi> pp;

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	int ans = n + m + x - max({ n,m,x });
	cout << max({ n,m,x }) * 10 + ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map> 
#include<vector>
#include<queue>
#include<set>
#include<bits/stdc++.h>
#include<deque> 
#include<bitset>
#include<string>
#define N 1e6
#define K 300005
#define MOD 1e9+7
#define int long long 
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
 
int max(int a, int b){
    if(a>b)
        return a;
    return b;
}
int min(int a, int b){
    if(a<b)
        return a;
    return b;
}
 
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 



int32_t main(){
	int n;
	cin>>n;
	int a[n + 1];
	int sum = 0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum += a[i];
	}
	//1st index is the length and the second one is the start point
	int dp[n + 1][n + 1];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j] = 0;
		}
	}
	for(int len = 1; len<=n;len++){
		for(int left = 1; left <= n; left++){
			int right = left + len - 1;
			if(right > n)
				continue;
			if(len == 1){
				dp[len][left] = a[left];
                continue;
                //cout<<left<<" "<<dp[len][left]<<endl;
			}
			//i choose left
			int op1 = a[left] + min(dp[len-2][left + 2], dp[len-2][left + 1]);
			//i choose right
			int op2 = a[right] + min(dp[len-2][left], dp[len-2][left+1]);
			dp[len][left] = max(op1, op2);
            //cout<<len<<" "<<left<<" "<<right<<" "<<dp[len][left]<<endl;
			
		}	
	}
	int x = dp[n][1];
    //cout<<x<<endl;
	int y = sum -x;
	cout<<x - y;


	
}








Measured memory_bytes: 70656
#include <iostream>

int mp[90][90];
int m,n;
int ans;
const int dx[] = {0,1,0,-1};
const int dy[] = {-1,0,1,0};

void dfs(int cnt, int x, int y)
{
	int tx,ty;
	if( ans<cnt )ans=cnt;
	//printf("cnt:%d  (%d,%d)\n",cnt,y,x);
	
	for(int k=0; k<4; k++){
		tx = dx[k] + x;
		ty = dy[k] + y;
		if( tx<0 || ty<0 || tx>=m || ty>=n ||
			 mp[ty][tx]==0 )continue;
		
		mp[y][x] = 0;
		dfs(cnt+1, tx, ty);
		mp[y][x] = 1;
	}
	return ;
}

int main()
{
	while(std::cin>>m>>n,m|n){
		ans = 0;
		
		for(int i=0; i<n; i++)
			for(int j=0; j<m; j++)
				std::cin>>mp[i][j];
			
		for(int i=0; i<n; i++)
			for(int j=0; j<m; j++)
				if( mp[i][j] )
					dfs(1,j,i);
					
		printf("%d\n",ans);
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P &element1, const P &element2)
{ //first昇順
	return element1.first < element2.first;
}
bool ps2(const P &element1, const P &element2)
{ //first降順
	return element1.first > element2.first;
}
bool ps3(const P &element1, const P &element2)
{ //second昇順
	return element1.second < element2.second;
}
bool ps4(const P &element1, const P &element2)
{ //second降順
	return element1.second > element2.second;
}
int digits(int n)
{
	int count = 0;

	while (n > 0)
	{
		n /= 10;

		count++;
	}
	return count;
}
int digit(int n)
{

	int ans = 0;
	while (n > 0)
	{
		ans += n % 10;
		n /= 10;
	}
	return ans;
}
ll combination(ll n, ll r)
{
	if (r * 2 > n)
		r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i)
	{
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int GCD(int x, int y)
{
	return x ? GCD(y % x, x) : y;
}
vector<int> divisor(int n)
{
	vector<int> value;
	FOR(i, 1, pow(n, 0.5) + 1)
	{
		if (i <= sqrt(n))
		{
			if (n % i == 0)
			{
				value.push_back(i);
				if (i * i != n)
				{
					value.push_back(n / i);
				}
			}
		}
	}
	return value;
}

// 入力
int k, t;

// DPテーブル
int dp[10010][10010];
int main()
{

	cin >> k >> t;
	int sum = 0;
	vector<int> num(t);
	for (int i = 0; i < t; ++i)
		cin >> num[i];
	sum = accumulate(all(num), 0);
	// DP初期条件: dp[0][w] = 0
	for (int w = 0; w <= sum/2; ++w)
		dp[0][w] = 0;

	// DPループ
	for (int i = 0; i < t; ++i)
	{
		for (int w = 0; w <= sum/2; ++w)
		{
			if (w >= num[i])
				dp[i + 1][w] = max(dp[i][w - num[i]] + num[i], dp[i][w]);
			else
				dp[i + 1][w] = dp[i][w];
		}
	}
	int alt=sum-dp[t][sum/2];
    int dis=abs(alt-dp[t][sum/2]);
	if(dis<=1){
		cout<<0<<endl;
	}else{
		cout<<dis-1<<endl;
	}
}


Measured memory_bytes: 3584
n, *goals = list(map(int, input().split()))
bamboos = list(map(int, [input().rstrip() for _ in range(n)]))


def get_best(li, goal):
    bam_mp_lis = {0: (-10, tuple())}
    li.sort()
    for i, v in enumerate(li):
        tmp = bam_mp_lis.copy()
        for bam, (mp, lis) in tmp.items():
            b0 = bam + v
            m0 = mp + 10
            l0 = lis + (i,)
            if b0 not in bam_mp_lis or m0 < bam_mp_lis[b0][0]:
                bam_mp_lis[b0] = (m0, l0)
    del bam_mp_lis[0]
    best = 10 ** 9
    for bam, (mp, lis) in bam_mp_lis.items():
        cost = mp + abs(goal - bam)
        if cost < best:
            best = cost
            beslis = lis
    return best, beslis


ans = 10 ** 9
from itertools import permutations

for junjo in permutations(goals):
    tmp = 0
    bambooo = bamboos.copy()
    for ju in junjo:
        if len(bambooo) == 0:
            tmp = 10 ** 9
            break
        be, beli = get_best(bambooo, ju)
        beli = sorted(beli, reverse=True)
        for beli0 in beli:
            del bambooo[beli0]
        tmp += be
    if tmp < ans:
        ans = tmp

print(ans)

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

typedef long long ll;

int main () {
	ll N;
	ll A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	ll d = (D - C) * (N - 1);
	ll w = D + C;
	ll min = A - (N-1)*D;
	while(min <= A + (N-1)*D) {
		//cout << min << " " << B << " " << min + d << endl;
		if (B >= min && B <= min + d) {
			cout << "YES" << endl;
			return 0;
		}
		min += w;
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

// reference: http://ir5.hatenablog.com/entry/20171209/1512821837

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: i32 = sc.read();
    let m: i32 = sc.read();
    println!("{}", n * m);
}

Measured memory_bytes: 2112
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char const *argv[])
 {
 	int n=0;
 	char c;

 	scanf("%d",&n);

 	for(int i = 0;i < n;i++){
 		scanf("%c",&c);
 		if(c == 'Y'){
 			printf("Four\n");
 			return 0;
 		}
 	}

 	printf("Three\n");

 	return 0;
 }

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

char getGrade(int m, int f, int r){
    int sum = m + f;
    char grade;
    if (m == -1 || f == -1) {
        grade = 'F';
    }
    else if ( 80 <= sum ){
        grade = 'A';
    }
    else if ( 65 <= sum && sum < 80){
        grade = 'B';
    }
    else if ( 50 <= sum && sum < 65){
        grade = 'C';
    }
    else if ( 30 <= sum && sum < 50){
        if (50 <= r) grade = 'C';
        else grade = 'D';
    }
    else if (sum < 30){
        grade = 'F';
    }
    return grade;
}

int main(){
    int m, f, r;

    while(1){
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        else {
           cout << getGrade(m, f, r) << endl;
        }
    }
   
}



Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
vector<int> par(1000000);//それぞれの頂点の親,最大値をsizeにする
vector<int> dis(1000000);//ランク
int n;
class union_find{
  public:
  void init(){
    for(int i = 0;i < n;i++){
      par[i] = i;//最初、親は自分自身とする
      dis[i] = 0;
    }
  }
  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else{
      return par[x] = root(par[x]);
    }
  }
  //xとyが同じ集合に属すか否か
  bool same(int x,int y){
    //cout << x << " " << y << endl;
    return (root(x) == root(y));
  }
  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y)return;
    if(dis[x] < dis[y]){
      par[x] = y;
    }
    else{
      par[y] = x;
      if(dis[x] == dis[y])dis[x]++;
    }
  }
};

int main(){
  ll m;
  cin >> n >> m;
  union_find tree;
  tree.init(); //これで初期化
  vector<ll> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    a[i]--;
  }
  for(int i = 0;i < m;i++){
    ll ina,inb;
    cin >> ina >> inb;
    ina--,inb--;
    tree.unite(ina,inb);
  }
  ll res = 0;
  for(int i = 0;i < n;i++){
    if(tree.same(i,a[i]))res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 11984
alpha2int = lambda x: ord(x) - ord("A") + 1
def int2alpha(x):
    if  x % 26 != 0:
        x = x % 26 
    else:
        x = 26
    return chr(x + 64)

N = int(input())
S = str(input())

out_s = ""
for i in range(len(S)):
    out_s += int2alpha(alpha2int(S[i]) + N)
    
print(out_s)

Measured memory_bytes: 3064
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) begin(x),end(x)
#include <bits/stdc++.h>
#define pll pair<ll,ll>
#define vi vector<int>
#define ld long double
#define ll long long
#define pb push_back
#define mid (l+r)/2
#define S second
#define F first
using namespace std;
int q;
bool mp;
string s[9];
int main(){
    fast,cin>>s[1]>>q;
    while(q--){
        int t; cin>>t;
        if(t == 1) mp = 1-mp;
        else{
            int f; cin>>f;
            char c; cin>>c;
            if(f == 1){
                if(mp) s[2] += c;
                else s[0] += c;
            }
            else{
                if(mp) s[0] += c;
                else s[2] += c;
            }
        }
    }
    if(mp){
        for(int i=s[2].size()-1;i>=0;i--){
            cout<<s[2][i];
        }
        for(int i=s[1].size()-1;i>=0;i--){
            cout<<s[1][i];
        }
        for(int i=0;i<s[0].size();i++){
            cout<<s[0][i];
        }
        cout<<endl;
    }
    else{
        for(int i=s[0].size()-1;i>=0;i--){
            cout<<s[0][i];
        }
        for(int i=0;i<s[1].size();i++){
            cout<<s[1][i];
        }
        for(int i=0;i<s[2].size();i++){
            cout<<s[2][i];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 1040
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}



int main() {

  long x;
  cin >> x;


  long sum =0;

  long ans =0;

  for (long i = 1; i < 10000000; ++i){
    if (sum + i > x)break;
    sum += i;
    ans++;
  }
  long remindist = x - sum;

  // long diff = x - sum - ans - 1;



  //reminを満たすための方法を求める
  long add =1;

  if (remindist ==0)add = 0;






  cout << ans + add <<endl;


}




















Measured memory_bytes: 256
import bisect
from collections import deque

n = int(input())
l = deque([int(input())])

for i in range(1, n):
  a = int(input())
  p = bisect.bisect_left(l,a)
  if p == 0:
    l.appendleft(a)
  else:
    l[p-1] = a

print(len(l))

Measured memory_bytes: 48216
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
bool issq(ll x){
  ll d = 1;
  while(d*d<=x){
    if(d*d==x)return true;
    d++;
  }
  return false;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
ll n, d; cin >> n >> d;
  ll x[n][d];
  rep(i,n){
    rep(j,d){
      cin >> x[i][j];
    }
  }
  ll ans = 0;
  rep(i,n){
    FOR(j,i,n){
      ll dis = 0;
      rep(k,d){
        dis += (x[i][k]-x[j][k]) * (x[i][k] - x[j][k]);
      }
      if(issq(dis))ans++;
    }
  }
  cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

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

    int N = (int)S.size();
    int cnt = 0;
    int ans = 0;
    while(1){
        if(S[cnt] != S[N - cnt - 1]){
            ans++;
        }
        if(cnt == (N - 1) / 2) break;
        cnt++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import math


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


def main():
    S = input()
    if int(S[:4]) < 2018:
        print("Heisei")
    elif int(S[:4]) > 2019:
        print("TBD")
    else:
        if int(S[5:7]) > 4:
            print("TBD")
        else:
            print("Heisei")

if __name__ == "__main__":
    main()


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

int main()
{
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int len=s.length();
    int num=0;
    int a=0;
    for (int i=0;i<len;i++)
    {
        if (s[i]=='R')
            {
                num++;
                if (num>a)
                    a=num;
            }
        else
            num=0;
    }
    cout<<a<<endl;
    return 0;
}


Measured memory_bytes: 3648
n = gets.chomp.to_i
s = gets.chomp

r_e = 0
r_w = 0
l_e = 0
l_w = 0

n.times do |i|
  if s[i] == 'W'
    r_w += 1
  else
    r_e += 1
  end
end

min = n

s.chars.each do |c|
  if c == 'W'
    r_w -= 1
  else
    r_e -= 1
  end

  if r_e + l_w < min
    min = r_e + l_w
  end

  if c == 'W'
    l_w += 1
  else
    l_e += 1
  end
end

puts min


Measured memory_bytes: 28548
S=str(input())
count_A=0
count_B=1
N=len(S)
for i in range(2,N,2):
  if S[i]!=S[0]:
    count_A +=1
  else:
    count_B +=1
for j in range(1,N,2):
  if S[j]==S[0]:
    count_A +=1
  else:
    count_B +=1
print(min(count_A,count_B))

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

using namespace std;

int main(){
    long long n, k, ans = 0;
    cin >> n >> k;
    long long arr[n] = {0};
    for(long long i = 0; i < n; ++i){
        cin >> arr[i];
    }
    sort(arr, arr + n, greater<long long>());
    if(k >= n){
        cout << 0;
        return 0;
    }
    for(long long i = 0; i < k; ++i){
        arr[i] = 0;
    }
    for(long long i = 0; i < n; ++i){
        ans += arr[i];
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void){
  int H,W,K;
  cin >> H >> W >> K;
  
  int black = 0;
  int ans = 0;
  
  vector<vector<char>>c(H, vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> c[i][j];
    }
  }
  
  for(int i=0;i<(1<<H);i++){
    for(int j=0;j<(1<<W);j++){
        for(int k=0;k<H;k++){
            for(int l=0;l<W;l++){
                if(!(i & (1<<k)) && !(j & (1<<l)) && c[k][l] == '#'){
                    black++;
                }
            }
        }
        if(black == K) ans++;
        black = 0;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
  int m1,m2,h1,h2,k;
  cin>>h1>>m1>>h2>>m2>>k;
  
  int h,m,mm;
  h=h2-h1;
  m=m2-m1;
  mm=h*60+m;
  cout<<mm-k<<endl;
  
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>

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

using namespace std;

int main(){
    int n; cin >> n;
    int f, s, ans = 0; cin >> f >> s;

    REP(i, n - 2){
        int x; cin >> x;
        if(s < max(f, x) && s > min(f, x))
            ans++;
        f = s; s = x;
    }cout << ans;

}        

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
#include <sstream>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

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

	if (stoi(s.substr(0, 4)) > 2019) cout << "TBD" << endl;
	else if (stoi(s.substr(5, 2)) > 4) cout << "TBD" << endl;
	else cout << "Heisei" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
    x=0;char c=getchar();bool f=0;
    while(!isdigit(c)) f|=c=='-',c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
    if(x<0){putchar('-'),write(-x);}
    else{if(x>9)write(x/10);putchar('0'+x%10);}
}




const int N=2e5+5;
int n,k;
double ans,pre[N];

signed main(){
	read(n);read(k);
	for(int i=1,x;i<=n;i++){
		read(x);
		pre[i]=pre[i-1]+1.0*(1+x)*x/2/x;
	}
	for(int i=k;i<=n;i++) ans=max(ans,1.0*(pre[i]-pre[i-k]));
	printf("%.10lf",ans);
}

Measured memory_bytes: 1792
import numpy as np 
from itertools import combinations
N,M,X = (int(x) for x in input().split())
C =np.zeros(N,dtype=int)
#A ={i:[] for i in range(1,M+1)}
A =np.zeros((N,M),dtype=int)
for i in range(N):
    x,*y = (int(x) for x in input().split())
    C[i] =x
    A[i] =np.array(y,dtype=int)

#何冊買うか、どれを買うか全探索
ans =[]
for i in range(1,N+1): #何冊買うか
    for j in combinations(range(N),i): #どの本を買うか
        understanding =np.sum(A[j,],axis=0)
        if np.all(understanding >=X):
            z =np.sum(C[j,])
            ans.append(z)
        #print(j,understanding)
        #print(j,end="- ")
if len(ans) >0:
    print(min(ans))
else:
    print(-1)

Measured memory_bytes: 27224
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int M_N = 300000;

vector<LL> fact;
vector<LL> inver(M_N+1);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=M_N;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[M_N]=fpow(fact[M_N],mod-2);
    for(int i=M_N-1;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}
 
LL hcombi(int n,int r){
    return combi(n+r-1,r); 
}

vector<LL> divi(LL K){
    vector<LL> v;
    for(LL i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}

vector<LL> pdivi(LL K){
    vector<LL> v;
    for(LL i=2;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        while(K%i==0){
            K/=i;
        }
    }
    if(K!=1) v.pb(K);
    return v;
}



int main(){
    set_combi();
    LL n,m,k;cin >> n >> m >> k;
    LL ans = 0;
    for (int i = 0; i < n; i++) {
        LL p = n - (i + 1);
        if(p <= k){
            if(i) ans = (ans + combi(n-1, i) * fpow(m-1,i) %mod * m %mod)%mod;
            else ans = (ans + combi(n-1, i) * m %mod)%mod;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main(){
    string s;
    cin >> s;
    bool app[26];
    for(int i=0;i<26;i++)app[i]=false;
    for(int i=0;i<s.size();i++)app[s[i]-'a']=true;
    for(int i=0;i<26;i++){
        if(!app[i]){
            printf("%c",(char)(i+'a'));
            cout << endl;
            return 0;
        }
    }
    puts("None");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,k,s,count=0;
  cin >> n >> k >> s;
  for (ll i=0;i<n;i++){
    if(count==0 && i<k){
      cout << s ;
      count++;
    }
    else if(i<k) cout <<" " << s ;
    else if(s!=1000000000) cout <<" " << s+1;
    else cout <<" " << 1;
  }
  cout << endl;
}

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

int main()
{
	long long n;

	cin >> n;
	long long ans = n;
	for (long long i=1; i*i<=n; ++i)
		if (n % i == 0)
			ans = min(ans, i+n/i-2);

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
a,b,c,d,e = map(int,input().split())

if a*1 == 0:
    print(1)
elif b*1 == 0:
    print(2)
elif c*1 == 0:
    print(3)
elif d*1 == 0:
    print(4)
elif e*1 == 0:
    print(5)

Measured memory_bytes: 9052
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int pier(int x)
{
    int c;
    while (x != 0)
    {
        c = x % 10;
        x /= 10;
    }
    return c;
}

int ost(int x)
{
    return x % 10;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector< vector<ll> > il(10, vector<ll>(10, 0));
    for (int i = 1; i <= n; ++i)
        ++il[pier(i)][ost(i)];
    ll odp = 0;
    for (int i = 1; i <= n; ++i)
        odp += il[ost(i)][pier(i)];
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

struct Trie {
    int cnt;
    int nxt[26];
};

Trie trie[1000005];
int trienxt = 1;

int n;

char s[1000005];
pair<int, char*> strs[200005];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%s", s);
        int len = strlen(s);
        char* ptr = new char[len + 10];
        strcpy(ptr, s);
        strs[i].first = len;
        strs[i].second = ptr;
    }
    sort(strs + 1, strs + n + 1);
    ll ans = 0;
    for (int S = 1; S <= n; S++) {
        //printf("%s", strs[i].second);
        char* str = strs[S].second;
        int curnode = 0;
        int curchr = strs[S].first;
        int cnt[26];
        for (int i = 0; i < 26; i++) cnt[i] = 0;
        for (int i = 0; str[i]; i++) cnt[str[i] - 'a']++;
        while (true) {
            for (int i = 0; i < 26; i++) {
                if (!cnt[i]) continue;
                ans += (ll)(trie[trie[curnode].nxt[i]].cnt);
                /*if (trie[trie[curnode].nxt[i]].cnt) {
                    printf("%s %c\n", str, i + 'a');
                }*/
            }
            curchr--;
            if (curchr < 0) break;
            if (!trie[curnode].nxt[str[curchr] - 'a']) {
                trie[curnode].nxt[str[curchr] - 'a'] = trienxt;
                trienxt++;
            }
            curnode = trie[curnode].nxt[str[curchr] - 'a'];
            cnt[str[curchr] - 'a']--;
        }
        trie[curnode].cnt++;
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 109364
n = int(input())
s = list(map(str,input().split()))
arare = [0,0,0,0]
#PWGY
for i in range(n):
  if s[i] == "P":
    arare[0] = "1"
  elif s[i] == "W":
    arare[1] = "1"
  elif s[i]== "G":
    arare[2] = "1"
  else:
    arare[3] = "1"
    
  if arare.count("1") == 4:
    print("Four")
    exit()
    
print("Three")



Measured memory_bytes: 62008
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    set<int> st;
    rep(i,3){
        int x;cin>>x;
        st.insert(x);
    }
    cout1(st.size())
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int main(){
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

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

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int n, m;
ll x[100000], y[100000];

ll xs[100000];
ll sy;
void solve(){
	ll ans = 0;
	rep(i, n - 1)
		xs[i] = ((x[i + 1] - x[i]) * (i + 1) * (n - i - 1)) % MOD;
	rep(i, m - 1)
		sy = (sy + (y[i + 1] - y[i]) * (i + 1) * (m - i - 1)) % MOD;
	rep(i, n - 1)
		ans = (ans + xs[i] * sy) % MOD;
	cout<<ans<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	rep(i, n)
		cin >> x[i];
	rep(i, m)
		cin >> y[i];
	solve();
	return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u == s) a--;
    else b--;
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

for i in range(M):
    t = heapq.heappop(A)
    heapq.heappush(A, (-1) * (-t // 2))
    #print(A)

print(-sum(A))

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

void max_self(ll& a, ll b) {
    a = max(a, b);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w+1);
    for(int i=0; i < n; ++i) {
        int weight, value;
        cin >> weight >> value;
        for(int j=w; j >= weight; --j) {
            max_self(dp[j], dp[j-weight]+value);
            /*above line finds out maximum of  dp[j](excluding ith element value) 
      and value + dp[j-weight] (including ith element value and the 
      profit with "KnapSack capacity - ith element weight") */    
        }
    }
    cout << dp[w] << "\n";
	return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

l = read().rstrip().decode()
n = len(l)
mod = 10 ** 9 + 7
dp = [[0, 0] for _ in range(n)]
dp[0] = [1, 2]
for i, check in enumerate(l[1:]):
    i += 1
    dp[i][0] = dp[i - 1][0] * 3
    dp[i][1] = dp[i - 1][1]
    if check == '1':
        dp[i][0] += dp[i - 1][1]
        dp[i][1] += dp[i - 1][1]
    dp[i][0] %= mod
    dp[i][1] %= mod
print(sum(dp[-1]) % mod)


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

int main(){
    int N;
    cin >> N;
    
    int ans = 0;
    for(int i=1; i<=N; i++){
        int nedan = i * 1.08;

        if(nedan == N){
            ans = i;
            break;
        }
    }

    if (ans == 0){
        cout << ":(" << endl;
    }
    else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    vector<int> a(3);
    cin >> a;
    sort(ALL(a));
    int ans = a[2] - a[1] + a[1] - a[0];
    cout << ans << endl;
    return 0;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(N);
  vector<int> C(M), D(M);
  for (int i=0; i<N; i++){
    cin >> A.at(i) >> B.at(i);
  }
  for (int i=0; i<M; i++){
    cin >> C.at(i) >> D.at(i);
  }
  for (int i=0; i<N; i++){
    int diff=400000000;
    int point;
    for (int j=0; j<M; j++){
      int diff_j = abs(A.at(i)-C.at(j))+abs(B.at(i)-D.at(j));
      if (diff_j < diff){
        diff = diff_j;
        point = j+1;
      }
    }
    cout << point << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	ll n,k;
	cin>>n>>k;
	if(n<k) {
		ll miin=abs(n-k);
		miin=min(miin,n);
		cout<<miin<<endl;

	}
	else{
		ll mood=(n%k);
		ll miin=abs(mood-k);
		miin=min(mood,miin);
		

		cout<<miin<<endl;

	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vct vector<ll>
ll n,m;
void deb(string s, ll vl){
  cout<<s<<" : "<<vl<<"\n";
}
void prv(vct v){
  for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
  cout<<"\n";
}

void solve(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll m1=b*d;
  ll m2=a*c;
  ll m3=c*b;
  ll m5=a*d;
  ll m4=LLONG_MIN;
  if((a<=0 && b>=0) || (c<=0 && d>=0))m4=0;
  ll ans=max(max(m1,m2),max(m3,m4));
  ans=max(m5,ans);
  cout<<ans<<"\n";
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t;
  t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3644
main=print.solve.map(map read.words).lines=<<getContents
solve([w,h,_]:xyas)=g$foldr f(0,w,0,h)xyas
f[x,_,1](w1,w2,h1,h2)=(max x w1,w2,h1,h2)
f[x,_,2](w1,w2,h1,h2)=(w1,min x w2,h1,h2)
f[_,y,3](w1,w2,h1,h2)=(w1,w2,max y h1,h2)
f[_,y,4](w1,w2,h1,h2)=(w1,w2,h1,min y h2)
g(w1,w2,h1,h2)=max(w2-w1)0*max(h2-h1)0

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

int main() {
  int x;
  cin >> x;
  for (int a = -118; a <= 119; a++) {
    for (int b = -119; b <= 118; b++) {
      if (a * a * a * a * a - b * b * b * b * b == x) {
        cout << a << " " << b << endl;
        exit(0);
      }
    }
  }
}


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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N, M; cin>>N>>M;
    vector<int> A[31];
    for(int i = 0; i < N; i++)
    {
        int k;
        cin>>k;
        for(int j = 0; j < k; j++)
        {
            int a; cin>>a;
            A[i].push_back(a);
        }
        
    }


    int ans = 0;
    for(int i = 1; i <= M; i++)
    {
        int c = 0;
        for(int j = 0; j < N; j++)
        {
            for(int x : A[j]){
                if(x==i){
                    c++;
                }
            }
        }
        if(c==N)ans++;
    }
    
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>                                                                                                                                                                                         
#include <cmath>
using namespace std;
const int MAX_N = 10000;
int main(){
    int N;
    cin >> N;
    int t, x, y;
    int t_old = 0; int x_old = 0; int y_old = 0;
    int dis, diff;
    for(int i = 1; i <= N; i++){
        cin >> t >> x >> y;  
        dis = abs(x - x_old) + abs(y - y_old);
        diff = (t - t_old) -  dis;
        if(diff % 2 != 0 || diff < 0){ 
            cout << "No" << endl;
            return 0;
        }   
        t_old = t; x_old = x; y_old = y;
    }   
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<list>
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define qread(x) x=read()
#define mes(x,y) memset(x,y,sizeof(x))
#define mpy(x,y) memcpy(x,y,sizeof(x))
#define INF 2147483647
inline int read(){
	int f=1,x=0;char ch;
	while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int a,b; 
int main(){ 
    qread(a),qread(b);
    for(int i=1;i<=3;i++){
    	if((a*b*i)%2==1){
    		printf("Yes\n");
    		return 0;
    	}
    }
    printf("No\n");
}

Measured memory_bytes: 256
s = input()
a = [int(c) for c in s]
b = len(s) 
if(a[b-1] == 3):
  print("bon")
elif(a[b-1] == 0 or a[b-1] ==  1 or a[b-1] == 6 or a[b-1] == 8):
  print("pon")
else:
  print("hon")

Measured memory_bytes: 9128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> A(n);
  for(auto& a : A) {
    cin >> a;
  }
  sort(A.begin(), A.end());

  int ans = 0;
  int ans2 = 0;
  for(int i = 1; i < n; i++) {
    ans += A[i] - A[i-1];
  }
  for(int i = n - 2; i >= 0; i--) {
    ans2 += A[i + 1] - A[i];
  }

  cout << min(ans, ans2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] x = new int[N + 1];
		double a = Math.pow(10, 9);
		int count = 0;
		double D = 0;
		
		for(int i = 1; i < (N + 1); i++) {
			x[i]  = sc.nextInt();
			a = Math.min(a, Math.abs(x[i] - X));
		}
		
		
		for(int j = 1; j <= a; j++) {
			count = 0;
			for(int i = 1; i < (N + 1); i++) {
				if((Math.abs(x[i] - X) % (a / j) == 0)) {
					count++;
				}	
			}
			if(count == N) {
				D = (a / j);
				break;
			}		
		}
		System.out.println((int)D);
	}
}


Measured memory_bytes: 52852
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {
    int N, K;
    cin >> N >> K;
    int a, tmp = 0;
    REP(i, N) {
        cin >> a;
        if (K <= a) tmp++;
    }
    cout << tmp << endl;

    return 0;
}

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

string ring;         //変数宣言
string apply;
int num;

int main()
{
    cin >> ring >> apply;    //文字入力

    ring = ring + ring;             //文字列を2つ並べることで末尾と先頭をつなげる
    num = ring.find(apply);
    if (num != -1) {                //find関数がｰ1を返さないつまり存在すればYesを表示
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3196