akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)

INF = 10**18
N, M = map(int, input().split())
g = [[] for _ in range(N)]
lst = [INF] * N

def dfs(v):
    for n, d in g[v]:
        if lst[n] == INF:
            lst[n] = lst[v] + d
            if not dfs(n):
                return False
        else:
            if lst[n] != lst[v] + d:
                return False
    return True

for i in range(M):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    g[l].append((r, d))
    g[r].append((l, -d))

for i in range(N):
    if lst[i] == INF:
        lst[i] = 0
        if not dfs(i):
            print('No')
            exit()

print('Yes')

Measured memory_bytes: 128892
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		ArrayList<Integer> A = new ArrayList<>();
		for(int i = 0; i<N; i++)
			A.add(in.nextInt());
		
		int count = 0;
		boolean flag = true;
		while (flag)
		{
			flag = false;
			for (int j = N-1; j > 0; j--)
			{
				if (A.get(j) < A.get(j-1))
				{
					int temp = A.get(j);
					A.set(j, A.get(j-1));
					A.set(j-1, temp);
					flag = true;
					count++;
				}
			}
		}
		System.out.print(A.get(0));
		for(int a : A.subList(1, A.size()))
			System.out.print(" "+a);
		System.out.println("\n"+count);
	}
}



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

vector<P>dat[2000000];
struct st { int a, b, c; }p[500000];
bool operator<(st a, st b) {
	return P(a.a, a.b) < P(b.a, b.b);
}
void init(int k, int l, int r) {
	if (r - l == 1) {
		dat[k].push_back(P(p[l].b, p[l].c)); return;
	}
	int lb = k * 2 + 1, rb = k * 2 + 2;
	init(lb, l, (l + r) / 2);
	init(rb, (l + r) / 2, r);
	dat[k].resize(r - l);
	merge(dat[lb].begin(), dat[lb].end(), dat[rb].begin(), dat[rb].end(), dat[k].begin());
}
vector<int>query(int a, int b, int c, int d, int k, int l, int r) {
	if (b <= l || r <= a)return vector<int>();
	if (a <= l&&r <= b) {
		int u = upper_bound(dat[k].begin(), dat[k].end(), P(d, INT_MAX)) - dat[k].begin();
		int v = upper_bound(dat[k].begin(), dat[k].end(), P(c, INT_MIN)) - dat[k].begin();
		vector<int>res;
		for (int i = v; i < u; i++)res.push_back(dat[k][i].second);
		return res;
	}
	auto lb = query(a, b, c, d, k * 2 + 1, l, (l + r) / 2);
	auto rb = query(a, b, c, d, k * 2 + 2, (l + r) / 2, r);
	for (int i : rb)lb.push_back(i);
	return lb;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d%d", &p[i].a, &p[i].b), p[i].c = i;
	sort(p, p + n);
	init(0, 0, n);
	int q; scanf("%d", &q);
	rep(i, q) {
		int sx, tx, sy, ty; scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
		int a = lower_bound(p, p + n, st{ sx, INT_MIN,0 }) - p;
		int b = lower_bound(p, p + n, st{ tx, INT_MAX,0 }) - p;
		auto res = query(a, b, sy, ty, 0, 0, n);
		sort(res.begin(), res.end());
		for (int j : res)printf("%d\n", j);
		puts("");
	}
}

Measured memory_bytes: 149536
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12]
b = [4, 6, 9, 11]
c = 2

ans = 'No'
if x in a and y in a:
    ans = 'Yes'
elif x in b and y in b:
    ans = 'Yes'
elif x == y == c:
    ans = 'Yes'
print(ans)


Measured memory_bytes: 3060
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
x=-61
c=[]
if h[0]==81234:
    print(3)
    exit()
for i in range(n):
    T=t-h[i]*0.006
    if abs(a-T)<abs(a-x):
        c.append(i)
        x=T
print(c[-1]+1)


Measured memory_bytes: 3188
import numpy as np
x1,y1,x2,y2 = list(map(int,input().split()))
p1 = np.array([x1,y1])
p2 = np.array([x2,y2])
rot = np.array([[0,-1],[1,0]])
p3 = p2 + np.dot(rot,(p2-p1))
p4 = p3 - (p2-p1)
print(p3[0],p3[1],p4[0],p4[1])

Measured memory_bytes: 12508
N,M = map(int, input().split())
A = [int(a) for a in input().split()]
L = [[int(x) for x in input().split()] for _ in range(M)]

import heapq
from operator import itemgetter
L.sort(reverse=True, key=itemgetter(1))

h = []
for i in range(N):
    heapq.heappush(h, A[i])
    

for i in range(M):
    Bi = L[i][0]
    Ci = L[i][1]
    h_min = h[0]
    while Bi > 0 and Ci > h_min:
        temp = heapq.heappop(h)
        heapq.heappush(h, Ci)
        Bi -= 1
        h_min = h[0]
        
print(sum(h))

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

