akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		long L = Long.parseLong(tokens[0]);
		long R = Long.parseLong(tokens[1]);
		long result = 0;
		if (R - L >= 2018) {
			result = 0;
		} else {
			List<Long> mods = new ArrayList<>();
			for (long i = L; i < R; ++i) {
				for (long j = i + 1; j <= R; ++j) {
					mods.add((i % 2019) * (j % 2019) % 2019);
				}
			}
			Collections.sort(mods);
			result = mods.get(0);
		}
		System.out.println(result);
		in.close();
	}

}

Measured memory_bytes: 107408
import java.util.*;

class Main {

	static int ub = 1000010;
	static boolean isPrime[] = new boolean[ub];

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		sieve();
		while(in.hasNext()){
			int a = in.nextInt(), d = in.nextInt(), n = in.nextInt();
			if(a==0 && d==0 && n==0) return ;
			int cnt = 0;
			for(int i = a;;i += d)if(isPrime[i] && ++cnt==n){
				System.out.println(i);
				break;
			}
		}
	}

	static void sieve(){
		for(int i=2; i<ub; i++) isPrime[i] = true;
		for(int i=2; i*i<ub; i++)if(isPrime[i]){
			for(int j=i*2; j<ub; j+=i){
				isPrime[j] = false;
			}
		}
	}
}

