akhauriyash/Code-Regression huggingface dataset:
/*#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n, a[N], f[N];
int32_t main(){_

   cin>>n;

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

   vector<int> s;

   for (int i = 0; i < n; ++i)
   {
      while(!s.empty() and a[i] > a[s.back()]){
         //s.back() is gonna be...
         int vals = s.back() + 1;
         if(sz(s)-2 >= 0)
            vals -= s[sz(s)-2];
         f[a[s.back()]] += vals;
         s.pop_back();
      }
      if(!s.empty()){
         f[a[i]] += i - s.back();
      }
      s.push_back(i);
   }

   cout<<s<<endl;

   for (int i = 1; i < sz(s)-1; ++i)
   {
      f[s[i]] += s[i] - s[i-1];
   }

   int ans = 0;
   for (int i = 0; i <= 10; ++i)
   {
      tr(i, f[i]);
      ans += f[i] * i;
   }
   
   cout<<ans;

   return 0;
}
*/

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = (int)1e5 + 10;

int n, pos[N];

int32_t main(){_

   cin>>n;

   for (int i = 0; i < n; ++i)
   {
      int x;
      cin >> x;
      --x;
      pos[x] = i;
   }

   multiset<int> ms;
   ms.insert(-1);
   ms.insert(-1);

   ms.insert(n);
   ms.insert(n);

   int ans = 0;
   for (int i = n-1; i >= 0; --i)
   {
      ms.insert(pos[i]);
      auto it = ms.find(pos[i]);
      --it;
      int a = *it;
      --it;
      int b = *it;

      ++it;++it;

      ++it;
      int x = *it;
      ++it;
      int y = *it;
      ans += (i+1) * ((a-b) * (x - pos[i]) + (y-x) * (pos[i] - a));
   }

   cout<<ans;

   return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  string S; cin >> S;
  int ans = 0;
  REP(i, S.size() / 2) if(S[i] != S[S.size() - 1 - i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3616
n = int(input())
s = []
for i in range(n):
    s.append(list(input()))
ans = []
for i in range(len(s[0])):
    cnt = 0
    for j in range(n):
        if s[0][i] in s[j]:
            cnt += 1
    if cnt == n:
        ans.append(s[0][i])
        for j in range(1,n):
            s[j].remove(s[0][i])
ans.sort()
print(''.join(ans))

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

ll n, fac = 1, ans = 1;
map<ll, ll> mp;

int main()
{
    cin >> n;
    for(ll i = 1; i <= n; i++){
        ll k = i;
        for(ll j = 2; k > 1; j++){
            while(k % j == 0){
                mp[j]++;
                k /= j;
            }
        }
    }

    map<ll, ll> :: iterator ite;
    for(ite = mp.begin(); ite != mp.end(); ite++){
        //cout << ite->second + 1 << endl;
        ans *= (ite->second + 1);
        ans %= 1000000007;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  int b = 0;
  for (auto s : S) {
    if (s == '1') b++;
  }
  int x = 0, y = 0;
  for (int i = 0; i < N; i++) {
    if (b - 1 > 0) {
      x += (S[i] - '0') * pow(2, i, b - 1);
      x %= b - 1;
    }
    y += (S[i] - '0') * pow(2, i, b + 1);
    y %= b + 1;
  }
  function<int(int)> rec = [&](int x) {
    if (x == 0) return 0;
    return rec(x % __builtin_popcount(x)) + 1;
  };
  for (int i = N - 1; i > -1; i--) {
    if (S[i] == '1') {
      if (b == 1) {
        cout << 0 << '\n';
      } else {
        cout << rec((x - pow(2, i, b - 1) + (b - 1)) % (b - 1)) + 1 << '\n';
      }
    } else {
      cout << rec((y + pow(2, i, b + 1)) % (b + 1)) + 1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 3740
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std; 
typedef long long ll; 
char str[200005]; 
int cnt[35]; 
int main()
{
	// freopen("AGC019-B.in", "r", stdin); 
	scanf("%s", str); 
	int n = strlen(str); 
	for (int i = 0; i < n; i++)
		cnt[str[i] - 'a']++; 
	ll ans = (ll)n * (n - 1) / 2; 
	for (int i = 0; i < 26; i++)
		ans -= (ll)cnt[i] * (cnt[i] - 1) / 2; 
	printf("%lld\n", ans + 1);
	return 0; 
}


Measured memory_bytes: 384
N = int(input())
L = list(map(int, input().split()))

import bisect

L.sort()
# print(L)

ans = 0
for i in range(0, N-1):
    for j in range(i+1, N-1):
        ix = bisect.bisect_left(L, L[i] + L[j])
        ans += max(0, ix - j - 1)

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int box[3];
	int i;
	for(i=0;i<3;i++)	cin>>box[i];
	sort(box,box+3,greater<int>());
	cout<<box[0]*10+box[1]+box[2]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S,T;
  cin>>S>>T;
  int U = S.size();
  int count=0;
  for (int i = 0; i < U; i++) {
 if(S[i] != T[i]){
   count++;
 }
}

  if(count==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll MOD= 1000000007;
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
int dp[1002][1002];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    if(n<=999)
        cout<<"ABC";
    else
        cout<<"ABD";
}

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

int main() {

    ll n; cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    if (a[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll tmp = 1;
    const ll u = 1000000000000000000LL;
    for (ll i = 0; i < n; i++) {
        if (u / a[i] < tmp) {
            tmp = -1;
            break;
        }
        else tmp *= a[i];
    }
     cout << tmp << endl;    
    return 0;
}

Measured memory_bytes: 3948
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll M = 3234566667;

int K;
vector<ll> ans;

void solve(int n, ll x){
    if(n == 10){
        ans.pb(x);
        return;
    }
    if(x%10 > 0) solve(n+1, x*10+x%10-1);
    solve(n+1, x*10+x%10);
    if(x%10 < 9) solve(n+1, x*10+x%10+1);
}

signed main(){
    cin >> K;
    rep(i, 10){
        for(int j=1; j<10; j++){
            solve(i+1, j);
        }
    }
    sort(all(ans));
    cout << ans[K-1] << endl;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <string.h>

int main(void)
{
  char A[100];
  char B[100];
  int n,i,countA=0,countB=0;

  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%s",A);
    scanf("%s",B);
    if (strncmp(A,B,100)>0){
      countA=countA+3;
    }else if(strncmp(A,B,100)<0){
      countB=countB+3;
    }else{
        countA++;
        countB++;
    }
  }

  printf("%d %d\n",countA,countB);
  return 0;
}

Measured memory_bytes: 608
N, M, X, Y = list(map(int,input().split()))
lst_x = input().split()
lst_x_int=[int(i) for i in lst_x]
lst_y = input().split()
lst_y_int=[int(i) for i in lst_y]
#print(lst_x_int,lst_y_int)
#print(max(lst_x_int),min(lst_y_int))

if max(lst_x_int)+1 <= min(lst_y_int) and X < min(lst_y_int) and max(lst_x_int) < Y:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

int main(void)
{
	long h[100][3];
	long i, j, t, k, r=1, N, p;
	cin >> N;
	for (i = 0; i < N; i++)
	{
		cin >> h[i][0];
		cin >> h[i][1];
		cin >> h[i][2];
		if (h[i][2] != long(0))
			p = i;
	}
	for (i = 0; i < 101; i++)
	{
		for (j = 0; j < 101; j++)
		{
			t = h[p][2] + abs(i - h[p][0]) + abs(j - h[p][1]);
			for (k = 0; k < N; k++)
			{
				if (max(t - abs(i - h[k][0]) - abs(j - h[k][1]), long(0)) != h[k][2])
				{
					r = 0;
					break;
				}
				r = 1;
			}
			if (r == 1)
				break;
		}
		if (r == 1)
			break;
	}
	cout << i << " " << j << " " << t << endl;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include <queue>
using namespace std;
#define ll long long
#define mp make_pair
int n, ck[300005], inQ[300005];
ll A[300005], ans;
int main() {
	ans = -1e17;
	scanf("%d", &n);
	for (int i = 1; i <= 3 * n; i++)scanf("%lld", &A[i]);
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >P, R;
	priority_queue<pair<int, int> > Q;
	ll sum = 0; ll sum2 = 0;
	//sum-sum2
	for (int i = 1; i <= n; i++) {
		P.push(mp(A[i], i));
		sum += A[i];
	}
	for (int i = 3 * n; i > 2 * n; i--) {
		inQ[i] = 1;
		Q.push(mp(A[i], i));//뒷그룹중에 작은 N개. 정렬은 큰거가 top
		sum2 += A[i];
	}
	for (int i = 2 * n; i > n; i--) {
		pair<int, int> tp = Q.top();
		if (tp.first > A[i]) {
			inQ[tp.second] = 0;
			inQ[i] = 1;
			sum2 -= tp.first;
			R.push(tp);//뒷그룹중에 큰 나머지. 정렬은 작은거가 top
			Q.pop(); Q.push(mp(A[i], i));
			sum2 += A[i];
		}
	}
	ans = max(ans, sum - sum2);
	int Qcnt = n;
	for (int i = n + 1; i <= 3 * n; i++) {
		ck[i] = 1; 
		if (inQ[i]) {
			inQ[i] = 0; sum2 -= A[i];
			Qcnt--;
		}
		while (Qcnt>0 && ck[Q.top().second])
			Q.pop();
		while (1) {
			if (Qcnt == n)break;
			while (!R.empty() && ck[R.top().second])R.pop();
			if (!R.empty()) {
				++Qcnt;
				inQ[R.top().second] = 1;
				Q.push(R.top()); sum2 += R.top().first;
				R.pop();
			}
			else break;
		}
		if (Qcnt!= n)break;
		
		if (P.top().first < A[i]) {
			sum -= P.top().first; sum += A[i];
			P.pop(); P.push(mp(A[i], i));
		}
		ans = max(ans, sum - sum2);
	}
	printf("%lld", ans);

}

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

#define pb push_back
#define mp make_pair

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

bool used[100];

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

  pii r[n];
  for(int i = 0; i < n; i++){
    int a, b;
    cin >> a >> b;

    r[i] = mp(b, a);
  }

  pii b[n];
  for(int i = 0; i < n; i++){
    int c, d;
    cin >> c >> d;

    b[i] = mp(c, d);
  }
  
  sort(r, r+n, greater<pii>());
  sort(b, b+n);

  int ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(!used[j] and b[i].first > r[j].second and b[i].second > r[j].first){
        used[j] = true;
        ans++;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(s) s.begin(),s.end()
#define ld long double

using namespace std;

const int maxn = 1e5 + 7;
const ld eps = 1e-6;
const ll inf = 1e9 + 7;

int n;

int main() {
	cin >> n;
	bool check = 1;
	for (int i = 1; i <= n; i++) {
		int t = 0, x = 0, y = 0;
		cin >> t >> x >> y;
		if ((x + y) % 2 == 0) {
			if (t % 2 == 0 && t >= (x + y))continue;
			check = 0;
		}
		if ((x + y) % 2 == 1) {
			if (t % 2 == 1 && t >= (x + y))continue;
			check = 0;
		}
	}
	if (check) cout << "Yes";
	else cout << "No";
	return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),ans=1,cnt;
        for(int i=2;i<=n;i++){
            cnt=0;
            while(n%i==0){
                cnt++;
                n/=i;
            }
            if(cnt>0) ans*=(int)(Math.pow(i,cnt)-Math.pow(i,cnt-1));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26352
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] b = new int[a];
        int[] c = new int[a];
        int sum = 0;
        for (int i = 0; i < a; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < a; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 0; i < a; i++) {
            if (b[i] - c[i]> 0) {
                sum += b[i]-c[i];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<stdlib.h>
#define H 500000

void buildMaxHeap(int *);
int left(int);
int right(int);
void maxHeapify(int *,int);

int n;
int Heap_size;

int main()
{
  int i;
  int *A;

  scanf("%d",&n);
  A = (int *)malloc(n * sizeof(int));
  for(i = 1;i <= n;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

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

void buildMaxHeap(int *A)
{
  int i;
  Heap_size = n;
  for(i = Heap_size/2;i >= 1;i--){
    maxHeapify(A,i);
  }
}
void maxHeapify(int *A,int i)
{
  int l,r,largest,tmp;
  l = left(i);
  r = right(i);
  if(l <= Heap_size && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= Heap_size && A[r] > A[largest]) largest = r;
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(A,largest);
  }
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i+1;
}

Measured memory_bytes: 2472
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s.length() >= 4 && s.substr(0, 4) == "YAKI") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>
#define int ll

void solve(){
    int x;
    cin >> x;
    const int maxn = 2e5;
    bool p[maxn];
    memset(p, 0, sizeof(p));
    for (int i = 2; i < maxn; ++i) {
        if (p[i] == 0) {
            for (int j = 2 * i; j < maxn; j += i)
                p[j] = 1;
        }
    }
    while (p[x])
        x++;
    cout << x << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int t = 1;
    while(t--){
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int q;
    cin >> q;
    string s1, s2;
    for(int i = 0; i < q; i++){
        cin >> s1 >> s2;
        int l1 = s1.size() + 1, l2 = s2.size() + 1, maxl = 0;
        int dp[1000 + 1][1000 + 1];
        for(int j = 0; j < l1; j++) dp[j][0] = 0;
        for(int k = 0; k < l2; k++) dp[0][k] = 0;
        for(int j = 1; j < l1; j++){
            for(int k = 1; k < l2; k++){
                if(s1[j - 1] == s2[k - 1]) dp[j][k] = dp[j - 1][k - 1] + 1;
                else dp[j][k] = max(dp[j - 1][k], dp[j][k - 1]);
                maxl = max(maxl, dp[j][k]);
            }
        }
        cout << maxl << endl;
    }
}


Measured memory_bytes: 7072
#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001], m1=-1,m2=-1,n;
int main() {
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n);
	int i=1;
	while(i<n){
		if(a[i]==a[i-1]){
			if(a[i]>m1){
				m2=m1;
				m1=a[i];
			}else{
				if(a[i]>m2){
					m2=a[i];
				}
			}
			i+=2;
		}else{
			i++;
		}
	}
	if(m2==-1){
		cout << 0;
	}else{
		cout << m1*m2;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>

using namespace std;



int main() {
	int n, p[50];
	cin >> n;
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		if (p[i] != i + 1)count++;
	}
	if (count == 2||count==0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 1;
    for(int i=1;i<n;++i) {
        if(s[i] != s[i-1]) {
            ++ans;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var A = one[0];
  var B = one[1];
  var K = one[2];
  if(A >= K){
     A = A - K;
  }else{
    K -= A;
    A = 0;
    B = Math.max(0,B - K);
  }
  myout(A + " " + B);
}


Measured memory_bytes: 7500
#include "bits/stdc++.h"

using namespace std;

//#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


int main() {
	int N;
	cin >> N;
	int ans = 0;
	if (N % 111 == 0) ans = N;
	else ans=(N / 111 + 1) * 111;
	printf("%d", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    vi dp(n);
    for (int i = 1; i < n; i++) {
        i64 nin = 1e9;
        if (i - 2 >= 0) {
            nin = min(nin, dp[i - 2] + abs(as[i] - as[i - 2]));
        }
        nin = min(nin, dp[i - 1] + abs(as[i] - as[i - 1]));
        dp[i] = nin;
    }
    cout << dp.back() << endl;
}

Measured memory_bytes: 1792
import math
import copy
 
 
 
 
def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:
 
            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l
 
a=nCast(input().split());
b=nCast(input().split());
c=nCast(inputArr1(a[0]));

 
def func():
    result=0
    for number in c:
        sumall=0
        for idx in range(0,len(number)):
            sumall+=number[idx]*b[idx]
        if sumall+a[2]>0:
            result+=1
    return result
print(func()) 

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

int main() {
    vector<long long> poloc;
    vector<long long> odd_poloc;
    for (long long i = 1; i * (i + 1) * (i + 2) / 6LL <= 1000000LL; ++i) {
        long long pl = i * (i + 1) * (i + 2) / 6LL;
        poloc.push_back(pl);
        if (pl % 2) odd_poloc.push_back(pl);
    }

    vector<int> dp(1000000LL + 100, INT_MAX);
    vector<int> odd_dp(1000000LL + 100, INT_MAX);
    dp[0] = odd_dp[0] = 0;
    for (int i = 0; i <= 1000000LL; ++i) {
        if (dp[i] != INT_MAX) {
            for (long long pl : poloc) {
                if (i + pl > 1000000LL) break;
                dp[i + pl] = min(dp[i + pl], dp[i] + 1);
            }
        }
        if (odd_dp[i] != INT_MAX) {
            for (long long pl : odd_poloc) {
                if (i + pl > 1000000LL) break;
                odd_dp[i + pl] = min(odd_dp[i + pl], odd_dp[i] + 1);
            }
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) break;
        cout << dp[n] << " " << odd_dp[n] << endl;
    }
    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		long []a = new long[n];
		long []b = new long[n];
		
		long []c = new long [n];
		long sum = 0;
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Long.parseLong(sc.next());
			b[i] = Long.parseLong(sc.next());
			c[i] = a[i] + b[i];
			sum += b[i];
		}
		
		Arrays.sort(c);
		
		int cnt = 0;
		
		long sum1 = 0;
		for(int i = n-1 ; i >= 0 ;i--) {
			if(cnt % 2 == 0) {
				sum1 += c[i];
			}
			cnt++;
		}
		
		System.out.println(sum1 - sum);
		
	}
}

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

using namespace std;

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

    int a, one_continue_count = 0;
    
    int sol = 0;
    for ( int i=0; i<n; ++i ) {
	cin >> a;
	if ( a == 0 ) {
	    sol = max( sol, one_continue_count );
	    one_continue_count = 0;
	}
	else {
	    ++one_continue_count;
	}
    }
    sol = max( sol, one_continue_count );
    cout << sol+1 << endl;
}



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

long long x, a = 1, b = 54;
long long f(long long a) {
	return a * a * a * a * a;
}

int main() {
	cin >> x;
	while (2 * f(a) < x)
		a++;
	while (2 * f(b) > x)
		b--;

	while (1) {
		if (f(a) + f(b) == x) {
			cout << a << ' ' << -b << endl;
			return 0;
		} else if (f(a) + f(b) > x)
			b--;
		else
			a++;
	}
}


Measured memory_bytes: 3624
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#include <string>
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30;
const int maxn=100005;

char a[maxn],b[maxn];
int ans=inf;
int lf[maxn],ri[maxn],mx[maxn];
int n;

void solve(){
	memset(ri,0,sizeof ri);memset(lf,0,sizeof lf);
	for(int i=0;i<n;i++){
		while(b[(i+ri[i])%n]=='0')++ri[i];
		while(b[(i+lf[i]+n)%n]=='0')--lf[i];
	}
	for(int s=0;s<n;s++){
		memset(mx,0,sizeof mx);
		int dif=0;
		for(int r=0;r<n;r++){
			if(a[r]!=b[(r+s)%n]){
				mx[-lf[r]]=max(mx[-lf[r]],ri[r]-s),++dif;
			}
		}
		int cur=0,tmp=inf;
		for(int i=n-1;i>=0;i--){
			tmp=min(tmp,cur+i);
			cur=max(cur,mx[i]);
		}
		ans=min(ans,2*tmp+s+dif);
	}
}

int main(){
	scanf("%s",a);scanf("%s",b);
	n=strlen(a);
	int cnta=0,cntb=0;
	for(int i=0;i<n;i++)if(a[i]=='1')++cnta;
	for(int i=0;i<n;i++)if(b[i]=='1')++cntb;
	if(cntb==0){	// 特判 
		if(cnta==0)puts("0");
		else puts("-1");
		return 0;
	}
	solve();
	reverse(a,a+n);
	reverse(b,b+n);
	solve();
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 1408
//Created Time:2019年09月28日 星期六 20时12分35秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 1000006

using namespace std;

int prime[N];
bool vis[N];

int main(){
	int m = 1000000, tot = 0;
	for(int i = 2; i <= m; ++i){
		if(!vis[i]) prime[++tot] = i;
		for(int j = 1; j <= tot && i * prime[j] <= m; ++j){
			vis[i * prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
	long long a, b;
	cin >> a >> b;
	long long tmp = __gcd(a, b); int ans = 0;
	for(int i = 1; i <= tot && tmp > 1; ++i){
		if(tmp % prime[i] == 0){
			++ans;
			while(tmp % prime[i] == 0) tmp /= prime[i];
		}
	}
	if(tmp > 1) ++ans;
	cout << ans + 1 << endl;
	return 0;
}


Measured memory_bytes: 1536
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;

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

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

int a, b;

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif	
	cin >> a >> b;
	if(a == 0){
		cout << abs(b) + (b >= 0 ? 0 : 1);
		return 0;
	}
	if(b == 0){
    	cout << abs(a) + (a > 0 ? 1 : 0);
    }
	if(a > 0 && b > 0){
		if(a <= b){
			cout << b - a;
			return 0;
		} else {
			cout << 2 + (a - b);
			return 0;
		}
	}
	if(a < 0 && b > 0){
		cout << 1 + abs(-a - b);
		return 0;
	}
	if(a > 0 && b < 0){
		cout << 1 + abs(-b - a);
		return 0;
	}
	if(a < 0 && b < 0){
		if(a <= b){
			cout << b - a;
			return 0;
		} else {
			cout << 2 + a - b;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<map>
#include<bitset>
#include<assert.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<set>
#include<queue>
#define long long long
using namespace std;
const int N=1e6,mod=1e9+7;
int aa[N+2],bb[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;int ans=0;set<int>st;
  for(int i=1;i<=n;i++)
  {
    cin>>aa[i];
    if(i%2)st.insert(aa[i]);
  }
  sort(aa+1,aa+n+1);
  for(int i=1;i<=n;i+=2)if(st.find(aa[i])==st.end())ans++;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = (int)(n)-1; 0 <= i; i--)
#define rrep1(i, n) for (int i = (int)(n); 1 <= i; i--)

#define each(it, c) \
    for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(obj) (obj).begin(), (obj).end()

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x) cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    bool ans = false;
    rep(i, x+1) rep(j, x+1) {
        if (i + j != x) continue;
        if (2 * i + 4 * j == y) ans = true;
    }
    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < n; i++)
 
int main()
{
  int N;
  cin >> N;
 
  int big = 0, hashi = 1;
  for(int i = 2; i <= N; i++) {
    cout << "? 1 " << i << endl;
    int k;
    cin >> k;
    if(big < k) {
      big = k;
      hashi = i;
    }
  }
 
  vector< int > dist(N);
  dist[0] = hashi;
  for(int i = 1; i <= N; i++) {
    if(i == hashi) continue;
    cout << "? " << hashi << " " << i << endl;
    int k;
    cin >> k;
    dist[k] = i;
  }
 
  cout << "!";
  for(int i = 0; i < N; i++) {
    cout << " " << dist[i];
  }
  cout << endl;
 
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;


#define int long long 
int dp[105][500][105];

signed main(){
	int N, W;
	cin >> N >> W;

	vector<int> w(N + 1), v(N + 1);
	rep(i,N){
		cin >> w[i + 1] >> v[i + 1];
	}

	int base;
	base = w[1] - 1;
	rep(i,N){
		w[i + 1] -= base;
	}

	

	range(i,1,N + 1){
		for(int j = 400; j >= 0; j--){
		for(int k = N + 1; k >= 1; k--){
				dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k]);
				if(k * base + j <= W && j - w[i] >= 0){
					dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - w[i]][k - 1] + v[i]);
					//show(dp[i][j][k])
				}
			}
		}
	}

	int ans = 0;
	rep(j,400) rep(k,N + 1){
		ans = max(ans, dp[N][j][k]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 42496
n = int(input())
arr = [0] * 60000
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            n_ = x**2 + y**2 + z**2 + x*y + y*z + z*x
            arr[n_-1] += 1

print(*arr[:n], sep='\n')


Measured memory_bytes: 9628
//author:luckYrat(twitter:@luckYrat_)

//#include <bits/stdc++.h>
//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007

#define pb push_back
#define fir first
#define scn second

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int B[100000];
int main() { 
  long long n;cin>>n;
  long long ans = 1;
  int a[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
    if(a[i]>i){
      cout << 0 << endl;
      return 0;
    }
  }
  
  B[0] = 1;
  for(int i = 1; n > i; i++){
    B[a[i]]++;
    if(B[a[i]] > 3){
      cout << 0 << endl;
      return 0;
    }

    if(a[i]==0 && B[a[i]]==2){
      ans = (ans*2)%MOD;
    }else if(a[i]==0){
    }else{
      ans = (ans*(B[a[i]-1]-B[a[i]]+1))%MOD;
      //cout << "!!" << B[a[i]-1] << " " << B[a[i]] << endl;
    }
    //cout << ans << endl;

    
    
  }
  

  cout << (ans*3)%MOD<< endl;
  
}




Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long l, r;
	cin >> l >> r;
	long long res = 1e10;
	for (long long i = l; i <= min(2019 + l, r); i++) {
		for (long long j = i + 1; j <= min(2019 + l, r); j++) {
			res = min(res, i * j % 2019);
		}
	}
	cout << res << endl;
}

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

int		main(void)
{
	string s, t;

	cin >> s >> t;
	for (int i = s.size() - 1; i > 0; i--)
	{
		string tmp = s.substr(i) + s.substr(0, i);

		if (tmp == t || s == t)
		{
			puts("Yes");
			return (0);
		}
	}
	puts("No");
}


Measured memory_bytes: 256
from collections import deque
N, K = map(int, input().split())
A = [int(x) for x in input().split()]
A = sorted(A)
B = deque()
C = deque()
mod = (10**9)+7
for h in range(N):
    B.append(A[h])
    C.append(A[h])


def cmb(n, r):  # 【Python】組み合わせ(nCr) 計算の高速化より引用
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


N_cmb = 10**5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for ZZZ in range(2, N_cmb + 1):
    g1.append((g1[-1] * ZZZ) % mod)
    inverse.append((-inverse[mod % ZZZ] * (mod//ZZZ)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


ans = 0
for i in range(N):
    if N - i >= K:
        kari = cmb(N - i - 1, K-1) % mod
        # print(kari)
        ans += (kari * B.pop()) % mod
        ans -= (kari * C.popleft()) % mod
        ans = ans % mod
print(ans)


Measured memory_bytes: 22980
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	REP(i, K) {
		if (i % 2 == 0) {
			if (A % 2 == 1) {
				A -= 1;
				A /= 2;
				B += A;
			}
			else {
				A /= 2;
				B += A;
			}
		}
		else {
			if (B % 2 == 1) {
				B -= 1;
				B /= 2;
				A += B;
			}
			else {
				B /= 2;
				A += B;
			}
		}
	}

	cout << A << " " << B << endl;


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int N;
vector<pair<pair<string,int>,int> > restaurant;

int main(void) {
    cin>>N;

    string s;
    int p;
    for(int i = 1;i <= N;i++) {
        cin>>s>>p;
        restaurant.push_back(make_pair(make_pair(s,-p),i));
    }

    sort(restaurant.begin(),restaurant.end());

    for(int i = 0;i < N;i++) {
        cout<<restaurant[i].second<<endl;
    }

    return 0;
}







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

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, mw, ms, to, w[1005], s[1005], v[1005], id[1005];
num pre[20005], dp[20005], ans;

bool cmp(int i, int j) {
    return w[i] + s[i] < w[j] + s[j];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    cont (i, n) {
        cin >> w[i] >> s[i] >> v[i];
        to = max(to, w[i] + s[i] + 1);
        id[i] = i;
    }
    sort(id + 1, id + n + 1, cmp);
    cont (pi, n) {
        int i = id[pi];
        memset(dp, 0, sizeof(dp));
        loop (j, s[i] + 1) {
            dp[j + w[i]] = pre[j] + v[i];
        }
        loop (j, to) {
            pre[j] = max(pre[j], dp[j]);
        }
    }
    loop (i, to) {
        ans = max(ans, pre[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int H, W, D, A;
int Q, L, R;
int px[90001], py[90001];
int d[90001];

int main() {

	cin >> H >> W >> D;

	//今まではAijで2次元配列に格納してたけど、
	//整数Aで検索できるこの形も覚える。!
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A;
			px[A] = i; py[A] = j;
		}
	}

	for (int i = D + 1; i <= H * W; i++) {
		d[i] = d[i - D] + abs(px[i] - px[i - D]) + abs(py[i] - py[i - D]);
	}

	cin >> Q;

	while (Q--) {
		cin >> L >> R;
		cout << d[R] - d[L] << endl;
	}

}


Measured memory_bytes: 2176
using System;

namespace Rectangle
{
	class Rectangle
	{
		private int height;
		private int weight;

		public Rectangle()
		{
			height = 0;
			weight = 0;
		}

		public void getHeightAndWeight()
		{
			string s = Console.ReadLine();
			string[] sArray = s.Split(' ');

			height = int.Parse(sArray[0]);
			weight = int.Parse(sArray[1]);
		}

		public int Height
		{
			set { height = value; }
			get { return height; }
		}

		public int Weight
		{
			set { weight = value; }
			get { return weight; }
		}

	}

	public class MainClass
	{
		public static void Main(string[] args)
		{
			int area = 0, periphery = 0;

			Rectangle rec = new Rectangle();

			rec.getHeightAndWeight();

			area = rec.Height * rec.Weight;
			periphery = rec.Height * 2 + rec.Weight * 2;

			Console.WriteLine("{0} {1}", area, periphery);
		}
	}
}

Measured memory_bytes: 9144
import java.util.*;


public class Main {

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

	}
	
	private void doit(){
		new A();
	}
	
	class A{
		A(){
			while(true){
				int w = sc.nextInt();
				int d = sc.nextInt();
				if((w|d) == 0)break;
				int [] data =new int[w];
				int [] data2 = new int[d];
				int sum = 0;
				for(int i = 0 ; i < w; i++){
					data[i] = sc.nextInt();
					sum += data[i];
				}
				for(int i = 0 ; i < d; i++){
					data2[i] = sc.nextInt();
					sum += data2[i];
				}
				//System.out.println(" sum = " +sum);
				
				boolean [] used = new boolean[w];
				boolean [] used2 = new boolean[d];
				for(int i = 0 ; i < w; i++){
					for(int j = 0 ; j < d; j++){
						if(! used2[j]){
							if(data[i] == data2[j]){
								sum -= data2[j];
								used2[j] = true;
								break;
							}
						}
					}
					//System.out.println("i = " + i+ "sum = " + sum);
				}
				System.out.println(sum);
			}
		}
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
int n,m;
int a[N];
int b[15]={1,2,5,5,4,5,6,3,7,6,0};
vector <pair<int,int> > vec;
vector <int> l,ans;
int dp[N],fa[N],check[10];
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        scanf("%d",&a[i]);
        check[a[i]]=1;
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=9;j++){
            if(check[j] && i>=b[j]){
                if(dp[i-b[j]]+1>=dp[i]){
                    dp[i]=dp[i-b[j]]+1;
                    fa[i]=j;
                }
            }
        }
    }
    for(int i=n;i>0;){
        ans.push_back(fa[i]);
        i-=b[fa[i]];
    }
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    for(auto v:ans) cout<<v;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int num, thr;
    cin >> num >> thr;

    vector<int> vecTall(num);
    for(int i=0; i<num; i++){
        cin >> vecTall.at(i);
    }
    
    int ans = 0;
    for(int i=0; i<num; i++){
        if(vecTall[i] >= thr){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,n;
        int array[]=new int[100];
        n=scan.nextInt();
        for(i=n-1;i>=0;i--){
        	array[i]=scan.nextInt();
        }
        for(i=0;i<n;i++) {
        	System.out.print(array[i]);
        	if(i==n-1)break;
        	System.out.print(" ");
        }
        System.out.println("");
    }
}



Measured memory_bytes: 26304
def main(K):
    lst = [i for i in range(1, 10)]
    K_str = str(K)
    if K_str[-1] in ['0', '2', '4', '5', '6', '8']:
        print(-1)
    else:
        counta = 1
        a = 7
        amari_memo = 70 % K
        while a % K:
            counta += 1
            a = a % K + amari_memo
            amari_memo = amari_memo * 10 % K
        print(counta)


if __name__ == '__main__':
    K = int(input())
    main(K)

Measured memory_bytes: 9164
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for i in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if(N<=K)
  {
    cout << N*X << endl;
  }
  else
  {
    cout << X*K+Y*(N-K) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    
    for i,a in enumerate(ans):
        if (a-s)%f == 0 and a > s:
            ans[i] += c
        elif a < s:
            ans[i] = c + s
        else:
            ans[i] += c + f - (a-s) % f
    ans.append(c+s)

ans.append(0)
for a in ans:
    print(a)

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

using namespace std;

int main() {
	long long x,y;
	cin >> x >> y;
	long long ans = abs(abs(x)-abs(y));

	if(x*y > 0){
		if(x > y){
			ans += 2;
		}
	}else if(x*y <= 0){
		if(x == 0 && y > 0 || x < 0 && y == 0){
		}else{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    k,n=MI()
    end = n - 1
    if k%2:
        ans=[k//2+1]*n
        for _ in range(n//2):
            if ans[end]==1:
                end-=1
            else:
                ans[end]-=1
                if end!=n-1:
                    for i in range(end+1,n):
                        ans[i]=k
                    end=n-1
    else:
        ans=[k//2]+[k]*(n-1)
    print(*ans[:end+1])

main()

Measured memory_bytes: 14412