akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(){
    int X;
    scanf("%d", &X);

    switch(X){
        case 7:
            printf("YES\n");
            break;
        case 5:
            printf("YES\n");
            break;
        case 3:
            printf("YES\n");
            break;
        default:
            printf("NO\n");
            break;
    }
    
    return 0;
}

Measured memory_bytes: 128
n = int(input())
a_L = list(map(int,input().split()))

L = []
for i in a_L:
    L.append(i+1)
    L.append(i-1)
    L.append(i)

import collections

L = collections.Counter(L)

L = sorted(L.items(),key=lambda x: x[1],reverse=True)
print(L[0][1])

Measured memory_bytes: 72516
S=input()
N=len(S)
def P(S,N):
	if S[0:(N-1)//2]!=S[(N+1)//2:]:
		return "No"
	elif S[0:(N-1)//2]!=S[0:(N-1)//2][::-1]:
		return "No"
	else:
		return "Yes"
print(P(S,N))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
ll ans,n;
void dfs(ll cur=0,int v3=0,int v5=0,int v7=0)
{	if(cur<=n&&v3&&v5&&v7) ans++;
	if(cur>n) return;
	dfs(cur*10+3,1,v5,v7); dfs(cur*10+5,v3,1,v7); dfs(cur*10+7,v3,v5,1);
}
int main()
{	cin>>n; dfs(); cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import perm
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

########

N, M = l_inpl()
A = l_inpl()

l = [0]
for i in range(N):
    l.append((l[i]+A[i]) % M)

d = defaultdict(int)
ans = 0
for i in range(N+1):
    ans += d[l[i]] 
    d[l[i]] += 1

print(ans)

Measured memory_bytes: 68204
#define _CRT_SECURE_NO_WARNINGS_
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod = 1e9+7;
ll dp[1010][1010];
char grid[1010][1010];
int n , m;
ll solve(int i , int j){
if(i==1 && j==1)return 1;
if(i <= 0 || j <= 0)return 0;
if(dp[i][j]!=-1)return dp[i][j];
if(grid[i][j]=='#')return 0;
ll d = 0;
d=(d+solve(i-1,j))%mod;
d=(d+solve(i,j-1))%mod;
return dp[i][j]=d%mod;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int _(1);
	//cin>>_;
	while (_--) {
        cin>>n>>m;
        for(int i = 1 ; i <= n ; i ++)for(int j = 1 ; j <= m ; j++)cin>>grid[i][j];
        memset(dp,-1,sizeof dp);
        cout<<solve(n,m)<<endl;
	}
}


Measured memory_bytes: 9344
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		System.out.println("A" + s2.charAt(0)+ "C");
	}
	

	
}


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

using namespace std;
#define BUF (100005)
#define ll long long 

int n;
char s[BUF]; 

int main(void){
	cin >> n;

	//first query.
	cout << 0 << "\n";	
	char res[BUF];
	cin >> res;
	if(res[0]=='V') return 0;
	s[0]=res[0];



	int bgn=0;
	int end=n-1;	
	while(1){
		int mid = (bgn+end+1)/2;
		cout << mid << "\n";
		cin >> res;
		if(res[0]=='V') return 0;

		s[mid]=res[0];

		if((bgn-mid)%2==0){
			if(s[bgn]!=s[mid]) end = mid;			
			else bgn = mid;
		}else{
			if(s[bgn]!=s[mid]) bgn = mid;			
			else end = mid;
			
		}
	}


	return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main (void)
{
  int a, b, i, N, people = 0;

  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &a, &b);
    people = people + (b - a + 1);
  }

  printf("%d\n", people);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <unordered_map>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;


int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(a-1)*(b-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr ll P = 1e9 + 7;
//constexpr ll P = 998244353;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

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

	ll n, lim;
	cin >> n >> lim;
	vector<ll> w(n), v(n);
	for (ll i = 0; i < n; i++) cin >> w[i] >> v[i];

	vector<vector<ll>> vec(4);
	for (ll i = 0; i < n; i++) vec[w[i] - w[0]].push_back(v[i]);
	for (ll i = 0; i < 4; i++) {
		sort(ALL(vec[i]));
		vec[i].push_back(0);
		ll m = vec[i].size();
		for (ll j = m - 2; j >= 0; j--) vec[i][j] += vec[i][j + 1];
	}

	ll a = vec[0].size();
	ll b = vec[1].size();
	ll c = vec[2].size();
	ll d = vec[3].size();
	ll ans = 0;
	for (ll i = 0; i < a; i++) {
		if (w[0] * i > lim) break;
		for (ll j = 0; j < b; j++) {
			if (w[0] * i + (w[0] + 1) * j > lim) break;
			for (ll k = 0; k < c; k++) {
				if (w[0] * i + (w[0] + 1) * j + (w[0] + 2) * k > lim) break;
				ll rest = lim - w[0] * i - (w[0] + 1) * j - (w[0] + 2) * k;
				ll sum = vec[0][a - 1 - i] + vec[1][b - 1 - j] + vec[2][c - 1 - k];
				ans = max(ans, sum + vec[3][max(0ll, d - 1 - rest / (w[0] + 3))]);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
/*
    Solution by:- 
	--------------Sannidhay Vashal
	----------------NIT SRINAGAR
 
*/
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>
#include<climits>
#include<set> 
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ull unsigned long long int
#define cinll(x) ll x;cin>>x;
#define cini(x) int x;cin>>x;
#define cout(x) cout<<x;
#define vect(x) vector<ll> x;
#define vect1(x) vector<ll> x;x.push_back(0);
#define vectdef(x,size,val) vector<ll> x;for(ll i=0;i<size;i++){x.push_back(val);}
#define vectdef1(x,size,val) vector<ll> x;for(ll i=0;i<=size;i++){x.push_back(val);}
#define pb(x) push_back(x);
#define MAX INT_MAX;
#define MIN INT_MIN;
#define MOD 1000000007;
 
using namespace std;

int main(){
  cinll(n);cinll(m);
  vector<ll> arr;
  float total  = 0;
  for(ll i=0;i<n;i++){
  	cinll(x);
    arr.pb(x);
    total+=x;
  }
  sort(arr.begin(),arr.end());
  ll cntm = 0;
  for(ll i=n-1;i>=0;i--){
  	if(arr[i]>=float(total/(4*m))){
    	cntm++;
      //cout<<arr[i]<<">="<<(total/(4*m))<<"\n";
    }
  }
  if(cntm>=m){
  	cout("Yes\n");
  }else{
    cout("No\n");
  }
	return 0;
}  


Measured memory_bytes: 256
import bisect
N = int(input())
S = set([7,5,3])
for i in range(8):
    for j in S.copy():
        for k in [7,5,3]:
            S.add(10*j+k)
T = []
for i in S:
    if str(i).count('3') and str(i).count('5') and str(i).count('7'):
        T.append(i)
T.sort()
print(bisect.bisect_right(T,N))

Measured memory_bytes: 6920
#include<bits/stdc++.h>
#define mod 1000000007

using namespace std;
typedef long long int ll;

void process()
{
   int n,x,y;
   cin>>n>>x>>y;
   set<ll>s1;

   cout<<min(n*x,y)<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ll t;cin>>t;
    //while(t--)
        process();

    return 0;
}


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

    ll N; cin >> N;
	ll ans = 0;
	REP(i, N) {
		ll a; cin >> a; ans += a-1;
	}
	cout << ans << endl;
    
	return 0;
}

//*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		//int B = scanner.nextInt();
		//String S = scanner.nextLine();
		if(N % 3 == 0){
			System.out.println(N/3);
		}else if(N % 3 == 1){
			System.out.println((N-1)/3);
		}else if(N % 3 == 2){
			System.out.println((N-2)/3);
		}
		scanner.close();
	}
}


Measured memory_bytes: 23764
N, S = map(int, input().split())
A = list(map(int, input().split()))
mod = 998244353
L = [0 for _ in range(S+1)]
L[0] = 1
F = {0}
for i in range(N):
  X = [[i, L[i]] for i in F]
  for j in F:
    L[j] *= 2
    L[j] %= mod
  for j in X:
    if A[i] + j[0] <= S:
      L[A[i]+j[0]] += j[1]
      L[A[i]+j[0]] %= mod
      F.add(A[i]+j[0])
print(L[S])


Measured memory_bytes: 131500
#include <bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    FAST
    ll a,b;cin>>a>>b;
    cout<<a*b;
}


Measured memory_bytes: 3656
n = int(input())
a = list(map(int,input().split()))
arr = [0] * 8
q = 0
for i in a:
    if i >= 3200:
        q += 1
    else:
        arr[i // 400] += 1
p = 0
for i in arr:
    if i != 0:
        p += 1
print(max(1, p), p + q)


Measured memory_bytes: 3060
/*________________________Bismillahir Rahmanir Rahim___________________
|                                                                      |
|                    /\     |     | |\    |     /\     |-------        |
|                   /  \    |     | | \   |    /  \    |               |
|                  /----\   |-----| |  \  |   /----\   |-----          |
|                 /      \  |     | |   \ |  /      \  |               |
|                /        \ |     | |    \| /        \ |               |
|                     14th batch CSE , ID : 12008029                   |
|                     Comilla University                               |
|                     Email : sheikhahnafshifat@gmail.com              |
|______________________________________________________________________*/
#include<bits/stdc++.h>
using namespace std;
#define ll                      long long
#define MAX                     1234567
#define pb(x)                   push_back(x)
#define mp(x,y)                 make_pair(x,y)
#define vii                     vector<int>
#define vll                     vector<long long>
#define vp                      vector<pair<int, int> >
#define v_min(a)                *min_element(a.begin(),a.end())
#define v_max(a)                *max_element(a.begin(),a.end())
#define v_sum(a)                accumulate(a.begin(),a.end(),0)
#define un(a)                   a.erase(unique(a.begin(),a.end()),a.end())
#define SORT(a)                 sort(a.begin(),a.end())
#define AHNAF                   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define YES                     cout<<"YES"<<endl;
#define NO                      cout<<"NO"<<endl;
#define testcase(t)             int t;cin>>t;while(t--)
#define reverse(a)              reverse(a.begin(),a.end())
#define ff                      first
#define ss                      second
int main()
{
    AHNAF;
    double a;
    cin>>a;
    double ans=2*M_PI*a;
    printf("%.10f",ans);
}


Measured memory_bytes: 3804
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

int[10^^5] BS;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    size_t i;
    int cnt;
    char fst, lst;
    foreach (j, s; readln.chomp) {
        if (!j) {
            fst = lst = s;
        }
        if (lst != s) {
            BS[i++] = cnt * (lst == '0' ? -1 : 1);
            lst = s;
            cnt = 0;
        }
        ++cnt;
    }
    BS[i] = cnt  * (lst == '0' ? -1 : 1);
    auto len = i+1;

    int max_c, cur;
    i = 0;
    size_t j = 0;
    for (;;) {
        cur += abs(BS[j]);
        if (BS[j] < 0) --K;
        ++j;
        while (i < len && K < 0) {
            cur -= abs(BS[i]);
            if (BS[i] < 0) ++K;
            ++i;
        }
        max_c = max(max_c, cur);
        if (j == len) break;
    }
    writeln(max_c);
}

Measured memory_bytes: 2812
n = int(input())
a = list(map(int,input().split()))
s = 1
count = 0
l = []
for i in range(int((n-1)/2)):
    count = count + a[s-1] - a[s]
    s = s + 2
count = count + a[n-1]
l.append(count)
for i in range(n-1):
    an = (a[i])*2 - l[i]
    l.append(an)
for i in l:
    print(i, end = " ")

Measured memory_bytes: 14028
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS 
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.flush();
	long long a,b;
    cin >> a >> b;
    if(a%2 != b%2)
      cout<<"IMPOSSIBLE";
    else
      cout<<(a+b)/2;
	return 0;
	// Bye Bye 2019
}


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