Measured memory_bytes: 13000
//2019/3/12 10分
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		int M = sc.nextInt();

		int C = sc.nextInt();

		int[] B = new int[M];

		for(int i=0;i<M;i++) B[i] = sc.nextInt();

		int[] A = new int[N*M];

		for(int i=0;i<N*M;i++) A[i] = sc.nextInt();

		int ans = 0;

		int x = 0;

		for(int i=0;i<N;i++) {

			x = 0;

			for(int j=0;j<M;j++) {

				x += B[j] * A[j+(i*M)];
			}

			if(x+C>0) ans++;

		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
n = int(input())
p = list(map(int, input().split()))

res = "YES"
if list(range(1, n+1)) == p:
  res = "YES"
else:
  count = 0
  for n_e, p_e in zip(range(1,n+1), p):
    if n_e != p_e:
      count += 1
    if count == 3:
      res = "NO"
      break


print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
struct edge {
  int to, cost;
};
typedef pair< int, int > Pi;
const int INF = 1 << 30;

int n, m;
vector< edge > graph[200];
int min_cost[200];

int Dijkstra()
{ 
  vector< int > min_cost(200, INF);
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.push(Pi(0, 0));
  min_cost[0] = 0;
  while(!que.empty()) {
    int now  = que.top().second;
    int cost = que.top().first;
    que.pop();
    if(now % n == n - 1) return(cost);
    if(cost > min_cost[now]) continue;
    for(int i = 0; i < graph[now].size(); i++) {
      edge e = graph[now][i];
      if(cost + e.cost < min_cost[e.to]) {
        min_cost[e.to] = cost + e.cost;
        que.push(Pi(min_cost[e.to], e.to));
      }
    }
  }
  return(-1);
}


int main()
{
  while(cin >> n >> m, n) {
    for(int i = 0; i < m; i++) {
      int a, b, c;
      cin >> a >> b >> c;
      --a, --b;
      graph[a].push_back((edge){b, c});
      graph[b].push_back((edge){a, c});
      graph[a + n].push_back((edge){b + n, c});
      graph[b + n].push_back((edge){a + n, c});
    }
    
    
    for(int i = 0; i < n; i++) { 
      for(int j = 0; j < graph[i].size(); j++) {
        for(int k = 0; k < graph[graph[i][j].to].size(); k++) {
          int to = graph[graph[i][j].to][k].to;
          if(to < n && i != to) graph[i].push_back((edge){to + n, 0});
        }
      }
    }

    cout << Dijkstra() << endl;

    for(int i = 0; i < 200; i++) {
      graph[i].clear();
    }

  }
}

Measured memory_bytes: 1288
H,W = map(int,input().split())
S = [input() for i in range(H)]

from collections import deque
q = deque([(int(S[0][0]=='#'),0,0)])

INF = float('inf')
costs = [[INF]*W for _ in range(H)]
costs[0][0] = int(S[0][0]=='#')
while q:
    k,x,y = q.popleft()
    for dx,dy in [(1,0),(0,1)]:
        nx,ny = x+dx,y+dy
        if nx >= W: continue
        if ny >= H: continue
        c = int(S[y][x] != S[ny][nx])
        if k+c >= costs[ny][nx]: continue
        costs[ny][nx] = k+c
        q.append((k+c, nx,ny))
print((costs[-1][-1]+1)//2)

Measured memory_bytes: 3572
#include <cstdio>
#include <vector>
using namespace std;

typedef long long int lli;

bool check[100000];

lli permu(lli n, lli r)
{
  lli ans = 1;
  for (int i = 0; i < r; i++)
  {
    ans = (ans * n) % 1000000007;
    n--;
  }
  return ans;
}

lli cnt_sb(vector<lli> *v, lli p, lli k)
{
  if (check[p])
  {
    return 1;
  }

  check[p] = true;
  lli ans = permu(k - 2, v[p].size() - 1);
  for (int i = 0; i < v[p].size(); i++)
  {
    lli u = v[p][i];
    ans = (ans * cnt_sb(v, u, k)) % 1000000007;
  }

  return ans;
}

lli cnt(vector<lli> *v, lli k)
{
  check[0] = true;
  lli ans = (k * permu(k - 1, v[0].size())) % 1000000007;
  for (int i = 0; i < v[0].size(); i++)
  {
    lli u = v[0][i];
    ans = (ans * cnt_sb(v, u, k)) % 1000000007;
  }
  return ans;
}

int main(void)
{
  lli n, k, a, b;
  vector<lli> v[100000];
  scanf("%llu %llu", &n, &k);
  for (int i = 0; i < n; i++)
  {
    check[i] = false;
  }

  for (int i = 0; i < n - 1; i++)
  {
    scanf("%llu %llu", &a, &b);
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }

  printf("%llu\n", cnt(v, k));

  return 0;
}


Measured memory_bytes: 10496
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

vector<int> solve(const vec<int, 2>& G, const vec<int, 2>& rG) {
  int N = G.size();
  vector<int> deg(N, 0);
  for (int i = 0; i < N; i++) deg[i] = G[i].size();
  queue<int> que;
  for (int i = 0; i < N; i++)
    if (deg[i] == 0) que.push(i);
  vector<int> dp(N, 0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int u : rG[v]) {
      dp[u] = max(dp[u], dp[v] + 1);
      --deg[u];
      if (deg[u] == 0) {
        que.push(u);
      }
    }
  }
  return dp;
}

int main() {
  int N, M;
  while (cin >> N >> M) {
    vec<int, 2> G(N), rG(N);
    for (int i = 0; i < M; i++) {
      int x, y;
      cin >> x >> y;
      --x;
      --y;
      G[x].push_back(y);
      rG[y].push_back(x);
    }
    auto a = solve(G, rG);
    auto b = solve(rG, G);
    int res = 0;
    for (int i = 0; i < N; i++) res = max(res, a[i] + b[i]);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 12408
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/07/25.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define all(x) (x).begin(), (x).end()
#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 INF 1000000
#define MOD 998244353



int main()
{
    int N;
    cin >> N;
    vector<int> A(N+1);
    
    int x;
    rep(i, N-1) {
        cin >> x;
        A[x]++;
    }
    rep1(i, N) {
        cout << A[i] << endl;
    }
    cout << endl;
    
    
    
    return 0;
}




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

#define LEN 12

int
main(void)
{
    char line1[LEN];
    char line2[LEN];
    char *p;
    int a, b, i;

    p = &line1[0];

    if ( fgets(line1, LEN, stdin) == NULL ) {
        exit(1);
    }
    
    while(*p != ' ') {
        p++;
    }
    *p = '\0';
    a = atoi(line1);
    b = atoi(++p);

    if ( fgets(line2, LEN, stdin) == NULL ) {
        exit(1);
    }
    p = &line2[0];

    for(i = 0; i < a; i++, p++ ) {
        if ( *p < '0' || *p > '9' ) {
            printf("No\n");
            exit(0);
        }
    }
    if ( *p++ != '-' ) {
        printf("No\n");
        exit(0);
    }
    for(i = 0; i < b; i++, p++ ) {
        if ( *p < '0' || *p > '9' ) {
            printf("No\n");
            exit(0);
        }
    }
    
    printf("Yes\n");
    exit(0);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();

        final CombinationCalculator comb = new CombinationCalculator(2 * n, MOD).init();
        long sum = 0;
        for (int i = 0; i < Math.min(n, k + 1); i++) {
            sum += comb.calc(n, i) * comb.calc(n - 1, n - i - 1);
            sum %= MOD;
        }

        System.out.println(sum);
    }

    private static class CombinationCalculator {
        private final int size;
        private final int mod;
        private final long[] factorials;
        private final long[] invertedElements;
        private final long[] invertedFactorials;

        CombinationCalculator(final int size, final int mod) {
            this.size = size;
            this.mod = mod;
            this.factorials = new long[size];
            this.invertedElements = new long[size];
            this.invertedFactorials = new long[size];
        }

        CombinationCalculator init() {
            factorials[0] = 1;
            factorials[1] = 1;
            invertedFactorials[0] = 1;
            invertedFactorials[1] = 1;
            invertedElements[1] = 1;
            for (int i = 2; i < size; i++) {
                factorials[i] = factorials[i - 1] * i % mod;
                invertedElements[i] = mod - invertedElements[mod % i] * (mod / i) % mod;
                invertedFactorials[i] = invertedFactorials[i - 1] * invertedElements[i] % mod;
            }
            return this;
        }

        long calc(final int n, final int k) {
            return factorials[n] * (invertedFactorials[k] * invertedFactorials[n - k] % mod) % mod;
        }
    }
}


Measured memory_bytes: 32340
N = int(input())
INI = ["M","A","R","C","H"]
c = [0]*5
for i in range(N):
    S = input()
    if S[0] in INI:
        c[INI.index(S[0])] += 1

ans = 0
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans += c[i]*c[j]*c[k]
print(ans)

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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  
  rep(i,k){
    if(a>=b && a>=c) a = 2*a;
    else if(b >= c) b = 2*b;
    else c = 2*c;
  }

  cout << (a+b+c) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        // long startTime = System.currentTimeMillis();

        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        scanner.close();

        System.out.println(resolve(a, b));

        // System.out.println(System.currentTimeMillis() - startTime);
    }

    private static int resolve(int a, int b) {

        int aPlusb = a + b;
        int aMinusb = a - b;
        int ab = a * b;

        int max = aPlusb;
        if (max < aMinusb) {
            max = aMinusb;
        }
        if (max < ab) {
            max = ab;
        }

        return max;
    }

}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1001001001001;

