akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<long long> a(n), f(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	for(int i = 0; i < n; i++) scanf("%lld", &f[i]);
	sort(a.begin(), a.end());
	sort(f.rbegin(), f.rend());
	long long l = -1;
	long long r = 1e12;
	while(abs(l - r) > 1) {
		long long mid = (l + r) / 2;
		bool ok = [&] {
			long long s = 0;
			for(int i = 0; i < n; i++) {
				s += max(0LL, a[i] - mid / f[i]);
			}
			return s <= k;
		}();
		if(ok) r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int a, b, c; cin >> a >> b >> c;

    c >= a ? b >= c ? cout << "Yes" : cout << "No" : cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> a(n + 2);
  vector<ll> b(n + 2);
  REP(i, n)
  {
    cin >> a[i + 1];
  }
  b[1] = 0;
  REP(i, n)
  {
    if ((i + 1) % 2 == 1)
    {
      b[1] += a[i + 1];
    }
    else
    {
      b[1] -= a[i + 1];
    }
  }
  for (ll i = 2; i <= n; i++)
  {
    b[i] = 2 * a[i - 1] - b[i - 1];
  }
  REP(i, n)
  {
    cout << b[i + 1];
    if (i != n - 1)
      cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, i;
    string a, b;
    cin >> N >>  a >> b;
    string ans;
    ans = "";
    for(i = 0; i < N; i++){
        ans += a[i];
        ans += b[i];
        
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1,gtest=1;
//	cin>>test;
	while(test--)
	{
		int a,b,k;
		cin>>k>>a>>b;
		int g=a/k;
		b/=k;
		if(a%k==0 || ((b)-(g))!=0)
		cout<<"OK";
		else
		cout<<"NG";
	}
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	int a[50], b[50], c[50];
	cin >> n;
	ff(i, 0, n) {
		cin >> a[i];
	}
	a[n] = 52;
	ff(i, 0, n) {
		cin >> b[i];
	}
	ff(i, 0, n-1) {
		cin >> c[i];
	}
	c[n]=0;
	int ans = 0;
	ff(i, 0, n) {
		ans += b[a[i]-1];
		if (a[i]+1 == a[i + 1]) {
			ans += c[a[i]-1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
 
fn main() {
  input! {
    n: usize,
    ais: [usize;n]
  }

  let mut copied = ais.clone();
  copied.sort();
  let max = copied[n-1];
  let second_max = copied[n-2];

  for v in ais {
    if max == v {
      println!("{}", second_max);
    } else {
      println!("{}", max);
    }
  }
}

Measured memory_bytes: 7196
#include <iostream>
#include <utility>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 1000000001
#define MOD 998244353
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef pair<int, int> pr_int;




int main()
{
	//freopen("input.txt", "r", stdin);
	int n;
	scanf("%d", &n);
  	vector<string> s(n);
  	for(int i = 0; i < n; ++i)
		cin >> s[i];
  	for(int i = 0; i < n; ++i)
		sort(s[i].begin(), s[i].end());
 	sort(s.begin(), s.end());
  	ll d = 0;
  	for(ll i = 0; i < n; ++i)
    {
      	ll j = i;
      	while(j < n && s[j] == s[i])
          j++;
      	d += (j-i)*(j-i-1)/2;
      	i = j-1;
    }
  	printf("%lld", d);

	return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int M,D;

	cin >> M >> D;

	int ans=0;
	for(int m=1;m<=M;m++)
	{
		for(int d=1;d<=D;d++)
		{
			int d1=d%10;
			int d2=d/10;
			if(d1>=2 && d2>=2 && d1*d2==m)
				ans++;
		}
	}

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



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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int N;
    string S;
    cin >> N >> S;
    int pre = S[0];
    int cnt = 1;
    for (int i = 1; i < N; ++i) {
        if (S[i] == pre) {

        } else {
            pre = S[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define __gnu_pbds::gp_hash_table unordered_map;
#define int long long int
#define pb push_back

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

int n;
cin>>n;
string a,b;
cin>>a>>b;
for(int i=0;i<n;i++)
cout<<a[i]<<b[i];


}

Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

for i in range(N - K):
    if T[i] == T[i + K]:
        T[i + K] = ""

ans = 0
for i in range(N):
    if T[i] == "r":
        ans += P
    elif T[i] == "s":
        ans += R
    elif T[i] == "p":
        ans += S

print(ans)


Measured memory_bytes: 49392
#include<iostream>
#include<vector>
#include<string>

using ll = long long;

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> score(n);
    ll sum = 0;
    ll minNOT10 = 1000;
    for(int i = 0; i < n; i++){
        std::cin >> score[i];
        sum += score[i];
        if(score[i] % 10 != 0){
            minNOT10 = std::min(minNOT10, score[i]);
        }
    }

    if(minNOT10 == 1000){
        std::cout << 0 << std::endl;
    }else{
        if(sum % 10 != 0) std::cout << sum << std::endl;
        else std::cout << sum - minNOT10 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	cout << fixed << setprecision(15);
	ld l;
	cin >> l;
	cout << pow(l/3.0, 3.0) << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
string s;
int a,b,c;
int main(){
cin >> s;
for(int i=0;i<3;i++){
if(s[i]=='a')a++;
if(s[i]=='b')b++;
if(s[i]=='c')c++;
}
if(a==1 and b==1 and c==1)cout << "Yes";
else cout << "No";
return 0;
}

Measured memory_bytes: 256
n = int(input())
a = map(int,raw_input().split())
p = int(input())
m = map(int,raw_input().split())
def goukei(i,m):
  if m ==0:
    return True
  if i >= n or m > sum(a):
    return False
  r = goukei(i + 1, m) or goukei(i + 1, m - a[i])
  return r
 
for u in range(0,p):

  if goukei(0, m[u]):
    print "yes"
  else:
    print "no"

Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, a, b; cin >> n >> a >> b;
    if (b < a) cout << 0 << endl;
    else {
        if (n == 1) cout << (a == b) << endl;
        else cout << (b-a) * (n-2) + 1 << endl;
    }
    return 0;
}

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

int main()
{
    ll n;cin>>n;
    int ans=0;
    for(ll i=2;i<1000000;++i){
        int k=0;
        while(n%i==0){
            n/=i;
            k++;
        }
        for(int j=1;j<1000;++j){
            k-=j;
            if(k<0)break;
            ans++;
        }
    }
    if(n>1)ans++;
    cout<<ans;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

const int coin[] = {1,5,10,50,100,500};
const int inf = 999999999;
int c[6],p;

int oturi(int x){
	int ret = 0;
	for(int i=5; i>=0 && x>0; i--){
		ret += (x/coin[i]);
		x -= (x/coin[i])*coin[i];
	}
	return ret;
}
int pay(int x){
	int ret = 0;
	for(int i=5; i>=0 && x>0; i--){
		ret += min(x/coin[i], c[i]);
		x -= min(x/coin[i],c[i]) * coin[i];
	}
	return x==0 ? ret : -1;
}
int main(){
	while(scanf("%d",&p),p){
		scanf("%d%d%d%d%d%d",c,c+1,c+2,c+3,c+4,c+5);
		int sum = 0;
		int ret = INT_MAX;
		
		rep(i,6)sum += coin[i]*c[i];
		
		for(int i=p; i<=sum; i++){
			int t = pay(i);
			if( t!=-1 ){
				ret = min(ret, t+oturi(i-p));
			}
		}
		printf("%d\n",ret);
	}
	return 0;
}

Measured memory_bytes: 880
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    string call;
    N %= 10;
    switch(N){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            call = "hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            call = "pon";
            break;
        case 3:
            call = "bon";
    }
    cout << call << endl;
}


Measured memory_bytes: 3624
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto a = readln.chomp[0];
  auto b = readln.chomp[1];
  auto c = readln.chomp[2];
  writeln(a,b,c);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

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

    std::vector<int> p(n);
    std::cin >> p.at(0) >> p.at(1);
    int count = 0;
    for(int i = 2; i < n; ++i){
        std::cin >> p.at(i);
        if(p.at(i - 2) < p.at(i - 1) && p.at(i - 1) < p.at(i)){
            ++count;
        }else if(p.at(i - 2) > p.at(i - 1) && p.at(i - 1) > p.at(i)){
            ++count;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 256
// In the name of Allah the Lord of the Worlds.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

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

    int x , a;
    cin >> x >> a;
    if(x<a)cout << "0" << endl;
    else cout << "10" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
const int N = (int) 1e5;
int n,k;
long long a[N+5],ans=(long long)2e16;
int main()
{
 
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    cin>>a[i];
     for(int i=1;i+k-1<=n;i++)
    {  
        int l=i,r=i+k-1;
        ans=min(ans,a[r]-a[l]+min(abs(a[l]),abs(a[r])));
    }
    cout<<ans;
    return 0;}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 10000000000

int main(){
  ll N,X,M;
  cin>>N>>X>>M;
  vector<ll> A(M+2);
  set<ll> s;
  A[0]=X;
  s.insert(A[0]);
  int left,right;
  for(int i=1;i<=M+1;i++){
    A[i]=A[i-1]*A[i-1]%M;
    if(s.count(A[i])==1){
      right=i;
      break;
    }
    s.insert(A[i]);
  }
  for(int i=0;i<right;i++){
    if(A[i]==A[right]){
      left=i;
      break;
    }
  }

  ll ans=0;
  for(int i=0;i<left;i++){
    ans+=A[i];
    N--;
    if(N==0){
      break;
    }
  }
  if(N==0){
    cout<<ans<<endl;
  }else{
    ll cnt=N/((ll)right-(ll)left);
    ll sub=0;
    for(int i=left;i<right;i++){
      sub+=A[i];
    }
    ans+=cnt*sub;
    ll res=N%((ll)right-(ll)left);
    for(int i=left;i<left+res;i++){
      ans+=A[i];
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 6336
let str = require('fs').readFileSync('/dev/stdin', 'UTF-8');
const W = Number(str.split(' ')[0]);
const H = Number(str.split(' ')[1]);
const x = Number(str.split(' ')[2]);
const y = Number(str.split(' ')[3]);
const r = Number(str.split(' ')[4])

if (((x - r) >= 0 && (x + r) <= W) && ((y - r) >= 0 && (y + r) <= H)) {
  console.log('Yes');
} else {
  console.log('No');
};


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

using namespace std;

int main(){
	int N;
	cin>>N;
    int h;
    int m=0;
    cin>>m;
    int c=1;
    for(int i=1; i<N; ++i){
        cin>>h;
        if(m<=h){
            c++;
            m=h;
        }
    }
    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
ans = 0
for i in range(2 ** (len(S) - 1)):
    js = 0
    for j in range(len(S)):
        if i >> j & 1 == 1:
            ans += int(S[js:j+1])
            js = j+1
        elif j == len(S)-1:
            ans += int(S[js:j+1])
            
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define debug(a) cout << a << endl;
const ll INF = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int a,b,c; cin >> a >> b >> c;
    if(a == b && b == c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
x = int(input())
a = []
b = []
t = 0
for i in range(-1000,1000):
    t = i**5
    a.append([t,i])
    b.append([t,i])
    
for i in a:
    for j in b:
        if i[0]-j[0] == x:
            print(i[1],j[1])
            sys.exit()

Measured memory_bytes: 66284
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main{


	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		char[] num = scanner.nextLine().toCharArray();

		String flag = "AC";

		//#1
		if(num[0] != 'A')flag = "WA";

		//#2
		int cnt  = 0;
		for(int i = 2; i < num.length - 1; i++) {

			if(num[i] == 'C') {

				cnt++;
			}else if(Character.isUpperCase(num[i])) {

				flag = "WA";
				break;
			}
		}

		if(Character.isUpperCase(num[1]) || cnt != 1)flag = "WA";
		if(Character.isUpperCase(num[num.length - 1]))flag = "WA";

		System.out.println(flag);



	}
}


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

int main() {
	// your code goes here
	int n,i;
	long long a[100005],b[100005],ans=0;
	cin >> n;
	for(i=0;i<=n;i++) cin >> a[i];
	for(i=1;i<=n;i++) cin >> b[i];
	for(i=1;i<=n;i++){
		ans+=min(a[i-1],b[i]);
		b[i]=max(0ll,b[i]-a[i-1]);
		if(b[i]>0){
			ans+=min(a[i],b[i]);
		}
		a[i]=a[i]-min(a[i],b[i]);
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edge(N);
  vector<int> height(N);
  rep(i, N) { cin >> height[i]; }
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  int result = 0;
  rep(i, N) {
    bool c = true;
    for (int e : edge[i]) {
      c = c && (height[i] > height[e]);
    }
    if (c) {
      result++;
    }
  }
  cout << result << endl;

  return 0;
}

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

int main(){
	int n, m;
	while( cin >> m >> n , n || m ){
		vector<int> v(n);
		for(int i=0 ; i < n ; i++ ){
			cin >> v[i];
		}
		
		// 二分探索で幅を求める
		int low=1, high=1500000, mid=-1, prev;
		while( true ){
			prev = mid;
			mid = (low + high) / 2;
			// 前と同じ結果のとき
			if( prev == mid ) break;
			
			// pos := 収めたい本の番号
			// v[pos] := pos 番目の本の厚さ
			int pos=0;
			// 段数 m だけループして本棚に収まる厚さの本を収めていく.
			for(int i=0 ; i < m ; i++ ){
				// width := m 段目の残りの本棚の幅
				int width = mid;
				while( true ){ 
					if( width >= v[pos] ){ // 本が収まるとき
						width -= v[pos];
						pos++;
						// すべての本を収めた時
						if( pos >= v.size() ) break;
					}else{ // 本が収まらないとき
						break;
					}
				}
				// すべての本を収めた時
				if( pos >= v.size() ) break;
			}
			// すべての本を収めた時
			if( pos >= v.size() ){
				high = mid+1;
			}else{
				low = mid-1;
			}
		}
		cout << mid+1 << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll a,b,d;
	cin>>a>>b>>d;
	int cnt = 0;
	for(int i=a;i<=b;i++){
		if(i%d==0)cnt++;
	}
	cout<<cnt<<"\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 3596
n, m = map(int,input().split())
s = input()
t = input()
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
g = gcd(n, m)
l = n * m // g
for i in range(0, g):
  if s[i * n//g] != t[i * m//g]:
    print('-1')
    exit()
print(l)

Measured memory_bytes: 3316
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string s,t;
  cin>>s>>t;
  cout<<t+s<<endl;
  
  
  
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//各種nil
template <class T>
constexpr T nil = static_cast<T>(-1);

constexpr int nil_i = nil<int>;
constexpr int nil_ll = nil<ll>;
constexpr double nil_d = nil<double>;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
struct Vec2D
{
    T x, y;
};

void solve()
{
    using namespace std;
    int n, l;
    cin >> n >> l;
    vector<string> v(n);
    for (auto& s : v) cin >> s;

    sort<>(v.begin(), v.end(), 
        [](string lhs, string rhs)
    {
        return lhs.compare(rhs) < 0;
    });

    for (auto s : v)
        cout << s;
    cout << endl;

}

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

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

map <pair <int, int>, int> c;
int cnt[10];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    auto check = [&] (int x, int y) {
        if (x + 2 > h || y + 2 > w) {
            return false;
        }
        return true;    
    };
    while (n--) {
        int x, y;
        cin >> x >> y;
        for (int a = -2; a < 1; a++) {
            for (int b = -2; b < 1; b++) {
                if (x + a < 1 || y + b < 1 || x + a > h || y + b > w || !check(x + a, b + y)) {
                    continue;
                }
                c[{x + a, y + b}]++;
            }
        }
    }
    for (auto to : c) {
        cnt[to.second]++;
    }
    ll total = (h - 2) * (ll) (w - 2);
    ll s = 0;
    for (auto to : cnt) s += to;
    total -= s;
    cout << total << '\n';
    for (int i = 1; i < 10; i++) {
        cout << cnt[i] << '\n';
    }
    return 0;
} 

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

namespace B
{
    public class Program

    {
        public static void Main(string[] args)
        {
            int[] nmc = RIntAr();
            int[] bs = RIntAr();

            int cnt = 0;
            for (int k = 0 ; k < nmc[0] ; k++)
            {
                int[] cur = RIntAr();
                int sum = nmc[2];
                for (int i = 0 ; i < nmc[1] ; i++)
                {
                    sum += cur[i] * bs[i];
                }
                if (sum > 0) cnt++;
            }         
            Console.WriteLine(cnt);
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}


Measured memory_bytes: 13140
#include <iostream>
#include<string.h>

using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && a != c || b == c && b != a || c == a && c != b) cout << "Yes";
	else cout << "No";
	return 0;

	
}

Measured memory_bytes: 3640
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for l in range(n)]
b=[[int(i) for i in input().split()] for l in range(m)]
for A in a:
    c=1
    r=0
    m=10000000000
    for B in b:
        k=abs(A[0]-B[0])+abs(A[1]-B[1])
        if m>k:
            m=k
            r=c
        c+=1
    print(r)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

int main(int argc, char** argv)
{
	int n, m;
	std::cin >> n >> m;

	std::vector<std::vector<int>> mat;
	std::vector<int> vec;
	for (int i = 0; i < n; ++i)
	{
		std::vector<int> tmp;
		for (int j = 0; j < m; ++j)
		{
			int v;
			std::cin >> v;
			tmp.push_back(v);
		}
		mat.push_back(tmp);
	}

	for (int i = 0; i < m; ++i)
	{
		int v;
		std::cin >> v;
		vec.push_back(v);
	}

	for (int i = 0; i < n; ++i)
	{
		int v = 0;
		for (int j = 0; j < m; ++j)
		{
			v += mat[i][j] * vec[j];
		}

		std::cout << v << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3172
import scala.io.StdIn

object Main extends App {
  val inputs = StdIn.readLine().split(" ")
  val stack = inputs.foldLeft(new Stack()){ (acc, elem) => acc.push(elem) }
  println(stack.pop)
}

class Stack(val elems: List[String]){
  def this() = this(Nil)

  def push: (String) => Stack = {
    case "+" =>
      val (x1, x2, xs) = pop2
      new Stack((x1 + x2).toString :: xs)
    case "-" =>
      val (x1, x2, xs) = pop2
      new Stack((x2 - x1).toString :: xs)
    case "*" =>
      val (x1, x2, xs) = pop2
      new Stack((x1 * x2).toString :: xs)
    case elem =>
      new Stack(elem :: elems)
  }

  def pop: String = elems.head

  def pop2: (Int, Int, List[String]) = {
    elems match {
      case x1 :: x2 :: xs =>
        (x1.toInt, x2.toInt, xs)
      case _ => (0, 0, elems)
    }
  }
}

Measured memory_bytes: 43792
#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;

int main(){

    int c[21][21],w,h;
    memset(c,0,sizeof(c));
    char t;
    while(1){
    cin>>w>>h;if(w==0&&h==0)return 0;
    for(int i=0;i<w*h;i++){cin>>t;c[i%w][i/w]=t;}
    for(int i=0;i<w*h;i++){
      for(int j=0;j<w*h;j++)
        if(c[j%w][j/w]==64){
	  if(c[j%w-1][j/w]==46)c[j%w-1][j/w]=64;
          if(c[j%w+1][j/w]==46)c[j%w+1][j/w]=64;
          if(c[j%w][j/w-1]==46)c[j%w][j/w-1]=64;
          if(c[j%w][j/w+1]==46)c[j%w][j/w+1]=64;
        }
    }
    int cou=0;
    for(int i=0;i<w*h;i++)if(c[i%w][i/w]==64)cou++;
    cout<<cou<<endl;
    } 
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
string s;

bool solve(string ans) {
  rep(i, 1, n) {
    if(ans[i] == 'S') {
      if(s[i] == 'o') {
        ans += "S";
      }else {
        ans += "W";
      }
    }else {
      if(s[i] == 'o') {
        ans += "W";
      }else {
        ans += "S";
      }
    }
    if(ans[i - 1] == 'W') ans[i + 1] = ans[i + 1] == 'W' ? 'S' : 'W';
  }
  if(ans[n] == ans[0]) {
    ans.pop_back();
    if(ans[0] == 'S') {
      if(s[0] == 'o') {
        if(ans[n - 1] != ans[1]) return false;
      }else {
        if(ans[n - 1] == ans[1]) return false;
      }
    }else {
      if(s[0] == 'o') {
        if(ans[n - 1] == ans[1]) return false;
      }else {
        if(ans[n - 1] != ans[1]) return false;
      }
    }
    cout << ans << endl;
    return true;
  }

  return false;
}

signed main() {
  cin >> n >> s;

  if(solve("SS")) return 0;
  if(solve("SW")) return 0;
  if(solve("WW")) return 0;;
  if(solve("WS")) return 0;

  cout << -1 << endl;
}


Measured memory_bytes: 684
#include <bits/stdc++.h>
#define ull unsigned long long
#define mem 26
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  string s;
  cin>>s;
  int n = s.length();
  int j = n-1;
  ull moves=0;
  for(int i=n-1;i>=0;i--) {
    if(s[i]=='B') {
      moves+=(j-i);
      j--;
    }
  }
  cout<<moves;
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 720
a,b,k = map(int,input().split())
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

d = gcd(a,b)
def make_divisors(n):
    divisors = []
    for  i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
div = make_divisors(d)
print(div[-k])

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)


void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(int *)> f) {
	int indexes[20];
	recursive_comb(indexes, n - 1, k, f);
}

ll num(vector<int> A) {
	ll ans = 0;
	for (int i = 0; i < A.size();i++) {
		ans += A[i] * pow(10, A.size() - i-1);
	}
	return ans;

}

int main() {
	int i, j, k;

	string S;
	cin >> S;
	ll X = stoll(S);
	int A[11] = { 0 };
	rep(i, 0, S.size()) {
		A[i] = S[i] - '0';
	}

	int flag;
	int N = S.size();
	ll ans =X ;
	for (i = 1; i < N; i++) {
		foreach_comb(N-1, i, [&ans, i, N, A, S](int *ind) {
			vector<int> B;
			int k = 0;
			for (int j = 0; j < N; j++) {
				B.push_back(A[j]);
				if (ind[k] == j) {
					ans += num(B);
					k++;
					B.clear();
				}

			}
			ans += num(B);
			B.clear();

		});
	
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll h, w;
bool c(ll a, ll b){
  if(a>=0&&a<h&&b>=0&&b<w) return true;
  return false;
}
int main(int argc, char const *argv[]) {
  std::cin >> h >> w;
  vector<string> d(h);
  vvl num = vv(h, w, 0, ll);
  re(i, h) std::cin >> d[i];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(d[i][j]=='#') continue;
      for(int l=-1;l<=1;l++){
        for(int r=-1;r<=1;r++){
          if(c(i+l, j+r)&&d[i+l][j+r]=='#') num[i][j]++;
        }
      }
    }
  }
  re(i, h){
    re(j, w){
      if(d[i][j]=='#') std::cout << "#";
      else std::cout << num[i][j];
    }
    std::cout << '\n';
  }
}


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

using lint = long long int;

int main(){
    string s;

    cin >> s;
    if(s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[0]){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
using namespace std;

int main() {

	unsigned long long a = 0.0;
	unsigned long long b = 0.0;
	unsigned long long c = 0.0;
	cin >> a;
	cin >> b;
	cin >> c;

	unsigned long long lv = 4 * a * b;
	unsigned long long rv = (c - a - b) * (c - a - b);

	if (c < (a + b)) {
		cout << "No" << endl;
	}
	else {
		if (lv < rv) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 256
A, B, C, X = [int(input()) for _ in range(4)]
res = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if X == 500 * i + 100 * j + 50 * k:
                res += 1
print(res)


Measured memory_bytes: 9168
N,A,B,C,D = map(int,input().split())
S = input()
A -= 1
B -= 1
C -= 1
D -= 1

def check1(l,r):
    if S[l:r+1].count("##") > 0:
        return False
    return True

def check2():
    if S[B-1:D+2].count("...") > 0:
        return True
    return False

if C < D:
    if check1(A,C) and check1(B,D):
        ans = "Yes"
    else:
        ans = "No"
elif D < C:
    if check1(B,D) and check2():
        ans = "Yes"
    else:
        ans = "No"
else:
    ans = "No"

print(ans)

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



int main() {
int r,g,x;
cin>>r>>g;
x=2*g-r;
cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
using namespace std;
const int N=4005,M=2e5+5,mod=1e9+7;
int n,x[M],y[M],f[N][N],fac[N<<1],inv[N<<1],ans;
void init(int n){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	rep (i,2,n) fac[i]=(ll)fac[i-1]*i%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	rep (i,2,n) inv[i]=(ll)inv[i-1]*inv[i]%mod;
}
int C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main(){
	scanf("%d",&n); init(8000);
	rep (i,1,n) scanf("%d%d",&x[i],&y[i]),f[2001-x[i]][2001-y[i]]++;
	rep (i,1,4001) rep (j,1,4001) f[i][j]=((ll)f[i][j]+f[i-1][j]+f[i][j-1])%mod;
	rep (i,1,n) ans=(ans+mod-C(2*(x[i]+y[i]),2*x[i]))%mod;
	rep (i,1,n) ans=(ans+f[2001+x[i]][2001+y[i]])%mod;
	ans=(ll)ans*((mod+1)/2)%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 64512
dic = {'A': 0, 'B': 1, 'AB': 2, 'O': 3}
sumlist = [0, 0, 0, 0]
while(1):
    try:
        i = raw_input()
        num, blood = i.split(',')
        sumlist[dic[blood]] += 1
    except:
        break
for i in sumlist:
    print i

Measured memory_bytes: 4200
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

#define MOD 1000000007
int N;
int X[100000];
map<int, bool> b;

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> X[i];
  }
  long long s = 1;
  int l = 0;
  for (int k=0; k<N; k++) {
    long long a = N-k;
    for (; l<N-k; l++) {
      if (l*2+1 <= X[l+k]) {
      }
      else {
        a = l+1;
        break;
      }
    }
    s = (s*a) % MOD;
  }
  cout << s <<"\n";
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
      	String s = sc.next();
      	
      if(a >= 3200){
        System.out.println(s);
      }else{
        System.out.println("red");
      }
    }
}

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

using namespace std;

int lib[5], k;

int main(){
	for(int i = 0; i < 5; i++)
		scanf("%d", &lib[i]);

	scanf("%d", &k);

	bool flag = true;
	for(int i = 0; i < 5; i++){
		for(int j = i; j < 5; j++){
			if(abs(lib[i]-lib[j]) > k){
				flag = false;
			}
		}
	}

	if(flag) printf("Yay!\n");
	else printf(":(\n");

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-10;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int K, R, L;
ld P;
ld E;
ld T;

ld getans(const ld amin, const ld amax, const int rest, const ld per) {
	if (!rest ) {
		return abs((amin + amax) / 2 - T) < E + eps;
	}
	if (amin > E + T + eps)return 0;
	if (amax < T - E - eps)return 0;
	if (amin > T - E - eps&&T + E + eps > amax)return 1;
	ld amid = (amin + amax) / 2;
	if (amid > T - eps) {
		return getans(amin, amid, rest - 1, per*(1 - P))*(1 - P) + getans(amid, amax, rest - 1, per*P)*P;
	}
	else {
		return getans(amin, amid, rest - 1, per*P)*P + getans(amid, amax, rest - 1, per*(1 - P))*(1 - P);
	}
}
int main() {
	cin >> K >> R >> L;
	cin >> P >> E >> T;
	ld ans = getans(R, L, K, 1);
	cout << setprecision(22) << fixed << ans << endl;
	return 0;
	
}

Measured memory_bytes: 3288
#line 2 "codes/header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "codes/solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    int x;cin>>x;
    int ans = lcm(x, 360) / x;
    cout << ans << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 
////////////////////////////////////////////////////////////////////////////////


int main(){
   
    vector<int> a(3);
    
    for(int i =0;i<3;i++) cin >> a[i] ;  
    
    int fc = count(all(a),5);
    int sc = count(all(a),7);
    
    if( fc == 2 && sc ==1)cout <<"YES"<<endl;
    else cout << "NO"<<endl;
        
   
     
}


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

#define	mp	make_pair

using namespace std;

int main(){
	for(int n;cin>>n,n;){
		pair< pair<int,int>,pair<int,char> > data[10];
		for(int i=0;i<n;i++){
			char nm;	cin>>nm;
			int res[3]={0};
			for(int j=0,t;j<n-1;j++)	cin>>t,res[t]++;
			data[i]=mp(mp(-res[0],res[1]),mp(i,nm));
		}
		sort(data,data+n);
		for(int i=0;i<n;i++)	cout<<data[i].second.second<<endl;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef pair<int, int> pii;

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;

int N, M;

struct UnionFind {
	vector<int> data;
	vector<int> dist;
	UnionFind(int _size) : data(_size, -1), dist(_size, iINF) {}
	
	bool unionSet(int x, int y, int d) {
		pii px = root(x), py = root(y);
		x = px.first; y = py.first;

		if (x != y) {
			data[x] += data[y];
			data[y] = x;
			dist[y] = d + px.second - py.second;
		}
		
		return x != y;
	}
	
	pii root(int x) {
		if (data[x] < 0) {
			dist[x] = 0;
			return pii(x, 0);
		}
		
		pii p = root(data[x]);
		data[x] = p.first;
		dist[x] += p.second;
		return pii(data[x], dist[x]);
	}
	
	int dist_of(int i) { return dist[i]; }
};

void solve() {
	UnionFind uf(N + 10);
	
	for_(i,0,M) {
		char c;
		int a, b, w;
		cin >> c;
		
		if (c == '!') {
			cin >> a >> b >> w;
			pii pa = uf.root(a), pb = uf.root(b);
			if (pa.first != pb.first) uf.unionSet(a, b, -w);
		} else {
			cin >> a >> b;
			pii pa = uf.root(a), pb = uf.root(b);
			if (pa.first == pb.first) {
				cout << ( uf.dist_of(a) - uf.dist_of(b) ) << endl;
			} else {
				cout << "UNKNOWN" << endl;
			}
		}
	}
}

int main() {
	while (cin >> N >> M, N) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 2796
def bellmanford(s,v,es):
    n=len(es)
    negative=False
    d=[inf for _ in xrange(v)]
    d[s]=0
    for i in xrange(n):
        update=False
        for fr,to,cost in es:
            if fr!=float('inf') and d[to]>d[fr]+cost:
                d[to]=d[fr]+cost
                update=True
                if i==n-1:
                    negative=True
        if not update:
            break
    return d,negative

inf=float('inf')
V,E,r=map(int,raw_input().split())
es=[map(int,raw_input().split()) for _ in xrange(E)]
d,negative=bellmanford(r,V,es)
if negative:
    print("NEGATIVE CYCLE")
else:
    for i in d:
        print(i if i<inf else "INF")

Measured memory_bytes: 6628
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int M;

template<class T>
class FenwickTree{
	vector<T> a;
public:
	FenwickTree(int n):a(n){}
	T sum(int i,int j)const{
		if(i==0){
			T s=0;
			for(;j>=0;j=(j&(j+1))-1) s=(s+a[j])%M;
			return s;
		}
		return (sum(0,j)-sum(0,i-1)+M)%M;
	}
	void add(int i,T v){
		for(;i<a.size();i|=i+1) a[i]=(a[i]+v)%M;
	}
};

int ofset;
char s[100001][16];
bool lex(int a,int b){
	return strcmp(s[a-ofset],s[b-ofset])<0;
}

int main(){
	for(int a,b;scanf("%d%d%d",&a,&b,&M),a;){
		int n=b-a+1,seq[100000];
		ofset=a;
		rep(i,n){
			seq[i]=a+i;
			sprintf(s[i],"%d",seq[i]);
		}
		sort(seq,seq+n,lex);

		FenwickTree<int> F(b-a+1);
		rep(i,n) F.add(seq[i]-a,F.sum(0,seq[i]-a)+1);

		printf("%d\n",F.sum(0,n-1));
	}

	return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	string S;
	cin >> S;
	N = S.length();
	ll ans = 0;
	ll htmp = 0;
	vl h(N + 1, 0);
	rep(i, N) {
		if (S[i] == '<') {
			h[i + 1] = max(h[i] + 1, h[i + 1]);
		}
	}
	rep(j, N) {
		int i = N - 1 - j;
		if (S[i] == '>') {
			h[i] = max(h[i + 1] + 1, h[i]);
		}
	}
	rep(i, N+1) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N,H;
    cin >> N >> H;
    vector<pair<ll,ll>> a(N),b(N);
    rep(i,N){
        cin >> a[i].first >> b[i].first;
        a[i].second = i;
        b[i].second = i;
    }
    sort(a.begin(), a.end(), greater<pair<ll,ll>>());
    sort(b.begin(), b.end(), greater<pair<ll,ll>>());
    ll maxa = a[0].first;
    ll cnt = 0;
    if(maxa >= b[0].first){
        cout << (H + maxa - 1) / maxa << endl; //ceil((H/double(a[0].first))) << endl;
        return 0;
    }
    ll rec=-1;
    rep(i,N){
        if(b[i].first > maxa && b[i].second != a[0].second){
            H -= b[i].first;
            cnt++;
        }else if(b[i].first > maxa){
            H -= b[i].first;
            cnt++;
            rec = i;
        }
        if(H <= 0){
            cout << cnt << endl;
            return 0;
        }
    }
    //H -= b[rec].first;
    //cnt++;
    if(H > 0){
        
        cnt += (H + maxa -1) / maxa;//ceil(H/double(maxa));
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3328
/*
      author  : nishi5451
      created : 14.08.2020 18:14:34
*/

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


int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    int tot=0;
    rep(i,n){
        cin >> a[i];
        tot += a[i];
    }
    sort(a.begin(),a.end());
    cout << n+(x-tot)/a.front() << endl;
    return 0;
}

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

using namespace std;
using LL = long long;
using VI = vector<int>;
using PI = pair<int, int>;

int main() {
	int n;
	while (cin >> n) {
		if (!n) break;
		vector<double> s(n, 0);
		double m = 0;
		for (auto & e : s) {
			cin >> e;
			m += e;
		}
		m /= n;
		double a = 0;
		for (int i = 0; i < n; i++) {
			a += pow(s[i] - m, 2);
		}
		cout << setprecision(8) << fixed << sqrt(a / n) << endl;
	}


	return 0;
}



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


def solve(N: int, A: str, B: str, C: str):

    ans = 0
    for i in range(N):
        if(A[i] == B[i] == C[i]):
            continue
        elif(A[i] == B[i] or B[i] == C[i] or A[i] == C[i]):
            ans += 1
        else:
            ans += 2

    print(ans)

    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()
    N = int(next(tokens))  # type: int
    A = next(tokens)  # type: str
    B = next(tokens)  # type: str
    C = next(tokens)  # type: str
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	
      	int num = sc.nextInt();
      	int nums[] = new int[num];
      	int c[] = new int[4];
      	String str[] = {"AC","WA","TLE","RE"};
      	String stack;
      
      	for(int i = 0;i < 4;i++) c[i] = 0;
      
      	for(int i = 0;i < num;i++) {
          stack = sc.next();
          for(int j  = 0;j < 4;j++) {
          	if(str[j].equals(stack)) c[j]++; 
          }
       	}
      
      	for(int i = 0;i < 4;i++) System.out.println(str[i] +" x " +c[i]);
        
	}
}

Measured memory_bytes: 58492