akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
  auto n = readln.chomp.to!int;
  int[][][] f = new int[][][](n, 5, 2);
  int[][] p = new int[][](n, 11);

  for (int i = 0; i < n; ++i) {
    auto l = readln.chomp.split.map!(to!int).array;
    for (int j = 0; j < 10; j += 2) {
      f[i][j / 2][0] = l[j];
      f[i][j / 2][1] = l[j + 1];
    }
  }

  for (int i = 0; i < n; ++i) {
    auto l = readln.chomp.split.map!(to!int).array;
    for (int j = 0; j < 11; ++j) {
      p[i][j] = l[j];
    }
  }

  int maxBenefit = -1000000007;

  for (int i = 1; i < (2 << 9); ++i) {
    int sum;
    int[] c = new int[](n);

    for (int j = 0; j < 10; ++j) {
      if (((i >> j) & 1) == 1) {
        for (int k = 0; k < n; ++k) {
          if (f[k][j / 2][j % 2] == 1) c[k]++;
        }
      }
    }

    for (int j = 0; j < n; ++j) sum += p[j][c[j]];

    if (maxBenefit < sum) maxBenefit = sum;
  }

  maxBenefit.writeln;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int MAXN = 2019;
const int MAXM = 10005;
const int INF = 0x3f3f3f3f;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, S, T, M1, M2, M3, M4;

struct Edge {
	int v, w, nxt;
	LL c;
} e[MAXM<<1];
int first[MAXN], eCnt;
	
inline void AddEdge(int u, int v, int w, LL c) {
	e[++eCnt].v = v;
	e[eCnt].w = w;
	e[eCnt].c = c;
	e[eCnt].nxt = first[u];
	first[u] = eCnt;
}

inline void Add(int u, int v, int w, LL c) {
	AddEdge(u, v, w, c);
	AddEdge(v, u, 0, -c);
}

LL dis[MAXN];
int inque[MAXN], pre[MAXN];
queue<int> q;

bool SPFA() {
	mset(dis, 0x80);
	dis[S] = 0;
	q.push(S);
	while (!q.empty()) {
		int u = q.front();
		q.pop(); inque[u] = 0;
		for (int i=first[u];i;i=e[i].nxt) {
			int v = e[i].v;
			if (e[i].w > 0 && dis[v] < dis[u] + e[i].c) {
				dis[v] = dis[u] + e[i].c;
				pre[v] = i;
				if (!inque[v]) {
					q.push(v);
					inque[v] = 1;
				}
			}
		}
	}
	return (dis[T] > 0);
}

LL Augment() {
	int flow = INF;
	for (int i=pre[T];i;i=pre[e[i^1].v]) {
		flow = min(flow, e[i].w);
	}
	for (int i=pre[T];i;i=pre[e[i^1].v]) {
		e[i].w -= flow;
		e[i^1].w += flow;
	}
	return dis[T] * flow;
}

void init() {
	read(n);
	S = n * 2 + 1; T = S + 1;
	M1 = T + 1; M2 = T + 2; M3 = T + 3; M4 = T + 4;
	eCnt = 1;
	for (int i=1;i<=n;++i) {
		int x, y, z;
		read(x); read(y); read(z);
		Add(S, i, z, 0);
		Add(i, M1, z, x + y);
		Add(i, M2, z, x - y);
		Add(i, M3, z, -x + y);
		Add(i, M4, z, -x - y);
	}
	for (int i=1;i<=n;++i) {
		int x, y, z;
		read(x); read(y); read(z);
		Add(n+i, T, z, 0);
		Add(M1, n+i, z, -x - y);
		Add(M2, n+i, z, -x + y);
		Add(M3, n+i, z, x - y);
		Add(M4, n+i, z, x + y);
	}
}

void solve() {
	LL ans = 0;
	while (SPFA()) {
		ans += Augment();
	}
	printf("%lld\n", ans);
}

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


Measured memory_bytes: 768
# ALDS1 : Dictionary

def main():
    n = input()
    dic = {}
    for i in xrange(n):
        command, ope = raw_input().split()
        if command == "insert":
            dic[ope] = 1
        elif command =="find":
            if ope in dic:
                print "yes"
            else:
                print "no"

if __name__ == '__main__':
    main()

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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int nums[n];
    for(int i=0;i<n;i++){
       int h;
       cin>>h;
       nums[i] = h;
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(nums[0]-nums[1]);
    if(n>2){
    for(int i=2;i<k;i++){
        int val= INT_MAX;
        for(int j=0;j<i;j++){
            val = min(val,dp[j]+abs(nums[j]-nums[i]));
        }
        dp[i] = val;
    }
   for(int i=k;i<n;i++){
        int value = INT_MAX;
    for(int j=1;j<=k;j++){
        value = min(value,dp[i-j]+abs(nums[i-j]-nums[i]));
    }
   dp[i] = value;
   }
    }
   cout<<dp[n-1];

}


Measured memory_bytes: 4340
menu = [int(input()) for _ in range(5)]
ans = 0
mod = []
for time in menu:
    if time % 10 == 0:
        ans += time
    else:
        ans += time
        mod.append(10 - time % 10)