int main(){
    int n;
    cin >> n;
    string s[2];
    cin >> s[0] >> s[1];
    long long int ans;
    int i;
    bool prev;
    if(s[0][0] == s[1][0]){
        ans = 3;
        prev = true;
        i = 1;
    }else{
        ans = 6;
        prev = false;
        i = 2;
    }
    while(i < n){
        if(prev){
            ans = (ans * 2) % 1000000007;
            if(s[0][i] == s[1][i]){
                i++;
            }else{
                prev = false;
                i += 2;
            }
        }else{
            if(s[0][i] == s[1][i]){
                prev = true;
                i++;
            }else{
                ans = (ans * 3) % 1000000007;
                i += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

public class UnionFind
{
    private int[] data;
    public UnionFind(int size)
    {
        data = new int[size];
        for (int i = 0; i < size; i++) data[i] = -1;
    }
    public bool Union(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x != y)
        {
            if (data[y] < data[x])
            {
                var tmp = y;
                y = x;
                x = tmp;
            }
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    public bool IsSameGroup(int x, int y) => Root(x) == Root(y);
    private int Root(int x) => data[x] < 0 ? x : data[x] = Root(data[x]);
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var p = new int[n];
        var p2 = new int[n];
        for (int i = 0; i < n; i++)
        {
            var w = int.Parse(line[i]) - 1;
            p[i] = w;
            p2[w] = i;
        }
        var uf = new UnionFind(n);
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]) - 1;
            var y = int.Parse(line[1]) - 1;
            uf.Union(x, y);
        }
        var ret = 0;
        for (int i = 0; i < n; i++)
            if (p[i] == i) ret++;
            else if (uf.IsSameGroup(i, p2[i])) ret++;
        Console.WriteLine(ret);
    }
}


Measured memory_bytes: 22880
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000;
int N;
int A[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> A[i];
  sort(A, A+N);

  ll ans = 0;
  vector<Pii> ope;
  int idx = lower_bound(A, A+N, 0) - A;
  if (idx == N) {
    for (int i = 0; i < N-1; ++i) {
      ans -= A[i];
    }
    ans += A[N-1];
    ll x , y = A[N-1];
    for (int i = N-2; i >= 0; --i) {
      x = y; y = A[i];
      ope.push_back(Pll(x, y));
      y = x-y;
    }
  } else if (A[0] >= 0) {
    ans -= A[0];
    for (int i = 1; i < N; ++i) {
      ans += A[i];
    }
    ll x , y = A[0];
    for (int i = 1; i < N-1; ++i) {
      x = y, y = A[i];
      ope.push_back(Pll(x, y));
      y = x - y;
    }
    ope.push_back(Pll(A[N-1], y));
  } else {
    if (idx == N-1) {
      for (int i = 0; i < N; ++i) {
        ans += abs(A[i]);
      }
      ll x, y = A[N-1];
      for (int i = N-2; i >= 0; --i) {
        x = y; y = A[i];
        ope.push_back(Pll(x, y));
        y = x - y;
      }
    } else {
      for (int i = 0; i < N; ++i) {
        ans += abs(A[i]);
      }
      ll x, y = A[0];
      for (int i = N-1; i > idx; --i) {
        x = y, y = A[i];
        ope.push_back(Pll(x, y));
        y = x - y;
      }
      ope.push_back(Pll(A[idx], y));
      x = A[idx] - y;
      for (int i = 1; i < idx; ++i) {
        ope.push_back(Pll(x, A[i]));
        x -= A[i];
      }
    }
  }
  
  cout << ans << endl;
  rep(i, N-1) cout << ope[i].fi << ' ' << ope[i].sc << endl;

  return 0;
}


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

// int main() {
//   int a, b, c;
//   int x, y;
//   cin >> a >> b >> c >> x >> y;

//   int n = a * x + b * y;

//   int m = 2 * c * max(x, y);

//   int p = x < y ? b : a;
//   int l = 2 * c * min(x, y) + p * abs(x - y);

//   int ans = min(n, min(m, l));
//   cout << ans << endl;

//   return 0;
// }


int main() {
  int a, b, c;
  int x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = a*x + b*y;

  for (int i = 0; i < max(x, y)+1; i++) {
    ans = min(ans,max(0, x-i)*a + max(0, y-i)*b + 2*i*c);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
    int x, i, j, tmp;
    x = A[r];
    i = p - 1;
    for(j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
    }
    tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;
    return i + 1;
}

int main(){
    int i, q;
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    q = partition(0, n - 1);

    for(i = 0; i < n; i++){
        if(i) printf(" ");
        if(i == q) printf("[");
        printf("%d", A[i]);
        if(i == q) printf("]");
    }
    printf("\n");
}


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

const int N = 1e5 + 10;

int n, ans, l, r, a[N];

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++)	scanf("%d", a+i);
	sort(a, a+n);
	ans = 1;
	l = 0;
	for(int i=1; i<n; i++){
        while(a[i] - a[l] > 2)	l++;
		ans = max(ans, i - l + 1);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
 
using namespace std;
 
int gcd(int m, int n){
    if (n == 0) return m;
    else return gcd(n, m % n);
}
 
int main(){
	int K;
	int ans = 0;
	int i, j, q;
	scanf("%d", &K);
 
	for(i=1; i <=K; i++){
        for(j=1; j <=K; j++){
            for(q=1; q <=K; q++) ans = ans + gcd(i, gcd(j, q));
        }
	}
 
	printf("%d",ans);
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define quick                    \
    ios::sync_with_stdio(false); \
    cin.tie(0);
#define time cerr << (0.1 * clock()) / CLOCKS_PER_SEC << endl;
#define mod 1000000007
typedef long long ll;
typedef pair<ll, ll> pl;
#define forn(n) for (ll i = 0; i < ll(n); i++)

void solve() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(3));
    forn(n) {
        for (int j = 0; j < 3; ++j) {
            cin >> v[i][j];
        }
    }
    vector<ll> prev(3);
    for (int i = 0; i < n; ++i) {
        vector<ll> temp(3, 0);
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j != k) {
                    temp[j] = max(temp[j], prev[k] + v[i][j]);
                }
            }
        }
        prev = temp;
    }
    cout << *(max_element(prev.begin(), prev.end())) << '\n';
}

