akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>

using namespace std;

int cnt = 0;
int A[1000000];

void print(int N, int *A) 
{

	for (int i = 0; i < N; i++)
	{
		cout << A[i];
		if (i == N - 1) 
		{
			//do nothing
		}
		else
		{
			cout << endl;
		}
	}
}


void inserSort(int N, int *A,int B)
{
	int v;
	int j;

	for (int i = B; i < N; i++)
	{
		v = A[i];
		j = i - B;

		while (j >= 0 && A[j] > v)
		{
			A[j + B] = A[j];
			j = j - B;
			cnt++;
		}

		A[j+B] = v;
	}
}

void shellSort(int N,int *A) 
{
	int j = 0,i=0, h=0, B[10000];

	while (true)
	{
		B[i] = 3 * h + 1;
		h = B[i];
		if ((3 * h + 1) > N) 
		{
			break;
		}
		i++;
	}
	cout << (i+1) << endl;
	for (int j = i; j >= 0; j--)
	{
		printf("%d", B[j]);
		inserSort(N,A,B[j]);
		if (j != 0) 
		{
			cout << " ";
		}
		else
		{
			cout << endl;
		}
	}
	printf("%d", cnt);
	cout << endl;
	print(N, A);

}

int main()
{
	int N,i=0;

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	shellSort(N, A);

	return 0;
}


Measured memory_bytes: 7128
#include<bits/stdc++.h>
using namespace std;
const int M=15;
int f[M][M];

int main(){
	int n,d;
	int ans=0;
	scanf("%d %d",&n,&d);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=d; j++) scanf("%d",&f[i][j]);
		for(int j=1; j<i; j++){
			long long res=0;
			for(int k=1; k<=d; k++){
				res+=1ll*(f[i][k]-f[j][k])*(f[i][k]-f[j][k]);
			}
			int m=sqrt(res);
			if(m*m==res) ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int money = 700;
		for(int i = 0; i < s.length(); i++){
			if(s.charAt(i) == 'o') money += 100;
		}
		System.out.println(money);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int digit(int n){
  int ans=0;
  while(n!=0){
    ans+=n%10;
    n=n/10;
  }
  return ans;
}
int main(){
  int n;
  cin >> n;
  if(n % digit(n)==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        int lower = Math.max(a, c);
        int upper = Math.min(b, d);

        System.out.println(Math.max(0, upper - lower));
    }
}


Measured memory_bytes: 22996
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

string S;
int sum[26][202020];
ll dp[202020];



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

	cin >> S;
	int N = S.size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 26; j++)sum[j][i + 1] = sum[j][i] + (S[i] - 'a' == j);
	}

	map<pair<int,ll>, ll>mp;
	for (int i = 1; i <= N; i++) {
		int mask = 0;
		int bitcnt = 0;
		for (int j = 0; j < 26; j++) {
			if (sum[j][i] % 2) { mask += (1 << j); bitcnt++; }
		}
		ll mi = inf;
		for (int j = 0; j < 26; j++) { if (mp.count({ 1 - (i % 2) , mask ^ (1 << j) }))mi = min(mi, mp[{1 - (i % 2), mask ^ (1 << j)}]); }
		if (bitcnt <= 1)dp[i] = 0;
		else {
			if (mp.count({ i % 2,mask }))dp[i] = min(mp[{i%2,mask}], mi) + 1;
			else dp[i] = mi + 1;
		}
		if (mp.count({ i % 2,mask }))mp[{i % 2, mask}] = min(mp[{i % 2, mask}], dp[i]);
		else mp[{i % 2, mask}] = dp[i];
	}
	puts(dp[N] + 1);
	return 0;
}


Measured memory_bytes: 35092
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;//例: VVI dp(10, vector<int>(10, INF);
typedef priority_queue<int, vector<int>, less<int> > QUE_int;
const int INF = pow(10, 5) + 1;//+1しないとREになる(out of rangeになるんかな?? )

vector<int> dx = { -1, 0, 1, 0, -1, -1, 1, 1 };
vector<int> dy = { 0, -1, 0, 1, -1, 1, -1, 1 };