try:
    mod.remove(max(mod))
    ans += sum(mod)
except:
    pass
print(ans)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
  int H,W;
  while(1){
    cin >> H >> W;
    if(H==0 && W == 0) break;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	cout << '#';
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3056
import std.stdio, std.conv, std.string, std.algorithm, std.range, std.math;

void main() {
  alias f = a => a == 2 ? 0 : (a == 4 || a == 6 || a== 9 || a == 11) ? 1 : 2;
  auto po = readln.split.to!(int[]).map!f.array;
  writeln(po[0] == po[1] ? "Yes" : "No");
}


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

using namespace std;

using LL = long long;
using PII = pair<int, int>;
using ll = long long;
using DBL = double;
using VI = vector<int>;
using VD = vector<DBL>;
using VVI = vector<VI>;
using VVD = vector<VD>;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)
#define SZ(a) ((int)((a).size()))
#define ALL(x) (x).begin(), (x).end()
#define SET(a,v) memset((a), (v), sizeof(a))
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

//#define trace(...) {__f(#__VA_ARGS__, __VA_ARGS__);}
//template<typename Arg> void __f(const char* name, Arg&& arg) {
//  cerr << name << " = " << arg << std::endl;
//} template <typename Arg1, typename... Args>
//void __f(const char* names, Arg1&& arg1, Args&&... args) {
//  const char* comma = strchr(names + 1, ',');
//  cerr.write(names, comma - names) << " = " << arg1<<" | ";__f(comma+1, args...); }
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; // OST: find_by_order, order_of_key
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//#pragma GCC optimize("Ofast")
//optimize("unroll-loops")
//target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
///*** RNGS ***/
//SEED=chrono::steady_clock::now().time_since_epoch().count();
//// or high_resolution_clock
//mt19937 rng(SEED); /*or*/ random_device rd; mt19937 rng(rd());
//uniform_int_distribution<> dis(MIN, MAX);// usage: dis(rng)
//struct chash {int operator()(int x) const {return x^SEED;}};
//gp_hash_table<int,int,chash>m;//use cc if very less updates
///*** FAST IO ***/
//inline int scan(){ bool y=0; int x=0; char c=getchar_unlocked();
//while(c<'0'||c>'9'){ if(c=='-')y=1; c=getchar_unlocked();}
//while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar_unlocked();}
//return y?-x:x; }

const int MAXN = 32, MAXMASK = (1<<21), MOD = 1000000007;
int a[MAXN][MAXN];
int dp[32][MAXMASK];
int n;

int calc(int pos, int mask) {
    int &y = dp[pos][mask];
    if(y != -1) return y;
    if(pos == 0) return y = 1;
    y = 0;
    for(int i=0; i<n; ++i) {
        if((mask&(1<<i)) and a[pos][i+1]) {
            y += calc(pos-1, mask - (1<<i));
            if(y >= MOD) y -= MOD;
        }
    }
    return y;

}

int main() {
    #ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
//    freopen("sample.out", "w", stdout);
    #else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    #endif
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i=1; i<=n; ++i) {
        for(int j=1; j<=n; ++j) {
            cin >> a[i][j];
        }
    }
    cout << calc(n, (1<<n)-1) << endl;
	return 0;
}


Measured memory_bytes: 265764
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int preT=0;
    int preX=0;
    int preY=0;

    for (int i=0; i<N; i++) {
      int postT=sc.nextInt();
      int postX=sc.nextInt();
      int postY=sc.nextInt();

      int dt=postT-preT;
      int dist=Math.abs(postX-preX)+Math.abs(postY-preY);
      if ((dt<dist) || ((dist-dt)%2!=0)) {
        System.out.println("No");
        return;
      }
      preT=postT;
      preX=postX;
      preY=postY;
    }

    System.out.println("Yes");
  }
}


Measured memory_bytes: 58808
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

ans = 0
p = 0
for i in l[::-1]:
    i[0] += p
    ans += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    p += i[1] - (i[0] % i[1]) if i[0] % i[1] else 0
    
print(ans)

Measured memory_bytes: 25844
#include <bits/stdc++.h>
using namespace std;
int N ;
int main (){
  
  cin >>N;
  int ans=N;
  for(int i=0; i<=N; i++){
    int c=i;
    int cc=0;
  	while(c>0){cc+=c%6; c/=6;}
    c=N-i;
    while(c>0){cc+=c%9; c/=9;}
    ans=min(ans,cc);
  } 
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int n, t; cin >> n >> t;
  vi arr(n);
  rep(i,n) cin >> arr[i];

  vi buy(n);
  buy[0] = arr[0];
  rep(i,n-1) buy[i+1] = min(buy[i], arr[i+1]);

  int profit = 0;
  int ans = 0;
  rep(i,n) {
    if (arr[i] - buy[i] == profit) ++ans;
    else if (arr[i] - buy[i] > profit) {
      profit = arr[i] - buy[i];
      ans = 1;
    }
  }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<ll> a(n);
  rep(i,n){
      cin >> a[i];
  }
  vector<ll> sa(n+1);
  sa[0] = 0;
  rep(i,n){
      sa[i+1] = sa[i] + a[i];
  }
  map<ll,ll> m;
  rep(i,n+1){
      m[sa[i]]++;
  }
  auto it = m.begin();
  ll ans = 0;
  while(it!=m.end()){
      ll num = it->second;
      ans += num * (num-1) /2;
      it++;
  }
  cout << ans << endl;

}

