akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n;
string s;

int main() {
	cin >> n >> s;
	
	int w = 0;
	inc(i, n) { if(s[i] == '.') { w++; } }
	
	int ans = w;
	inc(i, n) {
		if(s[i] == '.') { w--; } else { w++; }
		setmin(ans, w);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end() 
#define endl "\n"
#define int long long int
#define ll long long
#define ld long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
const int mod = 1000000007;
const int N=200005;
const int inf=1e18;
vector<vector<int>>adj(N);


bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n;++i){if(n%i==0){return false;}}return true;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res%mod;}
ll gcd(ll a,ll b){if (a==0)return b;return gcd(b%a,a);}

void fun(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}


signed main(){
    flash;
    fun();
    int t=1;
    //cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int l,r;      
        int ans1=-inf,ans2=inf;  
        while(m--){            
            cin>>l>>r;
            ans1=max(l,ans1);
            ans2=min(ans2,r);
        }
        int ans=ans2-ans1+1;
        if(ans>0)
        cout<<ans<<endl;
        else
        {
            cout<<0;
        }
        
    }
    return 0;
}

Measured memory_bytes: 7880
#include <iostream>

using namespace std;

int cnt = 0;

void search(int n, int k, int s) {
    if (k==0&&s==0) {
        cnt++;
        return;
    }
    if (k<=0||s<=0)
        return;
    for (int i = n; i > 0; i--)
        search(i-1, k-1, s-i);
}

int main() {
    int n, k, s;
    while (cin >> n >> k >> s, n|k|s) {
        cnt = 0;
        search(n, k, s);
        cout << cnt << endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int x;
  cin >> x;
  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;
import java.math.*;
 
class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;

    public static void main(String[] args) throws Exception {
        int N = Integer.parseInt(br.readLine());
        char[][] grid = new char[N][N];

        for (int i = 0; i < N; i++) {
            line = br.readLine();
            for (int j = 0; j < N; j++) {
                grid[i][j] = line.charAt(j);
            }
        }

        int ans = 0;
        for (int A = 0; A < N; A++) {
            boolean f = true;
            for (int i = 0; i < N && f; i++) {
                for (int j = 0; j < N; j++){
                    if (grid[i][(j+A)%N] != grid[j][(i+A)%N]){
                        f = false;
                        break;
                    }
                }
            }
            // System.out.println();
            if (f) {
                ans += N;
            }
        }
        pw.println(ans);

        pw.close(); 
        br.close();
    }
}

class Point implements Comparable<Point>{
    public int x, y;
 
    Point(int _x, int _y){
        x = _x;
        y = _y;
    }
 
    public String toString(){
        return x + " " + y;
    }

    public int compareTo(Point p){
        if (x != p.x) return x < p.x ? -1 : 1;
        if (y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
} 


Measured memory_bytes: 26500
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> // 文字幅の指定 setw(int), 詰めたい文字の指定 setfill(char)
#include <algorithm> // sort
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

// 定義する？→左揃えで0埋め
// cout << setfill('0') << left << setw(4) << 12; // "0012"
// http://marycore.jp/prog/cpp/padding-left-right-zero/

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

ll lcm (ll a, ll b) {
	return (a / gcd (a, b)) * b;
}

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

	int a, b, c, d; cin >> a >> b >> c >> d;
	cout << ((abs(a-c) <= d)|| (abs(a-b) <= d && abs(b-c) <= d) ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
from sys import stdin

N, K = map(int, input().split())

A_list = [0 for i in range(N)]

for _ in range(K):
  d = int(stdin.readline().strip())
  A = list(map(int, input().split()))
  for a in range(len(A)):
    A_list[A[a]-1] += 1

count = 0
for i in range(N):
  if A_list[i]==0:
    count += 1

print(count)

Measured memory_bytes: 9132
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		int a=cin.nextInt(),b=cin.nextInt();
		System.out.printf("%d %d %f\n",a/b,a%b,(double)a/(double)b);
		
	}

}



Measured memory_bytes: 26416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String dat;
		dat=br.readLine();
		
		do{
			int i=0;
			int g=0;
			do{
				g += Integer.parseInt(dat.substring(i,i+1));
				i++;
			} while(i<dat.length());
			System.out.println(g);
			dat=br.readLine();
		}while(dat.equals("0")==false);
		
	}

}

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