#define ll long long
int main() {
  ll N;
  cin >> N;
  
  vector<ll> count(100010, 0);
  
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll x;
    cin >> x;
    sum += x;
    count[x]++;
  }
  

  
  int Q;
  cin >> Q;
  
  for (int i = 0; i < Q; i++) {
    ll B, C;
    cin >> B >> C;
    
    sum += count[B] * (C - B);
    cout << sum << endl;
    count[C] += count[B];
    count[B] = 0;
  }

  
  
}

Measured memory_bytes: 4012
N, M = map(int, input().split())
ABs = [input().split() for i in range(M)]
 
 
MPs = {}
for a, b in ABs:
    a = int(a)
    b = int(b)
    if a not in MPs:
        MPs[a] = 1
    else:
        MPs[a] += 1
    if b not in MPs:
        MPs[b] = 1
    else:
        MPs[b] += 1
 
for mp in range(1, N+1):
    if mp not in MPs:
        MPs[mp] = '0'
 
for _, y in sorted(MPs.items()):
    print(y)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define N 100001
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
 
typedef long long ll;

int main(){
    IOS;
    ll n,D;
    cin>>n>>D;
    ll x,y;
    ll cnt=0;
    for(ll i=0;i<n;i++){
        cin>>x>>y;
        long double dist = sqrt(x*x + y*y);
        if(dist <= D){
            cnt++;
        }
    }

    cout<<cnt;

    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n;
	while (cin >> n, n)
	{
		vector<ll> map;
		vector<vi> day(50);
		REP(i, n)
		{
			int k, t;
			cin >> k;
			REP(j, k)
			{
				cin >> t;
				day[t].push_back(i);
			}
		}
		REP(i, n)
		{
			map.push_back((ll)1 << i);
		}
		REP(i, 50)
		{
			ll tmp = 0;
			REP(j, day[i].size()) tmp = tmp | map[day[i][j]];
			REP(j, day[i].size()) map[day[i][j]] = tmp;
			if (tmp == (((ll)1 << n) - 1))
			{
				cout << i << endl;
				goto end;
			}
		}
		puts("-1");
	end:;
	}
	return 0;
}