Measured memory_bytes: 15872
#include<iostream>
using namespace std;
int main(){
int n;
char s[100],t[100];
cin>>n;
for(int i=0; i<n;i++)cin>>s[i];
for(int i=0; i<n;i++)cin>>t[i];
for(int i=0; i<n;i++){
cout<<s[i]<<t[i];
}
cout<<endl;
}

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

#define mod 1'000'000'007
typedef long long ll;

template <typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << '\n';
}

int n;
string s;

void solve()
{
    cin >> n >> s;
    vector<int> b(n), a(n), w(n);
    for (int i = 0; i < n; ++i)
        a[i] = s[i] == '.' ? 0 : 1;
    b[n - 1] = a[n - 1];
    w[n - 1] = a[n - 1] == 0;
    for (int i = n - 2; i >= 0; --i)
    {
        b[i] = b[i + 1] + a[i];
        w[i] = w[i + 1] + (a[i] == 0);
    }
    int ans = w[0], cnt = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        cnt += a[i];
        ans = min(ans, cnt + w[i + 1]);
    }
    ans = min(ans, cnt);
    cout << ans << '\n';
}

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

    int t { 1 };
    //cin >> t;
    while (t--)
        solve();

    return 0;
}


Measured memory_bytes: 2964
N = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(N):
    if i != N-1:
        if p[i] == i+1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    else:
        if p[i] == i+1:
            p[i], p[i-1] = p[i-1], p[i]
            ans += 1

print(ans)

Measured memory_bytes: 13880
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define M 1046527
#define L 15

typedef long long ll;

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
ll getKey(char str[]){
  ll sum = 0, p = 1;
  int i;
  
  for ( i = 0; i < (int)strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 3;
  }
  //printf("%lld\n",sum);
  return sum;
}

int h1(ll key){
  return key%M;
}
int h2(ll key){
  return 1+key%(M-1);
}

int find(char str[]){
  int i=0,j=0;
  int f,g;

  ll key = getKey(str);
  f = h1(key);
  g = h2(key);

  while(1){
    i = ( f + g*j )%M;
    if( strcmp(H[i],str) == 0 ) return 1;
    else if( strlen(H[i]) == 0 ) return 0;
    j++;
  }
  return 0;
}

int insert(char str[]){
  int i=0,j=0;
  int f,g;

  ll key = getKey(str);
  f = h1(key);
  g = h2(key);

  while(1){
    i = ( f + g*j )%M;
    if( strcmp(H[i], str) == 0 ) return 0;  //check if str already exists

    if( H[i][0] == '\0' ){
      strcpy(H[i], str);
      return 1;
    }
    j++;
  }
}

int main(){
  int i, n;
  char str[L], com[10];
  
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    }
    else {
      if (find(str) == 1){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
  }
  return 0;
}



Measured memory_bytes: 17068
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdlib>
using namespace std;

int main(){
    string s; cin >> s;
    string a = "CODEFESTIVAL2016";

    int ans = 0;
    for(int i = 0; i < 16; ++i){
        if(s[i] != a[i]) ans++;
    }

    cout << ans << endl;
    return EXIT_SUCCESS;
}


Measured memory_bytes: 764
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(h):
        for j in range(w):
            if i%2==0:
                if j%2==0:
                    print("#",end="")
                else:
                    print(".",end="")
            else:
                if j%2==0:
                    print(".",end="")
                else:
                    print("#",end="")
        print("")
    print("")



Measured memory_bytes: 7008
import java.util.*;
import java.util.Map.Entry;
 

public class Main{
	
	
	
	
	public static long answer = 0;
	public static long MOD=1000000007;
	
	
	

	

 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int k) {
		long sum = 1;
		for(int i=1;i<=k;i++) {
			sum = (sum*i)%MOD;
		}
		return sum;
		
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
    
	
	
 public static void main(String[] args) {
	 
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 char[] c=sc.next().toCharArray();
	
	 for(int i=0;i<c.length;i++) {
		 int a=c[i];
		 a += N;
		 if(a > 90) {
			 a = 64 + (a - 90);
		 }
		 char b = (char)a;
		 System.out.print(b);
	 }
	 
	 
	 

	 
	 
	
}
 
 
}


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


long long rec(long long x) {
	if(x == 1) return 1;
	return 1 + 2 * rec(x / 2);
}

int main() {
	ios::sync_with_stdio(false);

	long long h; cin >> h;
	cout << rec(h) << '\n';	

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));



int main(){
    vector<int> A;
    for(int i = 0;; i++){
        int x;
        cin >> x;
        if(x == 0) break;
        else{
            A.push_back(x);
        }
    }
    for(int i = 1; i <= A.size(); i++){
        cout << "Case " << i << ": " << A[i - 1] << endl;
    }
}


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

