akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll= long long;
using ld= long double;
using vi= vector<int>;
using vl= vector<ll>;
using vd= vector<ld>;
using vs= vector<string>;
using vb= vector<bool>;
using vvi= vector<vector<int>>;
using vvl= vector<vector<ll>>;
using vvd= vector<vector<ld>>;
using vvs= vector<vector<string>>;
using vvb= vector<vector<bool>>;
using pll= pair<ll, ll>;
constexpr ll mod= 998244353;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for(ll(i)= 0; (i) < (n); (i)++)
#define REPS(i, n) for(ll(i)= 1; (i) <= (n); (i)++)
#define RREP(i, n) for(ll(i)= (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for(ll(i)= (n); (i) > 0; (i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())
#define YES(n) ((n) ? "YES" : "NO")
#define Yes(n) ((n) ? "Yes" : "No")
#define yes(n) ((n) ? "yes" : "no")

template <class T>
inline void chmin(T &a, T b) {
    if(a > b) { a= b; }
}

template <class T>
inline void chmax(T &a, T b) {
    if(a < b) { a= b; }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

vl ten;
ll N;

struct S {
    ll value;
    ll l;
    ll r;
};

S op(S l, S r) { return {modu(l.value + r.value), min(l.l, r.l), max(l.r, r.r)}; }

S e() { return {0, 0, 0}; }

S mapping(ll l, S r) {
    if(l ==100) {
        return r;
    } else {
        return {modu((ten[N-r.l] - ten[N-r.r])*l),r.l,r.r};
    }
}

ll composition(ll l, ll r) {
    if(l == 100) {
        return r;
    } else {
        return l;
    }
}

ll id() { return 100; }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    ll Q;
    cin >> N >> Q;
    ten.assign(N,0);
    ten[0]= 0;
    ten[1] = 1;
    REPS(i, N - 1) ten[i+1]= modu((ten[i] + (ten[i] - ten[i-1])*10));
    lazy_segtree<S, op, e, ll, mapping, composition, id> seg(N);
    REP(i,N){
        seg.set(i,{modu(ten[N-i]-ten[N-1-i]),i,i+1});
    }
    REP(i, Q) {
        ll l, r, d;
        cin >> l >> r >> d;
        seg.apply(l - 1, r, d);
        cout << seg.all_prod().value << "\n";
    }
}

Measured memory_bytes: 23828
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