int main(){
    int h,w;
    cin >> h >> w;
    int ch,cw;
    int dh,dw;
    cin >> ch>>cw;
    ch--;cw--;
    cin >> dh>>dw;
    dh--;dw--;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    
    vv check(h, vi (w,0));
    
    queue<P> qa,qb;
    qa.push(P(ch,cw));
    qb.push(P(ch,cw));
    check[ch][cw] = 1;
    vi di={0,1,0,-1};
    vi dj={-1,0,1,0};
    while(!qa.empty()){
        while(!qa.empty()){//あるいて移動
            int pi = qa.front().first;
            int pj = qa.front().second;
            qa.pop();
            rep(i,4){
                int ni = pi + di[i];
                int nj = pj + dj[i];
                if(ni<0 || ni>=h || nj<0 || nj>=w)continue;
                if(s[ni][nj]=='#')continue;
                if(check[ni][nj])continue;
                check[ni][nj]=check[pi][pj];
                qa.push(P(ni,nj));
                qb.push(P(ni,nj));
                //cout<<ni<<nj<<endl;
            }
        }
        swap(qa,qb);
        while(!qa.empty()){//ワープ移動
            int pi = qa.front().first;
            int pj = qa.front().second;
            qa.pop();
            for(int i=-2;i<=2;i++){
                for(int j=-2;j<=2;j++){
                    int ni = pi + i;
                    int nj = pj + j;
                    if(ni==pi && nj==pj)continue;
                    if(ni<0 || ni>=h || nj<0 || nj>=w)continue;
                    if(s[ni][nj]=='#')continue;
                    if(check[ni][nj])continue;
                    check[ni][nj]=check[pi][pj]+1;
                    qb.push(P(ni,nj));
                    //cout<<ni<<nj<<endl;
                }
            }
        }
        //swap(qa,qb);
        qa = qb;
    }
    cout<<check[dh][dw]-1<<endl;
    
    return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s,s1,s2;

	//char s[100000];

	int ara[n_size],ara2[n_size];

	ss st;
    sc sst;
	cin>>s;
	cin>>k;

	char c;
	vc ch;
	for(i=0;i<s.size();i++){
        ch.pb(s[i]);
        sst.insert(s[i]);
	}
	sort(ch.bb,ch.ee);
	c=ch[0];

        for(i=0;i<s.size();i++){
            s1="";
            for(j=i;j>=0;j--){
                s1=s[j]+s1;
                st.insert(s1);
                if(s1.size()>7) break;
            }
        }
//	else if(s.size()>100){
//        for(i=0;i<s.size();i++){
//            if(s[i]==c){
//                s1="";
//                for(j=i;j<s.size();j++){
//                    s1=s1+s[j];
//                    st.insert(s1);
//                    if(sst.size()==1){
//                        if(st.size()==k) break;
//                    }
//                }
//            }
//            if(sst.size()==1){
//                if(st.size()==k) break;
//            }
//        }
//	}



    for(auto x:st){
        count++;
        if(count==k){
            cout<<x<<endl,exit(0);
        }
        else{
            s2=x;
        }

    //cout<<x<<endl;

    }
    cout<<s2<<endl;
}