#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define all(x) x.begin(),x.end()
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

ll find(vector<ll> &v,vector<vector<ll>> &dp,ll i,ll j,ll n)
{
    if(i>j)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll xx = i+n-1-j;
    if(xx%2)
    {
        return dp[i][j] = min(-v[i]+find(v,dp,i+1,j,n),-v[j]+find(v,dp,i,j-1,n));
    }
    else
    {
        return dp[i][j] = max(v[i]+find(v,dp,i+1,j,n),v[j]+find(v,dp,i,j-1,n));
    }
}

int main(){

    IOS;
    ll t,n,m,a,b,k;
    t=1;
    while(t--)
    {
        cin >> n;
        vector<ll> v(n);
        vector<vector<ll>> dp(n,vector<ll>(n,-1));
        for(ll i=0;i<n;i++) cin >> v[i];
        ll ans = find(v,dp,0,n-1,n);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 71040
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

int main(void)
{
    int A, B;
    cin>>A>>B;

    int X=0;
    for(int i=0; i<2; i++)
    {
        if(A>B) 
        {
            X += A;
            A--;
        }
        else
        {
            X += B;
            B --;
        }
    }

    cout<<X<<endl;

    return 0;
}

Measured memory_bytes: 256
(defun aaa (N l)
  (if (= N 1) (car l)
    (aaa (1- N) (cdr l))))

(format t "~A~%" (aaa (read) `(1 1 1 2 1 2 1 5 2 2 1 5 1 2 1 14 1 5 1 5 2 2 1 15 2 2 5 4 1 4 1 51)))


Measured memory_bytes: 10216
import sys
input = lambda: sys.stdin.readline().rstrip()

x, n = map(int, input().split())
p = set([int(x) for x in input().split()])

for i in range(1000):
    x1 = x - i
    x2 = x + i
    if x1 not in p:
        print(x1)
        sys.exit()
    if x2 not in p:
        print(x2)
        sys.exit()

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

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


	for (int i = 0; i < n; i++) {
		if (flag == 0) {
			if (a[i] > a[i - 1])flag = 1;
			else if(a[i] < a[i-1])flag = 2;
		}
		else {
			if (flag != 999 && ((flag == 1 && a[i] >= a[i - 1]) || (flag == 2 && a[i] <= a[i - 1])))continue;
			//cout << "i:" << i << " flag:" << flag << " a[i]:" << a[i] << " a[i-1]:" << a[i-1] <<  endl;
			flag = 0;
			c++;
		}
	}

	cout << c << endl;
}

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

int main () {
  string s;
  int first,last;
  cin >> s;
  for(int i = 0;;i++){
    if(s.at(i) == 'A'){
      first = i;
      break;
    }
  }
  reverse(s.begin(),s.end());
  for(int i = 0;;i++){
    if(s.at(i) == 'Z'){
      last = i;
      break;
    }
  }
  cout << s.size() - last -first << endl;
}

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

ll max_bc = 0;

int main() {
    int ret = 0;
    int l, r, d;
    cin >> l >> r >> d;

    for(int i = l; i <= r; i++) {
        if((i % d) == 0) {
            ret++;
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3644
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,a,n) for(int i=(a);i<(n);i++)
#define repe(i,a) for(auto &i:a)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string s;cin>>s;
  int n=s.size();
  ll res=0,tmp;
  rep(i,1<<n-1){
    tmp=0;
    rep(j,n-1){
      tmp*=10;
      tmp+=s[j]-'0';
      if(i&(1<<j))res+=tmp,tmp=0;
    }
    tmp*=10;
    tmp+=s.back()-'0';
    res+=tmp;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 3652
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

------------------------------------------

primes :: [Int]
primes = 2 : filter isPrime [3,5..]
  where isPrime x = null . filter ((==) 0 . mod x) $ takeWhile ((<= x) . (^ 2)) primes

main :: IO ()
main = do
  n <- readInt
  putStrLn $ unwords . map show . take n $ filter ((== 1) . (`mod` 5)) primes

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
	int n,m;
	cin>>n>>m;
	vector<string> a,b;
	rep(i,n){
		string s;
		cin>>s;
		a.pb(s);
	}
	rep(i,m){
		string s;
		cin>>s;
		b.pb(s);
	}
	
	bool f = false;
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			bool g=true;
			rep(k,m){
				rep(l,m){
					if(b[k][l]!=a[i+k][j+l])g=false;
				}
			}
			f|=g;
		}
	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    int n, m;
    cin >> n >> m;
    multiset<int> s;
    rep(i, n) {
        int a;
        cin >> a;
        s.insert(a);
    }
    rep(i, m) {
        int k = *s.rbegin();
        s.erase(s.find(k));
        k /= 2;
        s.insert(k);
    }
    ll sum = 0;
    for(auto x : s) {
        sum += (ll) x;
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
  long long Min,Max;
  long long cnt = 1;
  long long tmpNum = 0;
  
  cin >> Min >> Max;
  
  tmpNum = Min;
  while(tmpNum <= Max){
    tmpNum *= 2;
    if(tmpNum <= Max) cnt++;
  }
  
  cout << cnt;
}


Measured memory_bytes: 256
table = [[[ 0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())

i = 0
while i < n:
    b,f,r,v = (int(x) for x in input().split())
    
    table[b-1][f-1][r-1] += v

    i += 1

for i,elem_i in enumerate(table):           # building
    for j,elem_j in enumerate(elem_i):      # floor
        for k, elem_k in enumerate(elem_j): # room
            print (" " + str(elem_k), end='')
        print ("")
    if i != 3:
        print ("####################")


Measured memory_bytes: 5624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();

		int s = scanner.nextInt();
		int t = s < 3 ? s + 1 : s - 1;

		for (int i = 0; i < n; i++) {
			System.out.print(i < k ? s : t);
			System.out.print(i == n - 1 ? "\n" : " ");
		}

	}

}


Measured memory_bytes: 41916
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = abc[0];
            int b = abc[1];
            int c = abc[2];
            int ans=0;
            foreach (var i in Enumerable.Range(a,b-a+1)){
                if (c % i == 0)
                {
                    ans++;
                }
            }
                    Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 9632
import numpy as np
N,W = map(int,input().split())

dp = np.full(10 ** 5 + 1, W + 1,dtype = int)
dp[0] = 0

for i in range(N):
  w,v = map(int,input().split())
  np.minimum(dp[:-v] + w,dp[v:],out = dp[v:])
  
for i in range(len(dp) - 1, -1, -1):
  if dp[i] <= W:
    print(i)
    break

Measured memory_bytes: 28152
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>

using namespace std;

typedef long long ll;

#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

int main()
{
    string s, t;
    int sum, ones;
    while(getline(cin, s) && s != "0") {
        s += " ";
        t = "";
        sum = ones = 0;
        for(int i = 0; i < s.size(); i++) {
            if(s[i] == ' ') {
                if(atoi(t.c_str()) == 1) {
                    ones++;
                } else {
                    if(atoi(t.c_str()) < 10) {
                        sum += atoi(t.c_str());
                    } else {
                        sum += 10;
                    }
                }
                t.clear();
            } else {
                t += s[i];
            }
        }
        sum += ones * 11;
        for(; ones-- && sum > 21;)
            sum -= 10;

        printf("%d\n", (sum > 21 ? 0 : sum));
    }
}

Measured memory_bytes: 0
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int Swap(vector<int>& A) {
        int n = A.size();
        int ret = 0;
        vector<int> visited(n, 0);
        for (int i = 0; i < n; i++) {
            if (!visited[i]) {
                int cnt = 1;
                int cur = i;
                visited[i] = 1;
                while (1) {
                    cur = A[cur];
                    if (cur == i) {
                        break;
                    }
                    visited[cur] = 1;
                    cnt++;
                }
                ret += (cnt - 1);
            }
        }
        return ret;
    }
};


int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) A[i]--;
    Solution S;
    int x = S.Swap(A);
    cout << (x <= 1 ? "YES" : "NO") << endl;
}


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

int main(void) {
	int X;
	int ans = 0;
	scanf("%d", &X);
	ans += X / 500 * 1000;
	X %= 500;
	ans += X / 5 * 5;
	X %= 5;

	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 3792
#include<iostream>
#include<string>

using namespace std;

int main(){
  int i, ans, count[4] = {0,0,0,0};
  string str;

  cin >> str;

  for(i=0; i<str.size(); ++i){
    if(str[i] == 'K') ++count[0];
    else if(str[i] == 'U') ++count[1];
    else if(str[i] == 'P') ++count[2];
    else if(str[i] == 'C') ++count[3];
  }
  for(i=1, ans=count[0]; i<4; ++i){
    if(ans > count[i]) ans = count[i];
  }

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

Measured memory_bytes: 0
def printString(n): 
    string = ["0"] * 10000
    i = 0
  
    while n > 0: 
        rem = n % 26
        if rem == 0: 
            string[i] = 'Z'
            i += 1
            n = int(n / 26) - 1
        else: 
            string[i] = chr((rem - 1) + ord('A')) 
            i += 1
            n = int(n / 26)
    string[i] = '0'
    string = string[::-1] 
    ans = "".join(string) 
    for i in range(10000):
        if ans[i]!="0":
            break
    print(ans[i:].lower())
    
n=int(input())
printString(n)

Measured memory_bytes: 9320
x = input(); n_x = len(x);
y = input(); n_y = len(y);
s = [[i+j for j in range(n_y+1)] for i in range(n_x+1)]
for i in range(n_x):
    for j in range(n_y):
        s[i+1][j+1] = min(s[i+1][j]+1,s[i][j+1]+1,s[i][j]+1*(x[i]!=y[j]))   
print(s[n_x][n_y])


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

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> v(n);
        for(int i=0; i<n; ++i) {
            cin >> v[i];
        }
        int res = 1e9;
        for(int i=0; i<n; ++i) {
            for(int j=i+1; j<n; ++j) {
                res = min(res, abs(v[i]-v[j]));
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 3040
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n,k,x,y; cin>>n>>k>>x>>y; int ans=0;
    for (int i=1; i<=n;i++)if(i<=k)ans+=x; else ans+=y;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
class OrderedSet:
    def __init__(self, a):
        self.c = {}
        self.a_sort = sorted(list(set(a)))
        for i, a in enumerate(self.a_sort):
            self.c[a] = i + 1
        self.r = {v: k for k, v in self.c.items()}
        self.size = len(self.c)
        self.tree = [0] * (self.size + 1)
        self.num = [0] * self.size
        self.all_count = 0  # 全要素数

    # BITのsum関数
    def _sum(self, index):
        s = 0
        while index:
            s += self.tree[index]
            index -= index & (-index)
        return s

    # xをk個挿入する
    def insert(self, x, k=1):
        index = self.c[x]
        self.num[index - 1] += k
        while index <= self.size:
            self.tree[index] += k
            index += index & (-index)
        self.all_count += k

    # xをk個削除する
    def erase(self, x, k=1):
        self.insert(x, k=-k)

    # 格納しているxの数を返す
    def count(self, x):
        return self.num[self.c[x] - 1]

    # 下から数えてk番目の要素を返す（要素がk個未満のときNoneを返す）
    def get_kth_bottom(self, k):
        if k <= 0:
            return None
        elif self.all_count < k:
            return None
        else:
            i = 0
            s = 0
            step = 1 << (self.size.bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < k:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return self.r[i + 1]

    # 上から数えてk番目の要素を返す（要素がk個未満のときNoneを返す）
    def get_kth_top(self, k):
        return self.get_kth_bottom(self.all_count - k + 1)

    # x以上の最小要素を返す
    def lower_bound(self, x):
        p = bisect_left(self.a_sort, x)
        if p == 0:
            k = 1
        else:
            k = self._sum(p) + 1
        return self.get_kth_bottom(k)

    # x以下の最大要素を返す
    def upper_bound(self, x):
        p = bisect_right(self.a_sort, x)
        if p == 0:
            return None
        else:
            k = self._sum(p)
            return self.get_kth_bottom(k)


def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    P = [0] * (N + 1)
    for i in range(N):
        P[A[i]] = i + 1

    OS = OrderedSet(P)
    ans = 0
    for i in range(N, 0, -1):
        p = P[i]
        c = OS.lower_bound(p)
        d = None if c is None else OS.lower_bound(c + 1)
        b = OS.upper_bound(p)
        a = None if b is None else OS.upper_bound(b - 1)

        a = a if a is not None else 0
        d = d if d is not None else N + 1

        if b is None:
            if c is not None:
                ans += i * p * (d - c)
        elif c is None:
            ans += i * (b - a) * (N - p + 1)
        else:
            ans += i * ((b - a) * (c - p) + (p - b) * (d - c))

        OS.insert(p)

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 134672
#include <iostream>
#include <cstring>
using namespace std;
char s[15];
int l,lmax;
int main()
{
    cin>>s;
    for(int i=0;i<strlen(s);i++)
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
            l++;
        else
        {
            lmax=max(lmax,l);
            l=0;
        }
    cout<<max(l,lmax);
    return 0;
}


Measured memory_bytes: 256
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);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	int[][] D;

	Main(BufferedReader in) throws IOException {
		int N = Integer.parseInt(in.readLine());
		D = new int[N][2];
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.readLine().split(" ");
			D[i][0] = Integer.parseInt(tokens[0]);
			D[i][1] = Integer.parseInt(tokens[1]);
		}

		boolean result = false;
		for (int i = 0; i + 2 < N; ++i) {
			if (check(i)) {
				result = true;
				break;
			}
		}
		if (result) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	boolean check(int i) {
		if (isSame(i) && isSame(i + 1) && isSame(i + 2)) {
			return true;
		} else {
			return false;
		}
	}

	boolean isSame(int i) {
		if (D[i][0] == D[i][1]) {
			return true;
		} else {
			return false;
		}
	}

	void calc() {
	}

	void showResult() {
	}
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007


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

    int H, W; cin >> H >> W;
    vvi a(H, vi(W)); cin >> a;

    vs ans;

    rep(h, H) {
        rep(i, W) {
            if (h == H-1 && i == W-1) break;
            int w = h%2==0 ? i : W-1-i;
            if (a[h][w]%2==1) {
                a[h][w]--;
                int h2, w2;
                if (h%2==0) {
                    if (w == W-1) {
                        w2 = W-1;
                        h2 = h+1;
                    } else {
                        w2 = w+1;
                        h2 = h;
                    }
                } else {
                    if (w == 0) {
                        w2 = 0;
                        h2 = h+1;
                    } else {
                        w2 = w-1;
                        h2 = h;
                    }
                }
                a[h2][w2]++;
                ostringstream os;
                os << h+1 << " " << w+1 << " " << h2+1 << " " << w2+1;
                ans.push_back(os.str());
            }
        }
    }
    
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i] << endl;
}


Measured memory_bytes: 9972
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

int M, N;
int P[10000], C[500], E[500];
int ruisekiwa[10000];
int dp[10001][500];
int ans = 0;

int main() {
	cin >> M >> N;
	for (int i = 0; i < M; i++)cin >> P[i];
	for (int i = 0; i < N; i++)cin >> C[i] >> E[i];

	sort(P, P + M, greater<int>());
	ruisekiwa[0] = P[0];
	for (int i = 1; i < M; i++)ruisekiwa[i] = ruisekiwa[i - 1] + P[i];

	for (int i = 0; i <= M; i++)for (int j = 0; j < N; j++)dp[i][j] = 1145141919;
	
	for (int i = 0; i < N; i++)dp[0][i] = 0;
	for (int i = 1; i <= C[0]; i++) {
		dp[i][0] = E[0];
		ans = max(ans, ruisekiwa[i - 1] - E[0]);
	}

	for (int i = 1; i <= M; i++) {
		for (int j = 1; j < N; j++) {
			dp[i][j] = min(dp[i][j - 1], dp[max(i - C[j], 0)][j - 1] + E[j]);
			ans = max(ans, ruisekiwa[i - 1] - dp[i][j]);
		}
	}

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

Measured memory_bytes: 22744
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k,n;
  cin >> k >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  int dif=0;
  for(int i=0;i<n-1;i++){
    int x=a.at(i+1)-a.at(i);
    dif=max(dif,x);
  }
  int tes=k-a.at(n-1)+a.at(0);
  dif=max(dif,tes);
  cout << k-dif << endl;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] p = new int[N];
            for (int i = 0; i < N; i++) {
                p[i] = in.nextInt();
            }
            int[] q = Arrays.copyOf(p, N);
            Arrays.sort(q);

            int count = 0;
            for (int i = 0; i < N; i++) {
                if (p[i] != q[i]) {
                    count++;
                }
            }
            out.println(count == 2 || count == 0 ? "YES" : "NO");
        }

    }
}



Measured memory_bytes: 21844
def compare(s1, s2):
    ans = 0
    for i in range(len(s1)):
        if s1[i] == s2[i]: ans += 1
    return ans

s = input()
n = len(s)
s1 = ('01' * n)[:n]
s2 = ('10' * n)[:n]
print(min(n - compare(s1, s), n - compare(s2, s)))


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

int main(){
  int h,w;
  cin>>h>>w;
  vector <vector<char>> list(h,vector <char>(w));
  for(int i=0;i<h;i++){
    for (int j=0;j<w;j++)
      cin>>list.at(i).at(j);
  }
  vector <bool> row(h,false),col(w,false);
  for(int i=0;i<h;i++){
    for (int j=0;j<w;j++){
      if(list.at(i).at(j)=='#'){
        row.at(i)=true;
        col.at(j)=true;
      }
    }
  }
    for(int i=0;i<h;i++){
      if (row.at(i)){
        for (int j=0;j<w;j++) {
          if (col.at(j)) cout<<list.at(i).at(j);
        }
      cout<<endl;
      }
    }
      
  return 0;
}

Measured memory_bytes: 3560
N,M=map(int,input().split())
perm=1
ans=0
perm2=1
if N==M:

    for i in range(N):
        perm=(perm*(i+1))%((10**9)+7)
    ans=(perm*perm*2)%((10**9)+7)

elif abs(N-M)==1:
    for i in range(N):
        perm=(perm*(i+1))%((10**9)+7)
    for i in range(M):
        perm2=(perm2*(i+1))%((10**9)+7)
    
    ans=(perm*perm2)%((10**9)+7)

else:
    ans=0

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

const int N = 1000000;

int main() {
  int s;
  cin >> s;
  
  vi vect;
  int x = s;
  while (count(all(vect),x)==0) {
    vect.push_back(x);
    if(x%2 == 0) {
      x /= 2;
    }
    else {
      x = x*3+1;
    }
  }
  
  cout << vect.size()+1 << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <random>
#include <string.h>      //文字列の代入に使う
#include <bits/stdc++.h> //piの利用で必要(M_PI)
#include <algorithm>

int main()
{

    int N, temp;
    std::cin >> N;
    std::vector<int> num_of_members(N);
    for (int i = 1; i < N; i++)
    {
        std::cin >> temp;
        num_of_members.at(temp - 1)++;
    }

    for (int i = 0; i < N; i++)
    {
        std::cout << num_of_members.at(i) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};
    int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};

    for(;;){
        int h, w;
        cin >> h >> w;
        if(h == 0)
        return 0;

        vector<string> grid(h);
        for(int i=0; i<h; ++i)
        cin >> grid[i];

        set<string> ss;
        string ret;
        int maxLen = -1;
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int d=0; d<8; ++d){
                    int y1 = y;
                    int x1 = x;
                    string s;
                    do{
                        s += grid[y1][x1];
                        y1 += dy[d] + h;
                        x1 += dx[d] + w;
                        y1 %= h;
                        x1 %= w;
                    }while(y1 != y || x1 != x);

                    int n = s.size();
                    while(n >= 2){
                        string t = s.substr(0, n);
                        if(ss.find(t) == ss.end()){
                            ss.insert(t);
                        }else{
                            if(n > maxLen || (n == maxLen && t < ret)){
                                maxLen = n;
                                ret = t;
                            }
                            break;
                        }
                        -- n;
                    }
                }
            }
        }

        if(maxLen == -1)
        cout << 0 << endl;
        else
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
#https://atcoder.jp/contests/abc153/submissions/9750027

import sys
input = sys.stdin.readline
from math import ceil
from collections import deque
N,D,A = map(int, input().split())
XH = [list(map(int,input().split())) for _ in range(N)]
XH.sort(key = lambda x:x[0])
#X,H = map(list, zip(*XH))
q = deque()
d = 0
ans = 0

for x,h in XH:
    while q and q[0][0] < x:    #今見ている座標が既にそれまでの爆弾範囲から外れていたら
        d -= q.popleft()[1]
    h -= d
    if h > 0:
        num = ceil(h/A)
        ans += num
        q.append((x+2*D, num*A))    #(末端, そこまででの爆弾の威力)
        d += num*A
print(ans)


Measured memory_bytes: 93532
#include<stdio.h>
#include<stdlib.h>
#define max(x,y) (x>y?x:y)
int a[200001],temp[200001];
int cmp(const void *a,const void *b)
{ return *(int *)a-*(int *)b; }

int main()
{
	int n,i,c,ch,sum,k,mm;
	ch=c=sum=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
		scanf("%d",&ch),
		a[ch]++,
		mm=max(mm,ch);
	
	for(i=0;i<=mm;i++)
		if(a[i]!=0)
			temp[c++]=a[i];
	
	if(c<=k)
		printf("0\n");
	else
	{
		qsort(temp,c,sizeof(int),cmp);
		for(i=0;i<(c-k);i++)
			sum+=temp[i];
		
		printf("%d\n",sum);
	}
		
}

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

int main() {
	int a[5];
	int min = 10, keep = 5;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] % 10 != 0 && min > a[i] % 10) {
			min = a[i] % 10;
			keep = i;
		}
	}

	int sum = 0;
	if (keep == 5) {
		for (int i = 0; i < 5; i++)
			sum += a[i];
		cout << sum << endl;
		return 0;
	}
	
	int lastone = a[keep] % 10 - 10;
	for (int i = 0; i < 5; i++) {
		if (a[i] % 10 != 0)
			a[i] = (a[i] / 10) * 10 + 10;
		sum += a[i];
	}
	sum += lastone;
	cout << sum << endl;
	return 0;
}

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

int main() {
    int K;
    int S;
    cin >> K >> S;

    int count = 0;
    int m = min(S, K);
    for (int i = 0; i <= m; i++) {
        for (int j = i; j <= m; j++) {
            for (int k = j; k <= m; k++) {
                if (i + j + k == S) {
                    if (i == j && j == k) {
                        count += 1;
                    } else if (i == j || j == k || i == k) {
                        count += 3;
                    } else {
                        count += 6;
                    }
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}


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

int main()
{
	long long sum = 0;
	long long i;
	long long N;
	cin >> N;
	for(i=1;i<=N;i++)
	{
		if(((i % 3) != 0)&&((i % 5) != 0))
		sum = sum + i;
	}
	cout << sum;
	return 0;
}
	
	


Measured memory_bytes: 3608
var a:array[1..201,1..201] of char;
    n,m,i,j:byte;
begin
readln(n,m);
for i:=1 to n do begin
  for j:=1 to m do read(a[i,j]); readln; end;
for i:=1 to n*2 do begin
  for j:=1 to m do write(a[(i+1)div 2,j]); writeln; end;
end.


Measured memory_bytes: 128
import std.stdio, std.algorithm, std.conv, std.array, std.string;

int[100][100] HW;
int H, W, N;

void main()
{
    auto hw = readln.split.to!(int[]);
    H = hw[0];
    W = hw[1];
    N = readln.chomp.to!int;
    auto as = readln.split.to!(int[]);

    size_t x, y;
    foreach (i, a; as) {
        ++i;
        while(a--) {
            HW[y][x] = i.to!int;
            if (y%2 == 0) {
                if (++x == W) {
                    --x;
                    ++y;
                }
            } else {
                if (--x == -1) {
                    ++x;
                    ++y;
                }
            }
        }
    }

    foreach (line; HW[0..H].dup.map!(line => line.dup[0..W].to!(string[])))
        writeln(line.join(" "));
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

const ll MAX = 10000;
vector <bool> color(MAX);
vector <ll> indeg(MAX);
vector <vector <ll>> v(MAX, vector <ll> ());
queue <ll> q;
vector <ll> res;

void bfs(ll n) {
  q.push(n);
  color.at(n) = 0;
  while (!q.empty()) {
    ll j = q.front(); q.pop();
    res.push_back(j);
    rep(k, v.at(j).size()) {
      ll tmp = v.at(j).at(k);
      indeg.at(tmp)--;
      if (indeg.at(tmp)==0 && color.at(tmp)) {
        color.at(tmp) = 0;
        q.push(tmp);
      }
    }
  }
  return;
}

void tsort(ll n) {
  rep(i, n) {
    color.at(i) = 1;
    indeg.at(i) = 0;
  }
  rep(i, n) {
    rep(j, v.at(i).size()) {
      ll tmp = v.at(i).at(j);
      indeg.at(tmp)++;
    }
  }
  rep(i, n) {
    if (indeg.at(i)==0 && color.at(i)) {
      bfs(i);
    }
  }
  rep(i, res.size()) {
    cout << res.at(i) << endl;
  }
  return;
}

int main() {
  ll n, m;
  cin >> n >> m;
  rep(i, m) {
    ll s, t;
    cin >> s >> t;
    v.at(s).push_back(t);
  }
  tsort(n);
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<=n; i++)
typedef long long ll;
using namespace std;

int main(){
  int n,count=0;
  cin >> n;
  vector<int> v(n,0);
  r(i,n){
    cin >> v.at(i);
    if(i>0&&v.at(i)==v.at(i-1)){
      count++;
      v.at(i)=1000;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a,b,c;
cin>>a>>b>>c;
string ans="No";
if((a==b && a!=c)||(a==c&&a!=b)||(b==c&&a!=b)){
    ans="Yes";
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
fn solve(l: i64, r: i64) -> i64 {
    if (r - l) > 2019 {
        0
    } else {
        let mut ans = 2019;
        for i in l..r {
            for j in (i + 1)..(r + 1) {
                if ((i * j) % 2019) < ans {
                    ans = (i * j) % 2019;
                }
            }
        }

        ans
    }
}

#[test]
fn solve_test() {
    assert_eq!(solve(2020, 2040), 2);
    assert_eq!(solve(4, 5), 20);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (l, r) = parse_line!(i64, i64);
    println!("{}", solve(l, r));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

int main(){
    int n;  cin >> n;
    string s, t; cin >> s >> t;

    int res=2*n;
    REP(i, n){
        if(s[i]!=t[0]) continue;
        if(s.substr(i, n-i)==t.substr(0, n-i)){
            res -= n-i; break;
        }
    }
    cout << res << endl;

}

Measured memory_bytes: 256
let n, t0 = Scanf.scanf " %d %d" @@ fun a b -> a, b
let cts = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ =
  let ans = ref max_int in
  for i = 0 to n - 1 do
    let c, t = cts.(i) in
    if t <= t0 then ans := min !ans c
  done;
  if !ans = max_int then print_endline "TLE" else Printf.printf "%d\n" !ans

Measured memory_bytes: 384
n = int(input())
a = list(map(int,input().split()))
flag = 0
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 != 0 and a[i] % 5 != 0:
            flag = 1
if flag == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#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...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

int main() {
  ll N;
  while (cin >> N) {
    vec<ll, 2> dp = make_v(2, 2, 0ll);
    dp[0][1] = 1;
    for (; N > 0; N /= 2) {
      int cur = N & 1;
      vec<ll, 2> ndp = make_v(2, 2, 0ll);
      for (int c = 0; c < 2; c++) {
        for (int p = 0; p < 2; p++) {
          for (int a = 0; a <= 2; a++) {
            int dig = (a + c) % 2;
            int nc = (a + c) / 2;
            int np;
            if (dig < cur) {
              np = 1;
            } else if (dig > cur) {
              np = 0;
            } else {
              np = p;
            }
            (ndp[nc][np] += dp[c][p]) %= MOD;
          }
        }
      }
      dp = ndp;
    }
    cout << dp[0][1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;
    vector<vector<P>> graph(n);
    for(int i = 0; i < m; ++i){
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        graph[l].emplace_back(r, d);
        graph[r].emplace_back(l, -d);
    }
    vector<int> x(n, INF);
    auto dfs = [&](auto&& self, int from) -> bool {
        for(auto e : graph[from]){
            int to = e.first, cost = e.second;
            if(x[to] != INF){
                if(x[to] != x[from] + cost) return false;
            }
            else{
                x[to] = x[from] + cost;
                if(!self(self, to)) return false;
            }
        }
        return true;
    };
    for(int i = 0; i < n; ++i){
        if(x[i] == INF){
            x[i] = 0;
            if(!dfs(dfs, i)){
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 15704
x,y,a,b,c=list(map(int,input().split()))
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
p=p[:x]
q=q[:y]
r.extend(p)
r.extend(q)
r.sort(reverse=True)

ans=sum(r[:x+y])

print(ans)


Measured memory_bytes: 23328