const ll p = 998244353LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	ll n,x,m;
	cin>>n>>x>>m;
	vector<bool> vis((int)m + 1);
	ll ans = 0LL;

	vector<ll> seq;

	while(!vis[(int)x])
	{
		vis[(int)x]=1;
		seq.push_back(x);
		n--;

		// cout << x << endl;

		ans += x;
		// ans %= m;

		if(n==0LL) 
		{
			cout << ans << endl;
			return 0;
		}

		x = x*x;
		x %= m;
	}

	reverse(all(seq));
	while(seq.back()!=x) seq.pop_back();
	reverse(all(seq));

	ll seq_sum = 0LL;

	for(auto thing : seq)
	{
		seq_sum += thing;
		// seq_sum %= m;
	}

	ans += ll(n/ll(len(seq))) * seq_sum;
	n -= ll(n/ll(len(seq))) * ll(len(seq));

	for(int i=0; i<(int)n; i++)
	{
		ans += seq[i];
		// ans %= m;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3864
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;

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

const long long INF = 1LL << 60;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

    int h[100100][3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> h[i][j];
        }
    }

    ll dp[100100][3];
    for(int i = 0; i < 100100; i++){
        for(int j = 0; j < 3; j++){
            dp[i][j] = 0;
        }
    }



    int previous;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k)continue;
                dp[i + 1][k] = max((ll)dp[i + 1][k], (ll)dp[i][j] + h[i][k]);
            }
        }
    }

    ll ans = 0;

    for(int i = 0; i < 3; i++){
        ans = max((ll)ans, (ll)dp[n][i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int N, M, R;
double S[2000][4], T[15][4], E[3];

void read();
void solve();

int main() {
	cout.setf(ios::fixed), cout.precision(10);
	while (cin >> N >> M >> R, N + M + R)
		read(), solve();
	
	return 0;
}

void read() {
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < 4; ++j)
			cin >> S[i][j];
	
	for (int i = 0; i < M; ++i)
		for (int j = 0; j < 4; ++j)
			cin >> T[i][j];
	
	cin >> E[0] >> E[1] >> E[2];
}

void solve() {
	static int f[2000];
	double res = 0, lv[15];
	
	fill(&f[0], &f[N], 0);
	for (int i = 0; i < M; ++i) {
		double ux = T[i][0] - E[0], uy = T[i][1] - E[1], uz = T[i][2] - E[2];
		lv[i] = T[i][3] / (ux * ux + uy * uy + uz * uz);
		for (int j = 0; j < N; ++j) {
			double vx = S[j][0] - E[0], vy = S[j][1] - E[1], vz = S[j][2] - E[2];
			double wx = S[j][0] - T[i][0], wy = S[j][1] - T[i][1], wz = S[j][2] - T[i][2];
			double d = 0;
			
			if (ux * vx + uy * vy + uz * vz < 0)
				d = sqrt(vx * vx + vy * vy + vz * vz);
			else if ((-ux) * wx + (-uy) * wy + (-uz) * wz < 0)
				d = sqrt(wx * wx + wy * wy + wz * wz);
			else {
				double x_ = uy * vz - uz * vy, y_ = uz * vx - ux * vz, z_ = ux * vy - uy * vx;
				d = sqrt((x_ * x_ + y_ * y_ + z_ * z_) / (ux * ux + uy * uy + uz * uz));
			}
			
			if ((sqrt(wx * wx + wy * wy + wz * wz) > S[j][3] || sqrt(vx * vx + vy * vy + vz * vz) > S[j][3]) && d < S[j][3])
				f[j] |= 1 << i;
		}
	}
	
	for (int s = 0; s < (1 << M); ++s) {
		double tmp = 0;
		int cnt = 0;
		
		for (int i = 0; i < M; ++i)
			if (s & (1 << i))
				tmp += lv[i];
		
		for (int i = 0; i < N; ++i)
			if (s & f[i])
				++cnt;
		
		if (cnt <= R)
			res = max(res, tmp);
	}
	
	cout << res << "\n";
}

Measured memory_bytes: 1364
n = int(input())
a_list = sorted(map(int, input().split()),reverse=True)

ans = 0
ans += a_list.pop(0)
cnt = 2
times_2 = 0
times_1 = 0
while 1:
  if cnt == n:
    break
  if n - cnt >= 2:
    cnt += 2
    times_2 += 1
  else:
    cnt += 1
    times_1 += 1
      
ind = 0
for i in range(times_2):
  ans += 2 * a_list[i]
  ind += 1
  
for i in range(times_1):
  ans += a_list[ind + i]

print(ans)

Measured memory_bytes: 31580
#include <bits/stdc++.h> 
#define LL long long int
using namespace std; 

int main() 
{
    int n;
    cin>>n;
    int a[n+5];
    for(int i=0; i<n; i++) {
        int temp; cin>>temp;
        a[temp] = i+1;
    } 

    for(int i=1; i<=n; i++) {
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll d=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            d=max(d,abs(a[i]-a[j]));
        }
    }
    cout<<d<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from bisect import *
n,*l=map(int, open(0).read().split())
l.sort()
n = len(l)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if len({l[i],l[j],l[k]}) ==3 and l[i] + l[j] > l[k] and l[i] > l[k]- l[j]:
                ans +=1
print(ans)



Measured memory_bytes: 9200
N = int(input())
A = [0]*N
xy = [[] for i in range(N)]
for i in range(N):
    A[i] = int(input())
    xy[i] = [tuple(map(int, input().split())) for i in range(A[i])]

ans = 0
for i in range(2**N):
    kind = [False]*N
    for j in range(N):
        if (i >> j) % 2 == 1:
            kind[j] = True

    flag = True
    tmp = 0
    for j in range(N):
        if kind[j]:
            tmp += 1

            for x, y in xy[j]:
                if (y == 1 and kind[x-1]) or (y == 0 and kind[x-1] == False):
                    continue

                else:
                    flag = False
                    tmp = 0
                    break

        if flag == False:
            tmp = 0
            break

    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
N,C = map(int,input().split())

D = []
c = []
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

d = {}
d[0] = {}
d[1] = {}
d[2] = {}
for i in range(C):
    d[0][i] = 0
    d[1][i] = 0
    d[2][i] = 0

for k in range(C):
    for i in range(N):
        for j in range(N):
            d[(i+j) % 3][k] += D[c[i][j]-1][k]



import itertools
ans = 10**50
l = []
for i in range(C):
    l.append(i)

for li in itertools.permutations(l,3):
    ans = min(ans , d[0][li[0]] + d[1][li[1]] + d[2][li[2]])
print(ans)


Measured memory_bytes: 44892
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
for i in range(n):
    a[i] = int(input())-1
s = set()
c = 0
while True:
#     print(c)
    if c in s:
        ans = -1
        break
    s.add(c)
    c = a[c]
    if c==1:
        ans = len(s)
        break
print(ans)

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);i++)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int a, b;
  cin >> a >> b;
  if(a*b % 2 == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    map<int,int> xmp, ymp;
    vector<int> A(N),B(N),C(N);
    vector<int> D(M),E(M),F(M);
    xmp[0] = 0;
    ymp[0] = 0;
    for (int i=0;i<N;i++){
        cin >> A[i] >> B[i] >> C[i];
        xmp[A[i]] = 0;
        xmp[B[i]] = 0;
        ymp[C[i]] = 0;
    }
    for (int i=0;i<M;i++){
        cin >> D[i] >> E[i] >> F[i];
        ymp[E[i]] = 0;
        ymp[F[i]] = 0;
        xmp[D[i]] = 0;
    }
    vector<int> xs, ys;
    for (auto& p : xmp){
        p.second = xs.size();
        xs.push_back(p.first);
    }
    for (auto& p : ymp){
        p.second = ys.size();
        ys.push_back(p.first);
    }

    int X = xs.size()*2;
    int Y = ys.size()*2;

    vector<vector<int>> s = vector<vector<int>>(X,vector<int>(Y));
    for (int i=0;i<N;i++){
        int a = 2*xmp[A[i]];
        int b = 2*xmp[B[i]];
        int c = 2*ymp[C[i]];
        for (int x=a;x<=b;x++) s[x][c] = -1;
    }
    for (int i=0;i<M;i++){
        int e = 2*ymp[E[i]];
        int f = 2*ymp[F[i]];
        int d = 2*xmp[D[i]];
        for (int y=e;y<=f;y++) s[d][y] = -1;
    }
    
    queue<pair<int,int>> q;
    q.push(make_pair(xmp[0]*2,ymp[0]*2));
    s[xmp[0]*2][ymp[0]*2] = 1;
    while (!q.empty()){
        pair<int,int> p = q.front();q.pop();
        for (int d=0;d<4;d++){
            int nx = p.first + dx[d];
            int ny = p.second + dy[d];
            if (nx < 0 || nx >= X || ny < 0 || ny >= Y) continue;
            if (s[nx][ny] != 0) continue;
            s[nx][ny] = 1;
            q.push(make_pair(nx,ny));
        }
    }
    ll ans = 0;
    for (int x=0;x<X;x++){
        for (int y=0;y<Y;y++){
            if (s[x][y] != 1) continue;
            if (x==0||x==X-1||y==0||y==Y-1){
                cout << "INF" << "\n";
                return 0;
            }
            if (x%2 == 0 || y%2 == 0) continue;
            ans += 1LL*(xs[x/2+1] - xs[x/2])*(ys[y/2+1] - ys[y/2]);
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 144452
T=[]
t=[]
for i in range(5):
    T.append(int(input()))
    t.append(T[i]%10)
if max(t) == 0 :
    ans = sum(T)
else :
    while 0 in t  :
        t.remove(0)
    ans = sum(T)+10*len(t)-sum(t)-10+min(t)
print(ans)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
N, K = map(int, raw_input().split())
a_arr = map(int, raw_input().split())

a_dic = {}

for idx in range(0, N):
  if str(a_arr[idx]) in a_dic:
    a_dic[str(a_arr[idx])] += 1
  else:
    a_dic[str(a_arr[idx])] = 1

a_len = len(a_dic.keys())

# https://qiita.com/shizuma/items/40f1fe4702608db40ac3
counter = 0
sum_val = 0
for k, v in sorted(a_dic.items(), key=lambda x: x[1]):
  if a_len - counter <= K:
    break
  sum_val += v
  counter += 1

print(sum_val)

# https://atcoder.jp/contests/abc081/tasks/arc086_a

Measured memory_bytes: 58744
n, x = map(int, input().split())
L = list(map(int, input().split()))

D = [0] * (n + 1)
for i in range(n):
    D[i + 1] = D[i] + L[i]

from bisect import bisect_left, bisect_right

idx = bisect_right(D, x)
print(len(D[:idx]))


Measured memory_bytes: 38384
n, h = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)], key = lambda x: x[1], reverse = True)

