akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int D = sc.nextInt();
        int[] c = new int[27];
        int[] t = new int[D + 1];
        int[] last_day = new int[27];
        Arrays.fill(last_day, 0);
        int[][] s = new int[D + 1][27];
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 1; i <= D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        Random random =new Random();
        for (int i = 1; i <= D; i++) {
            t[i] = 1+random.nextInt(26);
        }
        int[] tmp_array = t;
        long tmp_sum = 0;
        long last_sum =0;
        for (int j = 0; j < 9; j++) {
            int d = 1+random.nextInt(D);
            int q = 1+random.nextInt(D);
            t[d] = t[q];
            for (int i = 1; i <= D; i++) {
                last_day[t[i]] = i;
                tmp_sum += calcS(c, s, t[i], i, last_day);
            }
            if(tmp_sum>last_sum){
                continue;
            }else {
                t = tmp_array;
            }
        }


        for (int i = 1; i <= D; i++) {
            System.out.println(t[i]);
        }

    }

    private static long calcS(int[] c, int[][] s, int kaisai, int day, int[] last_day) {

        long loss = 0;
        for (int i = 1; i <= 26; i++) {
            if (i == kaisai) {
                last_day[i] = day;
                continue;
            }
            loss -= c[i] * (day - last_day[i]);
        }

        long plus = s[day][kaisai];
        return plus + loss;
    }

}


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

int N;
int main() {
	cin >> N;
	vector<vector<pair<int,ll>>> edge(N);
	for(int i=0;i<N-1;i++) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		edge[a].push_back({b,c});
		edge[b].push_back({a,c});
	}
	int Q, K;
	cin >> Q >> K;
	K--;
	queue<int> q;
	vector<ll> dist(N, LLONG_MAX);
	dist[K] = 0;
	q.push(K);
	while(!q.empty()) {
		int now = q.front(); q.pop();
		for(int i=0;i<edge[now].size();i++) {
			int next = edge[now][i].first;
			ll len = edge[now][i].second;
			if(dist[now] + len < dist[next]) {
				dist[next] = dist[now] + len;
				q.push(next);
			}
		}
	}
	for(int i=0;i<Q;i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << dist[x] + dist[y] << endl;
	}
}

Measured memory_bytes: 9984
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


string s;

long long f(int i,long long n,long long sum) {
	long long res = 0;
	if (i == s.size())return n+sum;
	if (n) {
		res += f(i + 1, s[i] - '0', sum + n);
	}
	res += f(i + 1, n*10 + s[i] - '0', sum);
	return res;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	cout << f(0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
//
// Created by 伊東麻沙美 on 2019/10/22.
//

#include<iostream>
#include<algorithm>
using namespace std;


int main(){

    int N;
    cin>>N;

    cout<<N*N*N<<endl;

    //cin>>a>>b>>x;
    //scanf("%d%s%d",&i,&x,&j);


       // printf("%d",i+j);
       //cout<<i+j<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long DP[2];

int main()
{
    long long A, B, C, D, N;
    cin >> N >> A >> B >> C >> D;
    if(A > B)
        swap(A, B);
    if(B - A > (N - 1) * D)
    {
        cout << "NO\n";
        return 0;
    }

    for(long long i = 0; i <= N - 1; i++)
    {
        long long diff = B - A;
        diff += i * C;
        diff -= (N - 1 - i) * C;
        long long aux = (C - D) * i;
        if(aux <= diff && aux + (D - C) * (N - 1) >= diff)
        {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace Test
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().abc131_b();
        }

        public void abc131_b()
        {
            var CinTemp = ReadLine().Split(' ');
            int a = int.Parse(CinTemp[0]);
            int b = int.Parse(CinTemp[1]);
            int ans = 100000;
            int total = 0;
            for (int i = 0; i < a; i++)
            {
                total += b+i;
                ans = Abs(ans) > Abs(b+i) ? b+i : ans;
            }
            WriteLine(total-ans);
        }
    }
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
    for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c, x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c, x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x, a, b)((x)>=a && (x)<=b    )
#define in1(x, a, b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int) (1e9) + 7;

void _() {
    ill(a);
    ill(b);
    ill(c);
    ill(k);
    cout <<(pow(2,k)*max(a,max(c,b))+a+b+c-max(a,max(c,b)));



};


int main() {
#if __MINGW32__
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin);
    freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    _();
    return 0;

}








Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner stdin = new Scanner(System.in);
        int i =1;
        int a = stdin.nextInt();
	while(a!=0){
	    System.out.println("Case "+i+":"+" "+a);
	    i++;
	    a = stdin.nextInt();
	    }
    }
}

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