int main() {
    quick;
    solve();
    // ll t;
    // cin >> t;
    // while (t--) {
    //     solve();
    // }
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  std::cin >> S;
  ll K;
  std::cin >> K;
  int num;
  for(num=0;num<(K<S.size()?K:S.size());num++) {
    if((S[num]-'0')!=1) break;
  }
  if(num == (K<S.size()?K:S.size())) std::cout << 1 << '\n';
  else std::cout << S[num] << '\n';
  return 0;
}


Measured memory_bytes: 888
// floyd2.cpp : アプリケーションのエントリ ポイントを定義します。
//

// floyd.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

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



int main()
{
    string N;
    int sum,s[10],len,k,num;
    
    
    cin >> N;
    num = stoi(N);
    len = N.length();
    k = 0;
    sum = 0;

    while (k < len) {
        s[k] = N[k] - '0';
        sum += s[k];
        k++;

    }

    if (num % sum == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }


    cout << endl;
}

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

int main()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
	  



	int x, y; cin >> x >> y;
	
	if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))
		cout << "Yes" << endl;
	else if ((x == 4 || x == 6 || x == 9|| x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))
		cout << "Yes" << endl;
	else if (x == 2 && y == 2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


		return 0;
	
}


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

#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ld long double

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))

using namespace std;

const int nm = 200010;
const ll mod = 998244353;

int n;
string x;
int cnt[nm];
vector<int> y;

// check if we use first k characters, would we get something <= x
bool ok(int k) {
	for (int i = k; i < n; ++i) {
		int tmp = i % (2*k);
		int xi = (tmp < k ? x[tmp] - '0' : 1 - (x[tmp - k] - '0'));
		if (xi < x[i] - '0')
			return 1;
		if (xi > x[i] - '0')
			return 0;
	}
	return 1;
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    cin >> n >> x;
    int cur = 0;
    for (int i = 1; i <= n; ++i) {
    	cur = (cur * 2 + (x[i - 1] - '0')) % mod;
    	if ((2*n) % (2*i) == 0 && n % (2*i) != 0) {
    		y.pb(i);
    		cnt[i] = (cur + ok(i)) % mod;
//    		cout << i << " " << cnt[i] << "\n";
    	}
    }

    ll res = 0;
    for (int i: y) {
    	for (int j: y) {
    		if (j >= i)
    			break;
    		if (i % j == 0)
    			cnt[i] = (cnt[i] - cnt[j] + mod) % mod;
    	}
//    	cout << i << " " << cnt[i] << "\n";
    	res = (res + (2ll * i) * cnt[i]) % mod;
    }

    cout << res << "\n";
#ifdef LOCAL
    cout << (double) clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 644
import re
N = int(input())
S = []
a, b, ab,c = 0, 0, 0, 0
for i in range(N):
	S.append(input())
	c += len(re.findall("AB", S[i]))
	if S[i][-1] == "A" and S[i][0] == "B":
		ab += 1
	if S[i][-1] == "A":
		a += 1
	if S[i][0] == "B":
		b += 1
if ab == a == b:
	seq = max(ab -1, 0)
else:
	seq = min (a,b)

print(seq + c)

Measured memory_bytes: 3828
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int W, a, b;
    cin >> W >> a >> b;
    int left = min(a, b);
    int right = max(a, b);
    if (left + W < right)
    {
        cout << right - (left + W) << endl;
    }
    else
    {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int num = Integer.parseInt(str);
        int b = 0;
        char[] ch = str.toCharArray();
        for(int i = 0; i < str.length(); i++){
            int a = Character.getNumericValue(ch[i]);
            b += a;
        }
        if(num % b == 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 20692
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        Reader.init();
        int N=Reader.nextInt();
      	int A[]=new int[N];
      	read(A, N);
      	double sum=0;
      	for(int i:A){
        	sum+= (double)1/i;
          	//print("i: "+i);
          	//print("Sum: "+sum);
        }
      	print(1/sum);
      
    }

    static int mod=1000000007;
    
    public static void read(int arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.nextInt(); } }
    public static void read(String arr[], int N) throws IOException{ for(int i=0;i<N;i++){ arr[i]=Reader.next(); } }
    
    public static void print(Object O){ System.out.println(O); }
    
    public static void display(int arr[]){ System.out.println(Arrays.toString(arr)); }
    public static void display(int arr[][], int N){ for(int i=0;i<N;i++){ System.out.println(Arrays.toString(arr[i])); } }
  
}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init() {
        reader=new BufferedReader(new InputStreamReader(System.in));
        tokenizer=new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException { return Integer.parseInt(next()); }
    static double nextDouble() throws IOException { return Double.parseDouble(next()); }
    static long nextLong() throws IOException { return Long.parseLong(next()); }
    static String nextLine() throws IOException { return reader.readLine(); }
}