m = sorted(ab, key = lambda x: x[0], reverse = True)[0][0]

ans = 0
for a, b in ab:
    if h > 0 and b >= m:
        h -= b
        ans += 1
    else:
        break

ans += -(-max(h, 0) // m)

print(ans)

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

string s[100];
int n, m, arr[100][100];

int main(){
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    cin >> s[i];
    s[i] = "0" + s[i];
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(s[i][j] == '#'){
        for(int k = -1; k <= 1; k++){
          for(int l = -1; l <= 1; l++){
            arr[i+k][j+l]++;
          }
        }
      }
    }
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(s[i][j] == '#'){
        cout << "#";
      }else{
        cout << arr[i][j];
      }
    }
    cout << endl;
  }
}

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

using namespace std;

using int64 = long long;

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

  deque< pair< int, int > > que;
  int v[100001];
  fill_n(v, 100001, 11451419);

  que.emplace_front(1, 1 % N);
  v[1 % N] = 1;

  while(!que.empty()) {
    int cost, num;
    tie(cost, num) = que.front();
    que.pop_front();
    if(cost < v[(num * 10) % N]) {
      que.emplace_front(cost, (num * 10) % N);
      v[(num * 10) % N] = cost;
    }
    if(cost + 1 < v[(num + 1) % N]) {
      que.emplace_back(cost + 1, (num + 1) % N);
      v[(num + 1) % N] = cost + 1;
    }
  }

  cout << v[0] << endl;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < x + k - 1; i++) {
        cout << i << " ";
    }
    cout << x + k - 1 << endl;
}


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