Measured memory_bytes: 1236
N, Y = map(int, input().split())
for i in range(N + 1):
    for j in range(N + 1):
        k = int((Y - 10000 * i - 5000 * j) / 1000)
        if k >= 0 and k <= N:
            if N == i+k+j:
                print(i, j, k)
                exit()
print("-1 -1 -1")

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

int main(){
  int n,t;
  cin >> n >> t;
  vector<int> cost(0);
  for(int i=0;i<n;i++){
    int x,y;  cin >> x >> y;
    if(y<=t) cost.push_back(x);
  }
  sort(cost.begin(),cost.end());
  if(cost.size()>0) cout << cost.at(0) << endl;
  else cout << "TLE" << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += 2 * min(x.at(i), K - x.at(i));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

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

    int n1 = s[0] - '0';
    int n2 = s[1] - '0';
    int n3 = s[2] - '0';
    int n4 = s[3] - '0';

    int a = n1 * 10 + n2;
    int b = n3 * 10 + n4;

    if (1 <= a && a <= 12)
    {
        if (1 <= b && b <= 12)
        {
            cout << "AMBIGUOUS";
        }
        else
        {
            cout << "MMYY";
        }
    }
    else if (a >= 13 || a == 0)
    {
        if (1 <= b && b <= 12)
        {
            cout << "YYMM";
        }
        else
        {
            cout << "NA";
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

int main(){
    using namespace std;

    int count = 0;
    string line;
    cin >> count;
    cin.ignore();
    getline( cin, line );

    istringstream stream( line );
    string field;
    vector<string> splitData;
    splitData.reserve( count );
    while( getline( stream, field, ' ' ) ){
        splitData.push_back( field );
    }

    if( splitData.size() == 0 ){ return 0; }

    long min   = 1000000;
    long max   = -1000000;
    long total = 0;
    for( const string& str : splitData ){
        int number = stoi( str );

        if( number < min ){ min = number; }
        if( number > max ){ max = number; }
        total += number;
    }

    cout << min << ' ' << max << ' ' << total << endl;
    
    return 0;
}

Measured memory_bytes: 1788
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float("inf")

for i in range(N - K + 1):
    if X[i] * X[K + i - 1] >= 0:
        ans1 = abs(X[i])
        ans2 = abs(X[K + i - 1])
        buf_ans = max(ans1, ans2)
        ans = min(ans, buf_ans)
    else:
        ans1 = abs(X[i])*2 + abs(X[K + i - 1])
        ans2 = abs(X[i]) + abs(X[K + i - 1])*2
        ans = min(ans, ans1, ans2)

print(ans)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
 
int rate(int x){
  if(x>=1 && x<=399){
    return 0;
  }else if(x>=400 && x<=799){
    return 1;
  }else if(x>=800 && x<=1199){
    return 2;
  }else if(x>=1200 &&x<=1599){
    return 3;
  }else if(x>=1600 && x<=1999){
    return 4;
  }else if(x>=2000 && x<=2399){
    return 5;
  }else if(x>=2400 && x<=2799){
    return 6;
  }else if(x>=2800 && x<=3199){
    return 7;
  }else{
    return 8;
  }
}

int main() {
  int N;
  cin >> N;
  
  vector<int> count(9,0);
  
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
    
    int color;
    color=rate(a[i]);
    count[color]++;
  }
  
  int answer=0;
  for(int i=0; i<8;i++){
    if(count[i]!=0){
      answer++;
    }
  }
  
  if(answer==0){
    cout << "1"<<" ";
  }else{
    cout << answer<<" ";
  }
    
   
  cout <<answer+count[8] << endl;   
  
}

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

int main() {
  vector<int> num(200);
  int n,count=0;
  bool flag=false;

  cin >> n;
  rep(i,n) cin >> num[i];

  while(1){
    rep(i,n){
      if(num[i]%2){
        flag=true;
        break;
      }else num[i] /= 2;
    }
    if(flag) break;
    count++;
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int number=0;
            int upstatus=0;
            boolean nowFloor = true;
            List<String> action = new ArrayList<String>();
            int up=sc.nextInt();
            if(up==0)break;
            for (int i = 0; i <up; i++) {
                action.add(sc.next());
            }//???????????£??¨??°?????????????????\?????????????°????
            for (String upString : action) {
                if (upString.equals("lu") || upString.equals("ru")) {
                    upstatus++;
                } else {
                    upstatus--;
                }
                if (nowFloor && upstatus == 2) {
                    nowFloor = false;number++;
                }
                if (!nowFloor && upstatus == 0) {
                    nowFloor = true;number++;
                }
            }System.out.println(number);
        }
    }
}

Measured memory_bytes: 36964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    string S;cin>>S;
	if(S[2] == S[3] and S[4] == S[5]) Yes
	No
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);

		boolean a[] = new boolean [50001];
		Arrays.fill(a, true);
		a[0]=a[1]=false;
		for(int i=0; i*i<=50000;i++)
		{
			if(!a[i])
				continue;
			for(int j=i*2; j<=50000; j+=i)
				a[j]=false;
		}

		while(sc.hasNext())
		{
			int n=sc.nextInt();
			if(n==0)
				return;
			int ans=0;

			for(int i=1; i<=n/2; i++)
			{
				if(!a[i])
					continue;
				if(a[n-i])
				{
					//System.out.println(i+" "+(n-i));
					ans++;
				}
			}
			System.out.println(ans);

		}
	}

}