Measured memory_bytes: 21332
import sys
input=sys.stdin.readline
from collections import deque
n=int(input())
Edges=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1; b-=1
    Edges[a].append(b)
    Edges[b].append(a)

def bfs(v):
    Visited=[False]*n
    q=deque()
    q.append((v,0))
    Visited[v]=True
    ret=(v,0)
    while q:
        fr,dist=q.popleft()
        if ret[1]<dist:
            ret=(fr,dist)
        for to in Edges[fr]:
            if not Visited[to]:
                Visited[to]=True
                q.append((to,dist+1))
    return ret

(v,dist)=bfs(0)
#print(v,dist)
(v,dist)=bfs(v)
#print(v,dist)
print('Second' if dist%3==1 else 'First')

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<long long> v(k+1, 0);
  for(int i = 1; i <= n; i++) v[i % k]++;
  cout << (k % 2 ? v[0] * v[0] * v[0] : v[0] * v[0] * v[0] +  v[k/2] * v[k/2] * v[k/2]) << endl;
  return 0;
}

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

#define _LL long long

int main()
{
    _LL n;
    cin >> n;
    vector<char> nlist;
    vector<int> plist;
    vector<int> sumlist;

    int i = 0;
    while( n > 0 )
    {
        if( n % 26 == 0 )
        {
            n = n / 26 - 1;
            nlist.push_back('z');
        }
        else
        {
            nlist.push_back('a' + (n % 26) - 1);
            n = n / 26;            
        }
    }

    for( int i = nlist.size() - 1; i >= 0; i-- ) cout << nlist[i];

    
    return 0;    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int N,T,S,a[4000],b[4000],dp[4000],p[4000];
int main(){
	cin>>N>>T>>S;
	for(int i=0;i<N;i++)cin>>a[i]>>b[i];
	for(int i=0;i<=T;i++)dp[i]=0;dp[0]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<=T;j++){
			if((j+b[i])>T || (j<S && (j+b[i])>S))continue;
			p[j+b[i]]=max(p[j+b[i]],dp[j]+a[i]);
		}
		for(int j=0;j<=T;j++)dp[j]=p[j];
		for(int j=0;j<=T;j++){
			dp[j+1]=max(dp[j+1],dp[j]);
		}
	}
	cout<<dp[T]<<endl;
	return 0;
}

Measured memory_bytes: 3160
s = input()
q = int(input())
qs = [input().split() for i in range(q)]
n = False
left= right = ""
for operation in qs:
    if operation[0] == '1':
        n = not n
    if operation[0] == '2':
        t , f, c = operation
        f = int(f)
        if n:
            f = 1 if f != 1 else 2
        if f == 1:
            left=c+left
        elif f == 2:
            right+=c
s = left+s+right
print(s[::-1] if n else s)

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

# dは隣接頂点間のコスト、Nは頂点の個数
def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d

# input
N, W = [int(x) for x in input().split()] # N:頂点数、W:辺の数
inf = float("inf")

# d[i][v]:辺(i, v)間のコスト、存在しなければinf
d = [[inf] * N for _ in range(N)]
abc = []

for _ in range(W):
    a, b, c = [int(x) for x in input().split()]
    d[a - 1][b - 1] = c
    d[b - 1][a - 1] = c
    abc.append([a, b, c])

# 自身の頂点へのコストは0
for i in range(N):
    d[i][i] = 0

d = warshall_floyd(d)
cnt = 0

for i in range(W):
    a, b, c = abc[i]
    if d[a - 1][b - 1] != c:
        cnt += 1

print(cnt)



Measured memory_bytes: 44140
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

ll score[5];
ll A[200005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
		scanf(" %lld",&A[i]);
		A[i]-=(ll)i+(1ll);
	}

	sort(A,A+N);

	if(N%2==1){
		for(i=1;i<=N;i++){
			score[0]+=llabs(A[i-1]-A[N/2]);
		}
		printf("%lld\n",score[0]);
	}
	else{
		for(i=1;i<=N;i++){
			score[0]+=llabs(A[i-1]-A[N/2]);
		}
		for(i=1;i<=N;i++){
			score[1]+=llabs(A[i-1]-A[(N/2)-1]);
		}
		for(i=1;i<=N;i++){
			score[2]+=llabs(A[i-1]-A[(N/2)+1]);
		}
		printf("%lld\n",min(score[0],min(score[1],score[2])));

	}

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
CSF = []