int main(){
    int n;
    int num;
    cin >> n;
    vector<int> d;
    for(int i = 0; i < n; i++){
        cin >> num;
        d.push_back(num);
    }
    sort(d.begin(), d.end());
    int count = 0;
    cout << d[n/2] - d[n/2-1] << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

int main () {

    int N, M;
    std::cin >> N >> M;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) std::cin >> A.at(i);

    double border = std::accumulate(A.begin(), A.end(), 0.) / (4 * M);

    std::sort(A.rbegin(), A.rend());

    bool ans = true;
    for(int i = 0; i < M; i++) if(A.at(i) < border) ans = false;

    if (ans) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)>(b)?(b):(a))
#define ll long long

int main(){
  ll n,a,b;
  scanf("%lld%lld%lld",&n,&a,&b);
  if((a-b)%2){
    printf("%lld\n",min(min(a-1,n-b)+((b-a)+1)/2,min(n-a,b-1)));
  }else {
    printf("%lld\n",(b-a)/2);
  }
  return 0;
}

Measured memory_bytes: 128
#include <map>
typedef long long ll;
int mod = 1e9+7;

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

int main(){
	ll A, B, C, D;
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D)+1;

	ll minC = (A + C-1)/C;
	ll maxC = B/C;
	ll cntC = maxC - minC + 1;

	ll minD = (A + D-1)/D;
	ll maxD = B/D;
	ll cntD = maxD - minD + 1;

	ll CD = C * D / GCD(C, D);
	ll minCD = (A + CD-1)/CD;
	ll maxCD = B/CD;
	ll cntCD = maxCD - minCD + 1;

	ll ans = (B - A + 1) - cntC - cntD + cntCD;

	printf("%lld", ans);

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
namespace QiFeng233{
	int n,m;
	double a[110],num,sum;
	void solve(){
		scanf("%d %d",&n,&m);
		for(int i=1;i<=n;++i)scanf("%lf",&a[i]),sum+=a[i];
		sum=sum/(double)m/4.0;
		for(int i=1;i<=n;++i)if(a[i]>=sum)++num;
		if(num>=m)printf("Yes");
		else printf("No");
	}
}
signed main(){
	QiFeng233::solve();
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	char a, b;

	scanf("%c %c", &a, &b);

	if (a == 'H') {
		if (b == 'H') {
			printf("H\n");
		}
		else {
			printf("D\n");
		}
	}
	else {
		if (b == 'H') {
			printf("D\n");
		}
		else {
			printf("H\n");
		}
	}

	return 0;
}

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