using namespace std;

const long long INF = 1e18;
const int N = 1e5;

const double PI = acos(-1);



int main() {
    string s;
    cin >> s;
    bool f = 1;
    for (int i = 1; i <= s.size(); i++) {
        if (i & 1) {
            if (s[i - 1] == 'L')
                f = 0;
        } else {
            if (s[i - 1] == 'R')
                f = 0;
        }
    }
    cout << (f ? "Yes" : "No");
}


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

int main(void)
{
	int a,b,c,d,e,f;
	float x,y;
	while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF){
		x = ((float)c * e - (float)b * f) / ((float)a * e - (float)b * d);
		y = ((float)a * f - (float)c * d) / ((float)a * e - (float)b * d);
		if(x <= 0.0 && x > -5.0e-4)
			x = 0.0;
		if(y <= 0.0 && y > -5.0e-4)
			y = 0.0;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 636
L1 = input()
L2 = list(map(int,input().split()))
L3 = L2.copy()
L3.sort()

cnt = 0

for a ,b in zip(L2 , L3) :
  if a != b:
    cnt += 1

if cnt == 2 or cnt == 0:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n;
  ccin >> n;
  string s;
  ccin >> s;

  vector<bool> ans(n);
  bool isOK = false;
  rep(j, 4) {
    bool a1 = (j & 0b01) != 0;
    bool a2 = (j & 0b10) != 0;
    vector<bool> animal(n);
    animal[0] = a1;
    animal[1] = a2;
    REP(i, 2, n) {
//      ll ii = i == n - 1 ? 0 : i;
      if (s[i - 1] == 'o')
        animal[i] = animal[i - 1] ? animal[i - 2] : !animal[i - 2];
      else
        animal[i] = animal[i - 1] ? !animal[i - 2] : animal[i - 2];
    }
    //judge
    isOK = false;
    if (s[n - 1] == 'o') {
      if (animal[n - 1])
        isOK = animal[n - 2] == animal[0];
      else
        isOK = animal[n - 2] xor animal[0];
    } else {
      if (animal[n - 1])
        isOK = animal[n - 2] xor animal[0];
      else
        isOK = animal[n - 2] == animal[0];
    }
    if (s[0] == 'o') {
      if (animal[0])
        isOK = isOK and (animal[n - 1] == animal[1]);
      else
        isOK = isOK and (animal[n - 1] xor animal[1]);
    } else {
      if (animal[0])
        isOK = isOK and (animal[n - 1] xor animal[1]);
      else
        isOK = isOK and (animal[n - 1] == animal[1]);
    }

    if (isOK) {
      ans = animal;
      break;
    }
  }
  if (isOK) {
    for (auto i : ans) {
      ccout << (i ? "S" : "W");
    }
  } else {
    ccout << -1;
  }
  ccout << endl;
}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 592
ans_list = []

while True:
    m, t, p, r = map(int, input().split())
    if m == 0 and t == 0 and r == 0 and p == 0:
        break

    team = [[[0, 1] for i in range(p)] for j in range(t)]

    for i in range(r):
        M, T, P, J = map(int, input().split())
        if J:
            team[T - 1][P - 1][0] += 20
        else:
            team[T - 1][P - 1][0] += M
        team[T - 1][P - 1][1] = J
    #    print(1, M, T, P, J)

    team_point = []
    for i in range(t):
        point = [0, 0, i]
        for j in range(p):
            if team[i][j][1] == 0:
                point[0] += 1
                point[1] += team[i][j][0]
        point[1] *= -1
        team_point.append(point)

    team_point.sort()
    team_point = team_point[::-1]
    ans = []
    same_point = [str(team_point[0][2] + 1)]
    for i in range(1, len(team_point)):
        if team_point[i][0] == team_point[i - 1][0]:
            if team_point[i][1] == team_point[i - 1][1]:
                same_point = [same_point[0] + "=" + str(team_point[i][2] + 1)]
            else:
                ans.append(same_point)
                same_point = [str(team_point[i][2] + 1)]
        else:
            ans.append(same_point)
            same_point = [str(team_point[i][2] + 1)]

    ans.append(same_point)
    ans_list.append(ans)
  #  print(team_point)