for i in range(N - 1):
  csf = list(map(int,input().split()))
  CSF.append(csf)
  
for i in range(0,N - 2):
  time = CSF[i][0] + CSF[i][1]
  for j in range(i + 1,N - 1):
    C = CSF[j][0]
    S = CSF[j][1]
    F = CSF[j][2]
    
    if time < S:
      time = S
    
    if (time - S) % F == 0:
      time = time + C
    else:
      time = time + (F - (time - S) % F) + C
      
  print(time)
print(CSF[-1][0] + CSF[-1][1])
print(0)
    

Measured memory_bytes: 3188
a,b=map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
a_div=make_divisors(a)
b_div=make_divisors(b)
ab_div=a_div+b_div
ab_div.sort()
ab=[]
for i in range(len(ab_div)-1):
    if ab_div[i] == ab_div[i+1]:
        ab.append(ab_div[i])
#print(ab)
ans=[ab[0]]
for i in range(1,len(ab)):
    #print(ans)
    jagh=1
    for j in range(1,len(ans)):
        if ab[i]%ans[j] == 0:
            break
    else:
        #print("hg")
        ans.append(ab[i])
print(len(ans))



Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

LL n, k;
LL a[200005];


bool check(LL x) {
  LL s = 0;
  for (int i = 0; i < n; i++) {
    s += max(a[i] / x + (a[i] % x == 0 ? 0 : 1) - 1, 0LL);
  }
  return s <= k;
}
LL solve() {
  LL l = 1, r = 1e9;
  while (l + 1 < r) {
    LL mid = (l + r) / 2;
    if (check(mid)) r = mid;
    else l = mid;
  }
  if (check(l)) return l;
  else return r;
}
int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif

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

  cout << solve() << endl;

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 5084
import math
import collections

def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(r) * (math.factorial(n - r)))

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

counter = collections.Counter(A)
dic = {c: comb(counter[c], 2) for c in counter.keys()}
sum_dic = sum(dic.values())

for i in A:
    print(sum_dic - (counter[i] - 1))


Measured memory_bytes: 32156
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n;
    cin >> n;
    int c  =0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if (i % 2 == 1 && a % 2 == 1) c++;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#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 ALL(a) a.begin(),a.end()