main(){
  int n;
  cin>>n;
  vector<int> a(n);
  map<int,int> mp;
  rep(i,n){
    int A; cin>>A;
    a[i]=A;
    mp[A]++;
  }
  map<ll,ll> each;
  ll s=0;
  for(auto x : mp){
    each[x.first]=x.second*(x.second-1)/2;
    s+=each[x.first];
  }
  rep(i,n){
    int A=a[i];
    int ans=s-each[A]+(mp[A]-1)*(mp[A]-2)/2;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 20660
import math

n = int(input())
base = 26

digit = math.floor(math.log(1+(base-1)*n, base))
position = int(n - (base**digit - 1) / (base  - 1))

txt = 'a' * digit

txt = list(txt)

for i in range(digit):
    txt[digit - i - 1] = chr(ord(txt[digit - i - 1])+(position % base))
    position = position // base

print(''.join(txt))

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

struct point {
	int x, y;
	bool used;
	bool operator<(const point& right) const {
		return x < right.x;
	}
};

int main() {
	int n;
	cin >> n;
	vector<point> r(n), b(n);
	for (int i = 0;i < n;i++) {
		cin >> r[i].x >> r[i].y;
		r[i].used = false;
	}
	for (int i = 0;i < n;i++) {
		cin >> b[i].x >> b[i].y;
	}

	sort(b.begin(), b.end());
	int ans = 0;
	for (int i = 0;i < n;i++) {
		int mj = -1, my = -1;
		for (int j = 0;j < n;j++) {
			if (!r[j].used&&r[j].x < b[i].x&&r[j].y > my&&r[j].y<b[i].y) {
				my = r[j].y;
				mj = j;
			}
		}
		if (mj != -1) {
			ans++;
			r[mj].used = true;
		}
	}



	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
import math

class Point:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    def __add__(self, other):
        return Point(self.x + other.x, self.y + other.y)
    def __sub__(self, other):
        return Point(self.x - other.x, self.y - other.y)
    def __mul__(self, other):
        return Point(self.x * other, self.y * other)
    def __floordiv__(self, other):
        return Point(self.x / other, self.y / other)
    def __repr__(self):
        return str(self.x) + ' ' + str(self.y)

class Vector(Point):
    pass

class Line:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2

class Segment(Line):
    pass

def points_to_vector(p1, p2):
    x = p1.x - p2.x
    y = p1.y - p2.y
    return Vector(x, y)

def vector(p):
    return Vector(p.x, p.y)

def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y

def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x

def norm(v):
    return v.x**2 + v.y**2

def distance(v):
    return math.sqrt(norm(v))

def project(s, p):
    base = points_to_vector(s.p1, s.p2)
    hypo = points_to_vector(p, s.p1)
    r = dot(hypo, base) / norm(base)
    return s.p1 + base * r

def reflect(s, p):
    return p + (project(s, p) -p) * 2

def get_distance(s1, s2):
    if intersect_s(s1, s2):
        return 0
    d1 = get_distance_sp(s1, s2.p1)
    d2 = get_distance_sp(s1, s2.p2)
    d3 = get_distance_sp(s2, s1.p1)
    d4 = get_distance_sp(s2, s1.p2)
    return min(d1, min(d2, min(d3, d4)))

def get_distance_pp(p1, p2):
    return distance(p1 - p2)

def get_distance_lp(l, p):
    return abs(cross(l.p2 - l.p1, p - l.p1) / distance(l.p2 - l.p1))

def get_distance_sp(s, p):
    if dot(s.p2 - s.p1, p - s.p1) < 0:
        return distance(p - s.p1)
    elif dot(s.p1 - s.p2, p - s.p2) < 0:
        return distance(p - s.p2)
    else:
        return get_distance_lp(s, p)

def ccw(p0, p1, p2):
    EPS = 1e-10
    COUNTER_CLOCKWISE = 1
    CLOCKWISE = -1
    ONLINE_BACK = 2
    ONLINE_FRONT = -2
    ON_SEGMENT = 0
    v1 = p1 - p0
    v2 = p2 - p0
    if cross(v1, v2) > EPS:
        return COUNTER_CLOCKWISE
    elif cross(v1, v2) < -EPS:
        return CLOCKWISE
    elif dot(v1, v2) < -EPS:
        return ONLINE_BACK
    elif norm(v1) < norm(v2):
        return ONLINE_FRONT
    else:
        return ON_SEGMENT

def intersect_p(p1, p2, p3, p4):
    return ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0

def intersect_s(s1, s2):
    return intersect_p(s1.p1, s1.p2, s2.p1, s2.p2)


import sys
# sys.stdin = open('input.txt')

q = int(input())
for i in range(q):
    temp = list(map(int, input().split()))
    points = []
    for j in range(0, 8, 2):
        points.append(Point(temp[j], temp[j+1]))
    s1 = Segment(points[0], points[1])
    s2 = Segment(points[2], points[3])
    print(get_distance(s1, s2))


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

int main()
{
  int n,l;
  cin >> n >> l;
  //taste:L+i-1
  vector<int> taste(n);
  int sum=0;
  for(int i=0;i<n;i++){
    taste.at(i)=l+i;
    sum+=taste.at(i);
  }
  int ans;
  if(l>=0){
    ans=sum-taste.at(0);
  }
  else if(l<0){
    if(taste.at(n-1)>=0){
      ans=sum;
    }
    else if(taste.at(n-1)<0){
      ans=sum-taste.at(n-1);
    }
  }
  cout << ans << endl;
  
}

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

int main(){
  long int n,m,i,j,left=-1,right=1000000001,mid,mai,kotae,kari;
  cin>>n>>m;
  int a[n];
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  while(right-left>1){
    mid=(right+left)/2;
    mai=0;
    for(i=0;i<n;i++){
      kari=a[i];
      for(j=0;kari>mid;j++){
        kari/=2;
      }
      mai+=j;
    }
    if(mai>m){
      left=mid;
    }else{
      right=mid;
    }
  }
  for(i=0;i<n;i++){
    kari=a[i];
    for(j=0;kari>right;j++){
      kari/=2;
    }
    m-=j;
    kotae+=kari;
  }
  cout<<kotae-(right-(right/2))*m;
}
        


Measured memory_bytes: 640
s = str(input())
if len(set(s)) == 1:
    print('No')
elif (s[0] == s[1]) and (s[2] == s[3]):
    print('Yes')
elif (s[0] == s[2]) and (s[1] == s[3]):
    print('Yes')
elif (s[0] == s[3]) and (s[1] == s[2]):
    print('Yes')
else:
    print('No')

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
  	for(int i = 0; i < N; i++) {
    	cin >> vec.at(i);
    }

    int min_cost = INT_MAX;
    for(int i = -100; i <= 100; ++i) {
        int cost = 0;
        for(int j : vec) {
            if(i != j) {
                cost += pow(i - j, 2.0);
            }
        }
        if(cost < min_cost) {
            min_cost = cost;
        }
    }

    cout << min_cost << endl;
}

Measured memory_bytes: 256
from math import ceil, sqrt
S = int(input())
x1, y1 = 0, 0
y2 = 0
x3 = 0
if S <= 10**9:
    x2, y2 = S, 0
    x3, y3 = 0, 1
else:
    sq_s = ceil(sqrt(S))
    x2, y2 = sq_s*sq_s - S, sq_s
    x3, y3 = sq_s, 1

print(x1, y1, x2, y2, x3, y3)


Measured memory_bytes: 3060
#include <stdio.h>

int
main(void)
{
	char line[80];

	int a, b, c;

	int h = 0;
	int r = 0;
	
	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			break;
		}
		if (sscanf(line, "%d,%d,%d", &a, &b, &c) != 3) {
			break;
		}

		if (a*a + b*b == c*c) {
			h ++;
		} else if (a == b) {
			r ++;
		}
	}
	
	printf("%d\n%d\n", h, r);

	return 0;
}