int main(){
  int L,R;
  cin >> L >> R;

  R = min (R,L+4038);
  int ans = 2018;
  for (ll i = L; i <= R; i++) {
    for (ll j = i+1; j <= R; j++) {
      int x = i * j % 2019;
      ans = min (ans,x);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N = int(input())
H = list(map(int, input().split()))

count = 0
max_h = 0

for i in range(N):
	if H[i] >= max_h:
		max_h = H[i]
		count += 1
		
print(count)


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

int main(void){
    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int d = 0, cnt = 1;
    rep(i,n){
        d = d + l[i];
        if (d <= x) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
const ll INF = (ll)1e18 + 1;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x, y; cin >> x >> y;
    string res = "Yes"; 
    
    if(y>=2*x && y<=4*x && y%2==0){
        cout << res << ln;
    }else{
        cout << "No" << ln;
    }
    return 0;
}

Measured memory_bytes: 3636
#include "algorithm"
#include "iomanip"
#include "iostream"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;

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

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

template <typename T>
void drop(const T& x) {
  cout << x << endl;
  exit(0);
}

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

  ll N;
  cin >> N;
  set<string> s;

  rep(i, N) {
    string a;
    cin >> a;
    s.insert(a);
  }

  ll res = s.size();
  cout << res << "\n";

  return 0;
}


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

int main() {
  string s; cin >> s;
  string ans;
  if (s[0] == 'S') ans = "Cloudy";
  if (s[0] == 'C') ans = "Rainy";
  if (s[0] == 'R') ans = "Sunny";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    char le[3][3];
    for(int i=0;i<3;i++){
        for (int j=0; j<3;j++)
            cin>> le[i][j];
    }
    cout<< le[0][0]<<le[1][1]<<le[2][2];
    return 0;
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;

    vector<int> C(N-1), S(N-1), F(N-1);
    rep(i, N-1) cin >> C[i] >> S[i] >> F[i];
    
    for (int i = 0; i < N; i++) {
        int t = 0;
        for (int j = i; j < N - 1; j++) {
            if (t <= S[j]) {
                t = S[j] + C[j];
            } else {
                t = S[j] + (t - S[j] + F[j] - 1) / F[j] * F[j] + C[j];
            }
        }
        cout << t << endl;
    }
}


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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> L(N);
    for ( int i = 0; i < N; i++ ) cin >> L[i];
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            for ( int k = j+1; k < N; k++ ) {
                if ( L[i] + L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i] ) ans++;
            }
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3628
main = do
  n <- getLine
  s <- getLine
  putStrLn . show . solve $ s

solve :: String -> Int
solve s = maximum $ map (calc s) [1..(length s)]

calc s i = length $ filter (\c -> c `elem` (removeDup . (take i) $ s) && c `elem` (removeDup . (drop i) $ s)) ['a'..'z']

removeDup xs = helperRem [] xs
  where 
    helperRem seen [] = seen
    helperRem seen (x:xs) = if x `elem` seen then helperRem seen xs else helperRem (x:seen) xs

Measured memory_bytes: 892
var n,m,i,j,now:longint;
    a,b,c,d:array[0..107] of int64;
begin
  readln(n,m);
  for i:=1 to n do
	readln(a[i],b[i]);
  for i:=1 to m do
	readln(c[i],d[i]);
  for i:=1 to n do
  begin
    now:=1;
    for j:=2 to m do
	  if (abs(c[j]-a[i])+abs(d[j]-b[i])<abs(c[now]-a[i])+abs(d[now]-b[i])) then now:=j;
	writeln(now);
  end;
end.
	  

Measured memory_bytes: 128
A, B = [int(_) for _ in input().split()]


def count(x, k):
    return 2**(k - 1) * (x // 2**k) + max([x % 2**k - 2**(k - 1) + 1, 0])


ans = 0
for k in range(1, 50):
    ans += 2**(k - 1) * ((count(B, k) - count(A - 1, k)) % 2)
print(ans)


Measured memory_bytes: 3060
D,G = map(int,input().split())
p = [0]*D
c = [0]*D
for i in range(D):
    p[i], c[i] = map(int,input().split())

ans = float('inf')

for bit in range(1 << D):
    temp_score = 0
    solved_num = 0
    uncompleted_idx = -1
    for i in range(D):
        if (bit & (1<<i)):
            temp_score += p[i]*100*(i+1) + c[i] #コンプリートする得点帯
            solved_num += p[i]
        else:
            uncompleted_idx = max(uncompleted_idx,i)


    if G <= temp_score:
        ans = min(ans,solved_num)
        continue
    # 半端に解く問題（未コンプのうち最も配点の高い問題）をシミュレーション
    if uncompleted_idx == -1:
        continue

    for j in range(p[uncompleted_idx]):
        temp_score += 100*(uncompleted_idx+1)
        solved_num += 1
        if G <= temp_score:
            ans = min(ans,solved_num)
            break
print(ans)

Measured memory_bytes: 40816
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
vector<int>vt;
set<int>st;
map<int,int>mp;
unordered_map<string,int> umap; 
const long long MAX = 1e5;
const long long INF = 1e9;
const double pi = acos(-1);


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  int sum=0;
  int x;
  for(int i=0;i<m;i++) {cin>>x;
  sum+=x;
  }
  if(n-sum>=0)
  cout<<n-sum<<endl;
  else
  {
    cout<<"-1"<<endl;
  }
  

    
   return 0;
}

Measured memory_bytes: 3664
import math

n = int(input())
S = list(map(int,input().split()))

q = int(input())
T = list(map(int,input().split()))
result= []
#print(T)
i = 0
right = 0
left = len(S)
for i in range(q):
    right = 0
    left = len(S)
    #print(result)
    while right<left:
        mid = (left+right)/2
        mid = math.floor(mid)
        if S[mid] == T[i]:
            result.append(T[i])
            break
        elif S[mid]<T[i]:
            right = mid+1
        else:
            left = mid
print(len(result))


Measured memory_bytes: 16772
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
int x, y, z;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x>>y>>z;
    if(x==y&&y==z) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
k = int(0.5+(2*N)**0.5)
if k*(k+1) == 2*N:
	print("Yes")
	print(k+1)
	ans = [[] for _ in range(k+1)]
	for i, (x, y) in enumerate(combinations(range(k+1), 2), 1):
		ans[x].append(i)
		ans[y].append(i)
	for l in ans:
		print(k, *l)

else:
	print("No")


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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}

template<typename U>
void pprint(U a){
    cout<<a;
}

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

    ll n;
    cin>>n;
    ll tmp;
    ll ans=0;
    ll max;
    cin>>max;
    rep(i,n-1){
        cin>>tmp;
        if(max>tmp){
            ans+=max-tmp;
        }else{
            max = tmp;
        }
    }
    print(ans);




    return 0;
}




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