Measured memory_bytes: 13000
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N, L; cin>>N>>L;
  int sum = 0, min_v = 1<<30;
  REP(i,N) {
    int a = L+i;
    sum	+= a;
    if(abs(min_v) > abs(a)) min_v = a;
  }
  cout <<  sum - min_v << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (ll)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
// メイン
int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];

	multiset<int> val;
	val.insert(A[0]);
	REPN(i, 1, N) {
		auto it = val.lower_bound(A[i]);
		if (it == val.begin()) {
			val.insert(A[i]);
		} else {
			val.erase(--it);
			val.insert(A[i]);
		}
	}

	cout << val.size() << endl;
	return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int x1,y1,x2,y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int x3,y3,x4,y4;
	int dx = x2-x1,dy = y2-y1;
	y3 = y2 + dx,x3 = x2 - dy;
	y4 = y3 - dy,x4 = x3 - dx;
	printf("%d %d %d %d\n",x3,y3,x4,y4);

	return 0;
}


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

int main(){
  int A , B;
  cin >> A >> B;
  if(A % 2 == 0 && B % 2 == 0) cout << (A + B) / 2 << endl;
  else if(A % 2 == 1 && B % 2 == 1) cout << (A + B) / 2 << endl;
  else cout << "IMPOSSIBLE" << endl;
}


 
 
 

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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define len(s) s.length()
#define forp(i,a,b) for( i=a;i<=b;i++)
#define FOR(tt,a,b) for(int tt=a;tt<=b;tt++)
#define rep(i,n)    for( i=0;i<n;i++)
#define ren(i,n)    for( i=n-1;i>=0;i--)
#define forn(i,a,b) for( i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define b(v) v.begin()
#define e(v) v.end()
#define mem(n,m) memset(n,m,sizeof(n))
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define pll pair<long long,long long>
#define vii vector<int>
#define vll vector<long long>
#define gl(cin,s)  getline(cin,s);
#define bitc(n) __builtin_popcountll(n)
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define SIZE 100001