Measured memory_bytes: 1036
/*
  coded by: mi_ni_
  "LIVE LONG AND PROSPER"
*/
 
#include <bits/stdc++.h>
using namespace std;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define newl '\n'
#define TEST_CASE(fun) int tc; cin>>tc; while(tc--){ fun(); }
#define TEST_CASE_2 int tc; cin>>tc; for(int i=1;i<=tc;i++)
#define TEST_CASE_3(fun) int tc; cin>>tc; for(int i=1;i<=tc;i++){ cout<<"Case #"<<i<<": "; fun(); }
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define forab(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define forabr(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define trav(i,x) for(auto& i:x)

using ll=long long int;
using ull=unsigned long long int;
using ld=long double;
using pii=pair<int, int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vii=vector<pii>;
using vll=vector<pll>;

const ld pi=acosl(-1);
const int inf=(int)1e9+7;
const ll llinf=(ll)1e18+7;
const ld eps=1e-7;

//other
template<typename T> inline bool powerof2(T a){ return (a&&(!(a&(a-1)))); }
template<typename T> inline T log_2(T a){ T res=-1; while(a){ a/=2; res++; } return res; }

//make sure to choose TEST_CASE in main for multiple test cases
void solve(){
	ll k;
	cin>>k;
	ll prev=k;
	forab(i,1,k){
		ll curr=(((prev*10ll)%k)+(7%k))%k;
		if(curr==0){
			cout<<i<<newl;
			return;
		}
		prev=curr;
	}
	cout<<-1<<newl;
}

int main(){
	FAST_IO
	cout<<fixed<<setprecision(15);
	cerr<<fixed<<setprecision(10);
	//init_fact();
	//TEST_CASE(solve)
	//TEST_CASE_2{}
	//TEST_CASE_3(solve)
	solve();
	return 0;
}

Measured memory_bytes: 3656
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt(),count=0;;
		int[] a=new int[n];
		int[] tem=new int[a.length];
		
		for(int i=0;i<n;i++)
		{
			a[i]=input.nextInt();
			tem[i]=a[i];
		}
		Arrays.sort(tem);	
          
		for(int i=0;i<n;i++)
			if(a[i] != tem[i]) count++;
			
		if(count <=2) 
			System.out.println("YES");
		else
			System.out.println("NO");	
		
	}
}




Measured memory_bytes: 27060
N = int(input())
num_list = [int(input()) for _ in range(N)]

temp_max_val = -1 * 10**9
temp_min = num_list[0]