Measured memory_bytes: 5968
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

struct THorizonalLine
{
	int Left;
	int Right;
};

int main()
{
	int w;
	cin >> w;
	int n;
	cin >> n;
	vector<int> StartingPoint(w);
	for(int i = 0; i < w; i++){
		StartingPoint[i] = i+1;
	}
	for(int i = 0; i < n; i++){
		THorizonalLine HorizonalLine;
		scanf("%d,%d",&HorizonalLine.Left,&HorizonalLine.Right);
		swap(StartingPoint[HorizonalLine.Left-1], StartingPoint[HorizonalLine.Right-1]);
	}
	for(int i = 0; i < w; i++){
		cout << StartingPoint[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
class Inv:
  def __init__(s, mod):
    s.MOD = mod
  def modpow(s, a, n):
    res = 1
    while n > 0:
      if n & 1:
        res = res * a % s.MOD
      a = a * a % s.MOD
      n >>= 1
    return res
  def invx(s, a):
    return s.modpow(a, s.MOD - 2)
  def invL(s, a, n):
    ia = s.invx(a)
    L = [1] * (n + 1)
    for i in range(1, n + 1):
      L[i] = L[i - 1] * ia % s.MOD
    return L
  def invN(s, n):
    L = [0, 1]
    for i in range(2, n):
      L.append(s.MOD - L[s.MOD % i] * (s.MOD // i) % s.MOD)
    return L

Q = int(input())
xdn = [list(map(int, input().split())) for _ in range(Q)]

MOD = 1000003
inv = Inv(MOD)

L = [1] * MOD
IL = [1] * MOD
for i in range(1, MOD):
  L[i] = L[i - 1] * i % MOD
  IL[i] = inv.invx(L[i])

for x, d, n in xdn:
  if d == 0:
    print(inv.modpow(x, n))
    continue

  id = inv.invx(d)
  k = x * id % MOD
  if k + n > MOD:
    print(0)
    continue
  t = inv.modpow(d, n)
  print(L[k + n - 1] * IL[k - 1] * t % MOD)

Measured memory_bytes: 97880
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
int main(){
    ll a,b;cin>>a>>b;
    if(a > 9 || b > 9)cout<<-1<<endl;
    else cout<<a*b<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = IO().exec {
    val n = int()
    val d = Array(n){LongArray(n){long()}}
    val redundant = Array(n){BooleanArray(n)}
    for (k in n) for (i in n) for (j in n) {
        if (d[i][j] > d[i][k] + d[k][j]) {
            println(-1)
            return@exec
        }
        if (d[i][j] == d[i][k] + d[k][j] && d[i][k] > 0 && d[k][j] > 0)
            redundant[i][j] = true
    }
    var ret = 0L
    for (i in n) for (j in i+1 until n) if (!redundant[i][j]) ret += d[i][j]
    println(ret)
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

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

typedef long long ll;
const int MAXN = 1e5 + 10, MOD = 1e9 + 7;
int n, cnt[MAXN];

ll powe(ll a, int b) {
	ll res = 1;
	do {
		if (b % 2)
			res *= a, res %= MOD;
		a *= a, a %= MOD;
	} while (b /= 2);
	return res;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		cnt[a]++;
	}
	int i;
	if (n % 2)
		i = 2;
	else
		i = 1;
	for (i; i < n; i += 2)
		if (cnt[i] != 2)
			return cout << 0, 0;
	cout << powe(2, n / 2);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
const int INF = 1e8;
// const ll INF = 1LL << 60;
typedef pair<int, int> P;

// const int mod = 1000000007;
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll N, S;
vector<ll> A;

mint dp[3010][3010][3];

int main() {
    cin >> N >> S;
    A.resize(N);

    mint ans = 0;

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

    dp[0][0][0] = 1;
    // 0: LもRも決まっていない
    // 1: L は決まった
    // 2: L、Rが決まった

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            // 配らない
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
            dp[i + 1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2];

            // 配る
            if (j + A[i] <= S) {
                dp[i + 1][j + A[i]][1] += dp[i][j][0] + dp[i][j][1]; 
                dp[i + 1][j + A[i]][2] += dp[i][j][0] + dp[i][j][1]; 
            } 
        }
    }
    ans = dp[N][S][2];

    cout << ans << endl;
}

Measured memory_bytes: 212608
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define lamsort(v,p) sort(v.begin(),v.end(),[](p a, p b){return a.num < b.num;});
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e8
typedef long long ll;
using namespace std;

int main() {
    ll n, a, b; cin >> n >> a >> b;
    if((b-a)%2==0) {
        ll ans = (b-a)/2;
        cout << ans << endl;
        return 0;
    }
    else {
        if(n-b<=a-1) {
            a += n-b+1;
            ll k = (n-a)/2;
            cout << k+n-b+1 << endl;
            return 0;
        }
        else {
            b -= a;
            ll m = b/2;
            cout << m+a << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node
{
    int x,y,h;
}a[105];
bool cmp(node xx,node yy)
{
    return xx.h>yy.h;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].h);
    sort(a,a+n,cmp);
    if(a[0].h==0)
    {
        for(int i=0;i<=100;i++)
        for(int j=0;j<=100;j++)
        {
            int ans=1e9;
            for(int k=0; k<n; k++)
            {
                int h=a[k].h+abs(a[k].x-i)+abs(a[k].y-j);
                ans=min(ans,h);
            }
            if(ans<=1) continue;
            printf("%d\n",ans-1);
            return 0;
        }
    }
    for(int i=0;i<=100;i++)
    {
        for(int j=0;j<=100;j++)
        {
            set<int>s;
            int flag=1;
            for(int k=0;k<n;k++)
            {
                if(a[k].h>0)
                {
                    int h=a[k].h+abs(a[k].x-i)+abs(a[k].y-j);
                    s.insert(h);
                    if(s.size()>1)
                    {
                        flag=0;break;
                    }
                }
                else
                {
                    int h=*s.begin();
                    int hh=h-abs(a[k].x-i)-abs(a[k].y-j);
                    if(hh<=0) continue;
                    else
                    {
                        flag=0;break;
                    }
                }
            }
            if(flag)
            {
                printf("%d %d %d\n",i,j,*s.begin());
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<string , int> p;
const int N=2e5+10;
map<string,int>mp;
bool cmp(const p &left,const p &right){
    if(left.second==right.second)
    return left.first<right.first;
    return left.second>right.second;
}
int main(){
    int n;
    cin >> n;
   // string a;
    for(int i=0;i<n;i++){
       string a;
        cin >> a;
        mp[a]++;
    }
    vector <p> vec(mp.begin(),mp.end());
    sort(vec.begin(),vec.end(),cmp);
    int cnt=1;
    for(vector<p>::iterator ite=vec.begin();ite!=vec.end()-1;++ite){
        if(ite->second==(ite+1)->second){
            cnt++;
        }
        else{
            break;
        }
        /*if(ite->second!=(ite+1)->second){
            cout<<ite->first;
            break;
        }
        else{
            cout<<ite->first<<endl;
            cout<<(ite+1)->first<<endl;
            ite++;
        }*/
    }
    for(int i=0;i<cnt;i++){
        cout<<vec[i].first<<endl;
    }
}

Measured memory_bytes: 28288
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
template<typename T>
T extgcd(T a,T b,T&x,T&y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	T q=a/b;
	T g=extgcd(b,a-q*b,y,x);
	y-=q*x;
	return g;
}
long N,ans;
vector<pair<long,int> >X;
void dfs(int id,long x)
{
	if(id<X.size())
	{
		dfs(id+1,x);
		for(int i=0;i<X[id].second;i++)
		{
			x*=X[id].first;
		}
		dfs(id+1,x);
		return;
	}
	long y=2*N/x;
	long l,m;
	long g=extgcd(x,y,m,l);
	m=-m;
	if(m>0&&(ans+m-1)/m>x)ans=min(ans,m*x);
	return;
}
main()
{
	cin>>N;
	if(N==1)
	{
		cout<<1<<endl;
		return 0;
	}
	ans=2*N-1;
	if(N%2==1)ans=N-1;
	long T=2*N;
	for(long i=2;i*i<=T;i++)
	{
		if(T%i==0)
		{
			X.push_back(make_pair(i,0));
			while(T%i==0)
			{
				X.back().second++;
				T/=i;
			}
		}
	}
	if(T>1)X.push_back(make_pair(T,1));
	dfs(0,1L);
	cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<string,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())

using namespace std;
int main() {
  ll N,A,B,C;
  cin>>N>>A>>B;
  C=A+B;
  if(N%C<=A) {
    cout<<A*(N/C)+N%C<<endl;
  }
  else 
    cout<<A*(N/C)+A<<endl;
}
  
    
  
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  ll n,a,b;
  cin >> n>>a>>b;
  if(a+b==0){
    cout << 0;
    return 0;
  }
  ll x = n/(a+b);
  ll ans = x*a;
  if(n%(a+b)>a) ans+=a;
  else ans+=n%(a+b);
  cout << ans;
}


Measured memory_bytes: 256
/*
Author:Jenil Mehta
Not yet serious but trying to be serious :)
Coding is lub
*/
 
#include <iostream>
#include <sstream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    ll i,j;
    for(i=1;i<=n;i++)
    {
        if(i%15==0||i%3==0||i%5==0)
        {
            continue;
        }
        else
        {
            sum+=i;
        }
    }
    cout<<sum<<endl;
}

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

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

using namespace std;
using ll = long long;

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

    ll n;
    int x, m;
    cin >> n >> x >> m;

    vector<bool> al(m, false);
    list<int> q;
    ll a = x;
    int c = 0;

    q.emplace_back(a);
    al.at(a) = true;
    c++;

    while(true) {
        a = a * a % m;
        if(al.at(a)) {
            break;
        } else {
            q.emplace_back(a);
            al.at(a) = true;
            c++;
        }
    }

    int d = 0;
    ll sum0 = 0;
    auto itr = q.begin();
    while(*itr != a) {
        sum0 += *itr;
        itr++;
        d++;
    }
    int per = c - d;

    auto itr2 = itr;
    ll sump = 0;
    rep(i, per) {
        sump += *itr2;
        itr2++;
    }

    ll ans = sum0 + (n - d) / per * sump;
    rep(i, (n - d) % per) {
        ans += *itr;
        itr++;
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll x;
    cin>>x;
    ll ans = (x - 400)/200 + 1;
    cout<<9 - ans<<'\n';
}

Measured memory_bytes: 3632
N,P = map(int,input().split())
A = list(map(int,input().split()))
C = [0,0]
for i in range(N):
    if A[i]%2==0:
        C[0] += 1
    else:
        C[1] += 1
if C[1]==0 and P==1:
    print(0)
elif C[1]==0 and P==0:
    print(2**C[0])
else:
    print((2**C[0])*(2**(C[1]-1)))

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

using PII = pair<int, int>;

int main() {
  int h, n;
  cin >> h >> n;
  vector<PII> AB(n);
  for (auto& ab : AB)
    cin >> ab.first >> ab.second;

  vector<int> dp(h + 1, 1e+9);
  dp[0] = 0;
  for (auto& ab : AB) {
    int a = ab.first;
    int b = ab.second;
    for (int i = 0; i < h; ++i) {
      int j = min(h, i + a);
      dp[j] = min(dp[j], dp[i] + b);
    }
  }
  cout << dp[h] << "\n";

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    int N,M;
    cin >> N >> M;
    priority_queue<int> nog;
    rep(i,N){
        int a;
        cin >> a;
        nog.push(a);
    }
    rep(i,M){
        int p;
        p=nog.top();
        nog.pop();
        nog.push(p/2);
    }
    ll sum=0;
    while(!nog.empty()){
        sum+=nog.top();
        nog.pop();
    }
    cout << sum;

}

/*



 */



Measured memory_bytes: 892
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  scanf("%d",&n);
  int tmp;
  int count = 0;
  rep(i,n){
    scanf("%d",&tmp);
    if(tmp % 2 != 0)count++;
  }
  if(count % 2 == 0)printf("YES\n");
  else printf("NO\n");
  return 0;
} 

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

#define MAXLINE 1000
#define CMD_LEN 9

void
flip(char *, int, int);

void
pri(char *, int);

int
main(void)
{
    char str[MAXLINE + 1];
    char rep[MAXLINE + 1];
    char cmd[CMD_LEN];
    int cmdCnt, param1, param2;
    scanf("%s", str);
    for (scanf("%d", &cmdCnt); cmdCnt > 0; cmdCnt--) {
        scanf("%s %d %d", cmd, &param1, &param2);
        if (!strcmp(cmd, "reverse"))
            flip(str, param1, param2);
        else if (!strcmp(cmd, "replace")) {
            scanf("%s", rep);
            strncpy(str + param1, rep, strlen(rep));
        } else if (!strcmp(cmd, "print"))
            pri(str + param1, param2 - param1);
    }

    return 0;
}

void
flip(char *str, int st, int end)
{
    char tmp;
    for ( ; st < end; st++, end--) {
        tmp = str[st];
        str[st] = str[end];
        str[end] = tmp;
    }
}

void
pri(char *str, int l)
{
    int i;
    for (i = 0; i <= l; i++)
        putchar(str[i]);
    putchar('\n');
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main(){
  char a[256],b[256],c[256];
  
  cin>>a;
  cin>>b;
  cin>>c;
  a[0]-=32;
  b[0]-=32;
  c[0]-=32;
  cout<<a[0]<<b[0]<<c[0]<<'\n';
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    is_prime = sieve(10 ** 5 + 1)
    is_like2017 = [(is_prime[i] and is_prime[(i + 1) // 2]) for i in range(10 ** 5 + 1)]
    counter = [0]
    for i in range(1, 10 ** 5 + 1):
        counter.append(counter[-1] + (1 if is_like2017[i] else 0))

    q = int(input())
    for i in range(q):
        l, r = map(int, input().split())
        print(counter[r] - counter[l - 1])


# O(nloglogn) https://mathtrain.jp/eratosthenes
def sieve(n):  # exclusive
    s = [True] * n
    s[0] = s[1] = False
    for x in range(2, int(n**0.5) + 1):
        if s[x]:
            for i in range(2 * x, n, x):
                s[i] = False
    return s

if __name__ == "__main__":
    main()


Measured memory_bytes: 7960
def gcd(a, b):
  if a < b:
    a, b = b, a
  if b == 0:
    return a
  c = a % b
  return gcd(b, c)
  
n=int(input())
a=list(map(int,input().split()))
g1=[0 for i in range(n)]
g2=[0 for i in range(n)]
g1[0]=a[0]
g2[n-1]=a[n-1]
for i in range(1,n):
  g1[i]=gcd(g1[i-1],a[i])
for i in range(n-2,-1,-1):
  g2[i]=gcd(g2[i+1],a[i])
ans=1
for i in range(n-2):
  a=gcd(g1[i],g2[i+2])
  ans=max(ans,a)
ans=max(ans,g1[n-2],g2[1])
print(ans)
  

Measured memory_bytes: 14436
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

map<char, char>mp;
signed main() {
	/*cin.tie(0);
	ios::sync_with_stdio(false);*/
	int A, B, C; cin >> A >> B >> C;

	int ans = min(min(A + B, B + C), C + A);
	print(ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include<ctype.h>
int srt(int a[],int n )
{
    for(int i =0 ; i<n ; i++)
      {for(int j=i+1 ; j<n ; j++)
    {
        if(a[j]>a[i])
        {
            int temp=a[j] ;
            a[j]=a[i] ;
            a[i]=temp ;
        }

    }
}




}

int main()
{
	int a[3434],b,sum=0,n,i,j,k,t ;
    char ch ;
    scanf("%d %d",&n,&k) ;

for(i=0 ; i<n ; i++)
    scanf("%d",&a[i]) ;
    srt(a,n) ;
    for(i=n-1 ; i>n-1-k ; i--)
    sum=sum+a[i] ;
    printf("%d",sum) ;


	return 0;
}

Measured memory_bytes: 1736
#include<stdio.h>

void sort(int *a, int n);

void sort(int *a, int n){
	int i, j, max, index;

	for(i=0; i<n-1; i++){
		max = a[i];	index = i;
		for(j=i+1; j<n; j++){
			if(max < a[j]){
				max = a[j];	index = j;
			}
		}
		a[index] = a[i];	a[i] = max;
	}
}
int main(void){
	int a[3], i, j;
	scanf("%d%d%d", a, a+1, a+2);
	sort(a, 3);

	if((a[0] == a[1] || a[1] == a[2]) && (a[0] != a[2])) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int f(int x){
    return x*(x+1)/2;
}
int main(){
    int a,b;
    cin>>a>>b;
    cout<<f(b-a)-b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX (ll)(500 + 4)
#define MOD (ll)(1e9 + 7)
#define PI (double)(3.14159265)
#define IO ios_base :: sync_with_stdio (false), cin.tie (nullptr);

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

ll adj[MAX][MAX];

int main () { 
	IO;
	ll n, m;
	ll ar[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	cin >> n >> m;
	char ch[n][m];
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < m; j++) {
			cin >> ch[i][j];
		}
	}
	ll nn = n * m;
	for (ll i = 0; i < nn; i++) {
		for (ll j = 0; j < nn; j++) {
			adj[i][j] = MOD;
			if (i == j) {
				adj[i][j] = 0;
			}
		}
	}
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < m; j++) {
			if (ch[i][j] == '#') {
				continue;
			}
			for (ll k = 0; k < 4; k++) {
				ll x = i + ar[k][0], y = j + ar[k][1];
				if (x >= 0 && x < n && y >= 0 && y < m && ch[x][y] == '.') {
					ll u = m * x + y, v = i * m + j;
					adj[u][v] = 1;
					adj[v][u] = 1;
				}
			}
		}
	}
	ll ma = 0;
	for (ll k = 0; k < n * m; k++) {
		for (ll i = 0; i < n * m; i++) {
			for (ll j = 0; j < n * m; j++) {
				adj[i][j] = min (adj[i][j], adj[i][k] + adj[k][j]);
			}
		}
	}
	for (ll k = 0; k < n * m; k++) {
		for (ll i = 0; i < n * m; i++) {
			if (adj[k][i] == MOD) {
				continue;
			}
			ma = max (adj[k][i], ma);
		}
	}
	cout << ma << "\n";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 0;

int main() {
	string S, T;
	cin >> S >> T;
	int ss = S.size(), c = 0;
	for (int i = 0;i < ss;i++) {
		if (S[i] != T[i])c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 3848
#include<iostream>

using namespace std;

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

	if (a<=b && b<=c)
	{
		cout << a << " " << b << " " << c << endl;
	}
	else if (a<=c && c<=b)
	{
		cout << a << " " << c << " " << b << endl;
	}
	else if (b<=c && c<=a)
	{
		cout << b << " " << c << " " << a  << endl;
	}
	else if (a>=b && a<=c)
	{
			cout << b << " " << a << " " << c << endl;
	}
	else if (a<=b && a>=c)
	{
		cout << c << " " << a << " " << b << endl;
	}
	else if (a>=b && b>=c)
	{
		cout << c << " " << b << " " << a << endl;
	}

}

Measured memory_bytes: 3076
import math
import fractions
A, B, C, D = map(int, input().split())

#B以下の整数の個数
x = B - (B // C) - (B // D)
#C,Dの最大公約数を求める
l = fractions.gcd(C, D)
#C,Dの最小公倍数を求める
temp = C * D // l 
#C,Dで重複して引いた数を足し合わせる
x += (B // temp)

#同様にA - 1以下の整数のうちの個数も求める
a = A - 1
y = a - (a // C) - (a // D)
y += (a // temp)

ans = x - y
print(ans)

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

int main() {
  int n;
  cin>>n;
  string JPY,BTC;
  
  vector<double> vec1(n);
  vector<string> vec2(n);
  
  rep(i,n){
    cin >> vec1.at(i) >> vec2.at(i);
  }
  double sum =0;
  rep(i,n){
    if (vec2.at(i) == "JPY"){
      sum+=vec1.at(i);
    }
    else {
      sum += vec1.at(i)*380000.0;
    }
  }
  cout <<  sum << endl;
}

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

using namespace std;

#define ll long long

int main(void){
	ll n, k, quot, x, y;

	cin >> n >> k;

	quot = (n/k) + 1;
	n = n - (k * quot);
	x = -n;
	y = n + k;

	if(x < y){
		cout << x;
	}
	else{
		cout << y;
	}

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x)  ((int)x.size ())
#define all(x) (x).begin(), (x).end()
#define re return
#define mp make_pair
#define sqrt(x) sqrt (abs(x))
#define y0 y3451
#define y1 y4562
#define j0 j25624
#define j1 j45624
#define makeunique(x) sort(all(x)), (x).resize (unique(all(x)) - (x).begin())

typedef pair <int, int> ii;
typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef long double ld;
typedef unsigned int uint;
typedef vector <string> vs;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <vi> vvi;

template <class T> using _tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> T abs (T x) { re x > 0 ? x : -x; }
template <class T> T sqr (T x) { re x * x; }
template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }
template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }

#define filename ""

const D pi = acos(-1.);
const int N = 2e5 + 20;
const int inf = 1e9 + 7;

int n, m;
ll a[1000];
ll dp[500][500];
int was[500][500];

ll sum(int l, int r) {
	if (l) re a[r] - a[l - 1];
	re a[r];
}

ll go(int l, int r) {
	if (l == r) re 0;
	if (was[l][r]) re dp[l][r];
	ll ans = (ll) inf * inf;
	was[l][r] = 1; 
	for (int i = l; i < r; i++)
		ans = min(ans, go(l, i) + go(i + 1, r));
	re dp[l][r] = ans + sum(l, r);
}	 

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i) a[i] += a[i - 1];
	}
	cout << go(0, n - 1);	
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		final String one = "1";
		int ans = 0;

		String s = scan().next();

		for(int i = 0; i < s.length(); i++){
			String a = String.valueOf(s.charAt(i));
			if(one.equals(a)){
				ans++;
			}
		}

		System.out.println(ans);
	}

	private static Scanner scan() {
		return new Scanner(System.in);
	}

}


Measured memory_bytes: 21844