akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;
  int cnt = 0;
  int n = s.size();
  vector<int> ans(n,0);
  rep(i,n){
    if(s[i] == 'L'){
      ans[i-1] += cnt/2+cnt%2;
      ans[i] += cnt/2;
      cnt = 0;
    }else{
      cnt++;
    }
  }

  cnt = 0;
  rep(i,n){
    if(s[n-i-1] == 'R'){
      ans[n-i] += cnt/2+cnt%2;
      ans[n-i-1] += cnt/2;
      cnt = 0;
    }else{
      cnt++;
    }
  }
  rep(i,n)cout<<ans[i]<<" \n"[i == n-1];
  return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

using Graph = vector<vector<int>>;


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

	int N, M; cin >> N >> M;
	Graph G1(N);
	int a, b;
	rep(i,M){
		cin >> a >> b;
		--a; --b;
		G1[a].push_back(b);
	}
	int dist[N][3];
	rep(i,N){
		rep(j,3){
			dist[i][j] = INF;
		}
	}
	cin >> a >> b;
	--a; --b;
	queue<P> que;
	dist[a][0] = 0;
	que.push(P(a, 0));
	while(!que.empty()){
		P p = que.front();
		que.pop();
		int u = p.first;
		int t = p.second;
		rep(i,G1[u].size()){
			int v = G1[u][i];
			int t1 = (t+1)%3;
			if(dist[v][t1] > dist[u][t] + 1){
				dist[v][t1] = dist[u][t] + 1;
				que.push(P(v,t1));
			}
		}
	}
	if(dist[b][0] == INF) cout << -1 << endl;
	else cout << dist[b][0]/3 << endl;
}

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

int main () {
  int N, M, X;
  cin >> N >> M >> X;

  vector<int> C(N, 0);
  vector<vector<int>> A(N, vector<int>(M, 0));
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  int min = 0;
  // {0, 1, ..., n-1} の部分集合の全探索
  for (int bit = 1; bit < (1<<N); ++bit) {
    vector<int> skill(M, 0);
    int value = 0;
    
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        value += C.at(i);
      	for (int j = 0; j < M; j++) {
          skill.at(j) += A.at(i).at(j);
      	}
      }
    }
        
    bool ok = true;
    for (int i = 0; i < M; i++) {
      if (skill.at(i) < X) {
        ok = false;
        break;
      }
    }
    
    if (ok) {
      if (min == 0 || value < min) {
        min = value;
      }
    }
  }
  
  if (min > 0) {
    cout << min;
  } else {
    cout << -1;
  }
}

Measured memory_bytes: 3572
import java.util.Scanner;