#    print(ans)
 #   print(team_point)

#print(ans_list)
for I in range(len(ans_list)):
    i = ans_list[I]
    for j in range(len(i)):
        print(i[j][0], end = "")
        if j != len(i) - 1:
            print(",", end = "")
    print()



Measured memory_bytes: 5792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    ll k = (a+b)/2;
    if(abs(a-k) == abs(b-k)) cout << k << endl;
    else cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	int sum = 0;

	if (n >= k) {
		for (int i = 0; i < k; i++) {
			sum += x;
		}

		for (int i = k; i < n; i++) {
			sum += y;
		}
	}

	else {
		for (int i = 0; i < n; i++) {
			sum += x;
		}
	}
	cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

template <class T> T read() { T t; cin >> t; return t; }
template <class T> vector<T> read_n(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> void write(const T &t) { cout << t << endl; }
struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
void solve();
int main() { solve(); return 0; }
/// template end ///

void solve()
{
	while (true)
	{
		READ(int, n, p);
		if (!n && !p) { break; }

		vector<int> tbl(n);
		int w = p;
		REP(i,INF)
		{
			int &u = tbl[i % n];
			if (!w) { swap(u, w); } else { w--; u++; }
			if (u == p) { write(i % n); break; }
		}
	}
}

Measured memory_bytes: 1196
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;

struct good
{
    int w,v;
}g[110];

bool cmp(good a,good b)
{
    return a.v > b.v;
}
good A[110],B[110],C[110],D[110];

LL swa[110],swb[110],swc[110],swd[110];//重量的前缀和
LL sva[110],svb[110],svc[110],svd[110];//价值的前缀和

int main(void)
{
    int n,w,i,j,k,l;
    int a,b,c,d;
    while(scanf("%d%d",&n,&w)==2)
    {
        a = b = c = d = 0;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&g[i].w,&g[i].v);
            if(g[i].w == g[1].w)
                A[++a] = g[i];
            if(g[i].w == g[1].w + 1)
                B[++b] = g[i];
            if(g[i].w == g[1].w + 2)
                C[++c] = g[i];
            if(g[i].w == g[1].w + 3)
                D[++d] = g[i];
        }
        sort(A+1,A+a+1,cmp);
        sort(B+1,B+b+1,cmp);
        sort(C+1,C+c+1,cmp);
        sort(D+1,D+d+1,cmp);
        swa[0] = swb[0] = swc[0] = swd[0] = 0;
        sva[0] = svb[0] = svc[0] = svd[0] = 0;
        for(i=1;i<=a;i++)
        {
            swa[i] = swa[i-1] + A[i].w;
            sva[i] = sva[i-1] + A[i].v;
        }
        for(i=1;i<=b;i++)
        {
            swb[i] = swb[i-1] + B[i].w;
            svb[i] = svb[i-1] + B[i].v;
        }
        for(i=1;i<=c;i++)
        {
            swc[i] = swc[i-1] + C[i].w;
            svc[i] = svc[i-1] + C[i].v;
        }
        for(i=1;i<=d;i++)
        {
            swd[i] = swd[i-1] + D[i].w;
            svd[i] = svd[i-1] + D[i].v;
        }
        int sumv = 0;
        int ans = 0;
        for(i=0;i<=a;i++)
        {
            for(j=0;j<=b;j++)
            {
                for(k=0;k<=c;k++)
                {
                    for(l=0;l<=d;l++)
                    {
                        LL sum = swa[i] + swb[j] + swc[k] + swd[l];
                        if(sum <= (LL)w)
                        {
                            ans = max((LL)ans,sva[i]+svb[j]+svc[k]+svd[l]);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++) cin>>a[i];
        sort(a,a+n,greater<int>());
        int alice=0,bob=0;
        for(int i=0;i<n;i++)
        {
                if(i%2==0) alice+=a[i];
                else bob+=a[i];
        }
        cout<<alice-bob<<endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<pair<pair<int, int>, int>> Qs;
  for(int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    Qs.push_back({{l - 1, r - 1}, i});
  }
  const int bs = (int) sqrt(n);

  sort(Qs.begin(), Qs.end(), [bs] (auto & a, auto & b) {
                               if(a.fi.fi / bs == b.fi.fi / bs)
                                 return a.fi.se < b.fi.se;
                               return a.fi.fi / bs < b.fi.fi / bs;
                             });
  long long sum = 0;
  int l = 0, r = 0;
  vector<int> cnt(1000000 + 10);
  cnt[a[0]]++;
  sum = 1;

  vector<long long> ans(q);
  for(auto & qq : Qs) {
    int ql = qq.fi.fi, qr = qq.fi.se;
    while(l < ql) {
      cnt[a[l]]--;
      if(cnt[a[l]] == 0) sum -= 1;
      l++;
    }
    while(l > ql) {
      l--;
      cnt[a[l]]++;
      if(cnt[a[l]] == 1) sum += 1;
    }
    while(r < qr) {
      r++;
      cnt[a[r]]++;
      if(cnt[a[r]] == 1) sum += 1;
    }
    while(r > qr) {
      cnt[a[r]]--;
      if(cnt[a[r]] == 0) sum -= 1;
      r--;
    }
    l = ql, r = qr;
    ans[qq.se] = sum;
  }

  for(int i = 0; i < q; ++i)
    cout << ans[i] << '\n';
}

Measured memory_bytes: 19556
S = list(input())
USED = [False] * 26

for s in S:
  USED[ord(s)-97] = True
  
ok = False
ans = None
for i in range(26):
  if not USED[i]:
    ans = chr(97+i)
    ok = True
    break
    
if ok:
  print(ans)
else:
  print("None")


Measured memory_bytes: 9720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int main(){
   int n,m;
   cin >> n >> m;
   int x[n];
   int y[m];
   for(int i = 0 ; i < n; i++) cin >> x[i];
   for(int i = 0 ; i < m; i++) cin >> y[i];
   mint X=0;
   mint Y=0;
   for(int i = 1; i <n; i++){
      mint d = x[i]-x[i-1];
      X+=d*i*(n-i);
   }
   for(int i = 1; i <m; i++){
      mint d = y[i]-y[i-1];
      Y+=d*i*(m-i);
   }
   mint ans = X*Y;
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 4384
#include <iostream>
 
int main() {
	int x, y;
  
  	scanf("%d", &x);
  	scanf("%d", &y);
  	
  	//std::string s = std::to_string( a );
  	std::string a;
  	std::string b;
  
  	for (int i = 0; i < y; i++) {
    	a += std::to_string(x);
    }
  
  	for (int i = 0; i < x; i++) {
    	b += std::to_string(y);
    }
  	
  	if (a < b) {
      std::cout << a << std::endl;
      return 0;
    
    }
  	std::cout << b << std::endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret), greater<>());
    return ret;
}

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

    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    vector<ll> div = divisor(sum);
    for (auto x:div) {
        vector<ll> now(n);
        ll now_sum = 0;
        for (int i = 0; i < n; i++) {
            now[i] = a[i] % x;
            now_sum += now[i];
        }

        sort(now.begin(), now.end(), greater<>());
        ll minus = now_sum / x;
        for (int i = 0; i < minus; i++)now_sum -= now[i];

        if (now_sum <= k) {
            cout << x << endl;
            return 0;
        }
    }
}

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

vector<int> otoshidama(int n, int y) {
  int i, j;
  vector<int> ans(3, -1);
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n - i; j++) {
      if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
        ans[0] = i;
        ans[1] = j;
        ans[2] = n - i - j;
        return ans;
      }
    }
  }
  return ans;
}