int main(void) {
	ll N, K;
	cin >> N >> K;
	vector<ll> H(N);
	for (int i = 0; i < N; i++) cin >> H[i];
	std::sort(H.begin(), H.end(), std::greater<ll>());
	//for (int i = 0; i < N; i++) cout << H[i] << endl;
	
	ll ans = 0;
	for (int i = K; i < N; i++) {
		ans += H[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int N, M;
vector<int> A, B;

long long solve()
{
    ll res = 1;
    int biggerX_a = 0, biggerX_b = 0; // A,B でxより大きい数値の個数

    for (int x = N * M; x >= 1; x--)
    {
        if (A[biggerX_a] > x)
            return 0;
        if (B[biggerX_b] > x)
            return 0;

        long long tmp = 1;
        if (A[biggerX_a] == x && B[biggerX_b] == x)
        {
            tmp = 1;
            ++biggerX_a, ++biggerX_b;
        }
        else if (A[biggerX_a] == x)
        {
            tmp = biggerX_b;
            ++biggerX_a;
        }
        else if (B[biggerX_b] == x)
        {
            tmp = biggerX_a;
            ++biggerX_b;
        }
        else
        {
            tmp = biggerX_a * biggerX_b - (N * M - x);
            if (tmp <= 0)
                return 0;
        }
        res = (res * tmp) % MOD;
    }
    return res;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    A.resize(N+1);
    B.resize(M+1);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(ALL(A), greater<int>());
    sort(ALL(B), greater<int>());
    cout << solve() << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(),k=s.nextInt();
        int freq[] = new int[n+1];
        while(k--!=0){
            int x =s.nextInt();
            while(x--!=0) freq[s.nextInt()]++;
        }

        int cnt=0;
        for(int i=1;i<=n;i++){
            if(freq[i]==0)cnt++;
        }
        System.out.println(cnt);
    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

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

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

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 26652
N, Y = map(int, input().split())
flag = False
for i in range(2001):
    for j in range(2001):
        k = N - i - j
        if 0 <= k and 10000 * i + 5000 * j + 1000 * k == Y:
            print(i, j, k)
            flag = True
            break
    if flag:
        break
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;

#include <tuple>
#include <string>
#include <vector>   
//入力数の桁数を出力
//https://atcoder.jp/contests/abc057/tasks/abc057_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

//最大公約数
ll gcd(ll a,ll b){
    if(b ==0) return a;
    else return gcd(b ,a % b);
}

//最小公倍数
ll lcm(ll a,ll b){
  ll g = gcd(a,b);
  return (a / g) * b;
}





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

    ll ans = 1LL;

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

        ll t;
        cin >> t;
        ans = lcm(ans,t);

    }

    cout << ans << endl;



    





    return 0;
}


Measured memory_bytes: 256
import sys
Mx = 999999999

H, N = map(int,sys.stdin.readline().split())
L = [list(map(int,sys.stdin.readline().split())) for i in range(N)]

D = [Mx] * 40000

D[0] = 0

for i in range(H+1):
    for spell in L:
        if D[i] + spell[1] < D[i+spell[0]]:
            D[i+spell[0]] = D[i] + spell[1]

sys.stdout.write(str(min(D[H:])))

Measured memory_bytes: 40304
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

int a[2000][2000];
int b[2000][2000];
int c[2000][2000];
int d[2000][2000];

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0; i<H; i++)
        cin >> S[i];


    int cnt;
    for(int i=0; i<H; i++){
        cnt = 0;
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') cnt = 0;
            else{
                a[i][j] = cnt;
                cnt++;
            }
        }
        cnt = 0;
        for(int j=W-1; j>=0; j--){
            if(S[i][j] == '#') cnt = 0;
            else{
                b[i][j] = cnt;
                cnt++;
            }
        }
    }
    for(int j=0; j<W; j++){
        cnt = 0;
        for(int i=0; i<H; i++){
            if(S[i][j] == '#') cnt = 0;
            else{
                c[i][j] = cnt;
                cnt++;
            }
        }
    }
    for(int j=0; j<W; j++){
        cnt = 0;
        for(int i=H-1; i>=0; i--){
            if(S[i][j] == '#') cnt = 0;
            else{
                d[i][j] = cnt;
                cnt++;
            }
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            ans = max(ans, a[i][j] + b[i][j] + c[i][j] + d[i][j] + 1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66816
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 3e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

#define int ll

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;
int n,dp[N][22];
inline int solve(int x, int rem) {
    int &res=dp[x][rem];
    if (x==n+1) {
        if (rem==5) res=1;
        else res=0;
        return res;
    }
    if (~res) return res;
    res=0;
    if (s[x]!='?') return res=solve(x+1,((rem*10)+(s[x]-'0'))%13);
    fo(i,0,9,1) {
        res+=solve(x+1,((rem*10)+i)%13);
        res%=mod;
    }
    return res;
}
main() {
    file("dishes");
    ios;
    cin>>s;
    memset(dp,-1,sizeof dp);
    n=s.size();
    s='#'+s;
    cout<<solve(1,0);
    return 0;
}
/**

*/


Measured memory_bytes: 24556
#include <iostream>

using namespace std;

int main()
{
    int ans[] = {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};

    int K;

    cin >> K;

    cout << ans[K - 1] << endl;

    return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define FOR_IN(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define IN(x, a, b) ((x) >= (a) && (x) <= (b))

using namespace std;

/*
n 10^5
m 10^5

n m
a1 b1
...
am bm
 */

int n,m;
int a[100000];
int b[100000];
vector<bool> done(100000, false);

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

  REP(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  bool f=false;
  int ans=0;
  while(!f){
    int bmin=n;
    int min_j=m;
    REP(j,m){
      if(done[j])
        continue;
      
      if(b[j]<bmin){
        bmin=b[j];
        min_j=j;
      }
    }
    int cut_i=b[min_j]-1;

    f=true;
    REP(j,m){
      if(IN(cut_i, a[j], b[j]-1))
        done[j]=true;

      f=f&&done[j];
    }
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = 1; i < 100000; i ++) {
    if ((a*i)%b == c) {
      cout << "YES";
      return 0;
    }
  }
  cout << "NO";
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    char s[4];
    int n[4];
    int i, flg = 0;

    scanf("%s", s);

    for (i = 0; i < 4; i++) {
        n[i] = s[i] - '0';
    }

    for (i = 0; i < 3; i++) {
        if (n[i] == n[i + 1]) {
            flg = 1;
            break;
        }
    }

    if (flg == 1) {
        printf("Bad\n");
    } else {
        printf("Good\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> P;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;
 
int main() {
	int n, c, k;
	cin >> n >> c >> k;
	
	int t[112345];
	REP(i, n) scanf("%d", t + i);
	sort(t, t + n);
	
	int ans = 0;
	bool done[112345] = {};
	REP(i, n) {
		if (done[i]) continue;
		
		ll now = t[i] + k;
		REP(j, c) if (i + j < n && t[i + j] <= now) done[i + j] = true;
		ans++;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1016
local length = io.read()
local data = {AC = 0, WA = 0, TLE =0, RE = 0}

for i = 1, length do 
    local key = io.read()
    if data[key] then
        data[key] = data[key] + 1
    end
end

print("AC x".." "..data["AC"])
print("WA x".." "..data["WA"])
print("TLE x".." "..data["TLE"])
print("RE x".." "..data["RE"])


Measured memory_bytes: 2720
package main

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

type student struct{ no, a int }
type students []student

func (s students) Len() int           { return len(s) }
func (s students) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s students) Less(i, j int) bool { return s[i].a < s[j].a }

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sts := students(make([]student, n))
	for i := range sts {
		sts[i].no = i + 1
		sc.Scan()
		sts[i].a, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(sts)
	wr := bufio.NewWriter(os.Stdout)
	for i, v := range sts {
		wr.WriteString(strconv.Itoa(v.no))
		if i != len(sts)-1 {
			wr.WriteString(" ")
			continue
		}
		wr.WriteString("\n")
	}
	wr.Flush()
}


Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int n;
int A,B,C;
vector<int> l(8);
int inf=1e9;
int dfs(int cur,int a,int b, int c);
int main(){
    cin>>n>>A>>B>>C;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    cout<<dfs(0,0,0,0)<<endl;

}
int dfs(int cur,int a,int b, int c){
    if(cur==n){
        if(min(a,min(b,c))>0){
            return abs(a-A)+abs(b-B)+abs(c-C)-30;
        }
        else{
            return inf;
        }
    }
    int ret0,ret1,ret2,ret3;
    ret0=dfs(cur+1,a,b,c);
    ret1=dfs(cur+1,a+l[cur],b,c)+10;
    ret2=dfs(cur+1,a,b+l[cur],c)+10;
    ret3=dfs(cur+1,a,b,c+l[cur])+10;
    return min(ret0,min(ret1,min(ret2,ret3)));
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {

  string s;

  std::cin >> s;

  if (s.size()==2){
    std::cout << s << '\n';
    return 0;
  }else{
      std::reverse(s.begin(), s.end());
    std::cout << s << '\n';
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int main()
{
	ll a[3];
	for(ll& x:a) cin>>x;
	ll ans=1ll<<61;
	auto f=[&](){
		ll s=a[1]*a[2];
		return (a[0]%2)*s;
	};
	for(int i=0; i<3; ++i){
		ans=min(ans, f());
		rotate(a,a+1,a+3);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (int i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (int i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    cout << (n >= 30 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define  gcd(a,b)         __gcd(a,b)
#define  lcm(a,b)         (a*b)/gcd(a,b)
#define  ll               long long int
#define  pb               push_back
#define  mod              1000000007
#define  End              return 0;
#define  pi               acos(-1)
int main()
{
    ll n,m,j,x,y,i,k,ttt;
    cin>>n;
    ll a[n+1];
    ll sum=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
    }
    ll c=0,ans=0;
    for(i=0;i<n-1;i++)
    {
        sum-=a[i];
        c=(a[i]%mod)*(sum%mod);
        c%=mod;
        ans+=c;
        ans%=mod;
    }
    cout<<ans;


}


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

const int N = 303,M = 303;
int a[M][N];

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> v;
  int a,b;
  for (int i = 0; i<m; i++) {
    cin>>a>>b;
    if (a == 1 || b == 1) {
      if (a == 1) v.push_back(b);
      else v.push_back(a);
    }
    else if (a == n || b == n) {
      if (a == n) v.push_back(b);
      else v.push_back(a);
    }
  }
  sort(v.begin(),v.end());
  for (int i = 0; i<(int)v.size() - 1; i++) {
    if (v[i] == v[i+1]) {
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");
  return 0;
}


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

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

class Solution
{
    void solve()
    {
        FastReader sc = new FastReader();

        String S = sc.next();
        String T = sc.next();

        String res = T + S;

        System.out.println(res);
    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

Measured memory_bytes: 37108
import numpy as np
N, M = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T
C, D = np.array(tuple(tuple(map(int, input().split())) for _ in range(M)), dtype=np.int64).T
print(*((np.abs(np.subtract.outer(A, C)) + np.abs(np.subtract.outer(B, D))).argmin(axis=1) + 1), sep="\n")

Measured memory_bytes: 12404
# -*- coding: utf-8 -*-
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap



@mt
def slv(N, K):
    from itertools import combinations
    ans = [(1, i) for i in range(2, N+1)]

    K -= (N-1)*(N-2) // 2
    if K > 0:
        print(-1)
        return
    for i, j in combinations(range(2, N+1), r=2):
        if K == 0:
            break
        ans.append((i, j))
        K += 1


    print(len(ans))
    for uv in ans:
        print(*uv)



def main():
    N, K = read_int_n()
    slv(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44524
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h,w,n;
    cin>>h>>w>>n;
    int i=1;
    int cnt=0;
    if(h<=w)
    {
        while(i<=h)
        {
            cnt=cnt+w;
            {
                if(cnt>=n)
                {
                    cout<<i;
                    break;
                }
            }
            i++;
        }
    }
    else
    {
        while(i<=w)
        {
            cnt=cnt+h;
            {
                if(cnt>=n)
                {
                    cout<<i;
                    break;
                }
            }
            i++;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int res=0;
  int j;
  int count=0;
  for(int i=0;i<s.size();i++)
  {
    count=0;
  char x=s[i];
    if(x=='R')
    {
      int j=i;
      while(s[j]==x)
      {
        j++;
        count++;
      }
      i=j-1;
      res=max(res,count);
      
      
          
    
    }

  
  
}
cout<<res<<endl;
}

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

using namespace std;

int main(){
	int i,k;
	cin >> k;
	long long a[100010],mn=2,mx=2;
	for(i=0;i<k;i++){
		cin >> a[k-1-i];
	}
	
	for(i=0;i<k;i++){
		mn = ((mn-1)/a[i]+1)*a[i];
		mx = mx/a[i]*a[i];
		if(mn>mx){
			cout << -1 << endl;
			return 0;
		}
		mx += a[i]-1;
	}
	cout << mn <<" " <<  mx << endl;
}

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

//int _; 

int n,m,a[100020],sum=0;
bool ans[100020];

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> n >> m;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		ans[i]=true;
	}
	for(int i=0;i<m;i++)
	{
		int b,c;
		cin >> b >> c;
		b--;
		c--;
		if(a[b] >= a[c])
			ans[c]=false;
		if(a[c] >= a[b])
			ans[b]=false; 
	}
	for(int i=0;i<n;i++)
		if(ans[i])
			sum++;
	cout << sum << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;

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

    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> book(n, vector<int>(m + 1));
    ll cost = 1e18;

    for (int i = 0; i < n; i++)
        for (int j = 0; j <= m; j++)
            cin >> book[i][j];

    for (int i = 1; i < (1 << n); i++)
    {
        ll total = 0;
        vector<ll> val(m);

        for (int j = 0; j < n; j++)
        {
            if (i & (1 << j))
            {
                total += book[j][0];
                for (int k = 0; k < m; k++)
                    val[k] += book[j][k + 1];
            }
        }

        bool flag = 1;

        for (int j = 0; j < m; j++)
            if (val[j] < x)
            {
                flag = 0;
                break;
            }

        if (flag)
            cost = min(cost, total);
    }
    if (cost == 1e18)
        cout << -1 << endl;
    else
        cout << cost << endl;
    return 0;
}


Measured memory_bytes: 3664
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort()
cum_A = copy.copy(A)

for i in range(N-1):
  cum_A[i+1] += cum_A[i]
#print(cum_A)
t = 0
for i in range(N-1, 0, -1):
  if A[i] <= 2 * cum_A[i-1]:
    t = i-1
  else:
    break
 
print(N-t)
        

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

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> p[i - 1] >> p[i];
  }

  for ( int i = 1; i <= n; i++ ) m[i][i] = 0;
  for ( int l = 2; l <= n; l++ ) {
    for ( int i = 1; i <= n - l + 1; i++ ) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for ( int k = i; k <= j - 1; k++ ){
	m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}



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

using namespace std;

long long dp[3001][3001], arr[3001], n;
bool vis[3001][3001];

long long helper(int left, int right, int turn){

    if(left > right)
        return 0;

    if(vis[left][right])
        return dp[left][right];

    if(turn == 0){
        dp[left][right] = max(helper(left + 1, right, 1) + arr[left], helper(left, right - 1, 1) + arr[right]);
    } else  {
        dp[left][right] = min(helper(left + 1, right, 0) - arr[left], helper(left, right - 1, 0) - arr[right]);
    }

    vis[left][right] = true;

    return dp[left][right];

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> arr[i];

    cout << helper(0, n - 1, 0) << "\n";

    return 0;
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
	ll A, B, M; cin >> A >> B >> M;
	vector<ll> a(A), b(B);
	ll mna = INT_MAX, mnb = INT_MAX;
	forn(i, A) 
	{
		cin >> a[i];
		mna = min(mna, a[i]);
	}
	forn(i, B)
	{
		cin >> b[i];
		mnb = min(mnb, b[i]);
	}
	ll res = mna + mnb;
	for (int i = 0; i < M; ++i)
	{
		ll x, y, c; cin >> x >> y >> c;
		res = min(res, a[x - 1] + b[y - 1] - c);
	}
	cout << res << endl;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector p(N, 0LL);
  for (ll i = 0; i < N; i++) cin >> p.at(i);
  sort(p.begin(), p.end());
  ll s = 0;
  for (ll i = 0; i < K; i++) s += p.at(i);
  cout << s << endl;

  return 0;
}



Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int[] dp = new int[2001];
        dp[0] = 1;
        dp[1] = 0;
        dp[2] = 0;
        dp[3] = 1;
        dp[4] = 1;
        dp[5] = 1;
        dp[6] = 2;
        for (int i = 7; i < N+1; i++) {
            for (int j = 0; j <= i-3; j++) {
                dp[i] = add(dp[i] , dp[j]);
            }
        }
        out.println(dp[N]);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33256
#include<stdio.h>

int main(){
    int a,b,c;
    int count = 0;
    scanf("%d %d %d",&a,&b,&c);

    for(int x=a;x<=b;x++){
        if(c%x==0){
            count++;
        }    
    }
    printf("%d\n",count);

    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair< int, int > Pi;

bool cmp(const pair< Pi, Pi >& p, const pair< Pi, Pi >& q)
{
  if(p.first.first + p.second.first, q.first.first + q.second.first)
    return(p.first.first + p.second.first < q.first.first + q.second.first);
  return(p.first.first * p.first.second + p.second.first * p.second.second <
         q.first.first * p.first.second + q.second.first * q.second.second);
}

// ax + by = d
pair< Pi, Pi > ask(int a, int b, int d)
{
  pair< Pi, Pi > ret({INF, INF}, {INF, INF});
  for(int x = 0; x < 5000; x++) {
    int f = abs(d - a * x);
    if(f % b == 0) ret = min(ret, {{x, a}, {f / b, b}}, cmp);
  }
  return(ret);
}

int main()
{
  int a, b, d;
  while(cin >> a >> b >> d, a) {
    auto alpha = ask(a, b, d), beta = ask(b, a, d);
    auto ret = min(alpha, beta, cmp);
    if(ret == beta) swap(ret.first, ret.second);
    cout << ret.first.first << " " << ret.second.first << endl;
  }
}

Measured memory_bytes: 3032
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
typedef struct E{
  int to,cost;
}edge;
const int MAX_V=200100;
const int Inf=1e9;
vector<vector<edge> >E(MAX_V);
int d[MAX_V];
void dijkstra(int s){
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >que;
  fill_n(d,MAX_V,Inf);
  d[s] = 0;
  que.push(pair<int,int>(0,s));
  while(!que.empty()){
    pair<int,int> p=que.top();que.pop();
    int v = p.second;
    if(d[v]<p.first)continue;
    for(int j=0;j<E[v].size();j++){
      edge t = E[v][j];
      if(d[t.to]>d[v]+t.cost){
	d[t.to]=d[v]+t.cost;
	que.push(pair<int,int>(d[t.to],t.to));
      }
    }
  }
}
int main(){
  int a,b,r;cin>>a>>b>>r;
  for(int i=0;i<b;i++){
    edge e;
    int s;cin>>s>>e.to>>e.cost;
    E[s].pb(e);
  }
  dijkstra(r);
  for(int i=0;i<a;i++){
    if(d[i]==Inf)cout<<"INF"<<endl;
    else
      cout<<d[i]<<endl;
  }
  return 0;
}



Measured memory_bytes: 15848
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll A,B,X;
	while(cin>>A>>B>>X) {
		double ans = 0;
		if(X < A*A*B/2.0) {
			double y = 2.0*X / B / A;
			ans = 90 - 360*atan(y/B)/(2*M_PI);
		} else {
			double y = 2.0*(A*A*B - X) / A / A;
			ans = 360*atan(y/A)/(2*M_PI);
		}
		
		cout<<setprecision(20)<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 512
#include <iostream>                                  
using namespace std;                                 
                                                     
int main() {                                         
  int a, b;                                          
  cin >> a >> b;                                     
  int S = a*b;                                       
  int R = 2*(a+b);                                   
  cout << S << " " << R << endl;                     
  return 0;                                          
}                     

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

int main(){
  int N; cin >> N;
  long long ans = 0;
  rep(i, N + 1) {
    if (i % 3 == 0 or i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
import numpy as np
n=int(input())
s=[chr(i) for i in range(97, 97+26)]
 
aa_cij=np.array([[s.index(i)+1  for i in list(input())] for _ in range(n)],dtype='int8')

ans=0
for i in range(n):
  aa_cij=np.concatenate( [ aa_cij[1:,:], aa_cij[[0],:] ], axis=0)
  if np.allclose(aa_cij, aa_cij.T):
    ans+=1 
print(ans*n)


Measured memory_bytes: 21324
#include <stdio.h>
#include <string.h>
int main(void){
    long long int A,B,K;
    scanf("%lld %lld %lld",&A,&B,&K);
    if(A>=K){
        printf("%lld %lld\n",A-K,B);
    }
    else if(A+B>=K){
        printf("0 %lld\n",B-K+A);
    }
    else{
        printf("0 0\n");
    }
    return 0;
}

Measured memory_bytes: 128
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

struct Ball {
    color: bool,
    num: usize,
}

fn main() {
    let n: usize = read();

    let mut balls = Vec::new();
    for i in 0..2 * n {
        let v = read_vec::<String>();
        let new_ball = Ball {
            color: v[0] == "B",
            num: v[1].parse::<i32>().unwrap() as usize - 1,
        };
        balls.push(new_ball);
    }

    let mut cnt_w = vec![vec![0; n + 1]; 2 * n + 1];
    for i in 1..2 * n + 1 {
        for j in 0..n {
            if i > 0 {
                cnt_w[i][j] = cnt_w[i - 1][j];
            }
            if !balls[i - 1].color && balls[i - 1].num >= j {
                cnt_w[i][j] += 1;
            }
        }
    }
    // println!("cnt_w {:?}", cnt_w);

    let mut cnt_b = vec![vec![0; n + 1]; 2 * n + 1];
    for i in 1..2 * n + 1 {
        for j in 0..n {
            if i > 0 {
                cnt_b[i][j] = cnt_b[i - 1][j];
            }
            if balls[i - 1].color && balls[i - 1].num >= j {
                cnt_b[i][j] += 1;
            }
        }
    }
    // println!("cnt_b {:?}", cnt_b);

    let mut idx_w = vec![0; n];
    let mut idx_b = vec![0; n];
    for i in 0..2 * n {
        if balls[i].color {
            idx_b[balls[i].num] = i;
        } else {
            idx_w[balls[i].num] = i;
        }
    }
    // println!("{:?}", idx_w);
    // println!("{:?}", idx_b);

    let mut dp = vec![vec![std::usize::MAX; n + 1]; n + 1];
    dp[0][0] = 0;

    for i in 0..n + 1 {
        for j in 0..n + 1 {
            if i > 0 {
                let i_w_pos = idx_w[i - 1];
                dp[i][j] = min(
                    dp[i - 1][j] + cnt_w[i_w_pos][i - 1] + cnt_b[i_w_pos][j],
                    dp[i][j],
                );
            }
            if j > 0 {
                let j_b_pos = idx_b[j - 1];
                dp[i][j] = min(
                    dp[i][j - 1] + cnt_w[j_b_pos][i] + cnt_b[j_b_pos][j - 1],
                    dp[i][j],
                );
            }
        }
    }
    // println!("{:?}", dp);
    println!("{}", dp[n][n]);
}


Measured memory_bytes: 209276
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
#define INF (1<<28)
#define FDBST int hogehogehoge;cin>>hogehogehoge;

int tc(char c){
	if(c=='A') return 1;
	if(c=='C') return 2;
	if(c=='G') return 3;
	if(c=='T') return 4;
}

int dict[10000000];

int main(){
	int n;
	cin>>n;
	lp(i,n){
		string s;
		cin>>s;
		if(s[0]=='i'){
			string x;
			cin>>x;
			int p=0;
			lp(j,x.size()){
				p*=5;
				p+=tc(x[j]);
			}
			dict[p]++;
		}
		else{
			string x;
			cin>>x;
			int p=0;
			lp(j,x.size()){
				p*=5;
				p+=tc(x[j]);
			}
			if(dict[p]>0) cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 20100
#include <iostream>
#include <vector>
#include <queue>

using namespace std;


int N, K;
vector<int> V;


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

	long long ans = 0;

	V = vector<int>(N);
	
	vector<int> acc_fw = vector<int>(N+1,0);
	vector<priority_queue<int>> mns_fw = vector<priority_queue<int>>(N+1);
	vector<int> acc_bc = vector<int>(N+1,0);
	vector<priority_queue<int>> mns_bc = vector<priority_queue<int>>(N+1);

	{
		priority_queue<int> minus_q;
		for (int i = 0; i < N; i++) {
			cin >> V.at(i);


			acc_fw.at(i+1) = V.at(i);
			if (i > 0) {
				acc_fw.at(i+1) += acc_fw.at(i);
			}

			if (V.at(i) < 0) {
				minus_q.push(-V.at(i));
			}

			mns_fw.at(i+1) = minus_q;
		}
	}

	{
		priority_queue<int> minus_q;
		for (int i = N - 1 ; i >= 0; i--) {
			acc_bc.at(i) = V.at(i);
			if (i < N - 1) {
				acc_bc.at(i) += acc_bc.at(i + 1);
			}

			if (V.at(i) < 0) {
				minus_q.push(-V.at(i));
			}

			mns_bc.at(i) = minus_q;
		}
	}

	int loop = min(K,N);
	for (int k = 1; k <= loop; k++) {
		int lest = K - k;

		for (int i = 0; i <= k; i++) {
			long long tmp = acc_fw.at(i) + acc_bc.at(N + i - k);

			priority_queue<int> mf = mns_fw.at(i);
			priority_queue<int> mb = mns_bc.at(N + i - k);
			for (int j = 0; j < lest && !(mf.empty() && mb.empty()); j++) {

				priority_queue<int> *tgt;
				if (mf.empty()) {
					tgt = &mb;
				}
				else if (mb.empty()) {
					tgt = &mf;
				}
				else {
					tgt = mf.top() < mb.top() ? &mf : &mb;
				}

				tmp += tgt->top();
				tgt->pop();
			}

			ans = max(ans,tmp);
		}

	}



	cout << ans << endl;


	return 0;
}



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

const ll INF = 1LL << 62;
const int EDGE_MAX = 2000;
const int VERT_MAX = 1001;

typedef struct Edge {
        int u;
        int v;
        ll cost;
} Edge;

Edge edges[EDGE_MAX];
bool negative[VERT_MAX];
ll dist[VERT_MAX];

int main() {

        int v_num, e_num;
        cin >> v_num >> e_num;

        for (int i=0; i<e_num; ++i) {
                int u, v;
                ll cost;
                cin >> u >> v >> cost;
                cost = -cost;
                edges[i].u = u;
                edges[i].v = v;
                edges[i].cost = cost;
        }

        for (int i=1; i<=v_num; ++i) {
                dist[i] = INF;
        }
        dist[1] = 0;

        for (int i=0; i<v_num-1; ++i) {
                for (int j=0; j<e_num; ++j) {
                        if (dist[edges[j].u]==INF) continue;
                        if (dist[edges[j].v] > dist[edges[j].u] +
                        edges[j].cost) {
                                dist[edges[j].v] = dist[edges[j].u] +
                                edges[j].cost;
                        }
                }
        }

        for (int i=0; i<v_num-1; ++i) {
                for (int j=0; j<e_num; ++j) {
                        if (dist[edges[j].u]==INF) continue;
                        if (dist[edges[j].v] > dist[edges[j].u] +
                        edges[j].cost) {
                                dist[edges[j].v] = dist[edges[j].u] +
                                edges[j].cost;
                                negative[edges[j].v] = true;
                        }
                        // if (negative[edges[j].u] == true) {
                        //         negative[edges[j].v] = true;
                        // }
                }
        }

        if (negative[v_num]) cout << "inf" << endl;
        else cout << -dist[v_num] << endl;
}


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

int main()
{
	
	int k,a,b;cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK";
			return 0;		
		}
	} 
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    //W,H,x,y,r
    let i:Vec<i32> = read_vec();
    let a = i[0];
    let b = i[1];
    let x:i32 = a/b;
    let y:i32 = a%b;
    let z:f64 = a as f64 / b as f64;
    println!("{} {} {}", x, y, z);
}


Measured memory_bytes: 5048