akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i++)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  cin >> n;
  bool ok = true;
  int nowx = 0,nowy = 0,nowt = 0,t,x,y;
  
  rep(i,0,n){
    cin >> t >> x >> y;
    if( (t-nowt)%2 != (abs(x-nowx)+abs(y-nowy))%2 ) ok = false;
    if( (t-nowt) < (abs(x-nowx)+abs(y-nowy)) ) ok = false;
    nowt = t;
    nowx = x;
    nowy = y;
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import Control.Applicative
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn "100 100"
    mapM_ putStrLn $ solve (a-1) (b-1)

solve :: Int -> Int -> [String]
solve a b = drawA a ++ drawB b

drawA :: Int -> [String]
drawA a = reverse $ foldl addA2lines [] [a,a-50..a-1200]

drawB :: Int -> [String]
drawB b = foldl addB2lines [] [b,b-50..b-1200]

addA2lines :: [String] -> Int -> [String]
addA2lines list n = (replicate 100 '#'):(drawline n):list

addB2lines :: [String] -> Int -> [String]
addB2lines list n = (replicate 100 '.'):(map (\x -> if x == '.' then '#' else '.') (drawline n)):list

drawline :: Int -> String
drawline n = map (f n) [1..100]
    where f n x | (div x 2) < n && (mod x 2) == 1 = '.'
                | otherwise = '#'


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

struct E {
    ll n1, n2, cost;
};

vector<E> edges;
vector<ll> nodes;

class UnionFind{
    public:
        ll size;
        vector<ll> rank;
        vector<ll> parent;
        vector<ll> cnt;
        vector<ll> weights;

        UnionFind(ll N){
            this->size = N;
            rank = vector<ll>(N, 0);
            parent = vector<ll>(N);
            cnt = vector<ll>(N, 0);
            weights = nodes;
            iota(parent.begin(), parent.end(), 0ll);
        }

        ~UnionFind(){
        }

        ll find(ll child){
            return (child == parent[child] ? child : parent[child] = find(parent[child]));
        }

        ll unit(ll x, ll y, ll w){
            ll ret = 0;
            x = find(x); 
            y = find(y);
            if(x == y){
                if(weights[x] >= w) ret++;
                else cnt[x]++;
                return ret;
            }
            if(rank[x] < rank[y]) swap(x, y);
            parent[y] = x;
            rank[x] += (rank[x] == rank[y]);
            weights[x] += weights[y];
            if(weights[x] >= w){
                ret = cnt[x] + cnt[y] + 1;
                cnt[x] = cnt[y] = 0;
            }else{
                cnt[x] = cnt[x] + cnt[y] + 1;
            }
            return ret;
        }

        bool same(ll x, ll y){
            return (find(x) == find(y));
        }

};

int main(){
    ll N, M;
    cin >> N >> M;
    nodes = decltype(nodes)(N);
    edges = decltype(edges)(M);
    for(ll &e : nodes) cin >> e;
    for(auto &e : edges){
        cin >> e.n1 >> e.n2 >> e.cost;
        e.n1--;
        e.n2--;
    }
    sort(edges.begin(), edges.end(), [](const auto &a, const auto &b){ return a.cost < b.cost; });
    UnionFind UF(N);
    ll ans = 0;
    for(const auto &e : edges) ans += UF.unit(e.n1, e.n2, e.cost);
    ans = M - ans;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let n=tn(),t=tnn(n),m=tn()
  for(let i=0;i<m;i++){
    let tt=[...t],a=0
    tt[tn()-1]=tn()
    for(let i=0;i<n;i++){
      a+=tt[i]
    }
    to(a)
  }
}
main()

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

void quickSort(int* a, int left, int right){
  if(left>=right) return;
  int p = a[(left+right)/2];
  int l = left, r = right, tmp;
  while(l<=r){
    while(a[l] > p) { l++; }
    while(a[r] < p) { r--; }
    if(l<=r){
      tmp = a[l]; a[l] = a[r]; a[r] = tmp;
      l++; r--;
    }
  }
  quickSort(a, l, right);
  quickSort(a, left, r);
}

int main(){
  int N;
  int a[110] = {};
  cin >> N;
  for(int i = 0; i < N; ++i) cin >> a[i];
  
  int alice = 0;
  int bob = 0;
  
  quickSort(a,0,110-1);
  for(int i = 0; i < N; ++i){
    if(i%2 == 0) alice += a[i];
    else bob += a[i];
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
 
int a,b,c;
cin>>a>>b>>c;
int a1=a+b+c;
int a2=a+b+c-max({a,b,c});
cout<<a2;
return 0;
}

Measured memory_bytes: 3584
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
long long GCD(long long a,long long b){
    if(b==0)return a;
    return GCD(b,a%b);
}
long long LCM(long long a,long long b){
    return a*b/GCD(a,b);
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin>>n>>k;
    V vec(n+1);
    rep3(i,1,n+1)cin>>vec[i];
    V dp(n+10,1e18);
    dp[1]=0;
    rep3(i,2,n+1){
        rep3(j,max(i-k,0LL),i){
            chmin(dp[i],dp[j]+abs(vec[j]-vec[i]));
        }
    }
    cout<<dp[n]<<endl;
}


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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

ll ten(ll x){
    ll res = 0;
    while(x != 0){
        if(x % 5 == 0){
            res++;
        }else{
            break;
        }
        x /= 5;
    }
    return res;
}

int main(){
    ll N;
    ll ans = 0;
    cin >> N;
    ll A = N;
    ll B = N-1;
    if(N % 2 == 1)cout << 0;
    else{
        A /= 2;
        while(A != 0){
            A /= 5;
            ans += A;
        }
        cout << ans;
    }
    //cin >> N;
}

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

void prime_factorization(set<int>& result, int x)
{
  for (int i = 1; i*i <= x; i++) {
    if (x % i == 0) {
      result.insert(i);
      result.insert(x/i);
    }
  }
}

bool verify(const vector<int>& a, int k, int block_size, int block_num)
{
  priority_queue<int> pq;
  for (int x : a) {
    pq.push(x);
  }
  while (0 < block_num) {
    int x = pq.top();
    pq.pop();
    int block_use = min(block_num, max(1, x / block_size));
    pq.push(x - block_size * block_use);
    block_num -= block_use;
  }
  int diff = 0;
  while (!pq.empty()) {
    int x = pq.top();
    pq.pop();
    if (0 < x) {
      diff += x;
    }
  }
  return diff <= k;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int sum = accumulate(a.begin(), a.end(), 0);
  set<int> s;
  prime_factorization(s, sum);
  int result = 0;
  for (int block_num : s) {
    int block_size = sum / block_num;
    if (verify(a, k, block_size, block_num)) {
      result = block_size;
      break;
    }
  }
  cout << result << '\n';
  return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
total = 0
for i in range(1, N + 1, 1):
    i_sum = 0
    for j in range(len(str(i))):
        i_sum += int(str(i)[j])
    # print("i_sum", i_sum)
    if A <= i_sum and i_sum <= B:
        total += i

print(total)

Measured memory_bytes: 3060
# import sys
# input = sys.stdin.readline

def frog_2():
    N, K = map(int,input().split())
    H = tuple(map(int,input().split()))

    dp = [float("inf")] * N
    dp[0] = 0

    for n in range(1, N):
        k = max(0, n - K) # k: 'n' ループ目の最大ジャンプ幅 'K' 
        h = H[n]          # h: 'n' ループ目の足場の高さ'H'
        dp[n] = min(abs(h - H[i]) + dp[i] for i in range(k, n))
        
    print(dp[-1])

frog_2()

Measured memory_bytes: 14184
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>

using namespace std;

int main()
{
    int n, i, j;
    cin >> n;

    vector<int> A(n, 0);

    for (i = 0; i < n; i++)
    {
        cin >> A[i];
    }

    stack<int> S;
    while (1)
    {
        int rem = -1;
        if (A.empty())
            break;
        for (int i = A.size() - 1; i >= 0; i--)
        {
            if (A[i] == i + 1)
            {
                rem = i;
                break;
            }
        }
        if (rem == -1)
        {
            cout << rem << endl;
            exit(0);
        }
        S.push(A[rem]);
        vector<int> B = {};
        for (int i = 0; i < A.size(); i++)
        {
            if (i != rem)
                B.push_back(A[i]);
        }

        A = B;
    }

    while (!S.empty())
        cout << S.top() << endl, S.pop();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    ll N;
    cin >> N;
    vector<string> words(N);
    RANGE(i,N) cin >> words[i];
    ll count = 0;
    ll count_typeA=0;
    ll count_typeB=0;
    ll count_typeC=0;
    for(string word:words){
        RANGE(i, word.size() - 1){
            if(word[i] == 'A' && word[i+1] == 'B') count++;
        }
        if(word.front() == 'B' && word.back() == 'A') count_typeA++;
        else if(word.front() == 'B') count_typeB++;
        else if(word.back() == 'A') count_typeC++;
    }
    if(count_typeA > 0){
        count += count_typeA -1;
        if(count_typeB > 0 || count_typeC > 0){
            count ++;
        }
    }
    count += min(count_typeB, count_typeC);
    cout << count << endl;
}


Measured memory_bytes: 768
using System;
using System.Linq;
using System.Collections.Generic;
namespace ABC151
{
    class D
    {
        static int X;
        static int Y;
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Y = input[0];
            X = input[1];

            char[,] map = new char[X, Y];
            for (int y = 0; y < Y; y++)
            {
                var s = Console.ReadLine();
                for (int x = 0; x < X; x++)
                {
                    map[x, y] = s[x];
                }
            }

            // tupleで組み合わせを作成
            int res = 0;
            List<Tuple<int, int, int, int>> t = new List<Tuple<int, int, int, int>>();
            for (int sy = 0; sy < Y; sy++)
            {
                for (int sx = 0; sx < X; sx++)
                {
                    if (map[sx, sy] == '#') continue;

                    res = Math.Max(BFS(sx, sy, map), res);

                }
            }
            Console.WriteLine(res);
        }

        static int BFS(int sx, int sy, char[,] map)
        {
            int[,] dist = new int[X, Y];
            for (int y = 0; y < Y; y++)
            {
                for (int x = 0; x < X; x++)
                {
                    dist[x, y] = -1;
                }
            }

            Queue<Tuple<int, int, int>> tq = new Queue<Tuple<int, int, int>>();
            tq.Enqueue(Tuple.Create(sx, sy, 0));
            int step = 0;
            //map[sx, sy] = '#';
            dist[sx, sy] = 0;

            int[] vx = { 0, 1, 0, -1 };
            int[] vy = { 1, 0, -1, 0 };
            while (0 < tq.Count)
            {
                var q = tq.Dequeue();
                int x = q.Item1;
                int y = q.Item2;
                step = q.Item3;

                for (int i = 0; i < 4; i++)
                {
                    int nx = x + vx[i];
                    int ny = y + vy[i];

                    if ((0 <= nx && nx < X) && (0 <= ny && ny < Y) && map[nx, ny] == '.' && dist[nx, ny] == -1)
                    {
                        //map[nx, ny] = '#';
                        dist[nx, ny] = dist[x, y] + 1;
                        tq.Enqueue(Tuple.Create(nx, ny, step + 1));
                    }
                }
            }
            return step;
        }
    }
}

Measured memory_bytes: 17616
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
     map<ll ,ll> cnt;
     ll sum=0;
    rep(i,n){
      cin >> a.at(i);
      cnt[i+1]=0;
    }
    rep(i,n){
      cnt[a.at(i)]++;
    }
    ll m;
    rep(i,n){
      m=cnt[i+1];
      if(m>=2){
      sum+=m*(m-1)/2;
      }
    }
    ll ans;
    rep(i,n){
      m=cnt[a.at(i)];
      if(m>=2)ans=sum-(m-1);
      else ans=sum;
      cout << ans << endl;
    }
}

Measured memory_bytes: 17200
#include<bits/stdc++.h>
using namespace std;
int main(){

	cout << fixed << setprecision(6);

	double r;
	cin>>r;
	cout<<(double)r * r * 3.141592653589<<" ";
	cout<<(double)( r + r ) * 3.141592653589<<endl;

	return 0;
}


Measured memory_bytes: 3260
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n;
    cin>>n;

    double sum = 0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        sum += (double)1/x;
    }

    cout<<setprecision(10)<<fixed<<(double)1/sum;
} 