typedef long long  ll;
typedef unsigned long long ull;
typedef long double  ldo;
typedef double  db ;
using namespace std;
int main()
{  	
	/* #ifndef ONLINE_JUDGE
	freopen(fi, "r", stdin);
	#endif */
	//freopen("route.in","r",stdin);
	//freopen("route.out","w",stdout);
	//cin.ignore();
	//cin.clear();
	boost;
	//cin.tie(0);
	//cout<<"Case #"<<tt<<": ";
	string s1,s2;
	cin>>s1>>s1>>s2;
	cout<<"A"<<s1[0]<<"C"<<endl;
	return 0;
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    int n;
    cin>>n;
    cout<<(n/2+ (n&1));
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	string s;
    cin >> s;
    s+= "aaa";
    if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
        cout << "Yes" << endl ;
    }else {
	   cout << "No" << endl;
    }
	

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
long long a[200005];
inline long long read(){
	long long x=0; int w=0; char ch=0;
	while (ch<'0'||ch>'9') w|=ch=='-',ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w? -x:x;
}
int main(){
	int n=read();
	for (int i=1; i<=n; i++) a[i]=read();
	long long sum=0;
	a[0]=0;  a[n+1]=0;
	for (int i=1; i<=n; i++) sum+=abs(a[i]-a[i-1]);
	sum+=abs(a[n+1]-a[n]);
	for (int i=1; i<=n; i++){
	    long long ans=sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]);
	    printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2048