for i in range(N-1):
    temp_max_val = max(temp_max_val, num_list[i+1] - temp_min)
    temp_min = min(temp_min, num_list[i+1])
    # print(temp_min)
    # print(temp_max_val)

print(temp_max_val)


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

using namespace std;

//const int N = 3003;
//int dp[2][N];
//
//// max as end, WA
//void solve() {
//    int n, T;
//    cin >> n >> T;
//    vector<int> a(n), b(n);
//    int mx = 0, mi = N, id = -1;
//    for (int i = 0; i < n; i++) {
//        cin >> a[i] >> b[i];
//        if (b[i] > mx || (b[i] == mx && a[i] < mi)) {
//            mx = b[i];
//            mi = a[i];
//            id = i;
//        }
//    }
//    for (int i = 0; i < n; i++) {
//        if (i == id) continue;
//        int x = a[i], y = b[i];
//        for (int t = N-1; t >= 0; t--) {
//            dp[1][t] = max({dp[1][t], t>=x?dp[1][t-x]+y:0, t>=min(x,mi)?dp[0][t-min(x,mi)]:0});
//        }
//        for (int t = N-1; t >= 0; t--) {
//            dp[0][t] = max(dp[0][t], t>=x?dp[0][t-x]+y:0);
//        }
//    }
//    int res = max(dp[0][T-1], dp[1][T-1]) + mx;
//    cout << res;
//}

const int N = 3003; 
int dp[N][N], back[N][N];

void solve() {
    int n, T;
    cin >> n >> T;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        int x = a[i], y = b[i];
        for (int t = 0; t < N; t++) {
            dp[i+1][t] = dp[i][t];
            if (t >= x) dp[i+1][t] = max(dp[i+1][t], dp[i][t-x] + y);
            if (t) dp[i+1][t] = max(dp[i+1][t], dp[i+1][t-1]);
        }
    }
    for (int i = n-1; i >= 0; i--) {
        int x = a[i], y = b[i];
        for (int t = 0; t < N; t++) {
            back[i][t] = back[i+1][t];
            if (t >= x) back[i][t] = max(back[i][t], back[i+1][t-x] + y);
            if (t) back[i][t] = max(back[i][t], back[i][t-1]);
        }
    }
    int res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < T; j++) {
            int tmp = dp[i][j] + back[i+1][T-1-j] + b[i];
            res = max(res, tmp);
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 70784
cnt = 0
n = int(input())
p = list(map(int, input().split()))
for i in range(1, n + 1):
  if int(i) != p[i - 1] :
    cnt += 1
    if cnt >= 3:
      break
if cnt <= 2 :
  print("YES")
else :
   print("NO")


Measured memory_bytes: 2940
program prob78
    implicit none
    character(3) :: s,t
    integer :: i, c
    read(*,*) s,t
    c = 0
    do i = 1, 3
        if(s(i:i) == t(i:i)) then
            c = c + 1
        end if
    end do
    write(*,*) c

    stop
contains
end program prob78

Measured memory_bytes: 2796
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second     
#define fio ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define mp make_pair
#define int long long
#define double float
using namespace std;
template <typename T>
void watch(vector<T> v)
{
    for(int i=0;i<v.size();i++)
        cout<<v[i]<<" ";
    cout<<"Look above\n";
    cout<<"\n";
}
const int INF = 1e12;
const int MAX = 1e5+3;
bool comp(pair<int, int> p1, pair<int, int> p2)
{
    if(p1.f > p2.f)
        return true;

    if(p1.f < p2.f)
        return false;

    if(p1.s > p2.s)
        return false;

    return true;
}
int32_t main()
{
    fio
    int n, m;
    cin>>n>>m;
    set<int> st;
    for(int i=0;i<m;i++)
        st.insert(i);
    vector<pair<int, int> > v;
    for(int i=0;i<n;i++)
    {
        int day, point;
        cin>>day>>point;
        v.pb({point, day});
    }
    sort(v.begin(), v.end(), comp);
    int sum = 0;
    for(int i=0;i<v.size();i++)
    {
        if(st.empty())
            break;
        int reqd = v[i].s, point = v[i].f;
        auto it = st.lower_bound(m-reqd);
        if(it == st.end())
            it--;
        //cout<<*it<<"\n";
        if(*it == m-reqd)
        {
           // cout<<i<<" 11111\n";
            sum += point;
            st.erase(it);
        }
        else if(*it <= m-reqd)
        {
           // cout<<i<<" 2222\n";
            sum += point;
            st.erase(it);
        }
        else if(it != st.begin())
        {
            //cout<<i<<" 3333\n";
            sum += point;
            it--;
            st.erase(it);
        }
        
    }
    cout<<sum;

}



Measured memory_bytes: 7160
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	long A,B,K;cin>>A>>B>>K;
	if(A+B<K){ A=0; B=0; }
    else if(A<K){  B-=K-A;A=0; }
	else{ A-=K; }
	cout<<A<<" "<<B<<endl;
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, m; cin >> n >> m;
    int ans = n*(n-1)/2;
    ans += m*(m-1)/2;
    cout << ans << '\n';
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
        int S, h, m, s;

        scanf("%d", &S);

        h = S/(60*60);
        m = (S%(60*60))/60;
        s = (S%(60*60))%60;

        printf("%d:%d:%d\n", h, m, s);

        return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n, W;
    cin >> n >> W;
    vector<ll> v(n);
    vector<ll> w(n);
    vector<ll> m(n);
    for(i = 0;i < n;++i){
        cin >> v.at(i) >> w.at(i) >> m.at(i);
    }
    ll INF = 1ll << 60;
    ll V_MAX = 50*n;
    vector<vector<ll>> dp(n+1,vector<ll>(V_MAX+1, INF));
    dp.at(0).at(0) = 0;
    for(i = 1;i <= n;++i){
        for(j = V_MAX;j >= 0;--j){
            if(j < v.at(i-1)) dp.at(i).at(j) = dp.at(i-1).at(j);
            else dp.at(i).at(j) = min(dp.at(i-1).at(j), dp.at(i-1).at(j - v.at(i-1)) + w.at(i-1));
        }
        --m.at(i-1);
        if(m.at(i-1)){
            for(j = V_MAX;j >= 0;--j){
                if(j >= v.at(i-1)) dp.at(i).at(j) = min(dp.at(i).at(j), dp.at(i).at(j - v.at(i-1)) + w.at(i-1));
            }
            --m.at(i-1);
        }
    }
    vector<ll> ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](ll i, ll j){
        return v.at(i)*w.at(j) > v.at(j)*w.at(i);
    });
    
    ll ans = 0;
    for(i = V_MAX;i >= 0;--i){
        if(dp.at(n).at(i) > W) continue;
        ll val = i;
        ll remain = W - dp.at(n).at(i);
        rep(j,n){
            ll ind = ord.at(j);
            ll greed = min(m.at(ind), remain/w.at(ind));
            remain -= greed*w.at(ind);
            val += greed*v.at(ind);
        }
        ans = max(ans, val);
    }
    cout << ans << endl;
    
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->

