akhauriyash/Code-Regression huggingface dataset:
/*author ADITYA BANSAL
         MNNIT ALLAHABAD     */
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long
ll power(ll,ll);
ll mul(ll a,ll b);
#define watch(x) cerr<<(#x)<<"is"<<x<<nl;
#define mod 1000000007
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi(a,b) for(ll i=a; i<b; i++)
#define fk(a,b) for(ll k=a; k<b; k++)
#define fri(a,b) for(ll i=a; i>b; i--)
#define fj(a,b) for(ll j=a; j<b; j++)
#define ffi(a,b) for(ll i=a;i*i<=b;i++)
#define mp make_pair
#define ff first 
#define  tc ll t; cin>>t; while(t--)
#define all(v) (v).begin(),(v).end()
#define ss second
#define pb push_back
#define mem(v) memset((v),0,sizeof(v));
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define sll set<ll>
#define vll vector<ll>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ad(a,b)  (a%mod+b%mod+mod)%mod
#define pob pop_back
#define nl endl
const ll  N=1000002LL;

signed main(){ fast
  // tc
 { ll a,b;
 cin>>a>>b;
  if(a==b)
  cout<<1<<nl;
  else {
	  if(b>a)
	  swap(a,b);
	  
	  ll e=(a+b)/2;
	//  cerr<<e<<nl;
	  if(a-e ==e-b)
	  cout<<e<<nl;
	  else cout<<"IMPOSSIBLE";
  }
  
 }
    return 0;
}


/******************************************************************************/

ll mul(ll a,ll b){
    return ((a)*1LL*(b))%mod;
}

/*--------------------<<BINARY EXPONENTIATION>>--------------------*/
ll power(ll a,ll n){
  ll res=1;
  while(n){
      if(n&1) res= mul(res,a);
     n>>=1; 
     a= mul(a,a);
  }
    return res;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String s1 = str.replace(str.substring(0,1),"");
        if(s1.length() !=2) {
            System.out.println("No");
            return;
        }
        String s2 = s1.replace(s1.substring(0,1),"");
        if(s2.length()==0) System.out.println("Yes");
        else System.out.println("No");

    }
}

Measured memory_bytes: 20820
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	set<int>s;
	for (int i = 0; i < N; i++) {
		cin >> M;
		s.insert(M);
	}
	if (s.size() % 2) {
		cout << s.size() << endl;
	}
	else {
		cout << s.size() - 1 << endl;
	}
	return 0;
}


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

int main(){
  int n,x;cin>>n>>x;
  int m[n],s=0,M=1000000000;
  for(int i=0;i<n;i++){
    cin>>m[i];
    s+=m[i];
    if(m[i]<M){
      M=m[i];
    }
  }
  int d=(x-s)/M;
  cout<<n+d<<endl;
  return 0;
}


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