while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    c = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i+j+k == x: c+=1
    print(c)

Measured memory_bytes: 7612
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	foreach (line; stdin.byLine) {
		auto str = line.chomp;
		if (str.length == 1) break;
		auto aScore = str[1..str.length].count!(a => a == 'A');
		auto bScore = str[1..str.length].count!(a => a == 'B');
		if (aScore > bScore) aScore++;
		else bScore++;
		writeln(aScore, " ", bScore);
	}
}

Measured memory_bytes: 1036
import sys

input = sys.stdin.readline


def main():
    N, A, B = map(int, input().split())
    max_XY = min(A, B)
    min_XY = max(A + B - N, 0)
    print("{} {}".format(max_XY, min_XY))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
while True:
    N,M,A = map(int,input().split())
    if N == 0: break
    amd = [{} for i in range(1001)]
    for i in range(M):
        h,p,q = map(int,input().split())
        amd[h][p] = q
        amd[h][q] = p

    now = A
    for d in reversed(amd):
        if now in d:
            now = d[now]
    print(now)

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

int main() {
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 1; i <= N; i += 2) {
		int yakusu = 0;
		for (int n = 1; n <= i; ++n) {
			if (i%n == 0) ++yakusu;
		}
		if (yakusu == 8)++ans;
	}
	cout << ans;

	return 0;

}