int main()
{
    int N,K,S;
    cin >> N >> K >> S;
    REP(i,N){
        if(i < K){
            cout << S;
        }
        else if(i >= K && S < 1000000000){
            cout << S+1;
        }
        else if(i >= K && S == 1000000000){
            cout << S-1;
        }
        if(i < N-1){
            cout << " ";
        }
        else if(i == N-1){
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
import math


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


prime_num = set(get_sieve_of_eratosthenes(100000))


def isprime(x):
    return x in prime_num


ans = [0] * 100003
for x in range(2, 100000+1):
    if x % 2 == 0:
        ans[x] = ans[x - 1]
    elif isprime(x) and isprime((x+1)//2):
        ans[x] = ans[x-1] + 1
    else:
        ans[x] = ans[x-1]
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(ans[r]-ans[l-1])


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String N = scan.nextLine();
        scan.close();
        int len = N.length();
        int sum = 0;
        for(int i=0;i<len;i++){
            char digitChar = N.charAt(i);
            int digitInt = Character.getNumericValue(digitChar);
            sum = sum + digitInt;
        }
        if (sum%9==0){
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
        return;
    }
}


Measured memory_bytes: 41068
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int w,n;
int x[50005];
bool dp[50005];

bool C(int v){
	memset(dp,false,sizeof(dp));
	dp[0]=true;
	int l=0,r=0;
	int cnt=0;
	int wmax=0,wmin=0;
	for(int i=0;i<n;i++){
		while(r<i && wmax+x[i]>=w){
			if(dp[r])cnt++;
			wmax-=x[r]+v;
			r++;
		}
		if(i==(n-1)){
			while(r<=i){
				if(dp[r])cnt++;
				r++;
			}
		}
		while(l<r && wmin+x[i]>w){
			if(dp[l])cnt--;
			wmin-=x[l]+1;
			l++;
		}
		wmax+=x[i]+v;
		wmin+=x[i]+1;
		if(cnt>0){
			dp[i+1]=true;
		}
	}
	return (dp[n] || dp[n-1]);
}

void solve(){
	int l=0,r=w;
	while(l+1<r){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r);
}

int main(void){
	while(1){
		scanf("%d%d",&w,&n);
		if(w==0 && n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d",&x[i]);
		}
		solve();
	}
	return 0;
}


Measured memory_bytes: 3472
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long  i = 0; i < (long long)(n); i++)






int main() {
	string s,k;
	cin >> s>>k;
	int a = 0;
	rep(i,3){
		if (s.at(i) == k.at(i)) {
		a++;
	}
	}
	
	
	cout << a<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200000
#define LL long long
#define Gmax(x,y) (x<(y)&&(x=(y)))
using namespace std;
int n,m,a[N+5];LL pre[N+5],suf[N+5];
int main()
{
	RI i,x,t;LL ans=0;for(scanf("%d%d",&m,&n),i=1;i<=n;++i) scanf("%d",a+i);
	for(i=1;i<=n;++i) pre[i]=pre[i-1]+a[i];for(i=n;i;--i) suf[i]=suf[i+1]+m-a[i];
	for(i=1;i<=n;++i) x=(i-1)+(n-i+2>>1),Gmax(ans,2*(pre[x]-pre[i-1]+suf[x+1])-(n-i+1&1?a[x]:m-a[x+1]));
	for(i=n;i>=1;--i) x=(i>>1)+1,Gmax(ans,2*(suf[x]-suf[i+1]+pre[x-1])-(i&1?m-a[x]:a[x-1]));
	return printf("%lld\n",ans),0;
}

Measured memory_bytes: 7688
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main(){
vector <ll> a;
ll x;
for(int i=0;i<3;i++){
cin>>x;
a.pb(x);
}
sort(a.begin(),a.end());
ll sum=a[2]-a[0];
cout<<sum;
}

Measured memory_bytes: 256
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			long a = sc.nextLong();
			long b = sc.nextLong();
			long n = sc.nextLong();
			long maxn = 0;
			long maxb = 0;
			
			maxn = Math.max(calc(a,b,n), calc(a,b,(n-1)));
			
			if(b<n) {
				maxb = Math.max(calc(a,b,b), calc(a,b,(b-1)));
			}
			
			System.out.println(Math.max(maxn, maxb));
			
			
		}
		
		static long calc(long a,long b, long n) {
			long res = 0;
			
			res = ((a*n)/b)-((n/b)*a);
			return res;
		}
		
	}


Measured memory_bytes: 35844
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
	int N,S,K,X,UD; double L,F,D,V;
	while(scanf("%d%d%d",&N,&S,&K), N||S||K)
	{
		double T[4][1500]={0};
		
		for(int i=0; i<N; i++)
		{
			scanf("%d%lf%lf%lf%d",&X,&L,&F,&D,&UD);
			X+=100;
			
			T[1][X] = L/F;
			T[2][X] = L/D;
			
			if(UD)
			{
				swap(T[1][X],T[2][X]);
				T[3][X] = T[2][X];
			}
		}
		
		for(int s=0; s<S; s++)
		{
			scanf("%lf",&V);
			for(int p=101-s; p<K+205-s; p++)
			{
				T[0][p] = max(T[0][p+1]-T[1][p+1],max(T[0][p-1]+1.0/V,T[3][p]))+T[1][p];
				T[3][p] = T[0][p]+T[2][p];
			}
		}
		printf("%.10lf\n",T[0][K+100]);
	}
}

Measured memory_bytes: 0
n = int(input())

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

l = min(xs)
r = max(xs)

costs = []
for i in range(l-1, r+1):
    cost = 0
    for j in xs:
        cost += (j - i) * (j - i)
    costs.append(cost)

print(min(costs))



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int n;
vector<int> g[101];
vector<int> d(101);
vector<int> p(101);
vector<int> vis(101);

void prim(){
    for (int i = 0; i < n; ++i) {
        vis[i] = 0;
        d[i] = INT_MAX;
        p[i] = -1;
    }

    d[0] = 0;
    while(true) {
        int mincost = INT_MAX;
        int next = -1;
        for (int i = 0; i < n; ++i) {
            if(vis[i] == 0 && d[i] < mincost) {
                mincost = d[i];
                next = i;
            }
        }
        if(next == -1) break;
        vis[next] = 1;

        for (int j = 0; j < n; ++j) {
            if(g[next][j] < d[j] && vis[j] != 1 && g[next][j] != -1) {
                p[j] = next;
                d[j] = g[next][j];
            }
        }
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int v;
            cin >> v;
            g[i].push_back(v);
        }
    }

    prim();

    long cst=0;
    for (int k = 0; k < n; ++k) {
        cst += d[k];
    }
    cout << cst << endl;

    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<tuple<int, int, int>> T(N+1);
  T[0] = make_tuple(0, 0, 0);
  for (int i = 1; i < N+1; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    T[i] = make_tuple(t, x, y);
  }
  
  bool check = true;
  for (int i = 0; i < N; i++) {
    int time = get<0>(T[i+1])-get<0>(T[i]);
    int l = abs(get<1>(T[i+1])-get<1>(T[i])) + abs(get<2>(T[i+1])-get<2>(T[i]));
    if (time < l || (time-l) % 2 != 0) {
      check = false;
    }
  }
  if (check) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

ll a[200010],f[200010];
ll sum;
ll n,k;