int cal(int n,int k)
{
	while(n>=k&&n%k!=0) {
		int div = n/k+1;
		n -= ((n-1)%k/div+1)*div;
	}
	return n/k;
}
int n;
int main()
{
	scanf("%d",&n);
	int val = 0;
	for(int i = 0;i < n;++i) {
		int a,b;
		scanf("%d%d",&a,&b);
		val ^= cal(a,b);
	}
	if(val > 0) {
		printf("Takahashi\n");
	} else {
		printf("Aoki\n");
	}
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x,y,r,w,h;

    cin>>w>>h>>x>>y>>r;
    if(x>=r && (w-r)>=x && y>=r && (h-r)>=y ) {
       cout<<"Yes"<<endl;
    } else {
       cout<<"No"<<endl;
    }

    return 0;
}



Measured memory_bytes: 3088
import sys
input = sys.stdin.buffer.readline

def main():
    H,W = map(int,input().split())
    point = [[0]*W for _ in range(H)]
    
    for i in range(H):
        a = list(map(int,input().split()))
        for j in range(W):
            point[i][j] += a[j]

    for i in range(H):
        b = list(map(int,input().split()))
        for j in range(W):
            point[i][j] = abs(point[i][j]-b[j])
    
    base = 3200
    dp = [[0]*W for _ in range(H)]
    dp[0][0] = (1 << (base+point[0][0])) | (1 << (base-point[0][0]))
    
    for i in range(H):
        for j in range(W):
            if j < W-1:
                dp[i][j+1] |= (dp[i][j] << point[i][j+1])
                dp[i][j+1] |= (dp[i][j] >> point[i][j+1])
            if i < H-1:
                dp[i+1][j] |= (dp[i][j] << point[i+1][j])
                dp[i+1][j] |= (dp[i][j] >> point[i+1][j])
    
    ans = dp[-1][-1] >> base
    for i in range(ans.bit_length()):
        if (ans >> i)&1:
            print(i)
            exit()
    
if __name__ == "__main__":
    main()


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

//inline int read(){int t = 0;int neg=1;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1;continue;}t=t*10+c-48;}return neg*t;}
//inline int readl(){long long t = 0;long long neg=1ll;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1ll;continue;}t=t*10+c-48;}return neg*t;}

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<pi> vpi;
typedef vector<plli> vplli;
const lli M=1000000007ll;

int main(){
	fast_io
	vi a(3);
	cin>>a[0];
	cin>>a[1];
	cin>>a[2];
	sort(a.begin(), a.end());
	if(a[0]+a[1]==a[2]) cout<<"Yes\n";
	else cout<<"No\n"; 
	
	return 0;
}

Measured memory_bytes: 256
n,y=map(int,input().split())
ans=[-1]*3
for i in range(n+1):
    for j in range(n-i+1):
        k=(y-i*10000-j*5000)//1000
        if i+j+k==n:
            ans=[i,j,k]
            break