Measured memory_bytes: 256
n = int(input())
l = []
d = {}
for i in range(n):
    s, p = input().split()
    p = int(p)
    if s in d:
        d[s].append([p, i])
    else:
        d[s] = [[p, i]]
l = sorted(d.keys())
for i in l:
    d[i] = sorted(d[i])
    while len(d[i]) != 0:
        print(d[i].pop()[1] + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(x,l,r) for(int x=l,x##_=r;x<=x##_;x++)
#define FR(x,l,r) for(int x=l,x##_=r;x<x##_;x++)
#define DOR(x,r,l) for(int x=r,x##_=l;x>=x##_;x--)
using namespace std;
const int N=200005;
const LL P=1e9+7;
LL dp[N];
int n,A[N],tot,R[N],L[N],top[N];
LL dfs(int x){
//	printf("%d\n",x);
	if(x==tot)return 1;
	if(dp[x])return dp[x];
	LL cnt=dfs(x+1);
	int to=R[x];
//	while(to){
//	printf("R:%d %d\n",to,tot);
	if(to)(cnt+=dfs(to))%=P;
//		to=R[to];
//	}
	return dp[x]=cnt;
}
void Add(int x,int id){
	if(top[x])R[top[x]]=id,L[id]=top[x];
	top[x]=id;
}
int main(){
	scanf("%d",&n);
	FOR(i,1,n){
		int x;
		scanf("%d",&x);
		if(x!=A[tot]){
			A[++tot]=x;
			Add(x,tot);
		}
	}
	dp[tot]=1;
	printf("%lld\n",dfs(1));
//	FOR(i,1,n)printf("%lld ",dp[i]);puts("");
	return 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num = s.nextInt();
		for(int i=0 ; i<num ; i++){
			double [] a = new double[6];
			for(int j=0 ; j<6 ; j++)
				a[j] = s.nextDouble();
			double d = Math.sqrt((a[3]-a[0])*(a[3]-a[0])+(a[4]-a[1])*(a[4]-a[1]));
			if(d<=a[2]+a[5]&&Math.abs(a[2]-a[5])<=d){
				System.out.println(1);
				continue;
			}
			if(d<Math.abs(a[2]-a[5])){
				if(a[2]>a[5])
					System.out.println(2);
				else
					System.out.println(-2);
				continue;
			}
			System.out.println(0);
		}
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

signed main(){
  int n,a,b;
  cin>>a>>b;
  if((a+b)%2)cout<<"IMPOSSIBLE"<<endl;
  else cout<<(a+b)/2<<endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,a[20];
ll dp(int l,int r,ll xl,ll xr)
{
	if(l+1==r) return 0;
	ll ans=1e18;
	for(int i=l+1;i<r;i++)
		ans=min(ans,dp(l,i,xl,xl+xr)+dp(i,r,xl+xr,xr)+(xl+xr)*a[i]);
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	printf("%lld",dp(1,n,1,1)+a[1]+a[n]);
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <deque>

using namespace std;

using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;

const i32 lr[] = {0, 0, -1, 1};
const i32 td[] = {-1, 1, 0, 0};
constexpr auto MIN = -1;
i32 H, W;
char S[20][20];
i32 ans;

void bfs(i32 x, i32 y) {
  vector<vector<i32>> d(H, vector<i32>(W, MIN));
  deque<pair<i32, i32>> queue;
  d[y][x] = 0;
  queue.emplace_back(x, y);
  while(!queue.empty()) {
    auto xy = *queue.begin();
    queue.pop_front();
    for(i32 i= 0; i < 4; ++i) {
      auto nx = xy.first + lr[i];
      auto ny = xy.second + td[i];
      if(S[ny][nx] == '#') continue;
      if(ny < 0 || nx < 0 ||
         ny >= H || nx >= W) continue;
      if(S[ny][nx] == '.' && d[ny][nx] == MIN) {
        d[ny][nx] = d[xy.second][xy.first] + 1;
        queue.emplace_back(nx, ny);
        ans = max(ans, d[ny][nx]);
      }
    }
  }
}


int main(int argc, char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  cin >> H >> W;
  
  for(i32 y = 0; y < H; ++y) {
    for(i32 x = 0; x < W; ++x) {
      cin >> S[y][x];
    }
  }
  
  ans = 0;
  //fill(d[0], d[H], MIN);
  for(i32 j = 0; j < H; ++j) {
    for(i32 i = 0; i < W; ++i) {
      if(S[j][i]=='.') bfs(i, j);
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
//using namespace std;
//scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
//printf("Yes\n");
int main() {
  int a,b,c,N=1,X=0;
  scanf("%d%d%d",&a,&b,&c);
  
  while(N <= c){
    
    if(c%N == 0 && a <= N && N <= b){
      N=N+1;
      X=X+1;
    }else{
      N=N+1;
    }
  }  
 
 printf("%d\n",X);
}


Measured memory_bytes: 2716
import sys
sys.setrecursionlimit(1000000)

N,M,Q = [int(x) for x in input().split()]
lr = [[int(x) for x in input().split()]for _ in range(M)]
pq = [[int(x) for x in input().split()]for _ in range(Q)]

dp = [[0 for _ in range(N+1)]for _ in range(N+1)]

for i in lr:
    dp[i[0]][i[1]]+=1

for j in range(N+1):
    for i in range(N-1,0,-1):
        dp[i][j] += dp[i+1][j]

for i in range(N,0,-1):
    for j in range(i,N+1):
        if(j!=i):
            dp[i][j] += dp[i][j-1]

for i in pq:
    print(dp[i[0]][i[1]])

Measured memory_bytes: 54524
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end

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

    ll n;
    in >> n;
    vector<ll> a(n);
    REP(i, n) in >> a[i];
    SORT(a);
    ll pre_a = 0, count_a = 0, ans = 0;
    REP(i, n){
        if (pre_a == a[i]){
            count_a += 1;
        }else{
            if (count_a % 2 == 1) ans += 1;
            count_a = 1;
        }
        pre_a = a[i];
        if (i == n-1){
            if (count_a % 2 == 1) ans += 1;
            count_a = 1;
        }
    }
    out << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

#define for1(n) for (int i = 0 ; i < n ; i++)
#define for2(n) for (int j = 0 ; j < n ; j++)
#define for3(n) for (int k = 0 ; k < n ; k++)
#define for4(n) for (int l = 0 ; l < n ; l++)
#define forl(n) for (ll i = 0 ; i < n ; i++)

int main() {
    ios::sync_with_stdio(false);
 	int n;
 	cin >> n;
 	if (n % 2 == 0) cout << n;
 	else cout << n * 2;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n;
    const int m = pow(10, 9) + 7;
    long long ans = 1;
    cin >> n;
    for(int i = 1; i <= n; i++){
        ans = (ans * i) % m;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    x,y,z=map(int,input().split())
    if x==-1 and y==-1 and z==-1:
        break
    if x==-1 or y==-1:
        print('F')
    elif x+y>=80:
        print('A')
    elif 65<=x+y<80:
        print('B')
    elif 50<=x+y<65:
        print('C')
    elif 30<=x+y<50:
        if z>=50:
            print('C')
        else:
            print('D')
    elif x+y<30:
        print('F')


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

typedef long long ll;

int N;
string S[(int)1e5];

int main() {
    cin >> N;
    rep(i, N) cin >> S[i];

    // 10通り 5C3
    string target[] = {"MAR", "MAC", "MAH", "MRC", "MRH", "MCH", "ARC", "ARH", "ACH", "RCH"};

    map<char, int> mp;
    rep(i, N) {
        mp[S[i][0]]++;
    }

    // for (auto iter = mp.begin(); iter != mp.end(); iter++) {
    //     cout << iter->first << endl;
    //     cout << iter->second << endl;
    // }
    // return 0;

    ll ans = 0;
    for (int i = 0; i < 10; i++) {
        string comb = target[i];
        // 1つめ
        ll tmp = mp[comb[0]];
        // printf("str: %s 1: %lld 2: %lld 3: %lld\n", comb.c_str(), mp[comb[0]], mp[comb[1]], mp[comb[2]]);
        for (int j = 1; j < comb.size(); j++) {
            tmp *= mp[comb[j]];
        }
        ans += tmp;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
  int n, k;
  cin>>n>>k;
  vector<int> Ventrada, Vcusto;
  for(int i=0;i<n;i++){
    int j;
    cin>>j;
    Ventrada.push_back(j);
  }
  Vcusto.push_back(0);
  int menor;
  for(int i=1;i<n;i++){
    menor = Vcusto[i-1]+abs(Ventrada[i]-Ventrada[i-1]);
    for(int j=i-k;j<i;j++){
      if(j>=0 && Vcusto[j]+abs(Ventrada[i]-Ventrada[j])<menor){
        menor=abs(Ventrada[i]-Ventrada[j]) + Vcusto[j];
      }
    }
    Vcusto.push_back(menor);
  }
  
  cout<<Vcusto[Vcusto.size()-1]<<endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a;
    cin>>a;
    if(a/1>=1&&a/1<=9)
        cout<<"Yes"<<endl;
    else if(a/2>=1&&a/2<=9&&a%2==0)
        cout<<"Yes"<<endl;
    else if(a/3>=1&&a/3<=9&&a%3==0)
        cout<<"Yes"<<endl;
    else if(a/4>=1&&a/4<=9&&a%4==0)
        cout<<"Yes"<<endl;
    else if(a/5>=1&&a/5<=9&&a%5==0)
        cout<<"Yes"<<endl;
    else if(a/6>=1&&a/6<=9&&a%6==0)
        cout<<"Yes"<<endl;
    else if(a/7>=1&&a/7<=9&&a%7==0)
        cout<<"Yes"<<endl;
    else if(a/8>=1&&a/8<=9&&a%8==0)
        cout<<"Yes"<<endl;
    else if(a/9>=1&&a/9<=9&&a%9==0)
        cout<<"Yes"<<endl;

    else
        cout<<"No"<<endl;
    return 0;
}

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

int main(){
	double v,h;
	while(scanf("%lf",&v)!=EOF){
		int n=1;
		h=v*v/19.6;
		while(1){
			if(5*n-5>h) break;
			n++;
		}
		cout<<n<<endl;
	}
}

Measured memory_bytes: 1232
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    lint N;
    cin >> N;
    lint base=1;
    int res=0;
    while(base-1<=N) base*=2,res++;
    base/=2,res--;
    vector<int> right;
    rep(i,res) right.push_back(i+1);
    lint rem=N-(base-1);
    int cnt=0;
    reprev(i,50){
        if(rem&(1LL<<i)){
            res++;
            right.insert(right.begin()+i,res);
        }
    }
    cout << res*2 << endl;
    rep(i,res) cout << i+1 << " ";
    rep(i,res) cout << right[i] << " ";
    cout << endl;
}

Measured memory_bytes: 3572
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
    val (_ , k) = readIs()
    val pp = readIs().sorted()
    println((0 until k).map(pp::get).sum())
}


Measured memory_bytes: 40952
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  int ans=100000000;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    int temp_ans=0;
    while(temp_ans<=ans){
      if(A.at(i)%2==0){
	A.at(i)=A.at(i)/2;
	temp_ans++;
      }
      else{
	ans=min(ans,temp_ans);
	break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    using pci = pair<char, int>;
    vector<pci> a;
    int cnt = 1;
    char b = s[0];
    for(int i = 1; i < s.size(); ++i){
        if(b != s[i]) {
            a.push_back({b, cnt});
            b = s[i];
            cnt = 1;
        }
        else ++cnt;
    }
    a.push_back({b, cnt});
    int ans = 0;
    bool flg = false;
    for(auto && p : a){
        if(flg) --p.second;
        flg = false;
        if(p.second % 3 == 0) ans += p.second / 3 * 2;
        else if(p.second % 3 == 1) ans += p.second / 3 * 2 + 1;
        else {
            ans += p.second / 3 * 2 + 2;
            flg = true;
        }
    }
    if(flg) --ans;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, T;
  cin >> N >> T;
  vector<ll> A(N);
  for (auto &it : A)
    cin >> it;
  ll MIN = INF;
  ll diff = 0;
  ll cnt = 1;
  for (int i = 0; i < N; i++)
  {
    ll tmp = A[i] - MIN;
    if (tmp > diff)
    {
      diff = max(diff, tmp);
      cnt = 1;
    }
    else if (tmp == diff)
      cnt++;
    MIN = min(MIN, A[i]);
  }
  cout << cnt << endl;
  return 0;
}

// 尺取りじゃなくてシンプルに最小値を管理すればいい


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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




int main() {
    string s;
    cin >> s;
    
    ll dp[100005][4] = {};
    for(ll i = s.size(); i >= 0; i--){
        for(ll j = 3; j >= 0; j--){
            if(i != s.size()){
                if(j < 3){
                    dp[i][j] = ((s[i] == '?')? 3 : 1) * dp[i + 1][j] + (s[i] == '?' || s[i] == "ABC"[j]) * dp[i + 1][j + 1];
                }
                else{
                    dp[i][j] = ((s[i] == '?')? 3 : 1) * dp[i + 1][j];
                }
            }
            else{
                dp[i][j] = (j == 3);
            }
            dp[i][j] %= MOD;
        }
    }
    cout << dp[0][0] << endl;
}

Measured memory_bytes: 3584
// 2745_CurryMaking.cpp
//
#include <bits/stdc++.h>
using namespace std;
int r0, w0, c, r, nr;
int main() {
  while(cin >> r0 >> w0 >> c >> r && r0 && w0 && c && r) {
    for(int i = 0;; ++i) {
      nr = r0 + i*r;
      if(nr / w0 >= c) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2976
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
    char c,a[4]={0},b[4]={0};
    cin >> a >> b;

    c = b[0];
    b[0] = b[2];
    b[2] = c;
    
    if(strcmp(a,b)==0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//indexの偶奇が同じ要素を1つ以上取り出すとき、取り出す要素の和を最大化
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[1000];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	int maxId = 0;
	rep(i, n) if (a[maxId] < a[i]) maxId = i;
	if (a[maxId] < 0) {
		cout << a[maxId] << endl;
		cout << n - 1 << endl;
		for (i = n - 1; i > maxId; i--) cout << i + 1 << endl;
		for (i = 0; i < maxId; i++) cout << 1 << endl;
		return 0;
	}
	
	vector<int> pos[2];
	int sum[2] = {0};
	rep(i, n) {
		if (a[i] >= 0) {
			sum[i % 2] += a[i];
			pos[i % 2].push_back(i);
		}
	}
	vector<int> ids;
	if (sum[0] > sum[1]) ids = pos[0];
	else ids = pos[1];
	
	vector<int> ans;
	for (i = n - 1; i > *ids.rbegin(); i--) ans.push_back(i);
	for (i = 0; i < ids[0]; i++) ans.push_back(0);
	for (i = 0; i + 1 < ids.size(); i++) {
		int m = (ids[i + 1] - ids[i]) / 2;
		for (j = m; j > 0; j--) {
			ans.push_back(j);
		}
	}
	
	cout << max(sum[0], sum[1]) << endl;
	cout << ans.size() << endl;
	rep(i, ans.size()) cout << ans[i] + 1 << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int a, b, x, y;
    //cin >> a >> b >> x >> y;
    scanf("%d%d%d%d",&a,&b,&x,&y);
    int ans = 0;
    if(2 * x == a && 2 * y == b) ans = 1;
    //int ans = (x+x==a && y+y==b);
    cout << fixed << setprecision(9) << (double(a)*double(b))/2 << " " << ans << endl;
    //printf("%lf %d\n", double(a) * double(b) / 2, x+x==a && y+y==b);
}


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;

ll K, N;
vl A, F;

int condition(ll score){
    //debug(score)
    ll sum = 0;
    rep(i, N){
        if(F[i] * A[N-i-1] <= score)continue;
        ll k = (F[i]*A[N-i-1] - score + F[i] - 1)/ F[i];
        //debug(k)
        //debug(F[i]*(A[N-1-1] - k))
        sum+=k;
    }
    if(sum <= K)return 1;
    return 0;
}

ll lowerbound() {
    ll low = -1;/////
    ll high = A[N-1]*F[N-1];//////array.size /// not N-1
    
    while (abs(high - low) > 1){
        ll mid = (high + low)/ 2;
        if(condition(mid)){///////////
            high = mid;
        }
        else{
            low = mid;
        }
    }
    
    return high;
    
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    
   
    cin >> N >> K;
    A = vl(N);
    F = vl(N);
    rep(i, N){
        cin >> A[i];
    }
    rep(i, N)cin >> F[i];

    sort(all(A));
    sort(all(F));
    
    ll ans = lowerbound();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int ans = Integer.MAX_VALUE;
        for(int i=0;i<N;i++){
            int c = sc.nextInt();
            int t = sc.nextInt();
            if(t<=T) ans = Math.min(ans,c);
        }
        if(ans == Integer.MAX_VALUE){
            System.out.println("TLE");
        }
        else System.out.println(ans);
    }
}


Measured memory_bytes: 23124
N, M = [int(v) for v in input().split(' ')]

a_array = []
b_array = []
c_array = []


for i in range(M):
    a, b = [int(v) for v in input().split(' ')]
    bit = 0
    for c in input().split(' '):
        bit |= 1 << (int(c) - 1)

    a_array.append(a)
    b_array.append(b)
    c_array.append(bit)

key = 0
for c in range(N):
    key |= (1 << c)

dp = [-1 for i in range(key+1)]
dp[0] = 0

for item in range(0, M):
    now = c_array[item]

    for bits in range(0, 1 << N):
        cost1 = dp[bits]
        if cost1 < 0:
            continue

        cost1 += a_array[item]
        cost = dp[bits | now]
        if cost < 0 or cost > cost1:
            dp[bits | now] = cost1
    
print(dp[key])

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <set>
using namespace std;

#define MP make_pair

bool flag[53][53][4];

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

int main(){
	int n,x0,y0,t;
	cin >> n >> x0 >> y0 >> t;
	x0++;
	y0++;
	for(int k=0;k<n;k++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a++;b++;c++;d++;
		if(a==c){
			if(b>d)swap(b,d);
			for(int i=b;i<d;i++){
				flag[a][i][0] = 1;
			}
			for(int i=d;i>b;i--){
				flag[a][i][2] = 1;
			}
		}
		if(b==d){
			if(a>c)swap(a,c);
			for(int i=a;i<c;i++){
				flag[i][b][1] = 1;
			}
			for(int i=c;i>a;i--){
				flag[i][b][3] = 1;
			}
		}
	}
	map<int,int> mp;
	int s = 0;
	for(int i=0;i<t;i++){
		int a;
		cin >> a;
		char b;
		cin >> b;
		s += a;
		if(b=='N'){
			mp[s] = 0;
		}else if(b=='E'){
			mp[s] = 1;
		}else if(b=='S'){
			mp[s] = 2;
		}else{
			mp[s] = 3;
		}
	}
	queue<pair<pair<int,int>,pair<int,int> > >q;
	map<pair<pair<int,int>,pair<int,int> >,bool> m;
	if(flag[x0][y0][0]==1){
		q.push(MP(MP(x0,y0),MP(0,0)));
	}
	if(flag[x0][y0][1]==1){
		q.push(MP(MP(x0,y0),MP(0,1)));
	}
	if(flag[x0][y0][2]==1){
		q.push(MP(MP(x0,y0),MP(0,2)));
	}
	if(flag[x0][y0][3]==1){
		q.push(MP(MP(x0,y0),MP(0,3)));
	}
	set<pair<int,int> > ans;
	while(1){
		auto x = q.front();
		q.pop();
		int a,b,c,d;
		a = x.first.first;
		b = x.first.second;
		c = x.second.first;
		d = x.second.second;
		//cout << a <<" " << b << " " <<c << " " << d << endl;
		if(c>s)break;
		if(c==s){
			ans.insert(MP(a-1,b-1));
		}
		if(mp.find(c+1)!=mp.end()){
			if(d==mp[c+1]){
				for(int i=0;i<4;i++){
					if(i!=d&&(i+4-d)%2==0)continue;
					if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
						m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
						q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
					}
				}
			}else{
				if((d+4-mp[c+1])%2!=0&&flag[a+dx[d]][b+dy[d]][mp[c+1]]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1]))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,mp[c+1])));
				}
			}
		}else{
			for(int i=0;i<4;i++){
				if(i!=d&&(i+4-d)%2==0)continue;
				if(flag[a+dx[d]][b+dy[d]][i]==1&&m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]==0){
					m[MP(MP(a+dx[d],b+dy[d]),MP(c+1,i))]=1;
					q.push(MP(MP(a+dx[d],b+dy[d]),MP(c+1,i)));
				}
			}
		}
	}
	for(auto x:ans){
		cout << x.first << " " << x.second << endl;
	}
	return 0;
}


Measured memory_bytes: 52872
# ABC139E - League
from collections import deque


def main():
    N = int(input())
    A = [0] + list(deque(map(int, input().split())) for _ in range(N))#対戦相手をキューに入れる
    cnt, cur, days = 0, [0] * (N + 1), [0] * (N + 1)#cntは開催した試合数、curは次対戦できる試合相手、daysは試合日数
    q = deque(list(range(1, N + 1))) #試合のできるプレイヤーを入れておく
    while q:
        x = q.popleft()#検討するプレイヤーを１人抽出しxに代入
        #y = A[x].popleft()#ここにy代入（削除）があると次のifで試合していないのに最後の対戦相手分を処理せずに終了になるためifの下にy代入を持ってくる。次がA[x]=0となるため。
        if not A[x]:  #プレイヤーxが全ての試合を終了した場合
            continue
        y = A[x].popleft()  #xの次の対戦相手を抽出し、yに代入
        if cur[y] == x:  #yの次の対戦相手がxであれば（すなわちxの対戦相手もy）以下を実行
            cnt += 1 #実行試合数を増やす
            days[x] = days[y] = max(days[x], days[y]) + 1  #xとyが試合をしたため、xとyの試合日数を増やすが、両方の最後の試合の次の日に試合を行う
            cur[x], cur[y] = 0, 0  #試合を行ったため対戦相手候補をお互い消去する
            q.append(x), q.append(y) #翌日以降に別の試合をする者としてqにプッシュ
        else:  #対戦相手yがxとの対戦の前に他の相手と試合する場合（つまり２つ目のifがFalseの場合）はxの次の相手としてはyを指定しておく　
            cur[x] = y
    flg = cnt == N * (N - 1) // 2  #全試合終了したかの確認
    print(max(days) if flg else -1)#全試合終了していたら日数を表示。そうでなければ-1を表示


if __name__ == "__main__":
    main()


Measured memory_bytes: 36096
n=int(input())
def rotate(l, n):
    return l[-n:] + l[:-n]
s=[list(input())for i in range(n)]
ans=0;
for _ in range(n):
  for i in range(n):
    s[i]=rotate(s[i],1)
  f=1
  for i in range(n):
    for j in range(i+1,n):
      f &= s[i][j]==s[j][i]
  ans+=f
print(ans*n)

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_X 100'000

int main() {
    i64 N, K; cin >> N >> K;
    vector<i64> dist(MAX_X + 1, 0);
    REP(i, N) {
        i64 a, b; cin >> a >> b;
        dist[a] += b;
    }

    vector<i64> C(MAX_X + 2, 0);
    REP(i, MAX_X + 1) {
        C[i + 1] = C[i] + dist[i];
    }

    i64 lb = 0;
    i64 ub = MAX_X + 1;
    while (ub - lb > 1) {
        i64 mid = (lb + ub) / 2;
        if (C[mid + 1] >= K) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;

    return 0;
}

Measured memory_bytes: 1792
/*

Author : AllKilled
Date   : 201911096

Contest: NIKKEI Programming Contest 2019-2.
Problem: Task A.
Result :

*/
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MAXN = 1e6+7;

///--------------------------------------------///



int main()
{
    int n;
    cin >> n;
    cout << (n-1)/2;
    return 0;
}


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

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

  for (int i = 0; i < S.size(); i++) {
    int X;
    X = S[i] - 'A';
    S[i] = 'A' + ((X + N) % 26);
  }
cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    N, Y = map(int, input().split())

    for x in range(N+1):
        for y in range(N+1-x):
            _sum = 10000 * x + 5000 * y + 1000 * (N-x-y)
            if _sum == Y:
                print(x, y, N-x-y)
                exit(0)

    print(-1, -1, -1)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 2940
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]
AB=sorted(AB,key=lambda x:x[1])
#print(AB)
c=0
ans="Yes"
for a,b in AB:
    c+=a
    if c>b:
        ans="No"
        break


print(ans)

Measured memory_bytes: 55264
n = int(input())
w = list(map(int, input().split()))

minDiff = 0
for t in range(1, n+1):
  s1 = sum(w[0:t])
  s2 = sum(w[t:])
  diff = abs(s1 - s2)
  if t == 1 or minDiff > diff:
    minDiff = diff

print(minDiff)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define D(x) cout<<"D: "<<#x<<'='<<x<<endl;
#define R(x, l) cout<<"R: Array "<<#x<<endl; for(int i = 0; i < l; i++) cout<<' '<<i<<':'<<*(x+i)<<endl;
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	for(unsigned i = 0; i < v.size(); i++) os<<v[i]<<' ';
	return os;
}
inline bool is_pa(string str)
{
	for(int i = 0; i < str.length()/2; i++)
		if (str[i] != str[str.length()-i-1]) return 0;
	return 1;
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s = next<string>();
	string str = " ";
	for(int i = 0; i < s.length(); i++) str.pb(s[i]);
	int l = s.length();
	string a = str.substr(1, (l-1)/2), b = str.substr((l+3)/2, l);
	if (is_pa(s) && is_pa(a) && is_pa(b)) puts("Yes");
	else puts("No");
	return ~~(0-0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100006
#define mo 1000000007
using namespace std;
char a[N],b[N];
int Q,x,y,q,w,na,nb,sa[N],sb[N];
int ksm(int x,int y)
{
	if(y==0)return 1;if(y==1)return x;
	int p=ksm(x,y>>1);
	if(y&1)return 1LL*p*p%mo*x%mo;return 1LL*p*p%mo;
}
int main()
{
	scanf("%s%s",a+1,b+1);
	na=strlen(a+1);nb=strlen(b+1);
	for(int i=1;i<=na;i++)sa[i]=sa[i-1]+(a[i]=='A'?1:2);
	for(int i=1;i<=nb;i++)sb[i]=sb[i-1]+(b[i]=='A'?1:2);
	scanf("%d",&Q);
	while(Q--){
		scanf("%d%d%d%d",&x,&y,&q,&w);
		int QwQ=(sa[y]-sa[x-1])%3;
		int QAQ=(sb[w]-sb[q-1])%3;
		if(QwQ==QAQ)puts("YES");else puts("NO");
	}
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int k,a,n,ai[200001],i,j,m=0,s=0,b,c,d,e,f=0;
    scanf("%d%d",&k,&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&ai[i]);
    }
    b=k-ai[n-1]+ai[0];
    for(i=0;i<n-1;i++)
    {
        c=ai[i+1]-ai[i];
        if(m<c)
        {
            m=c;
        }
    }
    if(b>=m)
    {
        for(i=0;i<n-1;i++)
        {
            a=ai[i+1]-ai[i];
            s=s+a;
        }
        printf("%d\n",s);
    }
    else
    {
        for(i=0;i<n-1;i++)
        {
            a=ai[i+1]-ai[i];
            if(a==m && !f)
                { f=1;
                    continue;}
            s=s+a;
        }
        s=s+(k-ai[n-1]);
        s=s+ai[0];
        printf("%d\n",s);
    }
    return 0;

}

Measured memory_bytes: 896