akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

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

struct primes_ {
	vector<int> d;
	primes_(int n): d{2, 3} {
		if (n < 3) {
			if (n == 2) d = vector<int>(1, 2);
			else d.clear();
			return;
		}
		bool f = false;
		int end = 1;
		for(int i = 5; i <= n; i += (f = !f) ? 2 : 4) {
			while(d[end] * d[end] <= i) end++;
			bool isprime = true;
			for(int k = 0; k < end; k++) {
				if (i % d[k] == 0) {
					isprime = false;
					break;
				}
			}
			if (isprime) d.push_back(i);
		}
	}
	auto begin() {return d.begin();}
	auto end() {return d.end();}
} primes(1000000);

int main() {
    int n;
    cin >> n;
    const int MX = 1000000;
    VI a(n), d(MX + 1);
    rep(i, n) {
        cin >> a[i];
        d[a[i]] += 1;
    }
    bool pc = true;
    for(int x = 2; x <= MX; x++) {
        int cnt = 0;
        for(int now = x; now <= MX; now += x) {
            cnt += d[now];
        }
        if (cnt >= 2) {
            pc = false;
            break;
        }
    }
    if (pc) {
        cout << "pairwise coprime" << endl;
    } else {
        int g = 0;
        rep(i, n) g = __gcd(g, a[i]);
        if (g == 1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}


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

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


Measured memory_bytes: 256
#include<stdio.h>
#define N 101
 
main(){
  int Gl[N][N];
  int i,j,v,r,s,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      Gl[i][j] = 0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d", &v,&r);
    for(j=0;j<r;j++){
      scanf("%d",&s);
      Gl[i][s-1] = 1;
    }
  }  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",Gl[i][j]);
      if(j < n-1){
    printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2108
n = gets.to_i
a = gets.split.map(&:to_i)
money = 1000
stock = 0
n.times do |idx|
  current = a[idx]
  if idx.zero?
    if a[idx+1] > current
      stock, money = money.divmod(current)
    end
  elsif idx == n - 1
    money += stock * current
    stock = 0
  else
    if a[idx-1] <= current && a[idx+1] < current
      money += stock * current
      stock = 0
    elsif a[idx-1] >= current && a[idx+1] > current && money >= current
      stock, money = money.divmod(current)
    end
  end
end
puts money

Measured memory_bytes: 14300
n = int(input())
a = [int(i) for i in input().split()]
ans1 = 0
ans2 = 0
b = []
for i in a:
    if i < 3200:
        k = i // 400
        if not k in b:
            ans2 += 1
            ans1 += 1
            b.append(k)
    else:
        ans2 += 1
print(max(ans1,1), ans2)

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

using namespace std;
typedef long long ll;
const int N = 100'010;
vector<int> g[N];
int p[N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    queue<pair<int, int>> q;
    q.push({1, 0});
    while (!q.empty()) {
        auto e = q.front();
        q.pop();
        if (p[e.first]) continue;
        p[e.first] = e.second;
        for (auto to : g[e.first]) {
            if (!p[to]) q.push({to, e.first});
        }
    }
    bool ans = 1;
    for (int i = 2; i <= n; i++) {
        if (!p[i]) {
            ans = 0;
            break;
        }
    }
    if (!ans) {
        printf("No\n");
    } else {
        printf("Yes\n");
        for (int i = 2; i <= n; i++) printf("%d\n", p[i]);
    }
}


Measured memory_bytes: 11416
cnt = [0] * 100
a, b = map(int, raw_input().split())
cnt[a] +=1
cnt[b] +=1
a, b = map(int, raw_input().split())
cnt[a] +=1
cnt[b] +=1
a, b = map(int, raw_input().split())
cnt[a] +=1
cnt[b] +=1
if max(cnt) == 3:print"NO"
else:print "YES"


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

#define DEBUG 0

#if DEBUG
  #define DLOG(...) fprintf(stderr, __VA_ARGS__)
  #define DFUNC(fname, ...) fname(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DFUNC(fname, ...)
#endif

ll N;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N;
  ll t = 0;
  while (N > 0) {
    t += N % 10;
    N /= 10;
  }
  if (t == 1)  t = 10;
  cout << t << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int S;
    cin >> S;
    
    cout << S / (60*60) << ":";
    S %= 60*60;
    cout << S / 60 << ":";
    S %= 60;
    cout << S << endl;
    return 0;
}



Measured memory_bytes: 3096
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 0, 1,-1};
const int dy4[6] = {1, -1, 0,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 3e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

ll n;
ll val[maxn];
map<ll, ll>hax;
void solve() {
   ll ans = 0;
   SLLA(n);
   REPP(i,1,n) {
    SLLA(val[i]);
    hax[val[i]]++;
   }
   for(auto g: hax) {
    ans += g.second * (g.second-1) / 2;
   }
   REPP(i,1,n) {
    ll k = val[i];
    ll all = ans;
    all -= hax[k] * (hax[k] - 1)/2;
    all += (hax[k]-1) * (hax[k] - 2)/2;
    printf("%lld\n", all);
   }

}

int main()
{   

    solve();
    return 0;
 
}
 

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	char c;
	cin>>c;
	if(c>96 && c<122) cout<<char(c+1);
	return 0;
}

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

AB = []
for i in range(n):
    ab = list(map(int, input().split()))
    AB.append(ab)

ans = 0
for [a,b] in AB[::-1]:
    if (ans +a)%b == 0:
        pass
    else:
        quo = (ans +a)//b
        ans = (quo+1)*b - a

print(ans)


Measured memory_bytes: 28148
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 = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int cnt = 0;
		
		for(int a_cnt=0 ; a_cnt<=a ; a_cnt++) {
			for(int b_cnt=0 ; b_cnt<=b ; b_cnt++) {
				for(int c_cnt=0 ; c_cnt<=c ; c_cnt++) {
					if( (a_cnt*500+b_cnt*100+c_cnt*50) == x ) {
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= b){
        rep(i,b){
            cout << a;
        }
    } else {
        rep(i,a){
            cout << b;
        }
    }
    cout << endl;
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    mp[s] += 1;
  }
  
  cout << mp.size() << endl;
}


Measured memory_bytes: 19236
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int L = in.nextInt();
            double b = L / 3.0;
            out.printf("%.12f\n", Math.pow(b, 3));
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
  int n,x,cul;
  do{
    cin >> n >> x;
    if(!(n == 0 && x == 0)){
      cul = 0;
      for(int min=1;min<x/3;min++){
        for(int mid=min+1;mid<x-min-mid;mid++){
          if(x-min-mid<=n) cul++;
        }
      }
      cout << cul << endl;
    }
  }while(!(n == 0 && x == 0));
}


Measured memory_bytes: 3108
#include <stdio.h>

int main(){
    int r, g, b;
    scanf("%d %d %d", &r, &g, &b);
    if ((r * 100 + g * 10 + b) % 4 == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  string s;
  cin >> s;
  
  int c = 0;
  int t = 0;
  int b = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s.at(i) == 'A' && c == 0) {
      t = i;
      c++;
    }
    if(s.at(i) == 'Z') {
      b = i;
    }
  }
  int ans = (b-t)+1;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<utility>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<climits>
#include<cmath>
#include<cstdlib>
using namespace std;
typedef pair<int,int> pii;
vector<vector<pii>> line;
int dist(pii a,pii b){
  return max(abs(a.first-b.first),abs(a.second-b.second));
}
pii operator-(pii a,pii b){
  return pii(a.first-b.first,a.second-b.second);
}
int out(pii a,pii b){
  return a.first*b.second - a.second*b.first;
}

bool judge(vector<pii> a,vector<pii> b){
  if(a.size()!=b.size())return false;
  for(int i=1;i<a.size();i++){
    if(dist(a[i],a[i-1])!=dist(b[i],b[i-1]))return false;
  }
  for(int i=2;i<a.size();i++){
    bool tmpa = (0<out(a[i]-a[i-1],a[i-1]-a[i-2]));
    bool tmpb = (0<out(b[i]-b[i-1],b[i-1]-b[i-2]));
    if(tmpa!=tmpb)return false;
  }
  return true;
}

void solve(){
  for(int i=1;i<line.size();i++){
    if(judge(line[0],line[i])||judge(line[0],vector<pii>(line[i].rbegin(),line[i].rend()))){
      cout<<i<<endl;
    }
  }
}


int main(){
  int n;
  while(cin>>n,n!=0){
    line.clear();
    for(int i=0;i<=n;i++){
      int m;
      cin>>m;
      vector<pii> ttmp;
      for(int j=0;j<m;j++){
        pii tmp;
        cin>>tmp.first>>tmp.second;
        ttmp.push_back(tmp);
      }
      line.push_back(ttmp);
    }
    solve();
    cout<<"+++++"<<endl;
  };
  return 0;
}

Measured memory_bytes: 1208
# -*- coding: utf-8 -*-
import math


def main():
    n, a, b = map(int, input().split())

    total = 0
    for i in range(1, n + 1):
        keta_total = 0
        temp = i
        for waru in [10000, 1000, 100, 10, 1]:
            keta_total += temp // waru
            temp = temp % waru

        if a<= keta_total <= b:
            total += i

    print(total)


if __name__ == '__main__':
    main()




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


signed main() {

    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    #endif

    long long int n;
    cin >> n;
    string s;
    while ( n > 0 ) {
        n--;
        // For converting any number base 1 -- a, to 0 -- a-1 do this.
        int d = n%26;
        s.push_back(char('a' + d));
        n /= 26;
    }
    reverse(s.begin(),s.end());
    cout << s << '\n';

}

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

#define rep(i, n) for(int i=0; i<n; i++)
#define rev(i, n) for(int i=(n)-1; i>=0; i--)

int n;
int d[111];
int r[111];
int A, B, C, D;

int main(int argc, char *argv[])
{
  cin >> n;
  rep(_, n * (n - 1) / 2){
    cin >> A >> B >> C >> D;
    if(C > D){
      d[A - 1] += 3;
    }
    else if(C < D){
      d[B - 1] += 3;
    }
    else{
      d[A - 1] += 1;
      d[B - 1] += 1;
    }
  }

  vector<int> res[333];
  rep(i, 333) rep(j, n) if(d[j] == i) res[i].push_back(j);

  int p = 1;
  rev(i, 333) if(res[i].size()){
    rep(j, res[i].size()) r[res[i][j]] = p;
    p += res[i].size();
  }

  rep(i, n) cout << r[i] << endl;
  
  return 0;
}

Measured memory_bytes: 1216
n,t = map(int,raw_input().split())
arr = []
for i in range(n):
    a,b = map(int,raw_input().split())
    arr.append((a,b))
cs = 10**20
for i in range(n):
    if arr[i][1] <= t:
        cs = min(cs,arr[i][0])
ans = cs if cs != 10**20 else "TLE"
print ans


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

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

  string ans;
  for (char c : s) {
    switch (c)
    {
    case '0':
    case '1':
      ans.push_back(c);
      break;
    case 'B':
      if (0 < ans.size()) ans.pop_back();
      break;
    }
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
  int N, D;
  cin >> N >> D;
  int num_search = D * 2 + 1;
  int num_need = N / num_search;
  if(N % num_search != 0) num_need += 1;
  cout << num_need << endl;
  return 0;
}

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

int main()
{
    // 整数の入力
    int R,G,B;
    cin >> R >> G >>B;
    if ((10 * G + B) % 4 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
    string S;  cin >> S;
    int N = S.length();
    int num = 753;
    int ans = 999;
    for(int i=0; i<N-2; i++){
        int tmp = 100*(S[i] - '0') + 10*(S[i+1] - '0') + (S[i+2] - '0');
        if(abs(tmp - num) < ans) ans = abs(tmp - num);
    }
    cout << ans << endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,m,a,ans[100010];
bool memo[100010];

signed main() {
    cin >> n >> m;
    rep(i,m) cin >> a,memo[a] = true;
    ans[0] = 1;
    rep(i,n) {
        if (!memo[i]) {
            ans[i+1] += ans[i];
            ans[i+2] += ans[i];
            ans[i+1] %= MOD;
            ans[i+2] %= MOD;
        }
    }
    cout << ans[n] << endl;
}



Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

string s;
int ans=0;

int main(){
    cin >> s;
    int n = s.size();
    for(int i=0;i<n/2;i++){
        //cout << s[i] << " " << s[n-i-1] << (s[i] == s[n-i-1]) << endl;;
        if(s[i] == s[n-i-1]) continue;
        else ans ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin
def input():
    return stdin.readline().strip()

def main():
    h, w, d = map(int, input().split())

    x = [0] * (h*w)
    y = x.copy()
    for i in range(h):
        a = list(map(int, input().split()))
        for j in range(w):
            x[a[j] - 1] = i
            y[a[j] - 1] = j

    # 累積和
    cost = [[0] for _ in range(d)]
    for i in range(d, h*w):
        cost[i%d].append(cost[i%d][-1] + abs(x[i]-x[i-d]) + abs(y[i]-y[i-d]))

    ans = []
    q = int(input())
    for _ in range(q):
        l, r = map(int, input().split())
        l -= 1
        r -= 1
        ans.append(cost[r%d][r//d] - cost[l%d][l//d])

    for i in ans:
        print(i)

main()

Measured memory_bytes: 87464
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A == B:
    print('YES')
elif A > B:
    B -= T * W
    A -= T * V
    if A <= B:
        print('YES')
    else:
        print('NO')
else:
    B += T * W
    A += T * V
    if A >= B:
        print('YES')
    else:
        print('NO')


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

using namespace std;

int main(){
  vector<bool> used(26,false);
  
  string s;
  cin >> s;
  bool f = false;
  for(int i = 0; i < s.size(); i++){
    if(used[int(s[i]-'a')]){
      f = true;
      break;
    }
    used[int(s[i] - 'a')] = true;
  }
  if(!f) cout << "yes";
  else cout << "no";


}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
long long output = 0;
vector<int> num(100000,0);
for(int i=0;i<n;i++){
int l;
cin >> l;
num.at(l-1) ++;
output += l;
}

int q;
cin >> q;
for(int i=0;i<q;i++){
int bef = 0;
int aft = 0;
cin >>bef >>aft;
output += num.at(bef - 1) * (aft - bef); 
num.at(aft - 1) += num.at(bef - 1);
num.at(bef - 1) = 0;

cout << output <<endl;
}
  

cout << endl;
}

Measured memory_bytes: 3792
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int n;
priority_queue <double, vector<double>, greater<double> > q;
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		double x;
		cin >> x;
		q.push(x);
	}

	while (q.size() > 1) {
		double x = q.top();
		q.pop();
		double y = q.top();
		q.pop();
		q.push((x + y) / 2);
	}
	cout << q.top() << endl;
	return 0;
}

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

using namespace std;

map<string,int> dp;
map<string,int> buy;
map<string, vector<string> > reci;

const int INF = 1000000;

#define rep(i,a) for(int i=0; i<(a); i++)

int solve(string to){
  int rtn;
  if(dp[to] == INF){
    if(reci[to].size() != 0){
      int ari = 0;
      rep(i,reci[to].size()){
	ari += solve(reci[to][i]);
      }
      rtn = min(buy[to] , ari);
    } else {
      rtn = buy[to];
    }
    dp[to] = rtn;
  } else {
    rtn = dp[to];
  }
  return rtn;
}


int main(){
  int n;
  while(cin >> n, n){
    dp.clear();
    buy.clear();
    reci.clear();
    rep(i,n){
      string str; int p;
      cin >> str >> p;
      buy[str] = p;
      dp[str] = INF;
    }
    int r; cin >> r;
    rep(i,r){
      string str; int m;
      cin >> str >> m;
      rep(j,m){
	string ing;
	cin >> ing;
	reci[str].push_back(ing);
      }
    }

    string to; cin >> to;
    cout << solve(to) << endl;
  }
  return 0;
}

    

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

int main(){
  long long n,a,b,count=1;
  cin>>n>>a>>b;
  if(a>b){
    cout<<0<<endl;
    return 0;
  }else if(a<b && n==1){
    cout<<0<<endl;
    return 0;
  }
  while(a<b){
    count+=n-2;
    a++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <stdlib.h>

void swap(int* xp, int* yp)
{
	int temp = *xp;
	*xp = *yp;
	*yp = temp;
}

int main() {
	int i, j, mini,flag, count = 0;

	int array_num = 0;
	scanf("%d", &array_num);

	//dynamic scan
	int* array;
	array = (int*)malloc(array_num * sizeof(int));
	for (i = 0; i != array_num; i++) {
		scanf("%d", &array[i]);
	}

	//selection sort
	for (i = 0; i < array_num - 1; i++) {
		flag = 0;
		mini = i;
		for (j = i+1; j < array_num; j++) {
			if (array[j] < array[mini]) {
				mini = j;
				flag = 1;
			}
		}
		if (flag == 1) {
			count++;
			swap(&array[mini], &array[i]);
		}
	}

	for (i = 0; i < array_num; i++) {
		if (i == array_num - 1)printf("%d\n", array[i]);
		else printf("%d ", array[i]);
	}
	printf("%d\n", count);
	free(array);
}



Measured memory_bytes: 2088
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main(void){
    long long N,D;
    cin >> N >> D;
    long long cnt = 0;
    
    long long D2 = pow(D, 2);
    
    long long x, y, d;
    
    for(long long i = 0 ; i < N ; i ++){
        cin >> x >> y;
        d = pow(x, 2) + pow(y, 2);
        if(d <= D2) cnt++;
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main () {
int N,i,j,maxint,index,maxint2;
vector<int> A;
cin>>N ;
A.reserve(N);
for(i=0;i<N;i++)
    { cin>>A[i];}

maxint=0;

for( j=0 ;j<N;j++) {
if (maxint<A[j] ) {
    maxint =A[j];
     index =j;
 }
}
maxint2=0;
for( j=0 ;j<N;j++){
        if ((maxint2<A[j] )&&(j!=index)){
                maxint2=A[j];}
    }
for( j=0 ;j<N;j++){if(j!=index){printf("%d\n",maxint);}
else {printf("%d\n",maxint2); }
}

}


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

typedef long long ll;

int main(void){
  int n; cin >> n;
  vector<ll> a(n);
  for(int i=0; i<n; ++i) cin >> a[i];
  ll dp[n][2];
  if( n == 2){
    cout << max( a[0]+a[1], -a[0]-a[1])<<endl;
    return 0;
  }
  dp[0][0] = a[0]; dp[0][1] = -a[0];
  for(int i=1; i<n-1; ++i){
    if( i != n-2){
      dp[i][0] = max(dp[i-1][0] + a[i], dp[i-1][1] - a[i]);
      dp[i][1] = max(dp[i-1][0] - a[i], dp[i-1][1] + a[i]);
    }
    else{
      dp[i][0] = max(dp[i-1][0] + a[i] + a[i+1], dp[i-1][1] - a[i] + a[i+1]);
      dp[i][1] = max(dp[i-1][0] - a[i] - a[i+1], dp[i-1][1] + a[i] - a[i+1]);
    }
  }
  cout << max(dp[n-2][0], dp[n-2][1]) <<endl;
  return 0;
}



Measured memory_bytes: 2560
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let (a, b, c) = scan_as_tuple![i32, i32, i32];
    println!("{}", if b - a == c - b { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, ans, n, a[100];

int main()
{
    sf("%d", &n);
    for (i = 0; i < n; i++) {
        sf("%d", &a[i]);
        ans += a[i];
    }
    if (ans % 10 == 0) {
        sort(a, a + n);
        for (i = 0; i < n; i++) {
            if (a[i] % 10 != 0) {
                ans -= a[i];
                pf("%d\n", ans);
                return 0;
            }
        }
        pf("0\n");
        return 0;
    }
    pf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define mod 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;


int main( ) {
     long long a,b,x;
    cin>>a>>b>>x;
      long long ans=b/x-max((a-1),0LL)/x;
      if(a==0LL)
        cout<<ans+1;
      else
        cout<<ans;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(int, n);
  Cin(string, 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
#include "bits/stdc++.h"
using namespace std;


int main() {

	int H, W;
	cin >> H >> W;
	vector<vector<char>> S(H + 2, vector<char>(W + 2));
	for (int i = 1;i < H + 1;i++) {
		for (int j = 1;j < W + 1;j++) {
			cin >> S.at(i).at(j);
		}
	}

	bool can = true;
	for (int i = 1;i < H + 1;i++) {
		for (int j = 1;j < W + 1;j++) {
			int count_i_j = 0;
			if (S.at(i).at(j) == '#') {
				if (S.at(i - 1).at(j) == '#')
					count_i_j++;
				if (S.at(i).at(j - 1) == '#')
					count_i_j++;
				if (S.at(i).at(j + 1) == '#')
					count_i_j++;
				if (S.at(i + 1).at(j) == '#')
					count_i_j++;
				if (count_i_j == 0) {
					can = false;
					break;
				}
			}
		}
		if (!can)
			break;
	}
	if (can)
		cout << "Yes";

	else
		cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;

using namespace std;

int main() {

	int n;
	cin >> n;

	int a[n];

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

	int mi, tmp, cut = 0;
	rep(i, n - 1) {
		mi = i;
		for (int j = i; j < n; j++) {
			if (a[mi] > a[j])
				mi = j;
		}
		if (mi != i) {
			cut++;
			tmp = a[mi];
			a[mi] = a[i];
			a[i] = tmp;
		}
	}

	rep (i, n) {
		if (i > 0) cout << ' ';
		cout << a[i];
	}
	cout << endl;
	cout << cut << endl;

}



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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  double conc=0;
  int i_a=0;int j_a=0;int k_a=0;int l_a=0;
  for (int i=0; i<=f/100/a; i++){
    for (int j=0; j<=(f-i*100*a)/100/b; j++){
      int k = 0;
      while(f-i*100*a-j*100*b-c*k>=0 && e*(a*i+b*j)>=c*k){
        int l = 0;
        
        while(f-i*100*a-j*100*b-c*k-d*l>=0 && e*(a*i+b*j)>=c*k+d*l){
          if (i==0 && j==0) break;
          double conc_tmp = 100.0*(c*k+d*l)/(100*a*i+100*b*j+c*k+d*l);
          if(conc <= conc_tmp){
            conc=conc_tmp;
            i_a=i;j_a=j;k_a=k;l_a=l;
          }
          l++;
        }
        k++;
      }
    }
  }
  cout << 100*(a*i_a+b*j_a)+c*k_a+d*l_a << " " << c*k_a+d*l_a << endl;
}

Measured memory_bytes: 256
import std.stdio, std.range, std.conv, std.string, std.array, std.functional;
import std.algorithm.comparison, std.algorithm.iteration, std.algorithm.mutation, std.algorithm.searching, std.algorithm.setops, std.algorithm.sorting;
import std.container.binaryheap;

void main()
{
    auto list = readln().strip.split.to!(long[]);
    list.sort!"a>b";
    writeln(list[0] * 10 + list[1..$].sum);
}

Measured memory_bytes: 256
import math


def is_prime(n: int) -> bool:
    if n == 2 or n == 3:
        return True
    for i in range(2, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return True


if __name__ == "__main__":
    num = int(input())
    total_prime_number_count = 0
    for _ in range(num):
        if (is_prime(int(input()))):
            total_prime_number_count += 1
    print(f"{total_prime_number_count}")



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

int main()
{
  int arr[5];
  for(int i=0;i<5;i++)
  {
   	cin>>arr[i];
  }
  for(int i=0;i<5;i++)
  {
   if(arr[i]==0)
   {
    cout<<i+1<<endl;
     break;
   }
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n ; i++)
using namespace std;
typedef long long ll;
int main(){ 
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n){
		cin >> p[i];
		p[i]--;
	}
	int cnt=0;
	rep(i,n) if(p[i] !=i) cnt++;
	if(cnt < 3) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



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

int main()
{
	int n;
  	cin>>n;
  	vector<int> sum(n);
  	cin>>sum[0];
  	for(int i=1 ; i<n ; ++i)
    {
    	cin>>sum[i];
      	sum[i]+=sum[i-1];
    }
  	int ans=abs(sum[sum.size()-1]-sum[0]*sum[0]);
  	for(int i=1 ; i<n ; ++i)
    {
    	ans=min(ans,abs(sum[sum.size()-1]-sum[i]*2));
    }
  	cout<<ans<<endl;
    return 0;
}

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

int main() {
	long long n, a, b;
	cin >> n >> a >> b;

	if ((b - a) % 2 == 0) {
		cout << (long long)(b - a) / 2 << endl;
	}
	else {
		if (b - a == 1) {
			cout << min(b - 1, n - a) << endl;
		} 
		else {
			cout << (b - a - 1) / 2 + min(a, n - b + 1) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3636
gets
c=0
puts$<.map{|s|a=0
[s.chop.bytes.map{a+=81-_1*2}.min,a]}.sort_by{_2>0? -_1:2e9-_2+_1}.map{_2-_1+c-=_2}.max>0||c<0?:No: :Yes

Measured memory_bytes: 103344
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n,0);
	rep(i, n) {
		cin >> h[i];
	}

	sort(h.begin(), h.end());
	ll cnt = 0, k_cnt = 0;
	for (int i = n - 1; i >= 0; --i) {
		if (k_cnt < k) {
			k_cnt++;
			continue;

		}
		cnt += h[i];
	}

	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
int main(){
    double a,ans;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf",&a);
        ans+=1.0/a;
    }
    printf("%.6f\n",1.0/ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

typedef complex<int> P;

int cross(const P &v1, const P &v2){
	return v1.real() * v2.imag() - v1.imag() * v2.real();
}

vector<int> lineinfo(const vector<P> &pl){
	vector<int> ret(pl.size() - 1);
	ret[0] = norm(pl[1] - pl[0]);

	for(int i = 1; i + 1 < pl.size(); ++i){
		ret[i] = cross(pl[i] - pl[i-1], pl[i+1] - pl[i]);
	}
	return ret;
}

int main(){
	int n, m;
	vector<P> lines;
	lines.reserve(10);

	int x, y;

	while( scanf("%d%d", &n, &m) == 2 ){
		lines.clear();
		for(int i = 0; i < m; ++i){
			scanf("%d%d", &x, &y);
			lines.push_back( P(x, y) );
		}

		vector<int> v0 = lineinfo(lines);

		for(int i = 1; i <= n; ++i){
			lines.clear();
			scanf("%d", &m);
			for(int j = 0; j < m; ++j){
				scanf("%d%d", &x, &y);
				lines.push_back( P(x, y) );
			}
			
			if( lineinfo(lines) == v0 ){
				printf("%d\n", i);
			}
			else{
				reverse(lines.begin(), lines.end());
				if( lineinfo(lines) == v0 ){
					printf("%d\n", i);
				}
			}
		}
		
		puts("+++++");
	}
}

Measured memory_bytes: 1064
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n = read_as_vec::<u64>()[0];
    let mut d: Vec<u64> = vec![];

    for _ in 0..n{
        d.push(read_as_vec::<u64>()[0]);
    }

    d.sort();
    d.dedup();
    println!("{}", d.len());
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)


int main() {
	int p = 500000;
	vector<bool> prime(p);
	rep(i, p) {
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;
	for (int i = 2, j = sqrt(p); i <= j; i++) {
		if (prime[i]) {
			for (int k = i + i; k < p; k += i) {
				prime[k] = 0;
			}
		}
	}

	int x;
	cin >> x;
	for (int i = x; i < p; i++) {
		if (prime[i]) {
			cout << i;
			break;
		}
	}


}

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

struct KnuthMorrisPratt {
    string ptn;
    vector<int> kmp, mp;
    KnuthMorrisPratt(const string &ptn) : ptn(ptn) {
        int m = ptn.size();
        mp.assign(m + 1, -1), kmp.assign(m + 1, -1);
        for (int i = 0, j = -1; i < m; i++) {
            while (j >= 0 && ptn[i] != ptn[j]) j = kmp[j];
            kmp[i + 1] = mp[i + 1] = ++j;
            if (i + 1 < m && ptn[i + 1] == ptn[j]) kmp[i + 1] = kmp[j];
        }
    }
    int period(int i) { return i - mp[i]; }
    vector<int> match(const string &s) {
        int m = ptn.size(), n = s.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; i++) {
            while (k >= 0 && s[i] != ptn[k]) k = mp[k];
            if (++k == m) res.emplace_back(i - m + 1);
        }
        return res;
    }
};

vector<long long> enum_divisors(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i * i <= n; i++) {
        if (n % i != 0) continue;
        res.emplace_back(i);
        if (i != n / i) res.emplace_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    string s; cin >> s;
    int n = s.length();
    int period = n;
    for (int d: enum_divisors(n)) {
        bool ok = true;
        for (int i = 0; i + d < n; i++) ok &= s[i] == s[i + d];
        if (ok) period = min(period, d);
    }
    if (period == n) return !(cout << 1 << endl << 1 << endl);
    if (period == 1) return !(cout << n << endl << 1 << endl);
    string s_r = s;
    reverse(begin(s_r), end(s_r));
    KnuthMorrisPratt kmp(s), kmp_r(s_r);
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (kmp.period(i) < i && i % kmp.period(i) == 0) continue;
        int j = n - i;
        if (kmp_r.period(j) < j && j % kmp_r.period(j) == 0) continue;
        cnt++;
    }
    cout << 2 << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 10116
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int L = in.nextInt();
            int R = in.nextInt();

            if (R - L + 1 >= 2019) {
//                System.out.println(2);
//                return;
                R = L + 2019;
            }

            int min = (int) 1e9;
            for (int i = L; i < R; i++) {
                for (int j = i + 1; j <= R; j++) {
                    min = Math.min(min, ((i % 2019) * (j % 2019)) % 2019);
                }
            }

            System.out.println(min);
        }
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  vector<int> c(N);
  loop(i,N)
    cin >> v.at(i);
  loop(i,N)
    cin >> c.at(i);
  int m = 0;
  loop(i,N){
    if(v.at(i)>c.at(i))
      m += v.at(i)-c.at(i);
  }
  cout << m;
}

Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))
P = sorted(p)
count = 0
for i in range(len(p)):
  if p[i] == P[i]:
    count += 1
if count == len(p) or count == len(p) - 2:
  print('YES') #昇順の数列と並び変える前の数列で一致している要素数が同じか2個だけ違う時条件OK
else:
  print('NO')

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

using namespace std;
const int MAXN = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], ind, val[MAXN << 1];
inline void add_edge(int u, int v, int w){ nxt[++ ind] = head[u]; head[u] = ind; to[ind] = v; val[ind] = w;}
inline void add(int u, int v, int w){ add_edge(u, v, w); add_edge(v, u, w); }
int n;
inline void init(void){
	cin >> n; int u, v, w;
	for(int i = 1; i < n; ++ i) cin >> u >> v >> w, add(u, v, w);
}
int rt1, rt2, siz[MAXN], mxsiz[MAXN], del = INF;
void dfs(int u, int fa){
	siz[u] = 1;
	for(int i = head[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		dfs(v, u); siz[u] += siz[v];
		mxsiz[u] = max(mxsiz[u], siz[v]);
	}
	mxsiz[u] = max(mxsiz[u], n - siz[u]);
	if(mxsiz[u] * 2 <= n){
		if(!rt1) rt1 = u; else rt2 = u;
	}
}
long long ans;
void solve(int u, int fa){ siz[u] = 1;
	for(int i = head[u]; i; i = nxt[i]){
		int v = to[i]; if(v == fa) continue;
		solve(v, u); siz[u] += siz[v];
		ans += 1ll * 2 * val[i] * min(siz[v], n - siz[v]); 
	}
}
inline void work(void){
	dfs(1, 0); solve(rt1, 0);
	for(int i = head[rt1]; i; i = nxt[i]){
		int v = to[i]; if(!rt2) del = min(del, val[i]);
		else if(v == rt2) del = val[i];
	}
	cout << ans - del;
}

int main(){
	init(); work();
	return 0;
}

Measured memory_bytes: 13648
#include <stdio.h>
int main(void){
  int x,y,work,zan;
  scanf("%d %d",&x,&y);

  if(x<y){
    work=x;
    x=y;
    y=work;
  }

  zan=x%y;

  while(zan!=0){
    x=y;
    y=zan;
    zan=x%y;
  }

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


Measured memory_bytes: 2140
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

bool is_match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }

int main() {
    int max_len = 2000;
    string a, b, c;
    cin >> a >> b >> c;
    int la = a.size(), lb = b.size(), lc = c.size();

    vector<bool> match_ab(max_len * 10, true), match_ac(max_len * 10, true), match_bc(max_len * 10, true);
    rep(i, la) rep(j, lb) if (!is_match(a[i], b[j])) match_ab[i - j + max_len * 4] = false;
    rep(i, la) rep(j, lc) if (!is_match(a[i], c[j])) match_ac[i - j + max_len * 4] = false;
    rep(i, lb) rep(j, lc) if (!is_match(b[i], c[j])) match_bc[i - j + max_len * 4] = false;

    int ans = max_len * 10;
    repr(i, -max_len * 2, max_len * 2 + 1) repr(j, -max_len * 2, max_len * 2 + 1) {
        if (match_ab[i + max_len * 4] &&
            match_ac[j + max_len * 4] &&
            match_bc[j - i + max_len * 4]) {
            int l = min({0, i, j}), r = max({la, i + lb, j + lc});
            chmin(ans, r - l);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem!
int main(){
	IOS
	string s;	cin>>s;
	if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3])	cout<<"Yes\n";
	else	cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=[0]*(2*10**5+1)
ans=0
for i in range(n):
    x[a[i]]+=1
z=[x[i] for i in range(2*10**5+1) if x[i]!=0]
z=sorted(z)
for i in range(max(len(z)-k,0)):
    ans+=z[i]
print(ans)


Measured memory_bytes: 104656
n = gets.to_i

now_time = 0
now_position = [0, 0]

data = []
n.times { |_| data << gets.chomp.split(' ').map(&:to_i) }

n.times do |i|
  t, x, y = data[i]
  move_distance = t - now_time
  distance = (now_position[0] - x).abs + (now_position[1] - y).abs
  
  unless move_distance >= distance
    puts 'No'
    exit
  end
  
  unless (move_distance - distance).even?
    puts 'No'
    exit
  end
  
  
  now_time = t
  now_position = [x, y]
end

puts 'Yes'

Measured memory_bytes: 9468