akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
	final long MOD = 1000000007;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();

		if(Math.abs(n-m)>1) {
			System.out.println(0);
			sc.close();
			return;
		}
		long ans = fact(n) * fact(m) % MOD;
		if(Math.abs(n-m)==0) {
			ans = ans * 2 % MOD;
		}
		System.out.println(ans);
		sc.close();
	}

	private long fact(long x) {
		long ans=1;
		for(long i=1; i<=x; i++) {
			ans = ans * i % MOD;
		}
		return ans;
	}
}


Measured memory_bytes: 24148
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 100000000
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	return sc
}()

// Input number
func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

// Input string
func scanString() (s string) {
	sc.Scan()
	return sc.Text()
}

func main() {
	N := scanIntNum()
	types := make(map[string]int)

	var S string
	for i := 0; i < N; i++ {
		S = scanString()
		types[S]++
	}
	fmt.Println(len(types))
}


Measured memory_bytes: 18284
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> p;
	p.resize(n);
	int a;
	for(int i=0; i<n; i++){
		cin >> p[i];
	}
		
	int count = 0;
//cout << "fiuyfi" << endl;
	for(int i=0; i<n-1; i++){
		if(p[i]==i+1){
//cout << p[i] << endl;
			a = p[i];
			p[i] = p[i+1];
			p[i+1] = a;
			count += 1;
		}
	}
	if(p[n-1] == n){
		count +=1;
	}
	
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>

long long gcd(long long x, long long y){
  if(y == 0) return x;
  return gcd(y, x%y);
}

long long lcm(long long x, long long y){
  return (x*y)/gcd(x, y);
}

main(){
  long long a1, m1, a2, m2, a3, m3;
  while(1){
    scanf("%lld %lld %lld %lld %lld %lld", &a1, &m1, &a2, &m2, &a3, &m3);
    if(a1 == 0 && m1 == 0 && a2 == 0 && m2 == 0 && a3 == 0 && m3 == 0) break;
    long long a=0, b=0, c=0;
    long long x=a1*1%m1, y=a2*1%m2, z=a3*1%m3;
    while(1){
      a++;
      if(x == 1) break;
      x = a1*x%m1;
    }
    while(1){
      b++;
      if(y == 1) break;
      y = a2*y%m2;
    }
    while(1){
      c++;
      if(z == 1) break;
      z = a3*z%m3;
    }
    printf("%lld\n", lcm(a, lcm(b, c)));
  }
}

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