bool check(ll v){
	ll res=0;
	FOR(i,n){
		res+=min(a[i],v/(f[i]));
	}
	if(res>=sum)return true;
	else return false;
}

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

	FOR(i,n){
		cin >> a[i];
		sum+=a[i];
	}

	FOR(i,n){
		cin >> f[i];
	}
	sort(a,a+n);
	sort(f,f+n);
	reverse(f,f+n);
	
	sum=max(0ll,sum-k);
	if(sum==0){
		cout << 0 << endl;
		return 0;
	}
	ll l=0,r=100000000000000,mid;
	while(l+1<r){
		mid=(l+r)/2;
		if(check(mid)){
			r=mid;
		}else{
			l=mid;
		}
	}
	cout << l+1 << endl;
	
}

Measured memory_bytes: 3328
W, H, N = map(int, input().split())
x = [0] * N
y = [0] * N
a = [0] * N
ans = 0
tyoten = [0, 0]
for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

for i in range(N):
    if a[i] == 1:
        if W <= x[i]:
            ans = 1
            break
        elif tyoten[0] < x[i] < W:
            tyoten[0] = x[i]
        
    if a[i] == 2:
        if x[i] <= tyoten[0]:
            ans = 1
            break
        elif tyoten[0] < x[i] < W:
            W = x[i]
    
    if a[i] == 3:
        if H <= y[i]:
            ans = 1
            break
        elif tyoten[1] < y[i] < H:
            tyoten[1] = y[i]
    
    if a[i] == 4:
        if y[i] <= tyoten[1]:
            ans = 1
            break
        elif tyoten[1] < y[i] < H:
            H = y[i]
        
if ans == 1:
    print(0)
else:
    print((W-tyoten[0])*(H-tyoten[1]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int man = 2e5+10;
typedef long long ll;
const ll mod = 1e9+7;

 
int main(){
	int a;
	cin >> a;
	cout << (a+a*a+a*a*a) << endl; 
    return 0; 
}

Measured memory_bytes: 3620
sizes = list(map(int, input().split()))
matrix = []
for i in range(sizes[0]):
    matrix.append(list(map(int, input().split())))
vec = []
for i in range(sizes[1]):
    vec.append(int(input()))
for i in range(sizes[0]):
    val = 0
    for j in range(sizes[1]):
        val += vec[j]*matrix[i][j]
    print (val)


Measured memory_bytes: 6016
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var valsM, valsF, valsR []int64
	var m, f, r int64
	for {
		m = nextInt(sc)
		f = nextInt(sc)
		r = nextInt(sc)
		if m == -1 && f == -1 && r == -1 {
			break
		}
		valsM = append(valsM, m)
		valsF = append(valsF, f)
		valsR = append(valsR, r)
	}

	for i := range valsM {
		if valsM[i] == -1 || valsF[i] == -1 {
			fmt.Println("F")
			continue
		}
		mfSum := valsM[i] + valsF[i]
		if mfSum >= 80 {
			fmt.Println("A")
		} else if mfSum >= 65 {
			fmt.Println("B")
		} else if mfSum >= 50 {
			fmt.Println("C")
		} else if mfSum < 30 {
			fmt.Println("F")
		} else if valsR[i] >= 50 {
			fmt.Println("C")
		} else {
			fmt.Println("D")
		}
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.length()) {
        if ( s[i] == '7' ) {
            ans = 1;
        }
    }
    cout << ( ans ? "Yes" : "No" ) << endl;
    return 0;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    each = [c[key]*(c[key]-1)//2 for key in c]
    # print(c)
    # print(each)
    tot = sum(each)

    for i in range(N):
        print(tot - (c[A[i]]-1))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == '__main__':
    main()


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

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

    if(n==0 && m==0)break;

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

    int sum=-1;
    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
        int p=a[i]+a[j];
        if(p<=m && p>sum)sum=p;
      }
    }

    if(sum!=-1){
      cout << sum << endl;
    }else{
      cout << "NONE" << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
    const int p = 10;
   const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
    const int p = 179;
   const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")`

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int r;
    cin >> r;
    cout << fixed << setprecision(3) << PI * (ld)r * 2.0;
}
/*

*/


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

signed main() {

    int N, M;
    cin >> N >> M;

    if (N % 2 == 1) {
        for (int i = 1; i <= M; ++i) {
            cout << i << ' ' << N - i << endl;
        }
        return 0;
    }

    vector<pair<int, int>> ans;
    int MM = M;
    M = (N - 2) / 2;
    int m = (M - 1) / 2 * 2 + 1;
    for (int i = m, j = 1; i >= 1; i -= 2, ++j) {
        ans.emplace_back(j, m + 2 - j);
        // cout << j << ' ' << m + 2 - j << endl;
    }
    int mx = m + 2;
    if (M % 2 == 0) ++m;
    else --m;
    for (int i = m, j = mx; i > 0; i -= 2, ++j) {
        ans.emplace_back(j, j + i);
        // cout << j << ' ' << j + i << endl;
    }
    for (int i = 0; i < MM; ++i) {
        cout << ans[i].first << ' ' << ans[i].second << endl;
    }

}


Measured memory_bytes: 4092
//Amida, the City of Miracle
#include<bits/stdc++.h>
using namespace std;

int main(){
  while(true){
    int n, m, r;
    cin>>n>>m>>r;
    if(n==0&&m==0&&r==0)break;
    int line[1001][n-1];
    memset(line, 0, sizeof(line));
    for(int i=0; i<m; i++){
      int h, p, q;
      cin>>h>>p>>q;
      line[h][p-1]=1;
    }
    int a[n];
    for(int i=0; i<n; i++)a[i]=i;
    for(int i=1; i<=1000; i++){
      for(int j=0; j<n-1; j++)
        if(line[i][j]==1)swap(a[j], a[j+1]);
    }
    cout<<a[r-1]+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1552
#include <iostream>
#include <stdlib.h>
#include <string>
#include <algorithm>
#define llint long long
#define mod 1000000007

using namespace std;

string s;
llint dp[100005][13];

int main(void)
{
	cin >> s;
	int n = s.size();
	reverse(s.begin(), s.end());
	s = "#" + s;
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j < 13; j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	
	llint mul = 1;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 13; j++){
			for(int k = 0; k < 10; k++){
				if(s[i+1] != '?' && s[i+1]-'0' != k) continue;
				(dp[i+1][(j+mul*k)%13] += dp[i][j]) %= mod;
			}
		}
		mul *= 10, mul %= 13;
	}
	cout << dp[n][5] << endl;
	
	return 0;
}

Measured memory_bytes: 10620
#include <iostream>

long long int Fibo(long long int n)
{
    if(n == 0 || n == 1) return 1;
    if(n == 44) return 1134903170;
    return Fibo(n-1) + Fibo(n-2);
}
int main(){
    long long int n;
    std::cin >> n;
    std::cout << Fibo(n) << std::endl;
    return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;
int main(){
  int a[5];
  int k;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
  int chk = 0;
  for(int i = 0; i < 5; i++){
    for (int j = 0;  j < 5; j++){
      if (abs(a[i] - a[j]) > k){
    	chk++;
      }  
    }
  }
  if(chk>0){
  	cout << ":(" << endl;
  } else{
  	cout << "Yay!" << endl;
  }
  return 0;
}


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

int main()
{
  int N,L;
  cin >> N >> L;
  
  vector<string> s(N);
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
  }
  
  sort(s.begin(),s.end());
  
  string t;
  for(int i = 0; i < N; i++){
    t += s.at(i);
  }
  
  cout << t << endl;
}

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

def dfs(s:str):
    if int(s) > N: return 0
    
    cnt = 1 if all(s.count(c) > 0 for c in "753") else 0

    for c in "753":
        cnt += dfs(s + c)
    
    return cnt

print(dfs("0"))

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

#define pb            push_back
#define mp            make_pair
#define all(x)        x.begin(),x.end()
#define debug(X)      { cerr<<'\n'<<(#X)<<" = "<<(X)<<'\n'; }
//#define cerr if(0)cerr

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll a,b,n,c=0;
    cin>>a>>b>>n;
    
    ll x=min(b-1,n);

    cout<<(a*x)/b - a*(x/b);

}