print(*ans) 

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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        if(H == 0 and W == 0){
            break;
        }
        
        for(int h = 0; h < H; h++){
            for(int w = 0; w < W; w++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;

    }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
const i64 MOD = 1000000007;
i64 mod_pow(i64 x, i64 n = MOD - 2) {
    if(n == 0LL) return 1;
    i64 res = mod_pow(x * x % MOD, n / 2);
    if(n & 1LL) res = res * x % MOD;
    return res;
}

i64 fact[200010], toinv[200010];
i64 calcfact(i64 x) {
    fact[x] = x == 0 ? 1LL : x * calcfact(x - 1) % MOD;
    toinv[x] = mod_pow(fact[x]);
    return fact[x];
}

i64 calc(i64 a, i64 b) {
    i64 p = a + b - 2, q = b - 1;
    return fact[p] * toinv[q] % MOD * toinv[p - q] % MOD;
}
int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    calcfact(H + W);
    i64 ans = 0;
    rep(i, H - A)
      ans = (ans + calc(i + 1, B) * calc(H - i, W - B) % MOD) % MOD;
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 6528
import sys
input = sys.stdin.readline

A=int(input())
B=int(input())
C=int(input())
X=int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    if 0 <= (X - 500*i - 100*j) // 50 <= C:
      ans += 1
print(ans)      

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int a = cin.nextInt();
            int b = cin.nextInt();
            int c = cin.nextInt();

            if(a <= c && c <= b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

	int N, A, B; cin >> N >> A >> B;

	cout << min(A, B) << " " << max(0, A+B-N) << endl;

}

Measured memory_bytes: 3616
#include<stdio.h>
int main(){
int a,b,c;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);

int d = 0;

if(a == 5 || a == 7){
d++;
}

if(b == 5 || b == 7){
d++;
}

if(c == 5 || c == 7){
d++;
}

if(d == 3){
if(17 == a+b+c){
printf("YES");
}
else{
printf("NO");
}
}

else{
printf("NO");
}

return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def gcd(a: int, b: int):
    if a < b:
        return gcd(b, a)
    while b != 0:
        a, b = b, a % b
    return a


def solve(A: int, B: int, C: int, D: int):
    cdl = C // gcd(C, D) * D
    A -= 1
    print(
        (B - A)
        - (B // C - A // C) - (B // D - A // D)
        + (B // cdl - A // cdl)
    )


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

struct Circle {
	int x, y, r, c, t;
	Circle(int x_, int y_, int r_, int c_)
		: x(x_), y(y_), r(r_), c(c_), t(0) {}
};

int N;
int ans;
vector<Circle> circles;

bool intersect(Circle c1, Circle c2) {
	int a = c1.x - c2.x;
	int b = c1.y - c2.y;
	int r = c1.r + c2.r;	
	return (a*a + b*b < r*r);
}

vector<bool> is_visited;

void dfs(int used, vector<Circle> circles, int cnt) {
	
	int n = circles.size();
	ans = max(ans, cnt);
	if(is_visited[used]) return;
	is_visited[used] = true;
	// ??????????????????????????¢???
	for(int i = 0; i < n; ++i) {
		Circle c1 = circles[i];
		if(c1.t != 0 || (used & (1<<i))) continue; 	
		for(int j = i+1; j < n; ++j) {
			if(circles[j].t != 0 || (used & (1<<j)) || c1.c != circles[j].c) continue; 
			vector<Circle> tmp = circles;
			for(int k = i+1; k < n; ++k) {
				if(intersect(c1, tmp[k])) tmp[k].t -= 1;			
			}
			Circle c2 = tmp[j];
			for(int k = j+1; k < n; ++k) {
				if(intersect(c2, tmp[k])) tmp[k].t -= 1;			
			}
			dfs((used | (1<<i) | (1<<j)), tmp, cnt + 2);
		}
	}
	return;
}

int main() {
	while(cin >> N, N) {
		int x, y, r, c;
		circles.clear();
		rep(nth, N) {
			cin >> x >> y >> r >> c;
			Circle circle = Circle(x, y, r, c);	
			// ????????????????????????
			rep(i, circles.size()) {
				if(intersect(circles[i], circle)) {
					circle.t += 1;
				}
			}
			circles.push_back(circle);
		}
		
		ans = 0;
		int used = 0;
		is_visited.assign((1<<N), false);
		dfs(used, circles, 0);
		cout << ans << endl;
	}	
	return 0;
}

Measured memory_bytes: 3112
n=int(input())
k=0
while k*(k+1)//2<n:
    k+=1
if k*(k+1)//2==n:
    if n==1:
        print(1)
    else:
        for i in range(1,k+1):
            print(i)
else:
    j=(k*(k+1)//2)-n
    for i in range(1,k+1):
        if i!=j: 
            print(i)
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

vector<pair<long long, long long>> prime_foctorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long i = 2; i * i <= N; i++) {
    if (N % i != 0) continue;
    long long ex = 0;
    while (N % i == 0) {
      ex++;
      N /= i;
    }
    res.push_back({i, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

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

  const auto &res = prime_foctorize(N);

  long long cnt = 0;
  for (auto p : res) {
    long long index = 1;
    long long border = 1;
    while (p.second >= border) {
      cnt++;
      index++;
      border += index;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
 int b1,b2,b3;
cin>>b1>>b2>>b3;
    if(b1==1&&b2==0&&b3==0){
        cout<<"Close"<<endl;
    }
    else if(b1==0&&b2==1&&b3==0){
        cout<<"Close"<<endl;
    }
    else if(b1==1&&b2==1&&b3==0){
        cout<<"Open"<<endl;
    }
    else if(b1==0&&b2==0&&b3==1){
        cout<<"Open"<<endl;
    }
    else if(b1==0&&b2==0&&b3==0){
        cout<<"Close"<<endl;        
    }
return 0;
}

Measured memory_bytes: 3072
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize, m: usize,
        ab: [(usize1, usize1); m]
    }

    let mut g = vec![vec![];n];
    for i in 0..ab.len() {
        let (a, b) = ab[i];
        g[a].push(b);
        g[b].push(a);
    }

    let mut dp = vec_md![None;n;1<<n];
    let ret =  rec(&mut dp, &g, 1, 0);
    println!("{}", ret);
}

fn rec(dp: &mut [Vec<Option<u64>>], g: &[Vec<usize>], mask: usize, c: usize) -> u64 {
    if mask == (1<<dp.len())-1 {
        return 1;
    }
    if let Some(src) = dp[c][mask] {
        return src;
    }

    let mut ret = 0u64;
    for &v in &g[c] {
        if mask >> v & 1 == 0 {
            ret += rec(dp, g, mask | (1 << v), v);
        }
    }
    dp[c][mask] = Some(ret);
    ret
}

Measured memory_bytes: 4352
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> cost(3,0);
	int a ,b ,c;
	for(int i = 0; i<n; i++) {
		cin >> a >> b >> c;
		vector<int> arr(3);
		arr[0] = a + max(cost[1] ,cost[2]);
		arr[1] = b + max(cost[0] ,cost[2]);
		arr[2] = c + max(cost[0] ,cost[1]);
		cost[0] = arr[0];
		cost[1] = arr[1];
		cost[2] = arr[2];
	}
	cout << max( {cost[0] ,cost[1] ,cost[2]} );
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>


using namespace std;

int main(){
  int N;
  cin >> N;
  int sum = 0;

  for(int i = 0; i < 6; i++){
    if(pow(10, i) <= N && N < pow(10, i+1)){
      // N = n * 10^i
      if(i % 2  == 0){
        int add = pow(10, i) - 1;
        sum += (N - add);
      }

      break;
    }else{
      if(i % 2  == 0){
        sum += (pow(10, i+1) - pow(10, i));

      }
    }
  }

cout << sum << endl;
  return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

std::vector<std::pair<ll,ll>> prime_factorization(ll n){
  std::vector<std::pair<ll,ll>> factor;
  for(ll p=2;p*p<=n;++p){
    if(n%p!=0)continue;
    ll num=0;
    while(n%p==0){
      num++;
      n/=p;
    }
    factor.emplace_back(p,num);
    if(n==1)return factor;
  }
  if(n!=1)factor.emplace_back(n,1);
  return factor;
}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);
  
  ll a,b;
  cin>>a>>b;

  auto fac = prime_factorization(gcd(a,b));
  //for(auto x:fac)cout<<x.first<<" "<<x.second<<endl;
  cout<<fac.size()+1<<endl;
  
}


Measured memory_bytes: 256
start_x, start_y, goal_x, goal_y = map(int, input().split())
n = int(input())
info = [(start_x, start_y, 0)] \
       + [tuple(map(int, input().split())) for i in range(n)] \
       + [(goal_x, goal_y, 0)]

#i番目のバリアからj番目のバリアまでの移動について、
#受ける光線量を辺の重みとしてグラフを構築する(O(N^2))
graph = [[0]*(n+2) for i in range(n+2)]
for i in range(n+2):
    for j in range(i,n+2):
        diff_x = info[i][0] - info[j][0]
        diff_y = info[i][1] - info[j][1]
        sum_radius = info[i][2] + info[j][2]
        cost = max(0, ((diff_x)**2 + (diff_y)**2)**(0.5) - sum_radius)
        graph[i][j] = cost
        graph[j][i] = cost
        graph = tuple(graph)

#ダイクストラ法でstartからgoalまでの最短距離を求める

import heapq
distance = [float("inf")]*(n+2)
used = [False]*(n+2)
distance[0] = 0

while True:
    v = -1
    for u in range(n+2):
        if not used[u] and (v == -1 or distance[u] < distance[v]):
            v = u
    if v == -1:
        break
    used[v] = True
    for u in range(n+2):
        distance[u] = min(distance[u], distance[v] + graph[v][u])
            
print(distance[n+1])

Measured memory_bytes: 24820
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a,v = LI()
    b,w = LI()
    t = I()

    s = abs(a - b)
    k = (v-w) * t
    if k < s:
        return 'NO'

    return 'YES'


print(main())




Measured memory_bytes: 10980
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        Map<Character, Set<Integer>> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            Set<Integer> set = new HashSet<>();
            if (map.containsKey(c)) {
                set = map.get(c);
            }
            set.add(i);
            map.put(c, set);
        }
        if (!map.containsKey('R') || !map.containsKey('G') || !map.containsKey('B')) {
            System.out.println(0);
            return;
        }
        Set<Integer> rset = map.get('R');
        List<Integer> rlist = new ArrayList<>(rset);
        Set<Integer> gset = map.get('G');
        List<Integer> glist = new ArrayList<>(gset);
        Set<Integer> bset = map.get('B');
        long sum = 0;
        for (int i = 0; i < rset.size(); i++) {
            for (int j = 0; j < glist.size(); j++) {
                int r = rlist.get(i);
                int g = glist.get(j);
                sum += bset.size();
                if (bset.contains(Math.max(r, g) + Math.abs(r - g))) {
                    sum--;
                }
                if ((r + g) % 2 == 0 && bset.contains((r + g) / 2)) {
                    sum--;
                }
                if (bset.contains(Math.min(r, g) - Math.abs(r - g))) {
                    sum--;
                }
            }
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 56388
require 'tsort'

V, E = gets.split.map(&:to_i)
g = Hash.new

(0...V).each do |i|
  g[i] = []
end

E.times do
  from, to = gets.split.map(&:to_i)
  g[from] << to
end

each_node = -> (&b) { g.each_key(&b) }
each_child = -> (n, &b) { g[n].each(&b) }
order = TSort.tsort(each_node, each_child).reverse

puts order



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

int main()
{
    int minimum;
    long int n, k;
    cin>>n>>k;
    if(k>=n)
        k=n-1;
    int h[n];
    int ans[n];
    for(int i=0; i<n; i++)
    {      
        cin>>h[i];
    }
    ans[0]=0;
    for(int i=1; i<k; i++)
    {
        ans[i]=abs(h[0]-h[i]);
    }
    for(int i=k; i<n; i++)
    {   
        ans[i]=INT_MAX;
        for(int j=1; j<=k; j++)
        {
            ans[i]=min(ans[i-j]+abs(h[i]-h[i-j]),ans[i]);
        }
    }
    cout<<ans[n-1];
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int c[9];
int main(void){
    for(int i=0;i<9;i++)scanf("%d",c+i);
    if(c[0]+c[4]==c[1]+c[3]&&c[1]+c[5]==c[2]+c[4]&&c[3]+c[7]==c[4]+c[6]&&c[4]+c[8]==c[5]+c[7])printf("Yes\n");
    else printf("No\n");
    
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n;cin >> n;
    vl a(2*n);
    rep(i,2*n)cin>>a[i];
    sort(rall(a));
    ll res = 0;
    for(int i=1;i<2*n+1;i+=2)res+=a[i];
    out(res);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
struct length
{
	int a;
	int b;
	int c;
};
int main()
{
	int n,i;
	cin>>n;
	length *p=new length [n];
	for(i=0;i<n;i++)
		cin>>p[i].a>>p[i].b>>p[i].c;
	for(i=0;i<n;i++)
		if((p[i].a * p[i].a == p[i].b * p[i].b + p[i].c * p[i].c)||(p[i].a * p[i].a == p[i].b * p[i].b - p[i].c * p[i].c)||(p[i].a * p[i].a + p[i].b * p[i].b == p[i].c * p[i].c))
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 100001
typedef long long ll;
ll n,a[SIZE],b[SIZE],c[SIZE];

int main(){
  ll ans=0;cin>>n;
  REP(i,n) cin>>a[i];
  REP(i,n) cin>>b[i];
  REP(i,n) cin>>c[i];
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  
  REP(i,n){
    auto Iter_a=lower_bound(a,a+n,b[i]);
    auto Iter_c=upper_bound(c,c+n,b[i]);
    ans+=(Iter_a-a)*(c+n-Iter_c);
  }

  cout<<ans;
}


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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

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

const int N = (int) 2e3;
const int INF = (int) 1e9 + 7;

ii p[N + 7];
ll dp[N + 7][N + 7];
int n;

ll f(int i, int l, int r) {
	if (i == 0) return 0;
	if (dp[l][r] != -1) return dp[l][r];

	ll x = f(i - 1, l + 1, r) + (ll) p[i].fs * abs(l - p[i].sc);
	ll y = f(i - 1, l, r - 1) + (ll) p[i].fs * abs(r - p[i].sc);

	return dp[l][r] = max(x, y);
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	sf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		sf("%d", &p[i].fs);
		p[i].sc = i;
	}

	sort(p + 1, p + n + 1);

	memset(dp, -1, sizeof(dp));
	printf("%lld", f(n, 1, n));

	return 0;
}


Measured memory_bytes: 35420
// Problem : C - Modulo Summation
// Contest : AtCoder - AtCoder Beginner Contest 103
// URL : https://atcoder.jp/contests/abc103/tasks/abc103_c?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define ll long long
int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	REP(i,n){
		cin>>v[i];
	}
	ll sum=0;
	REP(i,n){
		sum+=v[i];
	}
	cout<<(sum-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
mo = 10 ** 9 + 7
b = [0] * 64
for j in range(64):
	for i in range(n):
		if a[i] & (1 << j):
			b[j] += 1
ans = 0
for j in range(64):
	ans += b[j] * (n - b[j]) * (2 ** j)
print(ans % mo)


Measured memory_bytes: 122936
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

long long n, c, m = 0;
long long x[100002], v[100002], f[100002];

int main()
{
	cin >> n >> c;

	memset(x, 0, sizeof(x));
	memset(v, 0, sizeof(v));
	memset(f, 0, sizeof(f));

	for (long long i = 1; i <= n; i++)
		cin >> x[i] >> v[i];

	x[n + 1] = c;

	for (long long i = 1; i <= n; i++) {
		v[i] += v[i - 1];
		f[i] = max(f[i - 1], v[i] - x[i]);
	}

	for (long long i = n; i >= 0; i--)
		m = max(m, v[n] - v[i] - (c - x[i + 1]) * 2 + f[i]);

	memset(f, 0, sizeof(f));

	for (long long i = n; i > 0; i--)
		f[i] = max(f[i + 1], v[n] - v[i - 1] - c + x[i]);

	for (long long i = 0; i <= n; i++)
		m = max(m, v[i] - x[i] * 2 + f[i + 1]);

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
int main()
{
    int n,a,x,t;
    scanf("%d %d %d",&n,&a,&t);
    x=a*n;
    if(x>t) printf("%d\n",t);
    else if(x<t) printf("%d\n",x);
    else printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 128