Measured memory_bytes: 256
n=int(input())
ab=list()
cd=list()
for i in range(n):
    ab.append(list(map(int,input().split())))
for j in range(n):
    cd.append(list(map(int,input().split())))
cd.sort(key=lambda x:x[0])
AB=[[-1,-1]]*n
for i in range(n):
    S=[x for x in ab if x[0]<cd[i][0] and x[1]<cd[i][1]]
    S.sort(key=lambda k:k[1])
    if len(S)>0:
        AB[i]=S[-1]
        ab.remove(S[-1])
print(len(AB)-AB.count([-1,-1]))
      

Measured memory_bytes: 39024
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

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

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

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

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

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


N, M, *AB = map(int, read().split())
A = AB[::2]
B = AB[1::2]

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j, (a, b) in enumerate(zip(A, B)):
        if i != j:
            uf.union(a - 1, b - 1)
    if uf.group_count() > 1:
        ans += 1

print(ans)


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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = 2e15+7;
const ll mod = 1e9+7;
const int MAX_N = 5e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

int main() {
	ll n=in();
	ll a[n],dif[n],sum=0;
	REP(i,n) {
		a[i]=in();sum+=a[i];
	}
	REP(i,n) {
		dif[i]=a[i]-a[(i+1)%n];
	}
	ll A0=0,ncnt=0,cnt=(sum*2)/(n*(n+1));
	REP(i,n) {
		ll x=0;//x-N
		if ((cnt+dif[i])%n) {cout << "NO" << endl;return 0;}
		else {
			x = (cnt+dif[i])/n;
			if (x > cnt || x < 0) {cout << "NO" << endl;return 0;}
			ncnt+=x;
			A0+=(n-i)*x;
		}
	}
	if (ncnt==cnt && a[0]==A0) {cout << "YES" << endl;}
	else {cout << "NO" << endl;}
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<set>
#include<deque>
using namespace std;
char str[20][20];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		int sr,sc;
		int gr,gc;
		set<int>v;
		int m=0;
		int st=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<b;j++){
				if(str[i][j]=='@'){sr=i;sc=j;}
				if(str[i][j]=='E'){gr=i;gc=j;}
				if(str[i][j]=='c'){
					st*=100;
					st+=i*10+j;
					m++;
				}
			}
		}
		st*=100;
		st+=sr*10+sc;
		deque<pair<int,int> >Q;
		bool yet=true;
		Q.push_back(make_pair(0,st));
		while(Q.size()){
			int cost=Q.front().first;
			int at=Q.front().second;
			Q.pop_front();
			if(v.count(at))continue;
			
		//	printf("%d %d\n",cost,at);
			v.insert(at);
			if(at%100==gr*10+gc){
				yet=false;
				printf("%d\n",cost);
				break;
			}
			int row=at%100/10;
			int col=at%10;
			int tmp=at;
			tmp/=100;
			int br[5];
			int bc[5];
			for(int i=0;i<m;i++){
				br[i]=tmp%100/10;
				bc[i]=tmp%10;
				tmp/=100;
			}
			for(int i=0;i<4;i++){
				if(0<=row+dx[i]&&row+dx[i]<a&&0<=col+dy[i]&&col+dy[i]<b&&str[row+dx[i]][col+dy[i]]!='#'){
					bool W=false;
					bool C=false;
					for(int j=0;j<m;j++)if(row+dx[i]==br[j]&&col+dy[i]==bc[j])C=true;
					if(str[row+dx[i]][col+dy[i]]=='w')W=true;
					if(C&&!W){
						int nr=row+dx[i];
						int nc=col+dy[i];
						while(str[nr+dx[i]][nc+dy[i]]!='#'){
							nr+=dx[i];nc+=dy[i];
							bool nk=false;
							bool nw=false;
							for(int j=0;j<m;j++)if(nr==br[j]&&nc==bc[j])nk=true;
							
							if(str[nr][nc]=='w')nw=true;
							if(nw&&!nk)break;
							if(nk&&!nw){
								nr-=dx[i];nc-=dy[i];break;
							}
						}
						int to=at;
						for(int j=0;j<m;j++)if(row+dx[i]==br[j]&&col+dy[i]==bc[j]){
							int ad=1;
							for(int k=0;k<j*2+2;k++)ad*=10;
							to-=to%(ad*100)-to%ad;
							to+=ad*(nr*10+nc);
						}
						if(v.count(to))continue;
						Q.push_front(make_pair(cost,to));
					}
					if(W&&!C)continue;
					if(C&&!W)continue;
					int to=at-at%100+(row+dx[i])*10+col+dy[i];
					if(v.count(to))continue;
					Q.push_back(make_pair(cost+1,to));
				}
			}
		}
		if(yet)printf("-1\n");
	}
}

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