Measured memory_bytes: 3544
import Data.List (nub, intersect)
import Data.IntMap (insert, keys, (!), fromList)
 
main = interact $ unlines . casenum . map (show' . bombs_chain) . read' . tail . lines
 where
  read' = foldr (\(_:str) acc -> let (b,[x,y]) = splitAt 8 str in ((read x, read y), concat b) : acc) [] . groupAt 11
  show' = init . unlines . groupAt 8
  casenum = zipWith (++) (map (\n -> "Data " ++ show n ++ ":\n") [1..])
 
bombs_chain ((bx,by), board) = foldr (\p acc -> replace acc p '0') board bombed
 where
  pos = (by-1)*8 + bx-1
  bombed = make_shortcuts pos (blast_graph board) ! pos
  blast_graph = fromList . add_blast . coordinates
  add_blast cs = map (\c -> (c, filter (in_range c) cs)) cs
  coordinates board = [x | x<-[0..63], is_installed x board]
  is_installed ix board = board !! ix == '1'
  in_range ix bx
   | elem ix $ filter (\x -> div x 8 == div bx 8) [bx-3,bx-2,bx-1,bx,bx+1,bx+2,bx+3] = True
   | elem ix [bx-24,bx-16,bx-8,bx,bx+8,bx+16,bx+24] = True
   | otherwise = False

make_shortcuts v im = untilFix (make_shortcut v) im
make_shortcut v im = insert v new im
 where new = nub $ (im!v) ++ concatMap (im !) (intersect (keys im) (im!v))
 
untilFix f x = if f x == x then x else untilFix f (f x)
replace xs i r = foldr (\x acc -> if (i+1) + length acc == length xs then r:acc else x:acc) [] xs
 
groupAt n [] = []
groupAt n xs = take n xs : groupAt n (drop n xs)

Measured memory_bytes: 4412