int main() {
  int n, y, i, j;
  cin >> n >> y;
  vector<int> ans = otoshidama(n, y);
  cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;
using bigfloat = boost::multiprecision::cpp_dec_float_50;

using namespace std;

int main() {
  ll A;
  bigfloat B;
  cin >> A >> B;
  cout << ll(A * B) << endl;
}


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

namespace ConsoleApp_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = CIn.ReadLong();
            var a = CIn.ReadLongArray(n);

            var r = new long[n];

            r[0] = 0;
            for(var i = 0; i < n; i++)
            {
                r[0] = i % 2 == 0 ? r[0] + a[i] : r[0] - a[i];
            }

            Console.Write(r[0]);
            for(var i = 1; i < n; i++)
            {
                r[i] = 2 * a[i - 1] - r[i - 1];
                Console.Write(" {0}", r[i]);
            }
            Console.WriteLine("");


        }
    }

    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }
            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }
            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }
            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }
            return array;
        }

        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }
            return array;
        }
    }
}


Measured memory_bytes: 31060
/*
dreamerer
*/
#include <bits/stdc++.h>
using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; const int N = 5e5 + 5, M = 998244353, INF = 0x3f3f3f3f; const ll LNF = 0x3f3f3f3f3f3f3f3f; void Main();
void debug() { cerr << endl; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (sizeof...(y) > 0) cerr << ' '; debug(y...); } template <typename T> void debug(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cerr << "\033[31m" << a[i] << "\033[0m" << (i == r ? '\n' : c); }
void print() { cout << '\n'; } template <typename T, typename... Ts> void print(T x, Ts... y) { cout << x; if (sizeof...(y) > 0) cout << ' '; print(y...); } template <typename T> void print(const T& a, int l, int r, char c) { for (int i = l; i <= r; ++i) cout << a[i] << (i == r ? '\n' : c); }
void input() {} template <typename T, typename... Ts> void input(T& x, Ts&... y) { cin >> x; input(y...); } template <typename T> void input(T* a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; } template <typename T> void input(vector<T>& a, int l, int r) { for (int i = l; i <= r; ++i) cin >> a[i]; }
template <typename T> void Max(T& a, T b) { if (a < b) a = b; } template <typename T> void Min(T& a, T b) { if (a > b) a = b; } template <typename T> void Add(T& a, T b) { a += b; if (a > M) a -= M; if (a < 0) a += M; } template <typename T> void Mul(T& a, T b) { a = a * b % M; } template <typename T> T Mod(T a) { return (a % M + M) % M; }
int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); /* cout << setprecision(10) << fixed; */
#ifdef Zmm
    if (argc) { freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x; }