int main()
{
   int i,a=0,b=0;
   string s;
   cin>>s;
   
   for(i=0;i<3;i++){
       if(s[i]=='A'){
           a++;
       }else{
           b++;
       }
   }
   
   if(a>0 && b>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;
typedef unsigned long long ull;
using vi = vector<int>;
using vll = vector<ll>;
ll fast_exp(ll base,ll e){
    ll r=1;
    while(e>0){
        if(e%2)r=(r*base);
        base=base*base;
        e/=2;
    }
    return r;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,W;
    cin>>n>>W;
    vector<ll> dp(1e5+1,1e11L);
    // min total weight at i value
    dp[0]=0;
    for(int i=0;i<n;i++){
        ll w,v;cin>>w>>v;
        for(int j=1e5;j>=v;j--){
            dp[j]=min(dp[j],w+dp[j-v]);
        }
    }
    int ans=0;
    for(int i=0;i<=1e5;i++){
        if(dp[i]<=W)ans=max(ans,i);
    }
    cout<<ans;
}


Measured memory_bytes: 1024
from collections import defaultdict
import heapq as hq
N = int(input())
dicUD = defaultdict(list)
dicRL = defaultdict(list)
dicRUp = defaultdict(list)
dicDLp = defaultdict(list)
dicRDm = defaultdict(list)
dicULm = defaultdict(list)
for i in range(N):
    X,Y,U = input().split()
    X,Y = map(int,(X,Y))
    if U == "L":
        hq.heappush(dicRL[Y],(X,"L"))
        hq.heappush(dicDLp[X+Y],(X-Y,"L"))
        hq.heappush(dicULm[X-Y],(X+Y,"L"))
    if U == "R":
        hq.heappush(dicRL[Y],(X,"R"))
        hq.heappush(dicRUp[X+Y],(X-Y,"R"))
        hq.heappush(dicRDm[X-Y],(X+Y,"R"))
    if U == "U":
        hq.heappush(dicUD[X],(Y,"R"))
        hq.heappush(dicRUp[X+Y],(X-Y,"L"))
        hq.heappush(dicULm[X-Y],(X+Y,"R"))
    if U == "D":
        hq.heappush(dicUD[X],(Y,"L"))
        hq.heappush(dicDLp[X+Y],(X-Y,"R"))
        hq.heappush(dicRDm[X-Y],(X+Y,"L"))
time = 10000000
for q in dicUD.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
for q in dicRL.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
for q in dicRUp.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
for q in dicDLp.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
for q in dicRDm.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
for q in dicULm.values():
    cur = -1000000
    dir = "L"
    while q:
        X,U = hq.heappop(q)
        if U == "R":
            dir = "R"
        elif U == "L":
            if dir == "R":
                time = min(time,(X-cur)*5)
            dir = "L"
        cur = X
if time == 10000000:
    print("SAFE")
else:
    print(time)

Measured memory_bytes: 202780
import sys
h, w = map(int,sys.stdin.readline().split())
if w == 1 or h == 1:
  print(1)
else:
  if h % 2 != 0:
    if w % 2 != 0:
      print(h * w // 2 + 1)
    else:
      print(h * w // 2)
  else:
    print(h * w // 2)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;

bool vis[101010][2];

int main(){
  cin >> N;
  vector<i64> A(N),B(N);
  i64 as = 0;
  i64 bs = 0;
  rep(i,0,N - 1){
    cin >> A[i] >> B[i];
    as += A[i];
    bs += B[i];
  }

  using P = pair<i64,pair<i64,i64>>;
  vector<P> vec;
  rep(i,0,N - 1){
    vec.push_back({A[i] , {i , 0}});
    vec.push_back({B[i] , {i , 1}});
  }
  sort(all(vec));
  i64 sum = 0;
  rep(i,0,N - 1){
    vis[vec[i].second.first][vec[i].second.second] = true;
    sum += vec[i].first;
  }
  bool OK = false;
  rep(i,0,N - 1){
    if(vis[i][0] && vis[i][1]) OK = true;
  }
  if(!OK){
    i64 ans = 1e18;
    int idx = N - 1;
    rep(i,0,N - 1){
      int j = idx;
      if(i == vec[idx].second.first) j--;
      i64 a = vec[j].first;
      i64 b = A[i];
      if(vis[i][0]) b = B[i];
      ans = min(ans , sum - a + b);
    }
    sum = ans;
  }
  cout << min({sum , as , bs}) << endl;
}


Measured memory_bytes: 10096
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);
    private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long m = sc.nextLong();
        int pow = (int)(Math.log(m) / Math.log(2)) + 1;
        long res = (long)Math.pow(2.0, pow * 1.0) - 1L;
        System.out.println(res);

        System.exit(0);
    }
    static private class Point {
        public int x;
        public int y;
        Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
#include <stdio.h>

int main(void)
{
    char s[3];
    scanf("%s", s);

    char flag = 0;
    for (int i = 0; i < 3; i++)
    {
        flag |= 1 << (s[i] - 0x61);
    }
    if ((flag & 0x07) == 0x07)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}


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


int main() {
    int n,k;
    int ans = 0;
    cin >> n >> k ;
    for (int i = 0 ; i < n; i++){
        int x,t;
        cin >> x;
        t = k - x;
        if(t < 0){
            
            t = x - k;

        }
        if(x >= t){
            ans = ans + 2 * t;
        }else{
            ans = ans + 2 * x;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = []
for i in range(n):
    a.append(na())
a.sort(key=lambda x: x[1])
time = 0
ans = "Yes"
for ai in a:
    time += ai[0]
    if time > ai[1]:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 53724
// https://atcoder.jp/contests/abc092/tasks/abc092_b

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
  /* Magic word */
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  /* ---------- */

  int n, d, x;
  vector<int> a;

  cin >> n >> d >> x;
  REP(i, n)
  {
    int ai;
    cin >> ai;
    a.push_back(ai);
  }

  REP(i, n)
  {
    int ai = a[i];
    int day = 0;
    while (day < d)
    {
      day += ai;
      x++;
    }
  }

  cout << x << '\n';

  return 0;
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll a,b,c,k;
  cin >> a >>  b >> c >> k;

  ll ans = 0;

  ans += min(a,k);
  k -= min(a,k);

  if(k > 0)
  {
    k -= min(k,b);
  }

  if(k > 0)
  {
    ans -= min(k,c);
  }

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int n;
int a[310];

long dp1[310][90010];
long dp2[310][90010];

const long MOD = 998244353;

long whole, sole, twin, out;

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

    memset(dp1, 0, sizeof(dp1));
    dp1[0][0] = 2;
    dp1[0][a[0]] = 1;
    memset(dp2, 0, sizeof(dp2));
    dp2[0][0] = 1;
    dp2[0][a[0]] = 1;

    for (int t = 1; t < n; ++t){
        for (int r = 0; r <= s; ++r){
            (dp1[t][r] += (2*dp1[t-1][r] % MOD)) %= MOD;
            (dp2[t][r] += dp2[t-1][r]) %= MOD;
            if (r >= a[t]) {
                (dp1[t][r] += dp1[t-1][r-a[t]]) %= MOD;
                (dp2[t][r] += dp2[t-1][r-a[t]]) %= MOD;
            }   
        }
    }

    whole = 1;
    for (int i = 0; i < n; ++i){
        (whole *= 3) %= MOD;
    }

    sole = 0;
    for (int r = (s+1)/2; r <= s; ++r){
        (sole += dp1[n-1][r]) %= MOD;
    }

    twin = 0;
    if (s % 2 == 0){
        twin = dp2[n-1][s/2];
    }

    out = (whole + ((MOD - sole)*3) % MOD + (twin*3) % MOD) % MOD;
    cout << out << endl;
}

Measured memory_bytes: 436352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int main() {
    int n;
    cin >> n;
    vector<int> ai, bi, ci;
    rep(i, n) {
        int a;
        cin >> a;
        ai.push_back(a - 1);
    }
    rep(i, n) {
        int b;
        cin >> b;
        bi.push_back(b);
    }
    rep(i, n - 1) {
        int c;
        cin >> c;
        ci.push_back(c);
    }
    int total = 0;
    rep(i, n) {
        int idx = ai[i];
        total += bi[i];
        if (i > 0 && ai[i - 1] == idx - 1) {
            total += ci[idx - 1];
        }
    }
    cout << total << "\n";
} 

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

int main()
{
	int a, b;
  	cin>>a>>b;
  	if(a>=13)
      	cout<<b<<endl;
  	else if(a>=6 && a<=12)
      	cout<<b/2<<endl;
  	else
      	cout<<"0"<<endl;
  	
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include<iomanip>
using namespace std;
int main(void){
  double L;
  cin >> L;
  double l3 = L / 3.0;
  double cube = l3 * l3 * l3;
  cout << fixed << setprecision(10) << cube << endl;
}

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

#define ll long long
#define int long long
#define ALL(x) (x).begin(), (x).end()

using namespace std;

ll f(vector<ll> &a, ll x){
	return a[0] + a[1]*x + a[2]*x*x + a[3]*x*x*x + a[4]*x*x*x*x + a[5]*x*x*x*x*x;
}

signed main(){
	string str;
	cin >> str;
	vector<ll> a(10,0);
	for(int i = 0; i < str.size(); i++){
		if(str[i] == '+' || str[i] == '-'){
			int j = i;
			while(str[j] != 'x' && j < str.size())j++;
			int s;
			if(j < str.size()){
				if(j != str.size() && str[j+1] =='^'){
					s = str[j+2] - '0';
				}
				else{
					s = 1;
				}
			}
			else{
				s = 0;
			}
			string temp = str.substr(i+1,j-i-1);
			bool flag = true;
			for(auto t : temp){
				if(t < '0' || t > '9'){
					flag =false;
					break;
				}
			}
			if(flag && temp.size() > 0){
				try{
				a[s] = stoll(temp);
				}
				catch(const std::invalid_argument){
					continue;
				}
			}
			else{
				a[s] = 1;
			}
			if(str[i] == '-'){
				a[s] *= -1;
			}
		}
	}
	if(str[0] == 'x'){
		if(str[1] == '^'){
			a[str[2]-'0'] = 1;
		}
		else{
			a[1] = 1;
		}
	}
	vector<ll> b;
	for(ll i = -2*1000; i <= 2*1000;i++){
		if(f(a,i) == 0LL){
			b.push_back(i);
		}
	}
	sort(ALL(b));
	for(int i = b.size()-1; i >= 0;i--){
		cout << "(x";
		if(b[i] > 0){
			cout << "-";
		}
		else{
			cout << "+";
		}
		cout << llabs(b[i]);
		cout << ")";
	}
	cout << endl;		


	return 0;
}




Measured memory_bytes: 3216
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      int m=sc.nextInt();
      for(int i=0;i<n-1;i++)
        m=gcd(m,sc.nextInt());
      System.out.println(m);
      
	}
  	public static long gcd(long m, long n) {
		if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
  public static int gcd(int m, int n) {
		if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}

}


Measured memory_bytes: 47808
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var o=r[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)n.d(t,o,function(r){return e[r]}.bind(null,o));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=0)}([function(e,r,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,r){e.exports=function(e){for(var r=e[0],n=r.length,t=1;t<n;t++)if(r[t]==r[t-1])return void console.log(`${t} ${t+1}`);for(var o=2;o<n;o++)if(r[o]==r[o-2])return void console.log(`${o-1} ${o+1}`);console.log("-1 -1")}},function(e,r){e.exports=require("fs")}]);

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define MAX 402
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))
#define sz size
const int MOD = 1e9+7;

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int n,arr[MAX], dp[MAX][MAX], prefix[MAX];
int solve(int l, int r){
	if (l>r) return 0;
	if (l==r) return dp[l][r] = 0;
	if (l == r+1) return dp[l][r] = arr[l]+arr[r];
	if (dp[l][r] != -1) return dp[l][r];


	int mini = 10000000000000;
	For(i,l,r) mini = min(solve(l,i)+solve(i+1,r), mini);
	return dp[l][r] = mini + prefix[r] - prefix[l-1];
}


signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


	cin>>n;
	For(i,1,n+1) cin>>arr[i];
	prefix[0] = 0;
	For(i,1,n+1) prefix[i] = prefix[i-1] + arr[i];



	initialize(dp,-1);
	cout<<solve(1,n)<<endl;
	// For(i,1,n){
	// 	For(j,1,n) cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main()
{
	cin>>a>>b>>k;
	for (int i=0;i<k;i++)
		if (i%2==0)
		{
			if (a & 1) a--;
			b+=a/2;
			a-=a/2;
		}
		else
		{
			if (b & 1) b--;
			a+=b/2;
			b-=b/2;
		}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
d = {}  # key=match, val=num
d[2] = [1]
d[3] = [7]
d[4] = [4]
d[5] = [5, 3, 2]
d[6] = [9, 6]
d[7] = [8]
enable = [False] * 10
for a in l:
  enable[a] = True
# マッチをk(=2..7)本使う場合の一番大きい値を総当たり
def f(nokori, current):
  if nokori == 0:
    return current
  if nokori < 0:
    return -1
  temps = []
  for key, nums in list(d.items())[::-1]:
    for num in nums:
      if enable[num]:
        if nokori-key != 0 and current % 10 != 0 and current % 10 < num:
          # 98 ok, 89 重複するので最後の桁以外は skip
          continue
        temps.append(f(nokori-key, current*10+num))
        break
  return max(temps)

# 余裕があるうちは一番マッチの本数が少ないモノをヤケクソで詰めまくる
hoge = False
for key, nums in list(d.items()):
    # print(key, nums, type(nums))
    for num in nums:
      if enable[num]:
        hoge = True
        break
    if hoge:
      break
cs = []
while n > 50:
  n -= key
  cs.append(str(num))

# ヤケクソで詰めたやつと総当たりで調べたマックスを並び替えて辞書順で大きくする
num_ans = str(f(n, 0))
print(''.join(sorted(list(num_ans) + cs)[::-1]))


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

int main()
{
	int n,inp,sum;

	while(cin>>n,n!=0)
	{
		vector<int> score;
		for(int i=0;i<n;i++)
		{
			cin>>inp;
			score.push_back(inp);
		}

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

		sum=0;
		for(int i=1;i<n-1;i++)
			sum+=score[i];

		cout<<sum/(n-2)<<endl;
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,i,p,p1,q,q1,r,r1,s,s1,t,t1;
    int flag=0;
    cin>>A>>B;
    for(i=A;i<=B;i++)
    {
         p=i%10;
         p1=i/10;
         q=p1%10;
         q1=p1/10;
         r=q1%10;
         r1=q1/10;
         s=r1%10;
         s1=r1/10;
        t=s1%10;
         t1=s1/10;
         if(t==p && q==s)
         {
             flag++;
         }


    }


    cout<<flag<<endl;
    return 0;
}


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

int main()
{
  int P, Q, R;
  cin >> P >> Q >> R;
  int sum[3];
  sum[0] = P + Q;
  sum[1] = Q + R;
  sum[2] = R + P;
  cout << *min_element(sum, sum + 3);
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int P=998244353;
int main(){
	int k;
	string s;
	cin >> k >> s;
	int n = s.size();
	if(n<=k) cout << s;
	else cout << s.substr(0, k) << "...";
	cout << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define range 200010
#pragma GCC optimize ("Ofast")
#define endl '\n'

int B[100];
signed main(){

	//freopen("test.txt","r",stdin);
	ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++)cin>>B[i];
	int ans = B[0]+B[n-2];
	for(int i=1;i<=n-2;i++){
		ans+=min(B[i],B[i-1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)1e5 + 123;

int a[N];
int fact[N];
int n, k;
int ans;

int mult(int a, int b)
{
	a = 1ll * a * b % mod;
	return a;
}

int add(int a, int b)
{
	a += b;
	if(a >= mod) a %= mod;
	return a;
}

int sub(int a, int b)
{
	a -= b;
	if(a < 0) a += mod;
	return a;
}

int Binpow(int a, int n)
{
	if(!n) return 1;
	if(n & 1) return mult(a, Binpow(a, n - 1));
	else
	{
		int b = Binpow(a, n / 2);
		return mult(b, b);
	}
}

int C(int n, int k)
{
	if(k > n || n < 0 || k < 0) return 0;
	int a = fact[n];
	int b = mult(fact[n - k], fact[k]);
	return mult(a, Binpow(b, mod - 2));	
}
 
int main ()
{                             
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();   
	cin >> n >> k;
	fact[0] = 1;
	for(int i = 1; i <= 100000; i++) fact[i] = mult(fact[i - 1], i);
	for(int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++)
	{
		ans = add(ans, mult(a[i], C(i - 1, k - 1)));
		ans = sub(ans, mult(a[i], C(n - i, k - 1)));
	}
	cout << ans;
}                                

Measured memory_bytes: 1024
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= main'
    where
        main' [_, x] = breads >>= print . solve x

-- |
-- >>> solve 3 [1, 77, 11]
-- 2
-- >>> solve 81 [33, 105, 57]
-- 24
-- >>> solve 1 [1000000000]
-- 999999999
solve :: Int -> [Int] -> Int 
solve a = foldl1' gcd . diff . sort . (a :)
    where
        diff (x : y : zs) = (y - x) : diff (y : zs)
        diff _ = []

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 15740
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(omkar: Array<String>) {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    var line = jin.readLine()
    var six = line.indexOf(' ')
    val n = line.substring(0, six).toInt()
    val m = line.substring(six + 1).toInt()
    val rev = Array(n + 1) { mutableListOf<Int>() }
    for (j in 1..m) {
        line = jin.readLine()
        six = line.indexOf(' ')
        val a = line.substring(0, six).toInt()
        val b = line.substring(six + 1).toInt()
        rev[b].add(a)
    }
    val dp = IntArray(n + 1) { -2 }
    val stack = Stack<Int>()
    for (j in 1..n) {
        stack.push(j)
    }
    var answer = 0
    while (stack.isNotEmpty()) {
        val a = stack.pop()
        if (dp[a] == -2) {
            dp[a] = -1
            stack.push(a)
            stack.addAll(rev[a])
        } else {
            if (dp[a] == -1) {
                dp[a] = 0
                for (b in rev[a]) {
                    dp[a] = Math.max(dp[a], dp[b] + 1)
                }
            }
            answer = Math.max(answer, dp[a])
        }
    }
    println(answer)
}

Measured memory_bytes: 59876
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1000000001;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,k;cin>>n>>k;
    ll u=n%k;
    cout<<min(u,k-u)<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b; cin >> a >> b;
	if (b % a == 0) cout << a + b << endl;
	else cout << b - a << endl;
	return 0;
}

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

constexpr int INF = 1e9;

struct edge {
    int from, to, weight;
};

int main() {
    int m, n, k, d;
    while(cin >> m >> n >> k >> d, m) {
        vector<int> c(m);
        for(int i=0; i<m; ++i) {
            cin >> c[i];
        }
        auto get_id = [m, n](string const& s) {
            if(s[0] == 'H') {
                return 0;
            } else if(s[0] == 'C') {
                return s[1] - '0';
            } else if(s[0] == 'L') {
                return stoi(s.substr(1)) + m;
            } else {
                return m+n+1;
            }
        };
        vector<vector<int>> cost(1 << m, vector<int>(m+n+2, INF));
        vector<edge> es;
        for(int i=0; i<d; ++i) {
            string s, t;
            int e;
            cin >> s >> t >> e;
            int a = get_id(s), b = get_id(t);
            es.push_back((edge){a, b, e*k});
            es.push_back((edge){b, a, e*k});
        }

        cost[0][0] = 0;
        while(true) {
            bool update = false;
            for(int i=0; i<(1<<m); ++i) {
                for(int j=0; j<2*d; ++j) {
                    edge e = es[j];
                    if(cost[i][e.from] == INF) {
                        continue;
                    }
                    if(1 <= e.to && e.to <= m) {
                        if(!(i >> (e.to - 1) & 1) && cost[i | 1 << (e.to - 1)][e.to] > cost[i][e.from] + e.weight - c[e.to-1]) {
                            cost[i | 1 << (e.to - 1)][e.to] = cost[i][e.from] + e.weight - c[e.to-1];
                            update = true;
                        }        
                    } else if(cost[i][e.to] > cost[i][e.from] + e.weight) {
                        cost[i][e.to] = cost[i][e.from] + e.weight;
                        update = true;
                    }
                }
            }
            if(!update) {
                break;
            }
        }
        int res = INF;
        for(int i=0; i<(1<<m); ++i) {
            res = min(res, cost[i][m+n+1]);
        }
        cout << res << endl;
    }
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, m;
  cin >> n >> m;
  vi32 a(n);
  cin >> a;
  rep(i, n) a[i] /= 2;
  i64 l = 0;
  rep(i, n) {
    l = lcm(l, a[i]);
    if (l > m) {
      cout << 0 << endl;
      return;
    }
  }
  rep(i, n) {
    if ((l / a[i]) % 2 == 0) {
      cout << 0 << endl;
      return;
    }
  }
  cout << (m + l) / (2 * l) << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int a[105][105];
pair<int,int> ans[105];
int co;
int n;
void dfs(int x){
  if(ans[x].first==0){
    co++;
    ans[x].first = co ;
  }
  else return;
  //cout << n << endl;
  for(int i=1;i<=n;i++){
    //cout << a[x][i]<<endl;
    if(a[x][i]==1)dfs(i);
  }
  if(ans[x].second==0){
    co++;
    ans[x].second=co;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    int u,m;
    cin >> u >> m;
    for(int j=0;j<m;j++){
      int v;
      cin >> v;
      a[u][v]=1;
    }
  }
  for(int i=1;i<=n;i++){
    dfs(i);
  }
  for(int i=1;i<=n;i++){
    cout << i << " " << ans[i].first << " "<< ans[i].second << endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World" << endl;
  }else{
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import numpy as np

n,m = map(int,input().split())
ans = 0
tmp = int(m/n)
for i in range(1,int(np.sqrt(m)+1)):
    if m%i == 0:
        if (ans < i) and(i <= tmp):
            ans = i
        tmp2 = m//i
        if (ans < tmp2) and(tmp2 <= tmp):
            ans = tmp2
print(ans)

Measured memory_bytes: 12484
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
result = Array.new(n, 0)
possible = true
possibles = []
(n - 1).downto(0) do |i|
  if i + 1 > n / 2
    result[i] = arr[i]
  else
    loop_max = n / (i + 1)
    bit = 0
    2.upto(loop_max) do |j|
      bit = (bit + result[(i + 1) * j - 1]) % 2
    end
    result[i] = (arr[i] + bit) % 2
  end
  possibles.unshift(i + 1) if result[i] == 1
end
if possible
  if possibles.count > 0
    puts possibles.count
    puts possibles.join(' ')
  else
    puts 0
  end
else
  puts '-1'
end

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e6+10;
double res[MAXN];
double sum[MAXN];
int a[MAXN];
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        res[i]=(a[i]+1)/2.0;
    }
    double ans=-1;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+res[i];
        if(i>=k){
            ans=max(sum[i]-sum[i-k],ans);
        }
    }
    printf("%.10f\n",ans);




    return 0;
}


Measured memory_bytes: 9216
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) fixed << setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl DP(1e5 + 1, 0);
  REP(i, N) {
    ll a;
    cin >> a;
    DP[a]++;
  }
  ll Q;
  cin >> Q;
  vl A(Q + 1);
  REP(i, 1e5 + 1) { A[0] += i * DP[i]; }
  REP(i, Q) {
    ll b, c;
    cin >> b >> c;
    A[i + 1] = A[i];
    A[i + 1] += DP[b] * (c - b);
    DP[c] += DP[b];
    DP[b] = 0;
  }
  REP(i, Q) cout << A[i + 1] << endl;

  return 0;
}


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

using ll = long long;
//typedef long long ll;

#define INF (1LL << 31 - 1)
#define INFLL ((1LL << 62) - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for (int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

int vx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, vy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

inline bool check(int ux, int uy, int x, int y) {
  return (0 <= x and x < ux and 0 <= y and y < uy);
}

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
  string s;

  cin >> s;
  for (int i = 1; i < s.size(); ++i) {
    if (s.substr(i-1, 2) == "AC") {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  
  return 0;
}


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

int main()
{
   int n, k;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)cin>>a[i];
   ll ans[n+1][k+1];
   memset(ans, 0, sizeof(ans));
   ans[0][0]=1;
   for(int i=1;i<=n;i++)
   {
       for(int j=0;j<=k;j++)
       {
           if(j==0){ans[i][j]=1;}
           else if(j<=a[i-1])
           {
               ans[i][j]=(ans[i][j]%m+ans[i][j-1]%m+ans[i-1][j]%m)%m;
           }
           else
           {
               ans[i][j]=(ans[i][j]+ans[i][j-1]+ans[i-1][j]-ans[i-1][j-a[i-1]-1]+m)%m;
           }
       }
   }
   cout<<ans[n][k]%m<<endl;
   return 0;
}



Measured memory_bytes: 79104
#include <stdio.h>
int main() {
	int n, l, r, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &l, &r);
		ans += r - l + 1;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    string S;
    cin >> S;
    int R_cnt=0,L_cnt=0;
    int ans=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='R'){
            R_cnt++;
        }
        else{
            L_cnt++;
        }
        if(R_cnt-L_cnt==4){
            ans++;
            R_cnt=0;
            L_cnt=0;
        }
        if(L_cnt-R_cnt==4){
            R_cnt=0;
            L_cnt=0;
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3216
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    unused_imports,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::Included;
//use std::collections::VecDeque;

const MOD: i64 = 1_000_000_007;
fn main() {
    input! {
        Q:usize
    }
    let mut al = BinaryHeap::new();
    let mut ar = BinaryHeap::new();
    // first query
    input! {query:i64,a:i64,b:i64}
    al.push(a);
    // binary heap は最大値しかpopできないので、右側は逆順にしておく。
    ar.push(-a);
    let mut l = a;
    let mut r = a;
    let mut ans = 0;
    let mut bsum = b;

    for _ in 1..Q {
        input! {query:i64}
        if query == 1 {
            input! {a:i64,b:i64}
            bsum += b;
            if a < l {
                ans += l - a;
                al.push(a);
                al.push(a);
                r = al.pop().unwrap();
                ar.push(-r);
                l = *al.peek().unwrap();
            } else if a > r {
                ans += a - r;
                ar.push(-a);
                ar.push(-a);
                l = -ar.pop().unwrap();
                al.push(l);
                r = -*ar.peek().unwrap();
            } else {
                al.push(a);
                ar.push(-a);
                l = *al.peek().unwrap();
                r = -*ar.peek().unwrap();
            }
        } else {
            println!("{} {}", l, ans + bsum);
        }
    }
}


Measured memory_bytes: 10364
// C++ program to find Excel
// column name from a given
// column number
#include <bits/stdc++.h>
#define MAX 50
using namespace std;
#define ll long long
// Function to print Excel column name for a given column number
void printString(ll n)
{
	char str[MAX]; // To store result (Excel column name)
	ll i = 0; // To store current index in str which is result

	while (n > 0) {
		// Find remainder
		ll rem = n % 26;

		// If remainder is 0, then a 'Z' must be there in output
		if (rem == 0) {
			str[i++] = 'z';
			n = (n / 26) - 1;
		}
		else // If remainder is non-zero
		{
			str[i++] = (rem - 1) + 'a';
			n = n / 26;
		}
	}
	str[i] = '\0';

	// Reverse the string and print result
	reverse(str, str + strlen(str));
	cout << str << endl;

	return;
}

// Driver program to test above function
int main()
{
	ll n;
	cin>>n;
	printString(n);
}


Measured memory_bytes: 3588
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    println(if (Array.fill(sc.nextInt)(sc.next).groupBy(x => x).size == 3) ("Three") else ("Four"))
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 25528