int main(){
  int N;     //黒板にかかれた整数の数
  int K = 0; //割り算の操作回数
  int m = 0; //奇数が見つかった時のﾌﾗｸﾞ
  int amari;

  cin >> N;
  int a[N];

  for ( int i=0; i<N; i++ ){
    cin >> a[i];
  //    cout << a[i] << endl;
  }

  while ( m == 0 ){
    for ( int i=0; i<N; i++ ){
      amari = a[i] % 2;
      if ( amari != 0){
        m = 1;
        break;
      }
      a[i] /= 2;
    }
    if ( m == 0 ){
      K++;
    }
  }
  
  cout << K << endl;

}  

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ans = 0;
  for (int i = k; i < n; i++) {
    ans += a[i];
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut cnt = 0;
    for i in 0..3 {
        if s[i] == '1' {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,D;

    cin>>N>>D;

    int left = 1;
    int ans = 0;
    while(left <= N) {
        left += 2*D;
        left++;
        ans++;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
from collections import Counter


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    uf.union(a - 1, b - 1)

count = 0
for k, v in Counter(uf.parents).items():
    if k < 0:
        count += v

print(count - 1)

Measured memory_bytes: 80136
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>

//foolish

int main()
{
using namespace std;
long long int x, y;
std::cin >> x >> y;
if(abs(x) == abs(y)){
    if(x * y < 0){
        std::cout << 1 << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }
} else if(abs(x) < abs(y)){
    if(x * y < 0){
        std::cout << abs(y) - abs(x) + 1 << std::endl;
    } else if(y < 0){
        if(x == 0){
            std::cout << abs(y) - abs(x) + 1 << std::endl;
        } else {
            std::cout << abs(y) - abs(x) + 2 << std::endl;
        }
    } else {
        std::cout << abs(y) - abs(x) << std::endl;
    }
} else {
    if(x * y < 0){
        std::cout << abs(x) - abs(y) + 1 << std::endl;
    } else if(x < 0){
        std::cout << abs(x) - abs(y) << std::endl;
    } else {
        if(y == 0){
            std::cout << abs(x) - abs(y) + 1 << std::endl;
        } else { 
            std::cout << abs(x) - abs(y) + 2 << std::endl;
        }
    }
}
return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = inputInt()
	A = inputList()

	flg = False

	for i in A:
		if i % 2 == 0:
			if i % 3 == 0 or i % 5 == 0:
				pass
			else:
				flg = True

	if flg:
		print("DENIED")
	else:
		print("APPROVED")

if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int A, B, C, K;
int ans = 0;

signed main(){
    cin >> A >> B >> C >> K;

    ans += min(A, K);
    K -= min(A, K);

    K -= min(B, K);

    ans -= K;

    cout << ans << endl;
}

Measured memory_bytes: 3656
#include<cstdio>
#include<cmath>
#include<string.h>
#include<iostream>
using namespace std;
long long find(long long x,long long y)
{
	long long z,a,b;
   	a=x;b=y;
   	if(x<y)
   	swap(x,y);
  	z=y;    
   	while(z)
   	{
      	z=x%y;
      	x=y;
      	y=z;         
   	}
   	return a*(b/x);
}
int main()
{
    long long n,k,m;
    cin>>n;
    scanf("%lld",&k);
    n--;
    while(n--)
	{
		scanf("%lld",&m);
		k=find(k,m);
	}
	printf("%lld\n",k);
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
M, N = list(map(int, input().split()))
q = int(input())

Map = []
for i in range(M):
    Map.append(input())

def get_slide_sum(Map, kw):
    l = []
    for r in range(M):
        tmp = []
        for c in range(N):
            ll = 0 if c == 0 else tmp[c-1]
            ul = 0 if r == 0 or c == 0 else l[r-1][c-1]
            ur = 0 if r == 0 else l[r-1][c]
            count = ll + ur - ul
            if Map[r][c] == kw:
                count+=1
            tmp.append(count)
        l.append(tmp)
    return l

J = get_slide_sum(Map, 'J')
O = get_slide_sum(Map, 'O')
I = get_slide_sum(Map, 'I')

def get_sum(inp,L):
    a, b, c, d = list(map(int, inp.split()))
    ll = 0 if a == 1 else L[a-2][d-1]
    ul = 0 if a == 1 or b == 1 else L[a-2][b-2]
    ur = 0 if b == 1 else L[c-1][b-2]
    return L[c-1][d-1] - ll - ur + ul

for i in range(q):
    inp = input()
    print(get_sum(inp, J), get_sum(inp, O), get_sum(inp, I))

Measured memory_bytes: 128820
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  int a = N % 10;
  if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) cout << "hon" << endl;
  else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
  else cout << "bon" << endl;
}


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

using namespace std;


// union findの構造体による実装
// spaghetti-source(github)のunion_find.ccから
struct UnionFind {
    vector<int> parent; // parent[root] is the negative of the size.

    explicit UnionFind(int n) : parent(n, -1) {
    };                                       //初期化

    bool unite(int u, int v) {//ノードx,yが属する木を併合
        u = root(u);
        v = root(v);
        if (u == v) return false;
        if (parent[u] > parent[v]) swap(u, v);
        parent[u] += parent[v];
        parent[v] = u;
        return true;
    }

    bool find(int u, int v) {//ノードx,yが同じ木に属するかどうか
        return root(u) == root(v);
    }

    int root(int u) {//ノードuが属する木の根
        return parent[u] < 0 ? u : parent[u] = root(parent[u]);
    }

    int size(int u) {//ノードiを含む木の大きさ
        return -parent[root(u)];
    }
};


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

    vector<pair<int, int>> vt;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        vt.emplace_back(make_pair(a, b));
    }

    vector<pair<int, int>> tmp_vt;
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        //辺を1つ減らしてunion-find木を作成
        tmp_vt = vt;
        tmp_vt.erase(tmp_vt.begin() + i);
        auto uf = UnionFind(n);
        for (auto x:tmp_vt) {
            uf.unite(x.first, x.second);
        }

        //連結性のチェック
        for (int j = 1; j < n; ++j) {
            if (!uf.find(0, j)) {
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

bool s[110][110];
int p[110];

int ans=0;
int n,m;

void f(int k,bool b[]){
  if(k==n){
    int res=0;
    rep(i,m){
      int flag=0;
      rep(j,n){
        if(b[j]&&s[i][j]) flag++;
      }
      if(flag%2==p[i])res++;
    }
   if(res==m) ans++;
   return;
  } 

  b[k]=true;
  f(k+1,b);
  b[k]=false;
  f(k+1,b);
}


main(){

  cin>>n>>m;
  rep(i,m){
    int k;
    cin>>k;
    rep(j,k){
      int a;
      cin>>a;
      a--;
      s[i][a]=true;
    }
  }
  rep(i,m){
    cin>>p[i];
  }

  bool b[110]={};
  f(0,b);

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int a,b; cin >> a >> b;
    cout << a*(a-1)/2 + b*(b-1)/2 << endl;
    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

int dp[110][2][5];

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = S.size();
    dp[0][0][0] = 1;
    rep(i, N) rep(less, 2) rep(k, 4) {
        int x = less ? 9 : S[i] - '0';
        rep(d, x + 1) {
            dp[i + 1][less || d < x][k + (d > 0)] += dp[i][less][k];
        }
    }
    cout << dp[N][0][K] + dp[N][1][K] << '\n';
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  cnt := 0
  for {
    if b < a || b <= 0 || cnt >= c {
      fmt.Println(cnt)
      break
    }
    b = b - a
    cnt++
  }
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
 	while (x->left != NIL) 
 	x = x->left;
  return x;
}

Node treeSearch(Node u, int k){
   if(u == NIL || k != u->key){
    return u;
   }
  if(k < u->key){
    return treeSearch(u->left, k);
   }
  else{
    return treeSearch(u->right, k);
   }
}

Node treeSuccessor(Node x){
	
  Node y;
  if (x->right != NIL) 
  return treeMinimum(x->right);
 
  y = x->parent;
 
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
 
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y  
  if (z->left == NIL || z->right == NIL) y = z;
  else {
  	y = treeSuccessor(z);
 }
 
  if (y->left != NIL) x = y->left;
  else {
  	x = y->right;
 }
  if (x != NIL) x->parent = y->parent;
 
  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
 
  if (y != z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
    while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if (u != NIL) {
  inorder(u -> left);
  printf(" %d",  u->key);
  inorder(u -> right);
  }
  }
void preorder(Node u){
  if (u != NIL) {
  printf(" %d", u->key);
  preorder(u -> left);
  preorder(u -> right);
  }
  }


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
# include<bits/stdc++.h>
using namespace std;
int main(){
	long int W, H, x, y;
  	cin >> W >> H >> x >> y;
  cout << setprecision(10)<< W*H*1.0/2 <<" ";
  ((W-x == x) && (H-y == y))? cout << 1 <<'\n' : cout << 0 <<'\n';

	return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

struct Combination{
	using ll = int_fast64_t;
	std::vector<ll> fac, finv, inv;
	const int MOD = 1000000007;

	Combination(int max=6e5): fac(max+1), finv(max+1), inv(max+1) {
		fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
		for(int i=2; i<=max; i++){
			fac[i] = fac[i-1] * i % MOD;
			inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
			finv[i] = finv[i-1] * inv[i] % MOD;
		}
	}

	ll P(int n, int r) const {
		if(r<0 or n<r) return 0;
		return fac[n] * finv[n-r];
	}

	ll C(int n, int r) const {
		if(n<0 or n<r) return 0;
		return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
	}

	ll H(int n, int r) const {
		if(n<0 or r<0) return 0;
		if(r==0) return 1;
		return C(n+r-1, r);
	}
};

int main(){
	int x, y;
	scanf("%d %d", &x, &y);
	if((x+y)%3 or x*2<y or x>y*2){
		puts("0");
		return 0;
	}
	Combination com(10000000);
	printf("%ld\n", com.C((x+y)/3, (2*x-y)/3));	
	return 0;
}

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

const int N = (2e3) + 5;
int n, a[N];

int main() { // claudio van
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  ll cnt = 0;
  for (int i = 0; i + 1 < n; ++i) {
    for (int j = i + 1; j + 1 < n; ++j) {
      int sum = a[i] + a[j];
      int dif = abs(a[i] - a[j]);
      int l = upper_bound(a + j + 1, a + n, dif) - (a + j + 1);
      int r = upper_bound(a + j + 1, a + n, sum - 1) - (a + j + 1);
      if (l > r) continue;
      cnt += r - l;
    }
  }
  printf("%lld\n", cnt);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> a(q),p(n,k);
    for(int i = 0; i < q; i++) cin >> a[i];
    for(int i = 0; i < n; i++) p[i]-=q;
    for(int i = 0; i < q; i++) p[a[i]-1]++;
    for(int i = 0; i < n; i++){
        if(p[i] <= 0) cout << "No" <<endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-12; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);

}

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

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0,  count = 0, sum = 0,near=1000,r;
    llint  x,y;
	int value_to_remove = 0;
	bool check = false;
	string ss, sss;
	vector<llint> array,counter;
	vector<bool> bo;
	char c;
	cin >> c;
	if (isupper(c))cout << "A" << endl;
	else cout << "a" << endl;
	
	please AC;
}


Measured memory_bytes: 3672
from collections import Counter
from math import gcd
import sys
input = sys.stdin.readline
n = int(input())
same, diff, zero_a, zero_b, zero_zero = 0, 0, 0, 0, 0
same_cnt = Counter()
diff_cnt = Counter()

for i in range(n):
    a, b = map(int, input().split())
    if a == b == 0:
        zero_zero += 1
    elif a == 0:
        zero_a += 1
    elif b == 0:
        zero_b += 1
    elif a * b > 0:
        x = gcd(a, b)
        a, b = a // x, b // x
        same += 1
        same_cnt[(abs(a), abs(b))] += 1
    else:
        x = gcd(a, b)
        a, b = a // x, b // x
        diff += 1
        diff_cnt[(abs(a), -abs(b))] += 1


ans = 1
mod = 10 ** 9 + 7

for (a, b) in diff_cnt.keys():
    s = same_cnt[(-b, a)]
    d = diff_cnt[(a, b)]
    if s > 0:
        same -= s
        diff -= d
        ans = ans * (pow(2, s, mod) + pow(2, d, mod) - 1) % mod

ans = ans * pow(2, same + diff, mod) % mod

ans = ans * (pow(2, zero_a, mod) + pow(2, zero_b, mod) - 1) - 1
print((ans + zero_zero) % mod)

Measured memory_bytes: 112336
N, D = gets.split(" ").map(&:to_i)
X = []
N.times do
  X << gets.split(" ").map(&:to_i)
end

def ok(ar1, ar2)
  sum = 0
  ar1.zip(ar2).each do |a, b|
    sum += (a - b) ** 2
  end
  s = Math.sqrt(sum).to_i
  return s * s == sum
end

cnt = 0
(0...N).each do |i|
  (i + 1...N).each do |j|
    cnt += 1 if ok(X[i], X[j])
  end
end

puts cnt


Measured memory_bytes: 1788
card=[[0]*3 for i in range(3)]
for i in range(3):
  A=list(map(int,input().split()))
  card[i][0]=A[0]
  card[i][1]=A[1]
  card[i][2]=A[2]
N=int(input())
b=list()
for i in range(N):
  b.append(int(input()))
Kekka=[[False]*3 for i in range(3)]
for i in range(N):
  for j in range(3):
    for k in range(3):
      if card[j][k]==b[i]:
        Kekka[j][k]=True
flag=False
for i in range(3):
  if Kekka[i][0]==True and Kekka[i][1]==True and Kekka[i][2]==True:
    flag=True
for i in range(3):
  if Kekka[0][i]==True and Kekka[1][i]==True and Kekka[2][i]==True:
    flag=True
if Kekka[0][0]==True and Kekka[1][1]==True and Kekka[2][2]==True:
    flag=True
if Kekka[0][2]==True and Kekka[1][1]==True and Kekka[2][0]==True:
    flag=True
print("Yes" if flag==True else "No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

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

#define M 1000010

int main(){
	IOS;
	
	ll a,b;cin>>a>>b;
	if(a>b)swap(a,b);
	if(a==1 and b==2)cout<<3;
	else if(a==2 and b==3)cout<<1;
	else if(a==1 and b==3)cout<<2;
	return 0;
}



Measured memory_bytes: 256
import numpy as np

class Calculator:
    def __init__(self, N, K):
        self.arr = np.array([N,K])
        self.max_num = int((self.arr[0] + self.arr[1] - 1) / self.arr[1])
        self.min_num = int(self.arr[0] / self.arr[1])

    def get_answer(self):
        return self.max_num - self.min_num

def main():
    N, K, = map(int, input().split())
    c = Calculator(N, K)
    ans = c.get_answer()
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 13324
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

const pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int n;
	cin >> n;
	set<int> s;
	rep(i, n){
		int tmp;
		cin >> tmp;
		s.insert(tmp);
	}

	cout << (n == int(s.size()) ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 9600
program yakiniku_optimization_problem
  implicit none
  real(8), parameter :: tol = 1e-7
  integer :: n, k, i, j
  real(8) :: l = 0.d0, r = 1e6, m, xc, yc, s, t, u, v, w, z, ri, rj
  real(8), dimension(60) :: x = 0.d0, y = 0.d0, c = 0.d0
  character(64) :: ans
  read(*,*) n, k
  do i = 1, n
    read(*,*) x(i), y(i), c(i)
    c(i) = 1.d0 / c(i)
  end do
  do while (r - l > tol)
    m = 0.5 * (l + r)
    do i = 1, n
      if (ok(x(i), y(i), i, 0)) then
        r = m
        goto 100
      end if
      ri = m * c(i)
      do j = i + 1, n
        rj = m * c(j)
        z = d(x(i), x(j), y(i), y(j))
        if (z > ri + rj .or. z < abs(rj - ri)) cycle
        s = 2 * (x(j) - x(i))
        t = 2 * (y(j) - y(i))
        u = x(i) * x(i) - x(j) * x(j) + y(i) * y(i) - y(j) * y(j) + rj * rj - ri * ri
        v = s * s + t * t
        w = abs(s * x(i) + t * y(i) + u)
        z = sqrt(v * ri * ri - w * w)
        xc = (s * w - t * z) / v + x(i)
        yc = (t * w + s * z) / v + y(i)
        if (ok(xc, yc, i, j)) then
          r = m
          goto 100
        end if
        xc = (s * w + t * z) / v + x(i)
        yc = (t * w - s * z) / v + y(i)
        if (ok(xc, yc, i, j)) then
          r = m
          goto 100
        end if
      end do
    end do
    l = m
  100 end do
  write(ans,'(f32.16)') r
  write(*,'(a)') trim(adjustl(ans))
contains
  real(8) function d(x1, x2, y1, y2) result(res)
    real(8), intent(in) :: x1, x2, y1, y2
    real(8) :: dx, dy
    dx = x2 - x1
    dy = y2 - y1
    res = sqrt(dx * dx + dy * dy)
  end
  logical function ok(xd, yd, i, j) result(res)
    real(8), intent(in) :: xd, yd
    integer, intent(in) :: i, j
    integer :: l, cnt
    cnt = 0
    do l = 1, n
      if (l == i) then
        cnt = cnt + 1
        cycle
      end if
      if (l == j) then
        cnt = cnt + 1
        cycle
      end if
      if (d(xd, x(l), yd, y(l)) <= m * c(l)) cnt = cnt + 1
    end do
    res = cnt >= k
  end
end program yakiniku_optimization_problem

Measured memory_bytes: 3080
#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define show(x) cout<<#x<<" "<<x<<" ";
#define f(i,j,k) for(int i = j;i<=k;i++)
#define fr(i,j,k) for(int i = j;i>=k;i--)
#define ll long long
#define all(A)  A.begin(),A.end()  
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);  
const int MSIZE = 1e2+5;
const int MOD = 1e9+7;

int wts[MSIZE];
int vals[MSIZE];

ll dp[MSIZE][(int)1e5+5];

int main(){
    FIO
    int N, W; cin>>N>>W;

    f(i,1,N)  cin>>wts[i]>>vals[i];
  
    //Bottom Up
    memset(dp,0,sizeof(dp));

    f(i,1,N)    f(j,1,W) {
        dp[i][j] = max((j>=wts[i])?(vals[i]+dp[i-1][j-wts[i]]):0,dp[i-1][j]);
    }

    cout<<dp[N][W]<<endl;

    return 0;

}
    


Measured memory_bytes: 82304
x=int(input())
a=1
while (a)**5-(a-1)**5<x:
  a+=1
#print(a)
import itertools
seq=[i for i in range((-1)*a,a+1)]
lis=list(itertools.permutations(seq, r=2))
now=0
b=0
while now==0:
  if (lis[b][0])**5-(lis[b][1])**5==x:
    print(lis[b][0],lis[b][1])
    now=1
  else:
    b+=1

Measured memory_bytes: 13112
#include <iostream>
#include <vector>
#include <cassert>
#include <stdio.h>

using namespace std;

int main() {

  int N;
  cin >> N;

  vector<long long> A(N+1);
  for(auto i=1; i<N+1; i++) cin>>A.at(i);

  // F[l, i], length l start at i
  vector <vector<long long> > F(  N+1 );

  F.at(1) = vector<long long>( N+1, 0);

  for(auto i = 1; i <=N; i++) {
    F.at(1).at(i) = A.at(i);
      // printf("%d %d %d\n", 1, i, F.at(1).at(i));
  }

  for (auto l=2; l <=N; l++) {

    F.at(l) = vector<long long>( N-l+2, 0 );

    for (auto i=1; i <= N - l + 1; i++) {
      auto j = i + l - 1;
      assert(j <=N);
      F.at(l).at(i) = max(
         - F.at(l-1).at(i+1) + A.at(i),
         - F.at(l-1).at(i) + A.at(j)
      );

      // printf("%d %d %d\n", l, i, F.at(l).at(i));
    }
  }
  cout << F.at(N).at(1) << endl;
  return 0;
}

Measured memory_bytes: 35584
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    long[] s;
    foreach(i; iota(n)) {
        s ~= readLong();
    }
    auto ans = s.sum();
    if(ans % 10 != 0) {
        writeln(ans);
        return;
    }
    s.sort();
    auto t = s.filter!(a => a % 10 != 0)().array();
    t.sort();
    if(t.empty()) {
        writeln(0);
        return;
    }
    writeln(ans - t[0]);
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


#define WALL '#'
#define PATH '.'

class coord{
    public:
    coord(){}
    coord(int _x,int _y):x(_x),y(_y){}
    int x,y;
};

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

    int h, w;
    cin >> h >> w;

    int ch, cw;
    cin >> ch >> cw;
    int dh, dw;
    cin >> dh >> dw;

    vector<vector<int>> m(h, vector<int>(w));
    rep(i,h){
        string si; cin >> si;
        rep(j,w){
            m[i][j] = si[j];
        }
    }
    vector<vector<int>> d(h, vector<int>(w));
    vector<vector<int>> mahou(h, vector<int>(w));
    rep(i,h){
        rep(j,w){
            d[i][j] = -1;
        }
    }
    rep(i,h){
        rep(j,w){
            mahou[i][j] = inf;
        }
    }
    auto s = coord(ch-1, cw-1);

    d[s.x][s.y]=0;
    mahou[s.x][s.y]=0;

    queue<coord> q2;
    queue<coord> q;
    q.push(s);
    while(q.size()){
        while(q.size()){
            coord u = q.front(); q.pop();
            rep(ix,3)rep(jx,3){
                if(abs(ix-1)+abs(jx-1)==2) continue;                    
                int i = ix-1 + u.x;
                int j = jx-1 + u.y;                 
                if(i>=0&&i<h&&j>=0&&j<w&&(d[i][j]==-1)&&m[i][j]==PATH){
                    d[i][j] = 1;
                    mahou[i][j] = mahou[u.x][u.y];
                    q.push(coord(i,j));
                }
            }
            q2.push(u);
        }
        while(q2.size()){
            coord u = q2.front(); q2.pop();
            rep(ix,5)rep(jx,5){
                int i = ix-2 + u.x;
                int j = jx-2 + u.y;                 
                if(i>=0&&i<h&&j>=0&&j<w&&(d[i][j]==-1 || mahou[i][j] > mahou[u.x][u.y]+1)&&m[i][j]==PATH){
                    d[i][j] = 1;
                    mahou[i][j] = mahou[u.x][u.y]+1;
                    q.push(coord(i,j));
                }
            }
        }
    }


    // wcout << "d\n";
    // rep(i, h) {
    //     rep(j, w) {
    //         wcout << d[i][j] << " ";
    //     }
    //     wcout << "\n";
    // }
    // wcout << "mahou\n";
    // rep(i, h) {
    //     rep(j, w) {
    //         wcout << mahou[i][j] << " ";
    //     }
    //     wcout << "\n";
    // }
    auto res = mahou[dh-1][dw-1];
    if (res == inf) {
        wcout << -1 << "\n";

    } else {
        wcout << res << "\n";
    }
}

Measured memory_bytes: 15548
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
long long n,a[1000001],sum,ans=1e18,sum2;
int main()
{
  cin>>n;
  for (int i=1;i<=n;++i)
    {
      cin>>a[i];
      sum+=a[i];
    }
  for (int i=1;i<=n;++i)
    {
      sum2+=a[i];
      ans=min(ans,(long long)(abs(sum2*2-sum)));
    }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    int count = 0;
    char b[h][w];
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> b[i][j];
            if (b[i][j] == '.')
                count++;
        }
    }
    int dh[4] = {-1, 1, 0, 0};
    int dw[4] = {0, 0, 1, -1};
    queue<pair<int, int>> q;
    q.push(make_pair(0, 0));
    vector<vector<bool>> visited(h, vector<bool>(w, 0));
    int ans[h][w];
    ans[0][0] = 1;
    ans[h - 1][w - 1] = -1;
    while (!q.empty())
    {
        pair<int, int> cr = q.front();
        q.pop();
        visited[cr.first][cr.second] = 1;
        if (cr.first == h - 1 && cr.second == w - 1)
            break;
        for (int i = 0; i < 4; i++)
        {
            int nh = cr.first + dh[i];
            int nw = cr.second + dw[i];
            if (nh > h - 1 || nh < 0 || nw > w - 1 || nw < 0 ||
                b[nh][nw] == '#' || visited[nh][nw] == 1)
                continue;
            else
            {
                q.push(make_pair(nh, nw));
              visited[nh][nw] = 1;
                ans[nh][nw] = ans[cr.first][cr.second] + 1;
            }
        }
    }
    if (ans[h - 1][w - 1] == -1)
        cout << -1 << endl;
    else
        cout << count - ans[h - 1][w - 1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
long long gcd(long long a,long long b)
{
	if (b==0) return a;
	return gcd(b,a%b);
}
int main()
{
	int cas;
	scanf("%d",&cas);
	while (cas--)
	{
		long long a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if (a<b || d<b) { puts("No");continue; }
		if (c>=b) { puts("Yes"); continue; }
		long long x=gcd(b,d);a%=x;
		if (a-c+(b-a-1)/x*x>=1) puts("No");
		else puts("Yes");
	}
	return 0;
}


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


int main(){

int k;
cin>>k;

string s;
cin>>s;

int a = s.length();

if(a <= k) cout<<s<<endl;

else{
    for(int i = 0 ; i < k ; i++){
        cout<<s[i];
    }
    cout<<"..."<<endl;
}


}


Measured memory_bytes: 3624
"""
https://abc057.contest.atcoder.jp/tasks/abc057_b
"""
[n,m]=[int(i) for i in input().split()]
ab=[]
cd=[]
k=[]
box=[]
l=0
for i in range(n):
    ab.append([int(j) for j in input().split()])
for i in range(m):
    cd.append([int(j) for j in input().split()])

for i in range(n):
    for j in range(m):
        k.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
    #kには全てのjについてのマンハッタン距離が入る
    box.append(k)
    k=[]


for i in range(n):
    for j in box[i]:
        if j == min(box[i]):
            l=l+1
            print(l)
            break
        l=l+1
    l=0



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

int n;
int x[200001],y[200001];
int main(){
	cin>>n;
	FOR(i,0,n){
		cin>>x[i]>>y[i];
		if(x[i]<y[i]) swap(x[i],y[i]);
	}
	ll ans=0;
	int rmax=0,bmax=0,rmin=INF,bmin=INF;
	FOR(i,0,n){
		rmax=max(rmax,x[i]);
		rmin=min(rmin,x[i]);
		bmax=max(bmax,y[i]);
		bmin=min(bmin,y[i]);
	}
	ans=(ll)(rmax-rmin)*(bmax-bmin);
	vector<pint> v;
	FOR(i,0,n){
		v.push_back(pint(x[i],i));
		v.push_back(pint(y[i],i));
	}
	sort(all(v));
	int st=1,en;
	int used[200001]={},unum=0;
	FOR(i,1,2*n-1){
		pint p=v[i];
		if(used[p.second]==0){
			unum++;
		}
		used[p.second]++;
		en=i;
		if(unum==n) break;
	}
	int ans2=INF;
	while(en<2*n-1){
		ans2=min(ans2,v[en].first-v[st].first);
		if(used[v[st].second]>1){
			used[v[st].second]--;
			st++;
		}else{
			en++;
			used[v[en].second]++;
		}
	}
	ll ans2l=(ll)ans2*(rmax-bmin);
	co(min(ans,ans2l));
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    int n ;
    cin >> n ;

    vi v ( n + 10 ) ;
    for ( int i=1 ; i <= n ; i ++ )
        cin >> v[i] ;

    vi dp ( n + 10 ) ;

    dp[1] = 0 ;
    dp[2] = abs ( abs ( v[2] - v[1] ) ) ;

    for ( int i = 3 ; i <= n ; i ++ )
        dp[i] = min ( dp[i - 1] + abs ( v[i] - v[i - 1] ) , dp[i - 2] + abs ( v[i] - v[i - 2] ) ) ;

    cout << dp[n] ; line ;

}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())

X_l = list(map(int, input().split()))

min_ans = 100000000

for p in range(101):
    ans_cand = 0
    for i in range(N):
        ans_cand += (p-X_l[i])**2
    if ans_cand < min_ans:
        min_ans = ans_cand

print(min_ans)


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

namespace ConsoleApp3
{
    internal class Class2
    {
        private static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
            var n = nm[0];
            var m = nm[1];

            var lookup = Hoge(m).Distinct().ToLookup(x => x.Item1, x => x.Item2);
            var list = new HashSet<HashSet<long>>();
            var list2 = new HashSet<long>();

            foreach (var tomo in lookup.Select(x => x.Key))
            {
                if (list2.Contains(tomo))
                {
                    continue;
                }

                var newSet = new HashSet<long>();
                list.Add(newSet);

                Ho(list2, list, lookup, newSet, tomo);
            }

            try
            {
                Console.WriteLine(list.Select(x => x.LongCount()).DefaultIfEmpty(1).Max());
            }
            catch
            {
                Console.WriteLine("?");
            }
        }

        private static void Ho(HashSet<long> list2, HashSet<HashSet<long>> list, ILookup<long, long> lookup, HashSet<long> currentHashSet, long tomo)
        {
            if (list2.Contains(tomo))
            {
                return;
            }

            currentHashSet.Add(tomo);
            list2.Add(tomo);

            foreach (var nextTomo in lookup[tomo].Where(x => !list2.Contains(x)))
            {
                Ho(list2, list, lookup, currentHashSet, nextTomo);
            }
        }

        private static IReadOnlyList<(long, long)> Hoge(int m)
        {
            return Enumerable.Range(0, m)
                .SelectMany(_ =>
                {
                    var ab = Console.ReadLine().Split(" ").Select(long.Parse).ToArray();
                    var a = ab[0];
                    var b = ab[1];

                    return new List<(long, long)> { (a, b), (b, a), };
                })
                .ToArray();
        }
    }
}

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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
  #define DFUNC(fname, ...) fname(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFUNC(fname, ...)
#endif

ll N,K;
string S;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N >> K >> S;
  S.at(K-1) = tolower(S.at(K-1));
  cout << S << endl;
    

  return 0;
}



Measured memory_bytes: 256