akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#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
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int n,ct=0;
string data;
void solve(){
        if(n<=2) {
                cout<<"0"<<endl;
        }else{
                rep(i,n-2){
                        if(data.at(i)=='A') {
                                if(data.at(i+1)=='B') {
                                        if(data.at(i+2)=='C') {
                                                ct++;
                                        }
                                }
                        }
                }
                cout<<ct<<endl;
        }
}

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

        solve();
        return 0;
}


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

int main(){
	int N, K;
	int x[100010];
	int ans = 1000000000;
	int l;
	int r;
	int a;

	cin >> N >> K;
	for (int i = 0; i < N; i++){
		cin >> x[i];
	}
	for (int i = 0; i < N - K + 1; i++){
		l = x[i];
		r = x[i + K - 1];
		a = min(abs(l) + abs(r - l), abs(r) + abs(r - l));
		ans = min(ans, a);
	}
	cout << ans << endl;

	return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int res = 0;
  int zMax = 0;
  rep(i, s.size()) {
    if (s.at(i) == 'Z') {
      zMax = max(zMax, i);
    }
  }
  rep(i, s.size()) {
    if (s.at(i) == 'A') {
      res = max(res, zMax - i + 1);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, L;
  cin >> N >> L;
  vector<ll> score(N);
  for (int i = 0; i < N; i++) {
    score[i] = L + i;
  }
  ll all_sum = 0, ans = 0, diff = 300;
  for (int i = 0; i < N; i++) {
    all_sum += score[i];
  }
  for (int i = 0; i < N; i++) {
    ll cur_score = all_sum - score[i];
    ll cur_diff = abs(all_sum - cur_score);
    if (cur_diff < diff) {
      ans = cur_score;
      diff = cur_diff;
    }
  }
  cout << ans << endl;
}

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

int main(){
    int K = 26;
    int D;
    cin >> D;
    vector<ll> C(K);
    for (int i = 0; i < K; i++) cin >> C[i];
    vector<vector<ll>> s(D+1, vector<ll>(K, 0));
    for (int i = 1; i <= D; i++) {
        for (int j = 0; j < K; j++) {
            cin >> s[i][j];
        }
    }
    
    vector<int> ans(D+1, 0);
    
    vector<set<int>> day(K);
    for (int i = 0; i < K; i++) {
        day[i].insert(0);
        day[i].insert(D+1);
    }
    vector<int> cnt(K, 0);
    for (int i = 1; i <= D; i++) {
        int op = 0;
        int s_mx = 0;
        for (int j = 0; j < K; j++) {
            if (s_mx < s[i][j]) {
                s_mx = s[i][j];
                op = j;
            }
        }
        day[op].insert(i);
        ans[i] = op+1;
    }
    
    ll inf = 1e18;
    ll r = 123456789;
    ll mod = 1e9+7;
    int repmax1 = 50000;
    for (int rep = 0; rep < repmax1; rep++) {
        r = r*r%mod;
        int a = r%D+1;
        
        int def = ans[a]-1;
        
        ll pt_max = -inf; 
        ll op = 0;
        day[def].erase(day[def].find(a));
        for (int i = 0; i < K; i++) {
            auto it = day[i].lower_bound(a);
            ll nxt = (*it);
            it--;
            ll pre = (*it);
            ll pt = ((nxt-pre)*(nxt-pre+1)/2 - ((a-pre)*(a-pre+1)/2+(nxt-a)*(nxt-a+1)/2)) * C[i] + s[a][i];
            if (pt > pt_max) {
                pt_max = pt;
                op = i;
            }
        }
        day[op].insert(a);
        ans[a] = op+1;
    }
    
    int repmax2 = 10000;
    for (int rep = 0; rep < repmax2; rep++) {
        r = r*r%mod;
        int a = r%(D-1)+1;
        
        int def1 = ans[a]-1;
        int def2 = ans[a+1]-1;
        
        ll pt_max = -inf; 
        ll op1 = 0, op2 = 0;
        day[def1].erase(day[def1].find(a));
        day[def2].erase(day[def2].find(a+1));
        vector<int> nxt(K), pre(K);
        for (int i = 0; i < K; i++) {
            auto it = day[i].lower_bound(a);
            nxt[i] = (*it);
            it--;
            pre[i] = (*it);
        }
        
        for (int i = 0; i < K; i++) {
            for (int j = 0; j < K; j++) {
                ll pt = s[a][i]+s[a+1][j];
                if (i == j) pt += ((nxt[i]-pre[i])*(nxt[i]-pre[i]+1)/2 - ((a-pre[i])*(a-pre[i]+1)/2+(nxt[i]-a-1)*(nxt[i]-a)/2)) * C[i];
                else {
                    pt += ((nxt[i]-pre[i])*(nxt[i]-pre[i]+1)/2 - ((a-pre[i])*(a-pre[i]+1)/2+(nxt[i]-a)*(nxt[i]-a+1)/2)) * C[i];
                    pt += ((nxt[j]-pre[j])*(nxt[j]-pre[j]+1)/2 - ((a+1-pre[j])*(a+1-pre[j]+1)/2+(nxt[j]-a-1)*(nxt[j]-a)/2)) * C[j];
                }
                if (pt > pt_max) {
                    pt_max = pt;
                    op1 = i;
                    op2 = j;
                }
            }
        }
        day[op1].insert(a);
        day[op2].insert(a+1);
        ans[a] = op1+1;
        ans[a+1] = op2+1;
    }
    
    for (int i = 1; i <= D; i++) cout << ans[i] << endl;
    
    return 0;
}


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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

void ALLIN1_NUMBER(vector<ll>& V)
{
    for(auto& x : V)
    {
        cin >> x;
    }
}

void ALLOUT_NUMBER(vector<ll> V)
{
    ll N = V.size();
    for(ll i=0;i<N;i++)
    {
        cout << V[i];
        if(i<N-1) cout << ' ';
    }
    cout << endl;
}

template<class T>
void OUT0(T N)
{
    cout << N << endl;
}

static const double pi = acos(-1.0);

double Cos(double D)
{
    return cos(pi/180 * D);
}

void As(string& s, ll& K)
{
    for(auto& x : s)
    {
        if(x!='a')
        if(('z'+1-x)<=K)
        {
            K -= ('z'+1-x);
            x = 'a';
        }
    }
    K%=('z'-'a'+1);
    for(ll i=0;i<K;i++)
    {
        if(s[s.size()-1]=='z') s[s.size()-1] = 'a';
        else s[s.size()-1]++;
    }
}

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

    ll K;
    cin >> K;

    As(s,K);

    OUT0(s);

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n, k;
    cin >> n >> k;

    cout << n - k + 1 << endl;

    return 0;
}

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

int main(){
    int K,n;
    cin >> n >> K;
    pair<long long,long long> p[n],q[n];
    for(int i=0; i<n; i++){
        long long x,y;
        cin >> x >> y;
        p[i] = make_pair(x,y);
        q[i] = make_pair(y,x);
    }
    sort(p,p+n);
    sort(q,q+n);
    long long ans = 4000000000000000000;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            for(int k=0; k<n-1; k++){
                for(int l=k+1; l<n; l++){
                    int cnt=0;
                    long long u=q[l].first,d=q[k].first;
                    for(int m=i; m<=j; m++){
                        if(p[m].second <= u && p[m].second >= d) cnt++;
                    }
                    if(cnt == K) ans = min(ans,(u-d)*(p[j].first-p[i].first));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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


int a[100001];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,L;
	cin>>n>>L;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int x=0;
	for(x=1;x<n;x++)
		if(a[x]+a[x+1]>=L)
			break;
	if(x==n){
		cout<<"Impossible"<<endl;
	}
	else{
		cout<<"Possible"<<endl;
		for(int i=1;i<x;i++)
			cout<<i<<'\n';
		for(int i=n-1;i>x;i--)
			cout<<i<<'\n';
		cout<<x<<'\n';
	}
}


Measured memory_bytes: 1280
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N,K; cin>>N>>K;
  vector<ll> A(N);
  vector<ll> list(2001,0);
  rep(i,N)
  {
    cin>>A.at(i);
    ll a=A.at(i);
    if(a!=2000) {list.at(a+1)++;}
  }
  rep(i,2000)
  {
    list.at(i+1)+=list.at(i);
  }  
  
  ll ans=0;
  rep(i,N)
  {
    ll count=0;
    for(int j=i+1;j<N;j++)
    {
      if(A.at(i)>A.at(j)) {count++;}
    }
    ll a=A.at(i);
    ans+=count*K%MOD+K*(K-1)/2%MOD*list.at(a)%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <vector>
using namespace std;

vector<int> graph[100000];
int parent[18][100000];

vector< vector<int> > pre;
vector< vector< vector<int> > > seg;

int height[100000];
int belong[100000];
int next[100000];

int depth[100000];
int value[100000];
int N,Q;

int genLH(int pos,int num){
	if(pos == -1 || belong[pos] != -1){
		next[num] = pos;
		return 0;
	}else{
		height[pos] = genLH(parent[0][pos],num) + 1;
		belong[pos] = num;
		pre[num].push_back(value[pos]);
		return height[pos];
	}
}

void genTree(int pos,int prev,int dep){
	parent[0][pos] = prev;
	depth[pos] = dep;
	for(int i = 0 ; i < graph[pos].size() ; i++){
		if(graph[pos][i] != prev) genTree(graph[pos][i],pos,dep+1);
	}
	if(belong[pos] == -1){
		pre.push_back(vector<int>(1,-1));
		genLH(pos,pre.size()-1);
	}
}

void genLCA(){
	for(int i = 1 ; i < 18 ; i++){
		for(int j = 0 ; j < N ; j++){
			if(parent[i-1][j] != -1) parent[i][j] = parent[i-1][parent[i-1][j]];
		}
	}
}

int getLCA(int x,int y){
	if(depth[x] < depth[y]) swap(x,y);
	int d = depth[x] - depth[y];
	for(int i = 0 ; i < 18 ; i++)
		if(d>>i&1) x = parent[i][x];
	if(x==y) return x;
	for(int i = 17 ; i >= 0 ; i--){
		if(parent[i][x] != parent[i][y]){
			x = parent[i][x];
			y = parent[i][y];
		}
	}	
	return parent[0][x];
}

int uniq[100000] , U = 0;

void add(vector< vector<int> > &seg,int x,int v){
	while(x < seg.size()){
		seg[x].push_back(v);
		x += x & -x;
	}
}

int get(vector< vector<int> > &seg,int x,int k){
	//cout << "BAD" << " " << seg.size() << " " << x << endl;
	int ans = 0;
	while(x){
		ans += lower_bound(seg[x].begin(),seg[x].end(),k) - seg[x].begin() - 1;
		x -= x & -x;
	}
	return ans;
}

int query(int from,int to,int k){
	int A = belong[from] , B = belong[to];
	if(A==B){
		return get(seg[A],height[from],k) - get(seg[A],height[to]-1,k);
	}else{
		return get(seg[A],height[from],k) + query(next[A],to,k);
	}
}

int main(){
	memset(belong,-1,sizeof(belong));
	memset(parent,-1,sizeof(parent));
	memset(height,-1,sizeof(height));
	scanf("%d%d",&N,&Q);
	for(int i = 0 ; i < N ; i++){
		scanf("%d",&value[i]);
		uniq[U++] = value[i];
	}
	for(int i = 0 ; i < N - 1 ; i++){
		int a,b;
		scanf("%d%d",&a,&b);
		--a,--b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	sort(uniq,uniq+U);
	U = unique(uniq,uniq+U) - uniq;
	genTree(0,-1,0);
	for(int i = 0 ; i < pre.size() ; i++){
		seg.push_back( vector< vector<int> > (pre[i].size(),vector<int>(1,-1)) );
		for(int j = 1 ; j < pre[i].size() ; j++) add(seg.back(),j,pre[i][j]);
		for(int j = 0 ; j < seg.back().size() ; j++) sort(seg.back()[j].begin(),seg.back()[j].end());
	}
	genLCA();
	for(int i = 0 ; i < Q ; i++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		--a,--b;
		//a == b ツケツーツスツづ可妥篠可楪づつォツづつ「ツづゥツつゥ?ツづ慊つセツつオツづつ「ツづ按つ「ツづ債つク
		int l = 0 , r = U-1;
		int p = getLCA(a,b);
		//assert(depth[p] <= depth[a] && depth[p] <= depth[b]);
		while(l!=r){
			int m = (l+r+1)/2;
			int g = query(a,p,uniq[m]) + query(b,p,uniq[m]) - (value[p] < uniq[m]);
			
			if(g < c) l = m;
			else r = m-1;
		}
		printf("%d\n",uniq[l]);
	}
}

Measured memory_bytes: 28000
from sys import stdin

n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
t = stdin.readline().rstrip()
# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
# data = [stdin.readline().rstrip().split() for _ in range(n)]

ans = 2 * n
for i in range(n, 0, -1):
    if s[n-i:] == t[:i]:
        ans -= i
        break
print(ans, '\n')
# print(*data, sep='\n')


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    public static void Main()
    {
        int[] ab = SpIntRead(' ');
        Console.WriteLine(Math.Max(Math.Max(ab[0] + ab[1], ab[0] * ab[1]),ab[0] - ab[1]));
    }
}

public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static long LCM(long a, long b)
    {
        long c = a * b;
        if (a < b) Swap(ref a, ref b);
        long d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static string ToConvertBit(int N, int e)
    {
        string ret = "";
        int r = 0;
        while (N != 0)
        {
            r = N % e;
            ret += r.ToString();
            N -= r;
            N /= e;
        }
        ret = StrReverce(ret);
        return ret;
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <stdio.h>
#include <string.h>
#define int long long

using namespace std;

signed main()
{
	int n=50,K;
	scanf("%lld",&K);
	int avg=K/n,rst=K%n;
	printf("%lld\n",n);
	for(int i=1;i<=rst;i++) printf("%lld ",n-1+avg-rst+n);
	for(int i=rst+1;i<=n;i++) printf("%lld ",n-1+avg-rst);
	printf("\n");
}


Measured memory_bytes: 256
a=list(map(int,input().split()))
a.sort()
count=0
while a[1]!=a[2]:
    a[1]+=1
    a[0]+=1
    count+=1

if (a[1]-a[0])%2==0:
    count+=(a[1]-a[0])//2
else:
    count+=(a[1]-a[0])//2+2

print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>

using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;*/ //int order_of_key, it find_by_order

typedef long long ll;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> pii;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define isz(x) (int)(x).size()

/* <----------------------------------------------------------> */

void solve()
{
    string s;
    cin >> s;
    if (isz(s) >= 4 && s.substr(0, 4) == "YAKI") cout << "Yes\n";
    else cout << "No\n";
}

/* <----------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME ""

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 256
A = list(map(int,input().split()))
B = list(map(int,input().split()))
T = int(input())

distance = abs(A[0] - B[0])

A[1] = A[1] * T
B[1] = B[1] * T

if distance <= (A[1] - B[1]):
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(_itr, array) { cin >> *(_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
template <class T, class U>ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	string s;
	int ans=0;
	cin >>s;
	rep(i, s.size()) { ans += s[i] - '0';
		ans %= 9;
	}
	cout<<solve(ans==0)<<endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int M[2],D[2];
    cin >> M[0] >> D[0] >> M[1] >> D[1];
    int ans;
    if(M[0] != M[1]) ans = 1;
    else ans = 0;
    cout << ans << "\n";
    return 0;
}


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

using namespace std;

int main()
{
    int n, m;
    int dp[128];
    
    scanf("%d %d", &n, &m);
    
    fill(dp, dp + n + 1, 128);
    
    pair<int, int> p[128];
    
    for (int i = 0; i < m; i++){
        scanf("%d %d", &p[i].first, &p[i].second);
    }
    
    sort(p, p + m);
    
    dp[0] = 0;
    
    for (int i = 0; i < m; i++){
        for (int j = p[i].first; j <= p[i].second; j++){
            dp[j] = min(dp[j], dp[p[i].first - 1] + 1);
        }
    }
    
    if (dp[n] != 128) printf("%d\n", dp[n]);
    else printf("Impossible\n");
    
    return (0);
}

Measured memory_bytes: 1192
s=int(input())
c=0
for i in range(1,1000001):
    if i==1:
        c=s
    else:
        if c%2==0:
            c=c//2
        else:
            c=3*c+1
    if c==1:
        break
    if c==2:
        break
    if c==4:
        break
print(i+3)


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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
//

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    c[0]=0;
    ll sum=0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        sum+=b[i];
    }
    for(int i=1;i<n;i++)
        cin>>c[i];
    for(int i=0;i<n-1;i++)
    {
        if(a[i]+1==a[i+1])
            sum+=c[a[i]];
    }
    cout<<sum<<"\n";
  return 0;
 }


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

int main(){
  string s;
  cin >> s;
  int N = s.size(); 
  int len = N/2,count = 0;
  string sf,sb;
  if(N % 2 == 0) {
    sf = s.substr(0,len);
    sb = s.substr(len,N);
  }else{
    sf = s.substr(0,len);
    sb = s.substr(len+1,N);
  }
  reverse(sb.begin(),sb.end());
  for(int i=0;i<sf.size();++i){
      if(sf[i] != sb[i]) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://abc067.contest.atcoder.jp/tasks/abc067_b

"""
import sys
from sys import stdin

input = stdin.readline


def main(args):
    N, K = map(int, input().split())
    rods = [int(x) for x in input().split()]
    rods.sort()
    snake = rods[-K:]
    print(sum(snake))


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n; cin >> n;
    vector<ll> cnt(26,INF);
    rep(i,n){
        string s; cin >> s;
        vector<ll> temp(26,0);
        for(auto j : s){
            temp[j - 'a']++;
        }
        rep(k,26)chmin(cnt[k],temp[k]);
    }
    string ans;
    rep(i,26){
        rep(j,cnt[i])ans += 'a'+i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <vector>
# include <string>
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	for (int i = 0; i < w+2; i++) {
		cout << "#";
	}
	cout << endl;
	string a;
	for (int i = 0; i < h; i++) {
		std::cin >> a;
		std::cout << "#" << a << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef long long ll;

int main(){
	ll a[1001],b[1001],c[1001],d[1001];
	ll v,ans=0;
	int n;
	scanf("%d %lld",&n,&v);
	vector<ll> x;
	vector<ll> y;
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++) scanf("%lld",&b[i]);
	for(int i=0;i<n;i++) scanf("%lld",&c[i]);
	for(int i=0;i<n;i++) scanf("%lld",&d[i]);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			x.push_back(a[i]+b[j]);
			y.push_back(c[i]+d[j]);
		}
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());
	for(int i=0;i<x.size();i++){
		ans+=upper_bound(y.begin(),y.end(),v-x[i])-lower_bound(y.begin(),y.end(),v-x[i]);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 18824
#include <bits/stdc++.h>
#define ft first
#define sd second
#define mp make_pair
#define MAX 100010
#define pub push_back
#define pob pop_back
#define mt make_tuple
#define len length
#define dbgn(x) cerr<<#x<<": "<<x<<'\n'
#define dbg(x) cerr<<#x<<": "<<x<<' '
#define FOR(i,lbd,rbd) for((i)=(lbd);(i)<(rbd);++(i))
#define setZ(A) memset(A,0,sizeof A)
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> pll;
typedef pair<int,int> pii;
typedef map<lli,lli> mll;
typedef map<int,int> mii;
typedef priority_queue<int,vector<int>,greater<int> > pqi_min;
template<class T, class Y> 
T pow(T a,Y p) {
	if (p==0) return 1;
	if (p&1) {
		return (a*pow(a,p-1));
	}
	T y = pow(a,p>>1);
	return (y*y);
}
//int+string
//cin.ignore();

const int M=1e9+7;
lli dis[205][205];
const int INF = 2e9;
void solve() {
	int i,j,k,m,n,r,c;
	cin>>n>>m>>r;
	int arr[r];
	FOR(i,0,r) cin>>arr[i];
	FOR(i,0,n+1) {
		FOR(j,0,n+1) {
			if (i==j) dis[i][i]=0;
			else dis[i][j]=INF;
		}
	}
	FOR(i,0,m) {
		cin>>j>>k>>c;
		dis[j][k]=dis[k][j]=c;
	}

	FOR(i,1,n+1) {
		FOR(j,1,n+1) {
			FOR(k,1,n+1) {
				if (dis[j][i]==INF || dis[i][k]==INF) continue;
				dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]); 
			}
		}
	}
	sort(arr,arr+r);
	lli ans=INT_MAX;
	do{
		lli ds=0;
		for(i=0;i<r-1;i++) ds = ds + dis[arr[i]][arr[i+1]];
		ans=min(ans,ds);  
	} while(next_permutation(arr,arr+r));
	cout<<ans<<'\n';
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N; cin >> N;
	cout << 180*N - 360 << endl;
	return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int h, w, k, ans = 2000;
char s[12][1005];
int main(){
	scanf("%d%d%d", &h, &w, &k);
	rep(i,h) scanf("%s", s[i]);
	rep(bt, 1<<(h-1)){
		int n = __builtin_popcount(bt)+1, dp[12] = {}, cnt = n-1;
		bool ok = true;
		rep(i,w){
			int nw[12] = {}, e = 0;
			bool f = false;
			rep(j,h){
				if(s[j][i] == '1') nw[e]++;
				if((bt>>j)&1) e++;
			}
			rep(j,n) if(dp[j] + nw[j] > k){
				f = true;
				if(nw[j] > k) ok = false;
			}
			if(f){
				cnt++;
				rep(j,n) dp[j] = nw[j];
			}else rep(j,n) dp[j] += nw[j];
		}
		if(ok) ans = min(ans, cnt);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define itrep(it, a) for((it) = (a).begin(); (it) != (a).end(); (it)++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

int main(){
    bool prime[300005] = {1,1,1,1,1,1,0,1,0};
    vector<int> vi;
    rep(i,300005){
        if(not prime[i] && ((i - 1) % 7 == 0 || (i - 6) % 7 == 0)){
            vi.push_back(i);
            for(int j = i + i; j < 300005; j+=i){
                prime[j] = 1;
            }
        }
    }

    int n;
    while(cin >> n, n != 1){
        cout << n << ':';
        rep(i,vi.size()){
            if(n % vi[i] == 0) cout << ' ' << vi[i];
        }
        cout << endl;
    }
}

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

int keisan(int64_t N,int64_t K){
  int count=0;
  while(1){
    if(N/K>=1){
      count++;
      N/=K;
    }
    else
      break;
  }
  return count;
}


int main(){
  int64_t N,K,ans;
  vector<int> result();
  cin >> N >> K;
  cout<<keisan(N,K)+1<<endl;
  

}


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

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

int gcd(int a,int b){
    if (a%b==0) return(b);
    else return(gcd(b,a%b));
}

int main() {


    int k,x; cin >> k >> x;
    int left_max = -1000000;
    int right_max = 1000000;

    int ans = 0;

    int start = max((x-k+1),left_max);
    for(int i=start; i < x; i++) {
        cout << i << " ";
    }

    int end = min((x+k-1),right_max);
    for(int i=x; i < end; i++) {
        cout << i << " ";
    }

    cout << end << endl;

    return 0;

}


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

f=[0]*(10001)
for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            tmp=x*x+y*y+z*z+x*y+y*z+z*x
            if tmp>10000:continue
            f[tmp]+=1

for i in range(1,n+1):
    print(f[i])

Measured memory_bytes: 9232
a=[[10*[0]for _ in range(3)]for _ in range(4)]
for _ in range(int(input())):
 b,f,r,v=map(int,input().split())
 a[b-1][f-1][r-1]+=v
for i in range(4):
 for j in range(3):print('',*a[i][j])
 if i!=3:print('#'*20)


Measured memory_bytes: 5624
#define CPP17
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#ifdef CPP17
#include <variant>
#endif

#define endl codeforces

#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)

using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
using size_type = ssize_t;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

template <typename T, std::size_t Head, std::size_t... Tail> 
struct multi_dim_array { using type = std::array<typename multi_dim_array<T, Tail...>::type, Head>; };

template <typename T, std::size_t Head> 
struct multi_dim_array<T, Head> { using type = std::array<T, Head>; };

template <typename T, std::size_t... Args> using mdarray = typename multi_dim_array<T, Args...>::type;

#ifdef CPP17
template <typename T, typename F, typename... Args> 
void fill_seq(T &t, F f, Args... args) { 
    if constexpr (std::is_invocable<F, Args...>::value) { 
        t = f(args...); 
    } else { 
        for (size_type i = 0; i < t.size(); i++) fill_seq(t[i], f, args..., i); 
    } 
}
#endif

template <typename T> vec<T> make_v(size_type sz) { return vec<T>(sz); }

template <typename T, typename... Tail> 
auto make_v(size_type hs, Tail&&... ts) { 
    auto v = std::move(make_v<T>(std::forward<Tail>(ts)...)); 
    return vec<decltype(v)>(hs, v); 
}

namespace init__ { 
struct InitIO { 
    InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } 
} init_io; 
}
#define CPP17


ll solve() {
    ll x, k, d;
    std::cin >> x >> k >> d;
    ll ax = std::abs(x);
    ll div = ax / d;
    if (k < div) return ax - k * d;
    ll rest = k - div;
    ll ret = ax % d;
    if (rest & 1) ret = d - ret;
    return ret;
}

int main() {
    std::cout << solve() << "\n";
    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k=nxtl();
    cout<<"50\n";
    ll q=k/50;
    ll r=k%50;
    for(int i=0;i<r;i++)
        cout<<50+q<<" ";
    for(int i=0;i<50-r;i++)
        cout<<49-r+q<<" ";
    cout<<endl;
    
    
    
    return 0;   
}




 
 


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

dat = []

for i in range(n):
    a,b = map(int,input().split())
    dat.append((a,b))

dat.sort(key = lambda x:x[1])

now = 0
for l,t in dat:
    if now + l > t:
        print("No")
        exit(0)
    else:
        now += l
print("Yes")


Measured memory_bytes: 31860
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define re(i,n) for(ll i=0;i<(n);++i)
#define itn int
#define ocut cout
#define ouct cout
#define outc cout

int main(){
    long long n,k;
    cin >> n >> k;
    long long h[n];
    re(i,n){
        cin >> h[i];
    }
    sort(h,h+n);
    long long v=0;
    for(long long i=0;i<n-k;i++){
        v=v+h[i];
    }
    cout << v;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

#define REP(i,n) for(int i = 0;i < n;i++)
#define pyfor(j,s,n,i) for(int j = s;j < n;j += i)

using namespace std;
typedef long long ll;
const int INF = INT_MAX;

const int max_n = 1e3;

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

  int N;
  cin >> N;
  int a[N];
  REP(i, N){
    cin >> a[i];
  }

  int cnt = 0;
  REP(i, N){
    if(a[a[i]-1] == i + 1) {
      cnt++;
    }
  }

  cout << cnt/2 << "\n";
  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		StringTokenizer st = new StringTokenizer(br.readLine());
		int a=Integer.parseInt(st.nextToken());
		int b=Integer.parseInt(st.nextToken());

		int d=a/b;
		int r=a%b;

		double da=(double)a;
		double db=(double)b;
		double f=da/db;

		double befor=f;
		String after=String.format("%.5f",befor);

		System.out.println(d+" "+r+" "+after);
	}

}



Measured memory_bytes: 24872
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  int n, k; cin >> n >> k;
  vll plus, minus;

  rep(i, n) {
    int x; cin >> x;
    if (i == 0) minus.eb(0), plus.eb(0);

    if (x < 0) minus.eb(abs(x));
    else plus.eb(x);
  }

  sort(all(minus));
  int p = si(plus), m = si(minus);

  ll ans = MOD;
  rep(i, p) {
    int j = k - i;
    if (j >= m || j < 0) continue;

    chmin(ans, plus[i] * 2 + minus[j]);
  }

  rep(i, m) {
    int j = k - i;
    if (j >= p || j < 0) continue;

    chmin(ans, minus[i] * 2 + plus[j]);
  }

  if (k < p) chmin(ans, plus[k]);
  if (k < m) chmin(ans, minus[k]);

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 4496
#include <bits/stdc++.h>
#define LL long long
#define PI pair<int,int>
#define PL pair<LL,LL>
#define st first
#define nd second
#define all(x) x.begin(),x.end()
using namespace std;

const int MX = 1010;

struct Match{
    int x;
    int y;
    int v;
    bool operator<(const Match& M) const {
        if(v == M.v && x == M.x)
            return y < M.y;
        if(v == M.v)
            return x < M.x;
        return v > M.v;
    }
};

int n;
int a[MX][MX];
int b[MX][MX];
int itr[MX];
set<Match> s;
void add(int x,int y){
    Match M = {x,y,b[x][y]};
    Match N = {y,x,b[y][x]};
    s.erase(M);
    s.erase(N);
    M.v++;
    N.v++;
    b[x][y]++;
    b[y][x]++;
    s.insert(M);
    s.insert(N);
}
int main(){
    cin >> n;
    memset(b,0,sizeof(b));
    for(int i=1 ; i<=n ; ++i){
        for(int j=1 ; j<n ; ++j){
            cin >> a[i][j];
            s.insert({i,a[i][j],0});
        }
        itr[i] = 1;
    }
    for(int i=1 ; i<=n ; ++i)
        add(i,a[i][1]);
    int ans = 0;
    while(!s.empty()){
        ans++;
        int is = 0;
        vector<PI> def;
        while(!s.empty()){
            Match M = *s.begin();
            //cout << M.x << " " << M.y << " " << M.v << "\n";
            if(M.v == 2){
                s.erase(M);
                s.erase({M.y,M.x,M.v});
                itr[M.x]++;
                itr[M.y]++;
                if(itr[M.x] < n)
                    def.push_back(make_pair(M.x,a[M.x][itr[M.x]]));
                if(itr[M.y] < n)
                    def.push_back(make_pair(M.y,a[M.y][itr[M.y]]));
            }else break;
        }
        if(def.empty() && !s.empty()){
            puts("-1");
            return 0;
        }
        for(auto el : def)
            add(el.st,el.nd);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 70656
def k_judge(n, m, k):
    for i in range(n+1):
        for j in range(m+1):
            if i*(m-j)+j*(n-i) == k:
                return True
    return False


def main():
    n, m, k = map(int, input().split())
    if k_judge(n, m, k):
        print("Yes")
    else:
        print("No")
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(4100000)


def gcd(a,b):
  if b == 0:
    return a
  else:
    return gcd(b,a%b)


k=int(input())
ans=0
for i in range(1,k+1):
  for j in range(1,k+1):
    d=gcd(i,j)
    for l in range(1,k+1):
      if d!=1:
        ans+=gcd(d,l)
      else:
        ans+=1


print(ans)

Measured memory_bytes: 9196
M=1000000007
N=int(input())
C=sorted(map(int,input().split()),reverse=True)
def pow(x,p):
  if(p==0):
    return 1;
  if(p%2):
    a=pow(x,p-1)%M;
    return x*a%M
  else:
    a=pow(x,p//2)%M
    return a*a%M
ans=0;
p2=pow(2,2*N-2)%M
for k in range(N):
  ans=(ans+(C[k]*((p2*k)%M+2*p2))%M)%M
print(ans)

Measured memory_bytes: 25768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			int[][] league = new int[n][5];
			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				league[i][3] = i;
				league[i][4] = st.nextToken().charAt(0);
				for (int j = 0; j < n - 1; j++) {
					league[i][parseInt(st.nextToken())]++;
				}
			}
			Arrays.sort(league, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[0] != o2[0]) {
						return o2[0] - o1[0];
					} else {
						if (o1[1] != o2[1]) {
							return o1[1] - o2[1];
						} else {
							return o1[3] - o2[3];
						}
					}
				}
			});
			for (int[] team : league) {
				System.out.println((char) team[4]);
			}
		}
	}
}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

// greatest common divisor
LL GCD(LL a,LL b){
    LL t; LL r;
    if(a<b){t=a;a=b;b=t;}
    if(b==0){return a;}
    while(a%b!=0){r=a%b;a=b;b=r;}
    return b;
}

// least common multiple
LL LCM(LL a,LL b){LL ab=(a*b);return ab/GCD(a%b,b);}

LL f(Vll a, LL m){
    LL sum_mod = 0;
    for(LL i : a){
        sum_mod += m%i;
    }
    return sum_mod;
}

int main(){
    int N;
    cin>>N;
    Vll a(N);
    REP(i,N) cin>>a[i];

    LL ans = 0;
    REP(i,N) ans += a[i]-1;
    cout<<ans<<endl;

    return 0;
}

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

int main(int argc, char const *argv[]) {
  int A,B,C;
  cin >> A >> B >> C;
  
  if(A<=C && C<=B){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
A = list(map(int, input().split()))
T = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  T[a].append(b)
  T[b].append(a)
C = [a if len(T[i]) == 1 else a*2 for i, a in enumerate(A)]
def dfs(v, par=-1):
  for nv in T[v]:
    if nv != par:
      if not dfs(nv, v):
        return False
  if C[v] < 0:
    return False
  if par == -1:
    return C[v] == 0
  if C[v] > A[par] or C[v] > A[v]:
    return False
  C[par] -= C[v]
  return True
if dfs(0):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 114080
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
void swap(int *a,int *b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
int main(){
    int N,T;
    scanf("%d %d",&N,&T);
    int c[102],t[102];
    for(int i=1;i<=N;i++)
        scanf("%d %d",c+i,t+i);
    for(int i=1;i<=N;i++){
        for(int j=1;j<i;j++){
            if(c[j]>c[i]){
                swap(c+j,c+i);
                swap(t+j,t+i);
            }
        }
    }
    int f=1;
    for(int i=1;i<=N;i++){
        if(t[i]<=T){
            printf("%d",c[i]);
            f=0;
            break;
        }
    }
    if(f)
        printf("TLE");
    return 0;
}


Measured memory_bytes: 1688
package main

import "fmt"

func main() {
	var a, b string
	fmt.Scan(&a, &b)

	if a == "H" && b=="H"{
		fmt.Println("H")
	}else if a=="D" && b=="D"{
		fmt.Println("H")
	}else{
		fmt.Println("D")
	}

}



Measured memory_bytes: 512
#include <cstdio>
#define min(a,b) ((a)<=(b)?(a):(b))
int main() {
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++) {
        int x,y,b,p;
        scanf("%d %d %d %d",&x,&y,&b,&p);
        if(b>=5&&p>=2) {
            printf("%d\n",(int)((x*b+y*p)*0.8));
        }else if(b>=5) {
            printf("%d\n",(int)min((x*b+y*p),(x*b+y*2)*0.8));
        }else if(p>=2) {
            printf("%d\n",(int)min((x*b+y*p),(x*5+y*p)*0.8));
        }else {
            printf("%d\n",(int)min((x*b+y*p),(x*5+y*2)*0.8));
        }
    }
}

Measured memory_bytes: 1032
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let s = buf.split_whitespace().next().unwrap();

    fn easy_to_read(s: String) -> bool{
        let c: Vec<char> = s.chars().collect();
        for i in 0..c.len() {
            if i % 2 == 0 { // odd
                if c[i] == 'L' { return false; }
            }else {
                if c[i] == 'R' { return false; }
            }
        }
        return true;
    }

    println!("{}", if easy_to_read(s.to_string()) { "Yes" } else { "No "});
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }


ll h;
int n;
ll a[1005], b[1005];
ll dp[10005];
void solve() {
    cin >> h >> n;
    rep(i, n) cin >> a[i] >> b[i];

    fillArray(dp, inf);
    dp[0] = 0;
    rep(i, n) rep(j, 10002) {
        if (j >= a[i]) mins(dp[j], dp[j - a[i]] + b[i]);
    }

    ll ans = inf;
    loop(i, h, 10002) mins(ans, dp[i]);
    cout << ans << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 384