#endif
    Main();
}

void Main() {
    vector<string> T = {"dreamer", "dream", "eraser", "erase"};
    for (string& t : T) reverse(t.begin(), t.end());
    string s;
    input(s);
    reverse(s.begin(), s.end());
    for (int i = 0; i < (int)s.size(); ) {
        for (string& t : T) if (s.substr(i, t.size()) == t) {
            i += t.size();
            goto l1;
        }
        print("NO");
        return;
        l1:;
    }
    print("YES");
}

Measured memory_bytes: 3752
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
const ul INF = 1LL<<60;
ul N,i,X[200000],Y[200000];
inline void solve(){
  IN(N);
  REP(i,N){
    cin>>X[i];
    Y[i]=X[i];
  }
  sort(Y,Y+N);
  REP(i,N){
    if(X[i]<Y[N/2])OUT(Y[N/2]);
    else OUT(Y[N/2-1]);
  }
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

using namespace std;

std::string ab("AB");

bool can_mm(char c1, char c2) {
    if (c1 == '0') {
        return c2 != '0';
    } else if (c1 == '1') {
        return c2 == '0' || c2 == '1' || c2 == '2';
    } else {
        return false;
    }
}

int main(int argc, char** argv) {
    std::string str;
    cin >> str;

    bool first = can_mm(str[0], str[1]);
    bool second = can_mm(str[2], str[3]);

    if (first) {
        if (second) {
            cout << "AMBIGUOUS";
        } else {
            cout << "MMYY";
        }
    } else if(second) {
        cout << "YYMM";
    } else {
        cout << "NA";
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
		
	int n;
	ll k;

	cin >> n >> k;

	vector<ll> a(n);
	for(int i = 0; i < n; i++)
		cin >> a[i];

	ll lo = 1, hi = 2e9, opt = -1;
	while(lo <= hi){
		ll mid = (lo + hi) >> 1, sum = 0;

		for(int i = 0; i < n; i++)
			sum += (a[i] + mid - 1) / mid - 1;

		if(sum <= k){
			opt = mid;
			hi = mid - 1;
		}
		else lo = mid + 1;
	}

	cout << opt << endl;

	return 0;
}

Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>

using namespace std;
static const int dx[] = {1, 0, -1, 0};
static const int dy[] = {0, -1, 0, 1};
bool isVisited[51][51][51][51];

class point
{
public:
	int tx, ty;
	int kx, ky;
};

class data
{
public:
	point p;
	int cnt;
};

void solve()
{
	int X, Y;
	while (cin >> X >> Y, X || Y)
	{
		data d;
		cin >> d.p.tx >> d.p.ty >> d.p.kx >> d.p.ky;
		--d.p.tx; --d.p.ty;
		--d.p.kx; --d.p.ky;
		d.cnt = 0;
		vector< vector<char> > field(Y, vector<char>(X));
		for (int i = 0; i < Y; ++i)
		{
			for (int j = 0; j < X; ++j)
			{
				cin >> field[i][j];
			}
		}
		memset(isVisited, 0, sizeof(isVisited));
		queue<data> Que;
		Que.push(d);
		isVisited[d.p.ty][d.p.tx][d.p.ky][d.p.kx] = true;
		bool findFlag = false;
		while (!Que.empty())
		{
			data cur = Que.front();
			Que.pop();
			if (cur.cnt >= 100)
			{
				break;
			}
			if (cur.p.tx == cur.p.kx && cur.p.ty == cur.p.ky)
			{
				cout << cur.cnt << endl;
				findFlag = true;
				break;
			}
			for (int i = 0; i < 4; ++i)
			{
				data next;
				next.p.tx = cur.p.tx + dx[i];
				next.p.ty = cur.p.ty + dy[i];
				if (!(0 <= next.p.tx && next.p.tx < X && 0 <= next.p.ty && next.p.ty < Y) || field[next.p.ty][next.p.tx] == '1')
				{
					next.p.tx = cur.p.tx;
					next.p.ty = cur.p.ty;
				}
				next.p.kx = cur.p.kx + dx[(i + 2) % 4];
				next.p.ky = cur.p.ky + dy[(i + 2) % 4];
				if (!(0 <= next.p.kx && next.p.kx < X && 0 <= next.p.ky && next.p.ky < Y) || field[next.p.ky][next.p.kx] == '1')
				{
					next.p.kx = cur.p.kx;
					next.p.ky = cur.p.ky;
				}
				next.cnt = cur.cnt + 1;
				if (isVisited[next.p.ty][next.p.tx][next.p.ky][next.p.kx] == false)
				{
					Que.push(next);
					isVisited[next.p.ty][next.p.tx][next.p.ky][next.p.kx] = true;
				}
			}
		}
		if (!findFlag)
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 8000
def main():
    from itertools import chain

    N, M, K = map(int, input().split())
    A = map(int, input().split())
    *B, = map(int, input().split())

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48724
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i+=2){
        if((s[i]!='R')&&(s[i]!='U')&&(s[i]!='D')) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    for(int i=1;i<n;i+=2){
        if((s[i]!='L')&&(s[i]!='U')&&(s[i]!='D')) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;

}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int A,B; cin >> A >> B;
  if(A <= 5) { 
    B = 0;
  } else if(A <= 12) { 
    B /= 2;
  } else {
    //
  }
  cout << B << endl;
}



Measured memory_bytes: 3604
#include<iostream>
using namespace std;
int gl(int a,int b);
int main(){
	int a,b;
	while(cin >>a>>b){
		cout <<gl(a,b)<<" "<<a/gl(a,b)*b<<endl;
	}
	return 0;
}
int gl(int a, int b){
	if(b == 0){return a;}
	return gl(b,a%b);
}

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

bool chk(int a){
    for (int i = 2; i < a / 2; i++){
            if (a % i == 0){
                return true;
            }
        }
        return false;
}

int main() {
    int x;
    cin >> x;

    bool roop = true;
    bool a = false;
    while(roop){

        roop = chk(x);
        if (roop){
            x++;
        }
    }

    cout << x << endl;
}

Measured memory_bytes: 256
// template {{{

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

#define loop(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) loop(i, 0, n)
#define rloop(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define rrep(i, n) rloop(i, 0, n)
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define all(c) std::begin(c), std::end(c)
#define mp std::make_pair
#define mt std::make_tuple
#define fi first
#define se second
#define popcnt __builtin_popcountll

using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<double, double>;
using tp = tuple<int, int, int>;
using tp4 = tuple<int, int, int, int>;
using tp5 = tuple<int, int, int, int, int>;

template<typename T>
using max_pq = priority_queue<T, vector<T>, less<T>>;

template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 10;
const ll LLINF = 1e18 + 10;

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

template<typename T>
inline T sq(T x){ return x * x; }

template<typename T, typename U>
inline bool chmax(T &x, U y){ if (x >= y) return false; x = y; return true; }

template<typename T, typename U>
inline bool chmin(T &x, U y){ if (x <= y) return false; x = y; return true; }

template<typename T>
inline void sort(T &c){ std::sort(std::begin(c), std::end(c)); }

template<typename T>
inline void reverse(T &c){ std::reverse(std::begin(c), std::end(c)); }

template<typename T>
inline void unique(T &c){ std::sort(std::begin(c), std::end(c)); c.erase(std::unique(all(c)), std::end(c)); }

// }}}

int n;
double dp[100010][30];
double p[30];

double calc(int i, int j)
{
	if (i == 0 || j >= 30) return 0.0;
	if (dp[i][j] != -1.0) return dp[i][j];
	return dp[i][j] = p[j] * (1 + calc(i - 1, j + 1)) + (1 - p[j]) * calc(i - 1, 0);
}

int main()
{
	fill_n(*dp, 100010 * 30, -1.0);
	p[0] = 1.0;
	rep(i, 29) p[i + 1] = p[i] / 2;
	while (cin >> n, n){
		printf("%.20lf\n", calc(n, 0));
	}
}

Measured memory_bytes: 30764
function main(input) {
    var  S = input.split(/\n/)[0].trim().split('');
    if(S.slice(-1)[0]=='s') S.push('es')
    else S.push('s')

    
    console.log(S.join(""));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29700
# coding: utf-8
#ABC143B_TAKOYAKI2019.rb
n = gets.to_i
d = gets.split.map(&:to_i)

idx1 = 0
comb = []
ans = 0
while idx1 < n-1
  idx2 = idx1 + 1
  while idx2 < n
    ans +=  d[idx1]*d[idx2]
    idx2 += 1
  end
  idx1 += 1
end
puts ans


Measured memory_bytes: 1788