//Era Name
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int q = sc.nextInt();
			if((n|q)==0)break;
			String[] name = new String[n];
			int[] s = new int[n];
			int[] t = new int[n];
			for(int i=0;i<n;i++){
				name[i] = sc.next();
				int b = sc.nextInt();
				int y = sc.nextInt();
				s[i] = y-b;
				t[i] = y;
			}
			while(q--!=0){
				int x = sc.nextInt();
				boolean f = false;
				for(int i=0;i<n;i++){
					if(s[i]<x&&x<=t[i]){
						f = true;
						System.out.println(name[i]+" "+(x-s[i]));
					}
				}
				if(!f)System.out.println("Unknown");
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
s = input().rstrip()
chars = set(s)

ans = 1000
for char in chars:
    max_left = 0
    val = 0
    for i, c in enumerate(s):
        if c is not char:
            max_left += 1
        else:
            val = max(val, max_left)
            max_left = 0
    val = max(val, max_left)
    ans = min(ans, val)
print(ans)

Measured memory_bytes: 3060
import Foundation
func main(){
   let split = (readLine()!).split(separator: " ").map({ Int($0)! })
   let h = split[0]
   let w = split[1]
   let k = split[2]

   var c: [[Character]] = []
   for _ in 0..<h {
      let s = Array(readLine()!)
      c.append(s)
   }
   
   var casesArray: [Bool] = []
   for _ in 0..<h + w {
      casesArray.append(true)
   }

   let answer = recurse(casesArray: casesArray, array: c, curIndex: 0, k: k)
   print(answer)
}

func recurse(casesArray: [Bool], array: [[Character]], curIndex: Int, k: Int) -> Int {
   if curIndex == casesArray.count {
      return checkValid(casesArray: casesArray, array: array, k: k) ? 1 : 0
   } else {
      var tempArray = casesArray
      tempArray[curIndex] = false
      return recurse(casesArray: casesArray, array: array, curIndex: curIndex + 1, k: k) +
      recurse(casesArray: tempArray, array: array, curIndex: curIndex + 1, k: k)
   }
}

func checkValid(casesArray: [Bool], array: [[Character]], k: Int) -> Bool {
   var total = 0
   for i in 0..<array.count {
      for j in array.count..<casesArray.count {
         if array[i][j - array.count] == "#" && casesArray[i] && casesArray[j] {
            total += 1
         }
      }
   }
   return total == k
}
main()

Measured memory_bytes: 13600
mod = 10**9+7
from fractions import gcd
def lcm(list):
    num = 1
    for x in list:
        num = num//gcd(num, x)*x
    return num%mod

def Pow(a,n):
    if n == 0: return 1
    if n%2 == 0:
        return (Pow(a, n//2))**2%mod
    else:
        return Pow(a, n-1)*a%mod

N = int(input())
A = list(map(int, input().split()))
M = lcm(A)
R = [0]*N
for i in range(N):
    R[i] = Pow(A[i],mod-2)
ans = 0
for i in range(N):
    ans = (ans+M*R[i])%mod
print(ans)

Measured memory_bytes: 6108
def minimumSubSeq(a):
    n = len(a)
    f = [[0 for i in xrange(2)] for j in xrange(n)]
    f[0][0] = 1
    f[0][1] = 1
    for i in xrange(1, n):
        for j in xrange(2):
            f[i][j] = f[i-1][0] + 1
            f[i][j] = min(f[i][j], f[i-1][1] + 1)
            if (j==0 and a[i-1]>=a[i]) or (j==1 and a[i-1]<=a[i]):
                f[i][j] = min(f[i][j], f[i-1][j])
    return min(f[n-1][0], f[n-1][1])

def main():
    n = int(raw_input().strip())
    a = [int(i) for i in raw_input().strip().split()]
    print minimumSubSeq(a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 23000
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 3e6 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[N];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    if(s == "abc" or s == "acb" or s == "bca" or s == "bac" or s == "cab" or s == "cba")
    {
        cout <<"Yes";
        return 0;
    }
    cout <<"No";
}


Measured memory_bytes: 2304
#!/usr/bin/env python3
import sys


def solve(H: int, W: int):
    if H == 1 or W == 1:
        print(1)
        exit()

    hguu = H if H % 2 == 0 else H - 1
    wguu = W if W % 2 == 0 else W - 1
    res = hguu * wguu // 2

    if H % 2 == 1:
        res += wguu // 2
    if W % 2 == 1:
        res += hguu // 2
    if H % 2 == 1 and W % 2 == 1:
        res += 1

    print(res)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(H, W)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import numpy as np

a,b,x = (int(i) for i in input().split(' '))

c = -2*(x-a*a*b)/(a*a)

if b-c>=0:
	theta = np.arctan2(c,a)
else:
	theta = np.arctan2(b,2*x/a/b,)

print(np.degrees(theta))

Measured memory_bytes: 12500
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-8;

long long int N, M, K, H, W, L, R;

struct Enemy {
	long double x;
	long double y;
	long double z;
	long double r;
	long long int cost;
};

struct Place {
	long double sx;
	long double sy;
	long double sz;
	long double gx;
	long double gy;
	long double gz;
	long double dis;
	void Cal() {
		dis = sqrt(pow(sx - gx, 2) + pow(sy - gy, 2) + pow(sz - gz, 2));
		return;
	}
};

long double dist(long double x,long double y,long double z, Enemy e) {
	return sqrt(pow(x - e.x, 2) + pow(y - e.y, 2) + pow(z - e.z, 2));
}

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

	cin >> N >> M;
	vector<Enemy>e(N);
	for (int i = 0; i < N; i++) {
		cin >> e[i].x >> e[i].y >> e[i].z >> e[i].r >> e[i].cost;
	}
	vector<Place>p(M);
	for (int i = 0; i < M; i++) {
		cin >> p[i].sx >> p[i].sy >> p[i].sz >> p[i].gx >> p[i].gy >> p[i].gz;
		p[i].Cal();
	}
	vector<long long int>ans(M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			long double l = 0;
			long double r = p[j].dis;
			for (int k = 0; k < 200; k++) {
				long double ml = (l + l + r) / 3;
				long double mr = (l + r + r) / 3;
				long double lx, ly, lz, rx, ry, rz;
				lx = p[j].sx + (p[j].gx - p[j].sx)*ml / p[j].dis;
				ly = p[j].sy + (p[j].gy - p[j].sy)*ml / p[j].dis;
				lz = p[j].sz + (p[j].gz - p[j].sz)*ml / p[j].dis;
				rx = p[j].sx + (p[j].gx - p[j].sx)*mr / p[j].dis;
				ry = p[j].sy + (p[j].gy - p[j].sy)*mr / p[j].dis;
				rz = p[j].sz + (p[j].gz - p[j].sz)*mr / p[j].dis;
				long double ld, rd;
				ld = dist(lx, ly, lz, e[i]);
				rd = dist(rx, ry, rz, e[i]);
				if (ld < rd) {
					r = mr;
				}
				else {
					l = ml;
				}
				if (k == 199) {
					if (min(ld,rd) - EPS <= e[i].r) {
						ans[j] += e[i].cost;
					}
				}
			}
		}
	}
	for (auto i : ans) {
		cout << i << endl;
	}
	return 0;
}


Measured memory_bytes: 3280
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;


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

	bool ok = false;

	for (int i = A; i <= B; i++) {
		if (i%K == 0) {
			ok = true;
		}
	}
	if (ok) {
		cout << "OK\n";
	}
	else {
		cout << "NG\n";
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

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

  int n = 0, s = 0;
  cin >> n >> s;
  long long int m[n];
  for(int i = 0; i < n; i++){
    cin >> m[i];
  }
  sort(m, m + n);
  int t = n;
  for(int i = 0; i < s; i++){
    m[t] = 0;
    t--;
  }
  long long int sum = 0;
  for(int i = 0; i < n - s; i++){
    sum += m[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
N = int(input())
cnt_list = {}
for i in range(N):
  S = input()
  if S in cnt_list:
    cnt_list[S] += 1
  else:
    cnt_list[S] = 0

max_cnt = max(cnt_list.values())
res_list = []

for a in cnt_list.items():
  if a[1] == max_cnt:
    res_list.append(a[0])

res_list.sort()

for res in res_list:
  print(res)

Measured memory_bytes: 91224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    string ans;
    while(N>26) {
        if (N%26 == 0) ans += 'z';
        else ans += N%26+96;
        if(N%26 == 0) N = N/26-1;
        else N /= 26;
    }
    if (N%26 == 0) ans += 'z';
    else ans += N%26+96;
    reverse(ALL(ans));
    cout << ans << "\n";
}


Measured memory_bytes: 3648
#出来るだけループして端数を全部みるだとうまくいかない（最初と最後に負のスコアが固まっている場合など）

from numba import njit,i8
import numpy as np


n,k = map(int,input().split())
p = np.array([int(i)-1 for i in input().split()],np.int64)
c = np.array(list(map(int,input().split())),np.int64)

@njit(i8(i8,i8[:],i8[:]), cache = True)
def calc_score(x,p,c):
    n = p.size
    score = 0
    score_list = np.zeros(n,np.int64)
    cnt = 0
    visit = [0]*n
    while not visit[p[x]]:
        x = p[x]
        visit[x] = 1
        cnt += 1
        if cnt<=k:
            score += c[x]
            score_list[cnt-1] = score
        else:
            return score_list[:k].max()
    
    if score>0:
        tmp = np.arange(cnt)
        return (score_list[tmp] + ((k-1-tmp)//cnt) * score).max()
    else:
        return score_list[:cnt].max()

ans = max(calc_score(i,p,c) for i in range(n))
print(ans)

Measured memory_bytes: 122232
a=list(input())
b=list(input())
c=list(input())
t="a"
a.append(0)
b.append(0)
c.append(0)
while a!=[] and b!=[] and c!=[]:
  if t=="a":
    t=a[0]
    del a[0]
  elif t=="b":
    t=b[0]
    del b[0]
  else:
    t=c[0]
    del c[0]
if a==[]:
  print("A")
elif b==[]:
  print("B")
else:
  print("C")


Measured memory_bytes: 3064
// AOJ 1530 Lonely Adventuer
// 2019.3.24 bal4u

#include <stdio.h>
#include <stdlib.h>

//// 高速入力処理
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()  // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

//// 本問題関連
int cmp(const void *a, const void *b) {	return *(int *)a - *(int *)b; }
int t[1005], N;

int resolv(int n)
{
	int u, v;
	if (n == 1) return t[0];
	if (n == 2) return t[1];
	if (n == 3) return t[0] + t[1] + t[2];
	u = t[n-1] + t[0] + t[n-2] + t[0];  // (0, n-1)->(0)->(0,n-2)->(0)
	v = t[1] + t[1] + t[n-1] + t[0];    // (0,1)->(1)->(n-2,n-1)->(0)
	if (u > v) u = v;
	return u + resolv(n - 2);
}

int main()
{
	int i;

	N = in();
	for (i = 0; i < N; i++) t[i] = in();
	qsort(t, N, sizeof(t[0]), cmp);
	printf("%d\n", resolv(N));
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define ms(a, x) memset(a, x, sizeof(a))
#define fore(i, a, n) for (long long i = a; i < n; i++)
#define ford(i, a, n) for (long long i = n - 1; i >= a; i--)
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define debug(a) cout << a << endl
#define endl '\n'
#define pi acos(-1.0)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define IO ios::sync_with_stdio(false), cin.tie(0)
const double eps = 1e-8;
inline int sgn(const double &x) { return x < -eps ? -1 : x > eps; }
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn=1000100;
#define maxn0 1e9+7;
//=================================================

ll sum;
ll w[maxn];
ll dp[maxn];
ll v[maxn];

// void init() {
//     for(ll i=0;i<=n;i++){
//         w[i]=0;
//         v[i]=0;
//     }
// }
int main() {
    IO;
    ll n,W;
    cin>>n>>W;
    memset(dp,inf,sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];
        // sum+=v[i];
    }
    for(int i=1;i<=n;i++) {
        for(int j=100000;j>=v[i];j--) {
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }
    ll ans=-1;
    for(int i=1;i<=100000;++i) {
        if(dp[i]<=W)
            ans=max(ans,1LL*i);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 10496
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long e = sc.nextLong();
        long[] x = new long[n];
        long[] xsum = new long[n+1];
        for(int i=0; i<n; i++){
            x[i] = sc.nextLong();
            xsum[i+1] = xsum[i] + x[i];
        } 
        sc.close();

        BigInteger ans = BigInteger.valueOf(Long.MAX_VALUE);

        for(int i=1; i<=n; i++){
            BigInteger mans = BigInteger.ZERO;
            int pos = 0;
            int count = 0;
            while(pos < n){
                int mcount = count==0 ? 1 : count;
                if(n - pos >= i){
                    long mval = (xsum[n-pos] - xsum[n-pos-i]) * (2*mcount+3);
                    mans = mans.add(BigInteger.valueOf(mval));
                    count++;
                    pos += i;
                }else{
                    long mval = xsum[n-pos] * (2*mcount+3);
                    mans = mans.add(BigInteger.valueOf(mval));
                    pos = n;
                }
            }
            mans = mans.add(BigInteger.valueOf((n+i)*e));
            ans = ans.min(mans);
        }

        System.out.println(ans.toString());

        
    }
}

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

int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
} 

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

int main()
{
	int a,b;
	while(cin>>a>>b) 
		cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 2956
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int modPow(long long a, long long n, long long p) {//0でバグる
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

ll comb(ll n, ll p) {
	if (p * 2 > n) p = n - p;
	if (p > n - p) p = n - p;
	ll a = 1, b = 1;
	rrep(i, p + 1) {
		a = (a * (n - i + 1)) % mod;
		b = (b * i) % mod;
	}
	return a * (modPow(b, mod - 2, mod)) % mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m, k;
	cin >> n >> m >> k;
	ll ans = 0;
	for (ll i = 0; i < n; ++i) {
		for (ll j = 0; j < m; ++j) {
			ll tmp1 = i, tmp2 = j, tmp3 = n - i - 1, tmp4 = m - j - 1;
			ll tmp = 0;
			(tmp += m * (tmp1 + 1) * tmp1 / 2) %= mod;
			(tmp += m * (tmp3 + 1) * tmp3 / 2) %= mod;
			(tmp += n * (tmp2 + 1) * tmp2 / 2) %= mod;
			(tmp += n * (tmp4 + 1) * tmp4 / 2) %= mod;
			(ans += tmp) %= mod;
		}
	}
	(ans *= comb(n * m - 2, k - 2)) %= mod;
	while (ans % 2 != 0) {
		ans += mod;
	}
	ans /= 2;
	ans %= mod;
	cout << ans << endl;
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A, B, C;

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

    std::cin >> A >> B >> C;

    int res = std::min(B / A, C);
    std::cout << res << std::endl;
}


Measured memory_bytes: 256
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            tmp = A[i]
            A[i] = A[j]
            A[j] = tmp
    tmp = A[i + 1]
    A[i + 1] = A[r]
    A[r] = tmp
    return i + 1

def resolve():
    n = int(input())
    A = [int(i) for i in input().split()]
    ans = partition(A, 0, len(A) - 1)
    print(*A[:ans], "[{}]".format(A[ans]), *A[ans + 1:])


resolve()



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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b){
        if(b<c){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


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



int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >>Y;
  vector<int> x(N,0);
  vector<int> y(M,0);
  for(int i=0;i<N;i++){
    cin >>x[i];
  }
  for(int i=0;i<M;i++){
    cin >>y[i];
  }
  x.push_back(X);
  y.push_back(Y);

  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  if(x[N] < y[0]){
    cout<<"No War"<<endl;
  }else{
    cout<<"War"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int s = max(a, c);
	int e = min(b, d);
	int ans = max(0, e - s);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int LtoR[100010], RtoL[100010];
int lower[100010], upper[100010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    rep(i, N) cin >> LtoR[i + 1];
    rep(i, N) cin >> RtoL[i];
    RtoL[N] = 0;
    int ans = 1;
    lower[0] = 1;
    upper[0] = 1000000000;
    rep(i, N) {
        if (LtoR[i] < LtoR[i + 1]) {
            lower[i] = upper[i] = LtoR[i + 1];
        } else {
            lower[i] = 1;
            upper[i] = min(RtoL[i], LtoR[i]);
        }
    }
    rrep(i, N - 1) {
        if (RtoL[i] > RtoL[i + 1]) {
            lower[i] = max(lower[i], RtoL[i]);
            upper[i] = min(upper[i], RtoL[i]);
        }
        
    }
    rep(i, N) {
        //cout << i << " " << lower[i] << " " << upper[i] << endl;
        ans = (ans * max(0LL, upper[i] - lower[i] + 1)) % mod;
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 3328
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from copy import deepcopy

INF = 10 ** 20
sys.setrecursionlimit(2147483647)

def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n=I()
G=[[]for _ in range(n)]
r=-1
for _ in range(n-1):
    a,b=LI()
    G[a]+=[b]
    G[b]+=[a]
    if len(G[a])>2:
        r=a
    if len(G[b]) > 2:
        r=b

visited=[0]*n
visited[r]=1
def f(x):
    ret=0
    cnt=0
    for v in G[x]:
        if visited[v]:
            continue
        visited[v] = 1
        r=f(v)
        ret+=r
        if r==0:
            cnt+=1
    if cnt>1:
        ret+=cnt-1
    return ret

print(1 if r == -1 else f(r))



Measured memory_bytes: 67504
#include <bits/stdc++.h>
using namespace std;
#define lll __int128
typedef long long ll;
typedef pair<int,int> pii;
typedef double lf; const lf err=1e-7;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define qwq {cout<<"qwq"<<endl;}
#define orz(x) {cout<<#x": "<<x<<endl;}
const int N=110;
const int inf=1e9;
const int mod=1e9+7;
//#define int ll
ll n,cnt=0;
string s;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	cin>>s;
	repeat(i,0,s.length()-2)
		cnt+=(s.substr(i,3)=="ABC");
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  char a[4];
  for(int i = 0; i<4; i++)cin >> a[i];
  for(int i = 0; i<3; i++){
	  if(a[i]==a[i+1]){
		  cout << "Bad" << endl;
		  exit(0);
	  }
  }
  cout << "Good" <<  endl;
  return 0;
}


Measured memory_bytes: 256
def _round(x, d=0):
    p = 10 ** d
    return (x * p * 2 + 1) // 2 / p


try:
    while 1:
        a, b, c, d, e, f = list(map(int, input().split()))
        s = (a * e - b * d)
        x = e * c - b * f
        y = -c * d + a * f

        print("{:0.3f}".format(_round(x / s, 4)), "{:0.3f}".format(_round(y / s, 4)))
except:
    pass

Measured memory_bytes: 7588
#include<stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  int C[N];
  int S[N];
  int F[N];
  
  for(int i=1;i<N;i++){
    scanf("%d",&C[i]);
    scanf("%d",&S[i]);
    scanf("%d",&F[i]);
  }

  for(int i=1;i<N;i++){
    int t=S[i];
      t+=C[i];
      for(int j=i+1;j<N;j++){
        int a = S[j];
        while(t>a){
          a+=F[j];
        }
        t=a;
        t+=C[j];
      }
    printf("%d\n",t);
  }
  printf("0\n");
  return 0;
}




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

int main() {
    string s;ll k;cin >> s >> k;
    ll q=0;

    bool w=true;
    for(int i = 1; i < s.size(); i++) {
        if(s[i]!=s[0]) w=false;
    }
    if(w){
        ll z=s.size();
        cout << z*k/2 << endl;
        return 0;
    }
    ll a=1,b=1;
    if(s[0]==s[s.size()-1]){
        
        for(int i = 1; i < s.size(); i++) {
            if(s[i]!=s[0]) break;
            a++;
        }
        for(int i = s.size()-2; i >0; i--) {
            if(s[i]!=s[0]) break;
            b++;
        }
    }
    ll c=0,d=1;
    char x=s[0];
    for(int i = 1; i < s.size(); i++) {
        if(s[i]==s[i-1]) d++;
        else{
            d/=2;
            c+=d;
            x=s[i];
            d=1;
        }
    }
    d/=2;
    c+=d;

    if(s[0]==s[s.size()-1]){
        cout << c*k+(k-1)*((a+b)/2-a/2-b/2) << endl;
    }
    else{
        cout << c*k << endl;
    }


    return 0;
}


Measured memory_bytes: 3620
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut approved = true;
    for _i in 0..n {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        if a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0) {
            approved = false;
        }
    }

    if approved {
        return String::from("APPROVED");
    } else {
        return String::from("DENIED");
    }
}

#[test]
fn test() {
    let cases: Vec<(&str, &str)> = vec![
        (
            r"5
6 7 9 10 31",
            "APPROVED"
        ),
        (
            r"3
28 27 24",
            "DENIED"
        ),
    ];

    let mut all_ok = true;
    for (i, case) in cases.iter().enumerate() {
        print!("case {} : ", i);

        let expected = case.1;
        let actual = solve(case.0);

        if expected == actual {
            println!("OK");
        } else {
            println!("NG");
            println!("    Expected: {}", expected);
            println!("    Actual  : {}", actual);

            all_ok = false;
        }
    }

    assert_eq!(all_ok, true);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
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; }
int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    int x_start = 0;
    int y_start = 0;
    for (int i=0; i<N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1 && x > x_start) {
            x_start = x;
        } else if (a == 2 && W > x) {
            W = x;
        } else if (a == 3 && y > y_start) {
            y_start = y;
        } else if (a == 4 && H > y) {
            H = y;
        }
    }

    if (y_start >= H || x_start >= W) {
        cout << 0 << endl;
    } else {
        cout << (W - x_start) * (H - y_start) << endl;
    }

    return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    int Q; cin >> Q;
    ll x = -INF;
    priority_queue<ll> l;
    priority_queue<ll,VL,greater<ll>> r;

    ll num = 0;
    ll sum = 0, sum_b = 0;
    REP(_,Q){
        int t; cin >> t;
        if(t == 1){
            ll a,b; cin >> a >> b;
            if(num%2 == 0){
                if(x <= a){
                    r.push(a);
                    l.push(x);
                    x = r.top(); r.pop();
                }
                else{
                    l.push(a);
                }
                sum += abs(a-x);
            }
            else{
                sum += abs(a-x);
                if(x <= a){
                    r.push(a);
                }
                else{
                    l.push(a);
                    r.push(x);
                    x = l.top(); l.pop();
                }
            }
            sum_b += b;
            num++;
        }
        else{
            cout << x << " ";
            ll fx = sum + sum_b;
            cout << fx << en;
        }
    }
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 3828
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
typedef  long long ll;
int N,M,P,Y;
const int maxm=(int)1e5+5;
struct city{
int p;
int y;
int i;
int flag;
city(){
    flag = 0;
}
};
city C[maxm];
int tot;
bool cmp1(city city1,city city2){
    return city1.p<city2.p ||(city1.p==city2.p&&city1.y<city2.y);
}
bool cmp2(city city1,city city2){
    return city1.i<city2.i;
}
int main(){
    scanf("%d%d",&N,&M);
    tot=0;
    memset(C,0,sizeof(C));
    for(int i=0;i<M;i++){
        struct city tmp;
        scanf("%d%d",&P,&Y);
        tmp.p=P;tmp.y=Y;tmp.i=i;
        C[tot]=tmp;
        tot++;
    }
    sort(C,C + M,cmp1);
    C[0].flag=1;
    for(int i=1;i<M;i++){
        if(C[i].p==C[i-1].p)C[i].flag=C[i-1].flag+1;
        else C[i].flag=1;
    }
     sort(C,C + M,cmp2);
     for(int i=0;i<M;i++){
        printf("%06d%06d\n",C[i].p,C[i].flag);
     }
    //for(int i=0;i<M;i++)
      //  cout<<"p:"<<C[i].p<<"y:"<<C[i].y<<"flag:"<<C[i].flag<<"i:"<<C[i].i<<endl;
    return 0;
}


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

int n, l, a[101010], k;
bool ans;

int main(){

cin >> n >> l;
rep(i, 1, n){
cin >> a[i];
}

rep(i, 1, n-1){
if(a[i]+a[i+1]>=l){
        k = i;
        ans=true;
        break;
}
}
if(ans){
    cout << "Possible" << endl;
}
else return 0*printf("Impossible");

rep(i, 1, k-1){
cout << i << endl;
}

for(int i = n-1; i>=k+1; i--){
    cout << i << endl;
}
cout << k << endl;

return 0;}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;
#define h 100100

int t[h];

int main()
{
    int n;
    cin >> n;
    int i = 1;
    while(n --)
    {
        cin >> t[i];
        i ++;
    }
    int m;
    cin >> m;
    while(m --)
    {
        int p, x;
        cin >> p >> x;
        int c;
        c = t[p];
        t[p] = x;
        int sum = 0;
        for(int j = 1; j < i; j ++)
        {
            sum += t[j];
        }
        cout << sum <<endl;
        t[p] = c;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>=(0);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)

int main(){
    int N,M;
    cin >> N >> M;
    vector<P> reqest(M);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        reqest[i] = {b,a};
    }

    sort(all(reqest));

    int ans=0,last=-1;
    rep(i,M){
        if(last < reqest[i].second){
            ++ans;
            last = reqest[i].first-1;
        }
    }

    cout << ans << endl; 
}

Measured memory_bytes: 1152
// Aizu Vol-1 0162: Hamming Numbers
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

#define MAX 1000000

char t[MAX + 10];

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

int main()
{
	int i, j, k, c, a5, a3, a2, a35;
	char *pe;
	register char *ps;

	for (i = 0, a5 = 1; i <= 8; i++, a5 *= 5) {
		for (j = 0, a3 = 1; j <= 12; j++, a3 *= 3) {
			if ((a35 = a5 * a3) > MAX) break;
			for (k = 0, a2 = 1; k <= 19; k++, a2 <<= 1) {
				if (a35 * a2 > MAX) break;
				t[a35 * a2] = 1;
			}
		}
	}
	while (1) {
		gets(p = buf);
		if (!(k = getInt())) break;
		ps = t + k, pe = t + getInt();
		for (c = 0; ps <= pe; ps++) {
			if (*ps) c++;
		}
		printf("%d\n", c);
	}
	return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <string>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

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

	int k = K; k--;
	vector<string> sub;
	REP(i, K)
	{
		REP(j, S.length() - i)
		{
			sub.push_back(S.substr(j, i + 1));
		}
		sort(sub.begin(), sub.end());
		unique(sub.begin(), sub.end());
	}

	cout << sub[k] << endl;
	return 0;
}

Measured memory_bytes: 1660
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[] arrived = new boolean[n];
        arrived[0] = true;
        int arrivedCnt = 1;
        int[] ans = new int[n];
        ArrayList<ArrayList<Integer>> map = new ArrayList<>();
        for(int i = 0; i < n; i++){
            map.add(new ArrayList<Integer>());
        }
        for(int i = 0; i < m; i++){
            int a = sc.nextInt()-1;
            int b = sc.nextInt()-1;
            map.get(a).add(b);
            map.get(b).add(a);
        }
        Deque<Integer> q = new ArrayDeque<Integer>();
        q.add(0);
        while(q.size() > 0){
            int now = q.poll();
            for(int next : map.get(now)){
                if(arrived[next]){
                    continue;
                }else{
                    arrived[next] = true;
                    ans[next] = now+1;
                    arrivedCnt++;
                    q.add(next);
                }
            }
        }
        if(arrivedCnt != n){
            System.out.println("No");
        }else{
            System.out.println("Yes");
            for(int i = 1; i < n; i++){
                System.out.println(ans[i]);
            }
        }
    }
    
}
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
 
    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }
 
    public long nextLong() {
        return Long.parseLong(next());
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public double nextDouble() {
         return Double.parseDouble(next());
    }
 
    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }
 
    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 69460
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var num = int.Parse(Console.ReadLine());
        var vals = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        var costs = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); ;

        var max = 0;
        for (var i = 0; i < num; i++)
        {
            if (vals[i] <= costs[i]) continue;
            max = max + vals[i] - costs[i];
        }

        Console.Write(max);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  if(s.at(0)!='A'){
    cout<<"WA"<<endl;
    return 0;
  }
  string sub=s.substr(2, (s.size()-3));
  int count_c=0;
  for(int i=0;i<(sub.size());i++){
    if (sub.at(i)=='C'){count_c++;}
  }
  if(count_c!=1){
    cout<<"WA"<<endl;
    return 0;
  }
  int count_upper=0;
  for(int i=0;i<(s.size());i++){
    char c=s.at(i);
    if(isupper(c)){count_upper++;}
  }
  if(count_upper!=2){
    cout<<"WA"<<endl;
  } else {
    cout<<"AC"<<endl; 
  }
}

Measured memory_bytes: 768
#include <iostream>
#include <queue>
#include <cfloat>

using namespace std;

class State
{
public:
	double _time; //©©Á½Ô
	int _speed; //¬x
	int _town; //»Ýn
	int _utern; //OñÌ¬it^[Ö~j
	State(double time,int speed,int town,int utern)
		:_time(time),_speed(speed),_town(town),_utern(utern){}
	bool operator<(const State& tmp) const
	{
		return _time > tmp._time;
	}
};

class Edge
{
public:
	int _d; //£
	int _c; //§À¬x
	Edge(){}
	Edge(int d,int c):_d(d),_c(c){}
};

int main()
{
	for(;;)
	{
		//Init
		int n,m,s,g;
		cin >> n >> m;
		if(n==0 && m==0) break;

		cin	>> s >> g;
		--s;
		--g;

		Edge *Graph[30][30];
		for(int i=0;i<30;i++)
		{
			for(int j=0;j<30;j++)
			{
				Graph[i][j] = NULL;
			}
		}

		for(int i=0;i<m;i++)
		{
			int x,y,d,c;
			cin >> x >> y >> d >> c;
			--x;
			--y;
			Graph[x][y] = new Edge(d,c);
			Graph[y][x] = new Edge(d,c);
		}

		bool Visited[30][30][30]; //»Ýn@t^[Ö~@¬x
		double Cost[30][30][30];
		for(int i=0;i<30;i++)
		{
			for(int j=0;j<30;j++)
			{
				for(int k=0;k<30;k++)
				{
					Visited[i][j][k] = false;
					Cost[i][j][k] = DBL_MAX;
				}
			}	
		}

		priority_queue<State> PQ;
		PQ.push(State(0.0,0,s,s));
		Cost[s][s][0] = 0;

		double min_time = -1;

		//Dijkstra
		while(!PQ.empty())
		{
			State tmp = PQ.top();
			PQ.pop();
			if(Visited[tmp._town][tmp._utern][tmp._speed] == true) continue;
			//cout << "time " << tmp._time << " town "<< tmp._town+1 << " speed " << tmp._speed << endl;
			if(tmp._town == g && tmp._speed == 1)
			{
				min_time = tmp._time;
				break;
			}
			Visited[tmp._town][tmp._utern][tmp._speed] = true;

			for(int i=0;i<n;i++)
			{
				if(tmp._utern == i) continue;
				if(Graph[tmp._town][i] != NULL)
				{
					for(int j=-1;j<=1;j++)
					{
						int tmp_speed = tmp._speed + j;
						if(Visited[i][tmp._town][tmp_speed] == true) continue;
						if(tmp_speed <= 0) continue;
						if(tmp_speed > Graph[tmp._town][i]->_c) continue;
						double tmp_time = Graph[tmp._town][i]->_d / static_cast<double>(tmp_speed);
						tmp_time += tmp._time;
						if(Cost[i][tmp._town][tmp_speed] < tmp_time) continue;
						Cost[i][tmp._town][tmp_speed] = tmp_time;
						PQ.push(State(tmp_time,tmp_speed,i,tmp._town));
					}
				}
			}
		}

		//Output
		if(min_time == -1)
		{
			cout << "unreachable" << endl;
		}else
		{
			cout << min_time << endl;
		}

		//Free
		for(int i=0;i<30;i++)
		{
			for(int j=0;j<30;j++)
			{
				if(Graph[i][j] != NULL) delete Graph[i][j];
			}
		}
	}
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int n = S.size();
    int count = 0;
    for(int i=0; i<n/2; i++){
        if (S.at(i)!=S.at(n-1-i)) count++;
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
plus = []
minus = []
zero = 0
for i in map(int, input().split()):
    if i > 0:
        plus.append(i)
    elif i < 0:
        minus.append(i)
    else:
        zero += 1
plus.sort()
minus.sort(reverse=True)


def solve(mid):
    global N, K, zero
    cnt = 0
    if mid >= 0:
        cnt += len(plus) * len(minus)
        if mid > 0:
            cnt += zero * (zero - 1) // 2 + zero * (N - zero)
            for L in (plus, minus):
                l, r = 0, len(L) - 1
                while l < r:
                    while l < r and L[l] * L[r] >= mid:
                        r -= 1
                    cnt += r - l
                    l += 1
    else:
        r = len(minus) - 1
        for l in range(len(plus)):
            while r >= 0 and plus[l] * minus[r] < mid:
                r -= 1
            cnt += len(minus) - (r + 1)
    return cnt < K


# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok, ng = -10 ** 19, 10 ** 19
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 87000
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
 public static void Main(string[] args)
 {
   var s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
   var strList = new List<string>();
   for(var i=0; i<=s[0]; i++)
   {
    var line = Console.ReadLine();
    strList.Add(line);
   }
   strList.Sort();
   var ans = String.Join("", strList);
   Console.WriteLine(ans);
 }
}

Measured memory_bytes: 11488
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        final int C = sc.nextInt();

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

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

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

        int answer = 0;
        for (int i = 0; i < N; ++i) {
            int sum = C;
            for (int j = 0; j < M; ++j) {
                sum += A[i][j]*B[j];
            }
            if (sum > 0) {
                answer++;
            }
        }

        System.out.println(answer);
        System.out.flush();
        sc.close();
    }
}


Measured memory_bytes: 23252