bool cmp(pii &a, pii &b)
{
	return a.second<b.second;
}

void sort(map<int,int>m)
{
	vector<pair<int,int>>A;

	for(auto & it: m)
	{
		A.pb(it);
	}

	sort(all(A),cmp);

	// for(auto &it:A)
	// {
	// 	cout<<it.first<<" "<<it.second<<endl;
	// }
}

int main()
{

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

	int n,k;
	cin>>n>>k;

	vector<int>a(n);
	map<int,int>mp;

	loop(i,n)
	{
		cin>>a[i];
		mp[a[i]]++;
	}

    sort(mp);

    ll ans = 0;

	vector<int>an;

	for(auto it:mp)
	{
		an.pb(it.second);
	}
    
    sort(all(an));

    if(k>mp.size())
    {
    	cout<<0<<endl;
    	return 0;
    }
     

	for(int i=0; i<mp.size()-k; i++)
	{
		
		ans += an[i];
	}

	cout<<ans<<endl;
}


Measured memory_bytes: 24660
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main (String args[]) {

		Scanner sc = new Scanner(System.in);

		int[] a = new int[3];

		for(int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}
}



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

using namespace std;

int main() {
	long long n, sum = 0; cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0) continue;
		else sum += i;
	}
	cout << sum;
}



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

# def adjust(n):
#     if n < 10:
#         return '00' + str(n)
#     elif n < 100:
#         return '0' + str(n)
#     else:
#         return str(n)

if n < 1000:
    print('ABC')
else:
    print('ABD')



Measured memory_bytes: 2940
def solve(s1, s2, s3):
    S = [s1, s2, s3]
    return(max(S) - min(S))


H, W = map(int, input().split())
S = H * W
for j in range(1, W):
    S1 = H * j
    i = H // 2
    S2 = (W - j) * i
    S3 = (W - j) * (H - i)
    S = min(S, solve(S1, S2, S3))

for i in range(1, H):
    S1 = W * i
    j = W // 2
    S2 = (H - i) * j
    S3 = (H - i) * (W - j)
    S = min(S, solve(S1, S2, S3))

S = min(S, H * (W % 3 > 0))
S = min(S, W * (H % 3 > 0))


print(S)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
 int i,j,k,l,n,m,a[100],b[100][100];

 scanf("%d",&n);

 for(i=0;i<n;i++){
   scanf("%d %d",&a[i],&m);
 }

 a[n]=m;

 for(i=1;i<=n;i++){
   b[i][i]=0;
 }

 for(i=2;i<=n;i++){
  for(j=1;j<=n-i+1;j++){

    l=j+i-1;

    b[j][l]=1000000;

    for(k=j;k<=l-1;k++){

      m=b[j][k]+b[k+1][l]+a[j-1]*a[k]*a[l];

      if(b[j][l]>m) b[j][l]=m;
    }
  }
 }

 printf("%d\n",b[1][n]);

 return 0;
}

Measured memory_bytes: 1812
num=raw_input()
out=0
d={}
for i in set(num):
    d[i]=num.count(i)
#print d
#aaa
for i in range(len(num)):
    #out+=num[i:].count(num(i))
    #print len(num[i:])-num[i:].count(num[i])
    #out+=len(num[i:])-num[i:].count(num[i])
    out+=len(num[i:])-d[num[i]]
    d[num[i]]-=1