int main() {
  string s;
  bool cond = true;
  cin >> s;
  rep(i,s.size() / 2){
    if (s[i] != s[s.size() - 1 - i]) {
      cond = false;
    }
  }
  rep(i, s.size() / 2){
    if (s[i] != s[s.size() / 2 - 1 - i]){
      cond = false;
    }
  }
  rep(i, s.size() / 2){
    if (s[i + s.size() / 2 + 1] != s[s.size() - 1 - i]){
      cond = false;
    }
  }
  cout << (cond? "Yes":"No")<< endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)

int main()
{
   int n,k;
   cin >> n >> k;
   multimap<int,int> p;
   rep(i,0,n){
     int temp;
     cin >> temp;
     p.insert(make_pair(temp, i));
   }
   int c=0;
   int ans = 0;
   for (auto const& i: p)
    {
      ans += i.first;
      c++;
      if(c==k){
        break;
      }
    }
    cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    map<int,ll> mp1,mp2;
    rep(i,n){
        int a;
        cin >> a;
        mp1[a+i+1]++;
        mp2[i+1-a]++;
    }
    ll ans = 0;
    for(auto x:mp1){
        if(mp2.count(x.first))ans += x.second*mp2[x.first];
    }
    cout << ans << endl;
}

Measured memory_bytes: 26592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a(5);
    int k;
    string ans="Yay!";
    REP(i,5) cin>>a[i];
    cin>>k;
    REP(i,5) REP(j,5){
        if(j<=i) continue;
        if(abs(a[j]-a[i]>k)) ans=":(";
    }
    cout<<ans<<endl;
}


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

int n;
LL a[405];
LL pref[405];
LL dp[405][405];

int main(){
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
		pref[i] = pref[i-1] + a[i];
	}
	for (int i = 1; i <= n; i++)
		dp[i][i] = 0;
	for (int len = 2; len <= n; len++){
		for (int i = 1; i + len - 1 <= n; i++){
			dp[i][i+len-1] = 1e18;
			for (int k = i; k <= i + len - 1; k++){
				dp[i][i+len-1] = min(dp[i][i+len-1], dp[i][k] + dp[k+1][i+len-1] + pref[i+len-1] - pref[i-1]);
			}
		}
	}
//	for (int i = 1; i<= n; i++) for (int j = 1; j <= n; j++) cout << dp[i][j] << " \n"[j==n];
	cout << dp[1][n] << '\n';
	return 0;
}


Measured memory_bytes: 1536
import scala.io.{StdIn => in}

object Main extends App {
  val s = in.readLine
  val t = in.readLine
  val tabale = Array.ofDim[Char](26)

  val res = s./:(true, 0){ case ((b, i), ch) => {
    val c1 = ch - 'a'
    val c2 = t(i) - 'a'
    if(b && tabale(c1) == 0 && tabale.forall(_ != t(i))) {
      tabale(c1) = t(i)
      (b,i+1)
    }
    else if(b && tabale(c1) == t(i)) (b, i+1)
    else (false, i+1)
  }}._1

  // println(tabale.mkString)
  val ans = if(res) "Yes" else "No"
  println(ans)
}

Measured memory_bytes: 37952