print out+1


Measured memory_bytes: 11428
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N,T; cin >>N >>T;
  vector<int> A(N),B(N); rep(i, N) cin >>A[i] >>B[i];
  vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(T+1, vector<int>(2, -1000000000)));
  // dp[i][j][k] := i番目までの料理をj分以内に食べるときの満足度の最大値。
  //  最後に注文するものは時間を気にしなくてよいが、k=1のときはそれが既に決まっているとする。
  //  但しk=1とできるのはj < T の時に限る。
  dp[0][0][0] = 0;
  for (int i=0; i<N; i++){
    for (int j=0; j<=T; j++){
      for (int k=0; k<2; k++){
        if (dp[i][j][k] == -1000000000) continue;
        // 普通にこの料理を選ばない
        chmax(dp[i+1][j][k], dp[i][j][k]);
        if (k == 0){
          // 普通にこの料理を選ぶ。j<=T。
          if (j+A[i] <= T) chmax(dp[i+1][j+A[i]][k], dp[i][j][k] + B[i]);
          // この料理を最後の料理とする。j<=T-1。
          if (j < T) chmax(dp[i+1][j][1], dp[i][j][k] + B[i]);
        }else if (k == 1){
          // 普通にこの料理を選ぶ。j<T。
          if (j+A[i] < T) chmax(dp[i+1][j+A[i]][k], dp[i][j][k] + B[i]);
        }
      }
    }
  }
  int res = 0;
  for (int j=0; j<=T; j++){
    for (int k=0; k<2; k++){
      chmax(res, dp[N][j][k]);
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 493056
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define RG register
using namespace std;
const int N=1e4+10;
int n,k,num[N],ans,tot;
char ss[13];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
priority_queue<int> pn;
int main()
{
//	freopen("Problem Committee.in","r",stdin);
	//freopen(".out","w",stdout);
	read(n,k);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",ss);
		num[ss[0]-'A']++;
	}
	for(int i=0;i<26;i++) if(num[i]) pn.push(num[i]);
	while(pn.size()>=k)
	{
		int cnt=0;
		for(int i=1;i<=k;i++) 
		{
			int tt=pn.top();pn.pop();
			if(tt-1) num[++cnt]=tt-1;
		}
		for(int i=1;i<=cnt;i++) pn.push(num[i]);
		ans++;
	}
	printf("%d\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

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


int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int left = 0, right = 0;
    rep(i,m){
        int tmp;
        cin >> tmp;
        if(tmp < x) left++;
        else right++;
    }
    cout << min(left, right) << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a,v,b,w, t int
	fmt.Scan(&a, &v, &b, &w, &t)

	if w -v > 0 {
		fmt.Println("NO")
		return
	}
	if abs(b-a) <= (t* abs(w-v)) {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}


Measured memory_bytes: 1816
s = input()
MOD = 10 ** 9 + 7
n = len(s)
ABC = 'ABC'

dp = [[0] * 4 for i in range(n + 1)]
for i in range(n, -1, -1):
    for j in range(3, -1, -1):
        if i == n:
            if j == 3:
                dp[i][j] = 1
            else:
                dp[i][j] = 0
        else:
            if s[i] == '?':
                dp[i][j] = 3 * dp[i+1][j]
            else:
                dp[i][j] = dp[i+1][j]
            if j < 3 and (s[i] == '?' or s[i] == ABC[j]):
                dp[i][j] += dp[i+1][j+1]
            dp[i][j] %= MOD
print(dp[0][0])

Measured memory_bytes: 27612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            int n = NextInt();
            int[] ar = NextInts();

            for (int i = n - 1; i >= 0; i--) {
                Print((i==n-1?"":" ") + ar[i]);
            }
            Println("");

        }

        public static void Print (Object o) {
            Console.Write(o);
        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static string NextString() {
            return Console.ReadLine();
        }

        public static string[] NextStrings () {
            return Console.ReadLine().Split();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            string[] a = Console.ReadLine().Split();
            int[] b = new int[a.Length];
            for (int i = 0; i < a.Length; i++) {
                b[i] = int.Parse(a[i]);
            }
            return b;
        }

        public static double NextDouble () {
            return double.Parse(Console.ReadLine());
        }

    }
}



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


Measured memory_bytes: 256
// ABC055 B - Training Camp
#include <stdio.h>
#include <math.h>

int main(void) {
    int N;
    unsigned long long M;
    unsigned long long result = 1;

    scanf("%d", &N);
    M = (unsigned long long)pow(10.0, 9.0) + 7;
    unsigned long long i;
    for (i = 1; i<= N; i++) {
        result = ((result % M) * (i % M)) % M;
    }
    printf("%lld\n", result);

    return 0;
}

Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        integers: [usize; n],
    }

    let d = 1000000007;

    let mut ans = 0;

    for i in 0..60 {
        let mut one = 0;
        let mut zero = 0;
        let exp = 2usize.pow(i);
        for int in &integers {
            if (int >> i) & 1 == 1 {
                one += 1;
            } else {
                zero += 1;
            }
        }
        //println!("zero: {} one: {}", zero, one);
        ans = (ans + one * zero  % d * (exp % d) % d) % d;
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444