akhauriyash/Code-Regression huggingface dataset:
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<10000) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<10000) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 300932
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
#define mod 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;

int main(){
    int a[5];
    vector<int> v;
    int flag=0;
    rep(i,5)cin>>a[i];
    rep(i,5){
        if(a[i]%10==0)v.push_back(10);
        else{
            v.push_back(a[i]%10);
            flag++;
        }
    }
    sort(v.begin(),v.end());
    int sum=0;
    rep(i,5)sum+=a[i];
    if(flag==0||flag==1){
    }
    else if(flag>1){
        sum+=(flag-1)*10;
        rep(i,flag-1){
            sum-=v.at(i+1);
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int> A1(N),A2(N);
  for (int i=0; i<N; i++) cin >> A1.at(i);
  for (int i=0; i<N; i++) cin >> A2.at(i);
  
  int res = 0;
  for (int i=0; i<N; i++) {
    int r=0,n = 0;
    for (; n<=i; n++) {
      r += A1.at(n);
    }
    n--;
    for (; n<N; n++) {
      r += A2.at(n);
    }
    res = max(res,r);
  }
  
  cout << res << endl;
  
}

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

void fail(){
	cout<<"NO"<<endl;
	exit(0);
}
char g[1000][1000];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	memset(g,'.',sizeof g);
	if(n==1){
		if(b!=0||a*2>m)	fail();
		for(int i=0;i<a;i++)
			g[0][i<<1]='<',g[0][i<<1|1]='>';
	}
	else if(m==1){
		if(a!=0||b*2>n)	fail();
		for(int i=0;i<b;i++)
			g[i<<1][0]='^',g[i<<1|1][0]='v';
	}
	else if(n%2==0&&m%2==0){
		for(int i=0;i<n;i+=2)
			for(int j=0;j<m;j+=2){
				if(a){
					if(a){
						g[i][j]='<';
						g[i][j+1]='>';
						a--;
					}
					if(a){
						g[i+1][j]='<';
						g[i+1][j+1]='>';
						a--;
					}
				}
				else if(b){
					if(b){
						g[i][j]='^';
						g[i+1][j]='v';
						b--;
					}
					if(b){
						g[i][j+1]='^';
						g[i+1][j+1]='v';
						b--;
					}
				}
			}
		if(a||b)	fail();
	}
	else if(n%2==1&&m%2==1){
		for(int i=0;i+1<n;i+=2)
			if(b){
				g[i][m-1]='^';
				g[i+1][m-1]='v';
				b--;
			}
		for(int i=0;i+1<m;i+=2)
			if(a){
				g[n-1][i]='<';
				g[n-1][i+1]='>';
				a--;
			}
		if(a+b>(n-1)*(m-1)/2)	fail();
		if(a+b==(n-1)*(m-1)/2&&a%2==1){
			a--;b--;
			g[n-3][m-2] = '<';
			g[n-3][m-1] = '>';
			g[n-3][m-3] = '^';
			g[n-2][m-3] = 'v';
			g[n-2][m-1] = '^';
			g[n-1][m-1] = 'v';
		}
		for(int i=0;i+1<n;i+=2)
			for(int j=0;j+1<m;j+=2){
				if(a){
					if(a){
						g[i][j]='<';
						g[i][j+1]='>';
						a--;
					}
					if(a){
						g[i+1][j]='<';
						g[i+1][j+1]='>';
						a--;
					}
				}
				else if(b){
					if(b){
						g[i][j]='^';
						g[i+1][j]='v';
						b--;
					}
					if(b){
						g[i][j+1]='^';
						g[i+1][j+1]='v';
						b--;
					}
				}
			}
		if(a||b)	fail();
	}
	else if(n%2==1){
		for(int i=0;i+1<m;i+=2)
			if(a){
				g[n-1][i]='<';
				g[n-1][i+1]='>';
				a--;
			}
		for(int i=0;i+1<n;i+=2)
			for(int j=0;j+1<m;j+=2){
				if(a){
					if(a){
						g[i][j]='<';
						g[i][j+1]='>';
						a--;
					}
					if(a){
						g[i+1][j]='<';
						g[i+1][j+1]='>';
						a--;
					}
				}
				else if(b){
					if(b){
						g[i][j]='^';
						g[i+1][j]='v';
						b--;
					}
					if(b){
						g[i][j+1]='^';
						g[i+1][j+1]='v';
						b--;
					}
				}
			}
		if(a||b)	fail();
	}
	else{
		for(int i=0;i+1<n;i+=2)
			if(b){
				g[i][m-1]='^';
				g[i+1][m-1]='v';
				b--;
			}
		for(int i=0;i+1<n;i+=2)
			for(int j=0;j+1<m;j+=2){
				if(a){
					if(a){
						g[i][j]='<';
						g[i][j+1]='>';
						a--;
					}
					if(a){
						g[i+1][j]='<';
						g[i+1][j+1]='>';
						a--;
					}
				}
				else if(b){
					if(b){
						g[i][j]='^';
						g[i+1][j]='v';
						b--;
					}
					if(b){
						g[i][j+1]='^';
						g[i+1][j+1]='v';
						b--;
					}
				}
			}
		if(a||b)	fail();
	}
	cout<<"YES\n";
	for(int i=0;i<n;i++,cout<<'\n')
		for(int j=0;j<m;j++)
			cout<<g[i][j];
}


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

int conv(int x)
{
    int point=0;
    while(x/500>=1)
    {
        point += 1000;
        x -= 500;
    }
    while(x/5>=1)
    {
        point += 5;
        x-= 5;
    }
    return point;
}

int main()
{
    int x;
    cin >> x;
    int hap_point = conv(x);
    cout << hap_point;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
dic = {}
for i in range(n):
  elem = input()
  if not elem in dic:
    dic[elem] = 1
  else:
    dic[elem] += 1
max_ = max(dic.values())

res = []
for k, v in dic.items():
  if v == max_:
    res.append(k)

res = sorted(res)
for elem in res:
  print(elem)

Measured memory_bytes: 32988
a[10];
int dfs(int l,int r,int i){
  if(i>9)return 1;
  if(a[i]>l&&dfs(a[i],r,i+1))return 1;
  if(a[i]>r&&dfs(l,a[i],i+1))return 1;
  return 0;
}
main(n){
  scanf("%d",&n);
  for(;n;n--)scanf("%d%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]),dfs(0,0,0)?puts("YES"):puts("NO");
  return 0;
}

Measured memory_bytes: 0
#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(){
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll an = min(a, k);
	k -= an;
	ll bn = min(b, k);
	k -= bn;
	ll cn = min(c, k);
	k -= cn;
	cout << an - cn << endl;
	return 0;
}


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

using namespace std;

int main(){
	char n[3];
	cin>>n[0]>>n[1]>>n[2];
	for(int i=0;i<=2;i++){
		if(n[i]=='7'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
/*input
3 0
1000000000 1000000000 1000000000
*/

#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>

using namespace std;

void run() {
	int n, k, i, j=0;
	cin >> n >> k;
	vector<int> h(n);
	for(i=0; i<n; i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end(), greater<>());
	ll ret = 0;
	while(k < n) {
		ret += (ll)h[k];
		k++;
	}
	cout << ret << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	//cin >> t;
	while(t--) {
		run();
	}
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N;
    cin >> N;
    vector<ll> a(N), b(N);

    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    ll sum_a = 0, sum_b = 0;
    rep(i, N) {
        if (a[i] < b[i]) sum_b += (b[i] - a[i]) / 2;
        if (a[i] > b[i]) sum_a += a[i] - b[i];
    }

    if (sum_b >= sum_a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3792
A,B,C,D = map(int,input().split())

import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
A -= 1
s = lcm(C,D)
X =  A - (A//C + A //D - A//s)
Y =  B - (B//C + B //D - B//s)
print(Y-X)

Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m=0,tmp=0,ax=0,k=0,t[500000],p[500000],x,y,res[5000],a,b,c,GCD,two=1,kisuu=0;
	string str, str2[5000];
	cin >> n>>a>>b;
	

	if (n == 1 && a != b) { cout << "0"; return 0; }

	if (n == 1 && a == b) { cout << "1"; return 0; }

	if (b<a) { cout << "0"; return 0; }

	cout << (n - 1)*b + a - (n - 1)*a - b+1;
}

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


int main()
{
	string a;
    cin >> a;

    int i;
    i = 0;
    int sum;
    sum = 0;

    string b;

    while (true) {
        if (!a[i]) break;
        b = a[i];
        const char* c = b.c_str();
        sum = sum + stoi(c);
        i++;
    }

    if (sum % 9) cout << "No" << endl;
    else cout << "Yes" << endl;
}



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

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

  int a,b;cin>>a>>b;
  cout<<(a-b+1)<<endl;
  
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<cmath>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

string S;
bool flg=true;

int main() {
	cin>>S;
	int n=S.size();
	for(int i=0;i<n/2;i++)flg&=(S[i]==S[n-1-i]);
	for(int i=0;i<n/2/2;i++)flg&=(S[i]==S[n/2-1-i]);
	cout<<(flg?"Yes":"No")<<endl;
	return 0;
}



Measured memory_bytes: 384
#include <stdio.h>
 int main(void)
{
	int d[3];
	int b=0;
	int i,n;
	int a=0,c=0,f=0;
	
	for(i=0; i<3; ++i)
	scanf("%d",&d[i]);
	
	for(i=0; i<3; ++i){
		for(n=i+1; n<3; ++n){
			if(d[i] > d[n]) {
				b = d[i];
				d[i] = d[n];
				d[n] = b;
			}
		}
	}
		c = d[1] - d[0];
		f = d[2] - d[1];
		a = c+f;
		printf("%d\n",a);
		
		
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector<pair<ll,P> >edge;
ll x[100005];
struct uf{
	int par[100005],ran[100005];
	ll sum[100005];
	void init(){
		for(int i=1;i<=n;i++){
			par[i] = i; ran[i] = 0; sum[i] = x[i];
		}
	}
	int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
	ll get(int x){ return sum[find(x)]; }
	void unite(int x,int y,bool bad){
		x = find(x); y = find(y);
		if(ran[x] < ran[y]){
			par[x] = y;
			if(bad) ran[y] = ran[y]+ran[x]+1;
			else ran[y] = 0;
			sum[y] += sum[x];
		}
		else{
			par[y] = x;
			if(bad) ran[x] = ran[y]+ran[x]+1;
			else ran[x] = 0;
			sum[x] += sum[y];
		}
	}
	void add_ran(int x){ ran[find(x)]++; return; }
	int get_ran(int x){ return ran[find(x)]; }
	bool same(int x,int y){ return find(x)==find(y); }
}kaede;
int main(){
	scanf("%d%d",&n,&m);
	repn(i,n) scanf("%lld",&x[i]);
	for(int i=0;i<m;i++){
		int a,b; ll y; scanf("%d%d%lld",&a,&b,&y);
		edge.pb(mp(y,mp(a,b)));
	}
	sort(edge.begin(),edge.end());
	kaede.init();
	for(int i=0;i<edge.size();i++){
		ll cs = edge[i].fi;
		int u = edge[i].sc.fi, v = edge[i].sc.sc;
		if(kaede.same(u,v)){
			if(kaede.get(u) < cs){
				kaede.add_ran(u);
			}
		}
		else{
			ll sum = kaede.get(u) + kaede.get(v);
			bool flag = false;
			if(sum < cs) flag = true;
			kaede.unite(u,v,flag);
		}
	}
	cout << kaede.get_ran(1) << endl;
}

Measured memory_bytes: 4336
import sys
input = sys.stdin.buffer.readline

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    l, r = 0, N-1
    MOD = 10**9+7
    if K == N:
        ans = 1
        for num in A:
            ans *= num
            ans %= MOD
        print(ans)
        exit()
    elif A[-1] < 0 and K%2 == 1:
        ans = 1
        for i in range(K):
            ans *= A[-i-1]
            ans %= MOD
        print(ans)
        exit()
    ans = 1
    if K%2 == 1:
        ans *= A[-1]
        r -= 1
    for _ in range(K//2):
        nl = A[l]*A[l+1]
        nr = A[r]*A[r-1]
        if nl > nr:
            ans *= nl
            l += 2
        else:
            ans *= nr
            r -= 2
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 100736
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int mul = a * b;

        if (mul % 2 == 1) {
            System.out.println("Odd");
        } else {
            System.out.println("Even");
        }
    }
}

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

public static class Program {
    public static void Main() {
        int[]nq=Console.ReadLine().Split().Select(int.Parse).ToArray();
        int n=nq[0];
        int q=nq[1];

        int N=1;
        while(N<n)N*=2;
        n=N;
        N=2*n;
        int inf=int.MaxValue;
        int[]table=new int[N];
        for(int i=0;i<N;i++){
            table[i]=inf;
        }

        for(int t=0;t<q;t++){
            int[]query=Console.ReadLine().Split().Select(int.Parse).ToArray();
            if(query[0]==0){
                int i=query[1]+n;
                int x=query[2];
                table[i]=x;
                for(i/=2;1<=i;i/=2){
                    table[i]=Math.Min(table[i*2],table[i*2+1]);
                }
            }else{
                int l=query[1]+n;
                int r=query[2]+n+1;
                int ans=inf;
                for(;l!=r;l/=2,r/=2){
                    if(l%2==1)ans=Math.Min(ans,table[l++]);
                    if(r%2==1)ans=Math.Min(ans,table[--r]);
                }
                Console.WriteLine(ans);
            }
        }
    }
}




Measured memory_bytes: 23040
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 2010

ll asum[SIZE*2];
bool visited[SIZE];
vector<pair<int,ll> > vec[SIZE];

ll dfs(int i, int now, int back = -1, int area = 0){
  ll res = -LLINF;

  if(i == 0){
    if(visited[now]) return area * 2;
    else return 0;
  }

  
  if(visited[now]) return -LLINF;
  visited[now] = true;

  if(i == 1) res = 0;
  
  for(int j=0;j<vec[now].size();j++){
    if(vec[now][j].first != back)
      res = max(res, dfs(i-1, vec[now][j].first, now, vec[now][j].second));
  }
  
  visited[now] = false;
  return res + area * 2;
}

bool solve(){
  int n, q, s;
  int p[SIZE][3];

  scanf("%d%d%d", &n, &q, &s);

  if(n == 0) return false;
  
  for(int i=0;i<n;i++){
    vec[i] = vector<pair<int, ll> >();
    for(int j=0;j<3;j++)
      scanf("%d", p[i]+j);
  }

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int d[3];
      for(int k=0;k<3;k++){
        int minp = max(p[i][k], p[j][k]);
        int maxp = min(p[i][k], p[j][k])+s;

        d[k] = max(0, maxp - minp);
      }

      if(!d[0] || !d[1] || !d[2]) continue;

      ll sum = (ll)d[0] * d[1] + (ll)d[1] * d[2] + (ll)d[2] * d[0];
      //debug(sum);
      vec[i].push_back({j, sum});
      vec[j].push_back({i, sum});
      //cerr << i << " " << j << " " << sum << endl;
    }
  }

  ll ans = -LLINF;
  
  for(int i=0;i<n;i++){
    ans = max(ans, dfs(q, i));
  }
  
  if(ans + s * s * 6 * q < 0){
    puts("-1");
  }else{
    printf("%lld\n", (ll)s * s * 6 * q - ans);
  }
  
  return true;
}

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



Measured memory_bytes: 3296
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <map>
#include <string.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <vector>

using namespace std;
#define set_precision cout << fixed << setprecision(10)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define replb(i, a, b) for (ll i = a; i >= b; i--)
#define repl(i, a, b) for (ll i = a; i < b; i++)
#define repit(arr) for (auto it = arr.begin(); it != arr.end(); it++)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
#define pb push_back
#define ll long long
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');
#define castl static_cast<ll>
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
}
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
}
int cel(int a,int b){return((a-1)/b+1);} 
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
} 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t, n;string s1;
    cin >> n;int c1=0,c2=0,c3=0,c4=0;
    rep(i,0,n){
        cin>>s1;
        if(s1=="AC")c1++;
        else if(s1=="WA")c2++;
        else if(s1=="TLE")c3++;
        else if(s1=="RE")c4++;
    }
    cout<<"AC x "<<c1<<"\n";
    cout<<"WA x "<<c2<<"\n";
    cout<<"TLE x "<<c3<<"\n";
    cout<<"RE x "<<c4<<"\n";
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define cincout ios::sync_with_stdio(false)
#define mp make_pair
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef map<int, int> mii;

int n;
ll a;
ll mins = 2e9;
int cnt=0;
ll total=0;

int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a;
		if(abs(a)<mins) mins=abs(a);
		if(a<0) cnt++;
		total+=abs(a);
	}
	if(cnt%2==0){
		cout << total <<endl;
	}else {
		cout << total-2*mins <<endl;
	}
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(N: Int, A: IntArray){
    A.map{ 1/it.toDouble() }.sum().let{ println(1/it) }
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val A = IntArray(N)
    for (i in 0 until N) {
        A[i] = sc.next().toInt()
    }
    solve(N, A)
}



Measured memory_bytes: 29704
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
#from __future__ import print_function, division    #while using python2

def is_valid(x):
    # print(x)
    # input()
    return str(x).count('7') == len(str(x))

def main():
    #sys.stdin = open('input.txt', 'r')
    #sys.stdout = open('output.txt', 'w')

    k = int(input())
    s = 7

    for i in range(1, int(1e6)+5):
        if s % k == 0:
            print(i)
            return
        s = (s * 10 + 7) % k
    print(-1)

#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

if __name__ == '__main__':
   main()


Measured memory_bytes: 63192
#include <stdio.h>
#define NUM (60)

int main(void)
{
    int num_sec;
    int seconds,minutes,hours;

    scanf("%d",&num_sec);

    seconds = num_sec % NUM;
    minutes = (num_sec/NUM)%NUM;
    hours = (num_sec/NUM)/NUM;

    printf("%d:%d:%d\n",hours,minutes,seconds);
    return (0);
}

Measured memory_bytes: 1768
#include <iostream>
using namespace std;
	typedef long long ll;
int main() {
	ll q,h,s,d,n;
	cin>>q>>h>>s>>d>>n;
	h = min(h, 2*q);
	s = min(s, 2*h);
	d = min(d, 2*s);
	cout<<(n/2)*d + (n%2)*s<<'\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i,  n, q, nq, t, x;
  fscanf(stdin, "%d %d", &n, &nq);
  int **stack = (int**)malloc(sizeof(int*)*n);
  int *sp = (int*)malloc(sizeof(int)*n);
  for (i=0; i<n; i++) {
    stack[i] = (int*)malloc(sizeof(int)*nq);
    sp[i]=-1;
  }
  
  for (i=0; i<nq; i++) {
    fscanf(stdin, "%d %d", &q, &t);
    switch (q) {
    case 0:
      fscanf(stdin, "%d", &x);
      stack[t][++sp[t]] = x;
      break;
    case 1:
      if (sp[t]>=0)
	printf("%d\n", stack[t][sp[t]]);
      break;
    case 2:
      if (sp[t]>=0) sp[t]--;
    }
  }
  return 0;
}



Measured memory_bytes: 6492
from math import gcd
from functools import reduce
from collections import Counter

class Factorize:
    def __init__(self):
        self.primes = Counter()

    def add_target(self, n):
        for i in range(2, int(n**0.5)+1):
            while n%i==0:
                self.primes[i] += 1
                n //= i
            if not n:
                break
        if n>1:
            self.primes[n] += 1
    
    def get_result(self):
        return dict(self.primes)

N = int(input())
*A, = map(int, input().split())
def f():
    cnt = Counter()
    for i in A:
        ins = Factorize()
        ins.add_target(i)
        res = ins.get_result()
        for j in res.keys():
            cnt[j] += 1
            if cnt[j] >= 2:
                return False
    return True

cond1 = f()
cond2 = (reduce(gcd, A)==1)

if cond1:
    print("pairwise coprime")
elif cond2:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 199764
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[N];
		int[] w = new int[N];
		for(int i=0; i<N; i++){
			v[i] = sc.nextInt();
			w[i] = sc.nextInt();
		}
		int[][] dp = new int[N+1][W+1];
		for(int i=0; i<N; i++){
			for(int j=0; j<W+1; j++){
				if(j>=w[i]){
					dp[i+1][j] = Math.max(dp[i][j], dp[i][j-w[i]]+v[i]);
				}
				else{
					dp[i+1][j] = dp[i][j];
				}
			}
		}
		System.out.println(dp[N][W]);
	}
}


Measured memory_bytes: 30980
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from collections import deque
    from itertools import combinations

    h, w = map(int, readline().split())
    a = list()
    cnt = 0
    for i in range(h):
        s = input()
        cnt += s.count("#")
        a.append(s)

    if cnt != (h + w - 1):
        return print("Impossible")

    for per in combinations(range(h + w - 2), h - 1):
        cr, cc = 0, 0
        for i in range(h + w - 2):
            if i in per:
                cr += 1
            else:
                cc += 1
            if a[cr][cc] == ".":
                break
            if (cr, cc) == (h - 1, w - 1):
                return print("Possible")
    return print("Impossible")


if __name__ == '__main__':
    main()


Measured memory_bytes: 73824
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  int N, T, L, B;
  while(cin >> N >> T >> L >> B, N||T) {
    bool Lose[N+1], Back[N+1];
    CLR(Lose); CLR(Back);
    FOR(i,0,L) {
      int l; cin >> l;
      Lose[l] = true;
    }
    FOR(i,0,B) {
      int b; cin >> b;
      Back[b] = true;
    }
    // i???????????????j??????????¢??????§1???1?????????
    double dp[T+1][N+1][2]; CLR(dp);
    dp[0][0][0] = 1.0;
    FOR(i,0,T) {
      // i + 1 ???????????????
      FOR(j,0,N+1) {
        // ??????????????\??????
        dp[i+1][j][0] += dp[i][j][1];
        for(int k = j - 1; k >= j - 6 && k >= 0; k--) {
          if(Lose[j]) dp[i+1][j][1] += dp[i][k][0] / 6.0;
          else if(Back[j]) dp[i+1][0][0] += dp[i][k][0] / 6.0;
          else dp[i+1][j][0] += dp[i][k][0] / 6.0;
        }
        if(j == N) continue;
        // ????°?????????\???
        int N2 = N - j + N;
        for(int k = N - 1; k >= 0 && k >= N2 - 6; k--) {
          if(Lose[j]) dp[i+1][j][1] += dp[i][k][0] / 6.0;
          else if(Back[j]) dp[i+1][0][0] += dp[i][k][0] / 6.0;
          else dp[i+1][j][0] += dp[i][k][0] / 6.0;
        }
      }
    }
    double ans = 0;
    FOR(i,0,T+1) {
      ans += dp[i][N][0];
    }
    printf("%.10lf\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3204
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb push_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e6+5;
char s[N];int n,k;
inline void print(R char *s){s[n]='\0',printf("%s\n",s);}
void solve(R int k){
	R int i=1;
	while(i<=n&&k--){
		R int op=(i<=n?((i-1)&1):((n-1)&1));
		if((s[i]=='A')^op){s[i]=(s[i]=='A'?'B':'A');continue;}
		s[i+n]='A',++i;
	}
	if(i<=n){
		R int op=(i-1)&1;
		fp(k,i,i+n-2){
			if(op)s[k]=(s[k]=='A'?'B':'A');
			if(k+1>n)op^=1;
		}
		s[i+n-1]='A';
		return print(s+i);
	}
	if(n&1^1){
		fp(i,1,n)s[i]=((i&1)?'B':'A');
		print(s+1);
		return;
	}
	R int op=(n-1)&1;
	if(op)--k;
	s[n]=(k&1?'B':'A');
	fp(i,1,n-1)s[i]=((i&1)?'A':'B');
	reverse(s+1,s+1+n);
	print(s+1);
}
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	solve(k);
	return 0;
}

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

int main() {
    int x, a,b;
    cin >> x;
    for(int i=0; i<=1000; i++){
        bool flag=false;
        for(int j=i; j>=-1000; j--){
            if(i*i*i*i*i-j*j*j*j*j==x){
                a=i;
                b=j;
                flag=true;
                break;
            }
        }
        if(flag) break;
    }
    cout << a << " " << b;
}

Measured memory_bytes: 3548
#include<iostream>
#include<algorithm>
using namespace std;
int n,key,cnt,ans;
int t[1000001];
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i];
    t[n]=ans=-1;
    sort(t,t+n);
    key=t[0];
    cnt=1;
    for(int i=1;i<=n;i++){
      if(key==t[i])cnt++;
      else{
	if(cnt>n/2)ans=key;
	key=t[i];
	cnt=1;
      }
    }
    if(ans==-1)cout<<"NO COLOR"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b;

    if((a % 2 == 1) && (b % 2 == 1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;

}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		String n = "";
		for (int i = 0; i < N.length(); i++) {
			if (String.valueOf(N.charAt(i)).equals("9")) {
				n+="1";
			}else  {
				n+="9";
			}
		}
		System.out.println(n);
		sc.close();
	}
}

Measured memory_bytes: 21332
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 2050
struct edge{int t,next;}ed[N*2];
int head[N],cnt,n,mn[N],mx[N],sz[N],a,b,as=1e9;
char is[N];
void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}
void dfs(int u,int fa)
{
	sz[u]=(is[u]=='1');mn[u]=mx[u]=0;
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs(ed[i].t,u),mx[u]+=mx[ed[i].t]+sz[ed[i].t],sz[u]+=sz[ed[i].t];
	for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)mn[u]=max(mn[u],mn[ed[i].t]+mx[ed[i].t]-mx[u]+sz[ed[i].t]*2);
}
int main()
{
	scanf("%d%s",&n,is+1);
	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);
	for(int i=1;i<=n;i++)dfs(i,0),as=min(as,(mn[i]||(mx[i]&1))?1000000000:mx[i]/2);
	printf("%d\n",as>1e8?-1:as);
}

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

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int n, r;
    cin >> n >> r;

    if(n == 0 && r == 0) break;

    vector<int> v(n);
    REP(i,n){
      v[i] = n - i;
    }

    REP(i,r){
      int c, p;
      cin >> p >> c;

      vector<int> tmp(c+p-1);
      REP(i,c+p-1){
        if(i < c){
          tmp[i] = v[i+p-1];  
        }else{
          tmp[i] = v[i-c];
        }

      }
      REP(i,c+p-1){
        v[i] = tmp[i];
      }

    }

    cout << v[0] << endl;
  }
  return 0;
}




Measured memory_bytes: 3092
#include<string>
#include<iostream>
#include<stdio.h>
#include<queue>

/*day4 a*/
using namespace std;
const int H = 51;
const int W = 51;
char board[H][W];
int guide[8][2] = { { -1,0 },{ -1,-1 },{ -1,1 },{ 0,1 },{ 0,-1 },{ 1,0 },{ 1,1 },{ 1,-1 } };

int dfs(int i,int j,int h,int w)
{
	int time=0;
	if (board[i][j] == '.')
	{
		for (int k = 0; k < 8; k++)
		{
			int ii = i + guide[k][0];
			int jj = j + guide[k][1];
			if (board[ii][jj] == '#'&&ii >= 0 && ii < h&&jj >= 0 && jj < w)
				time++;
		}
	}
	return time;
}

int main()
{
	int h, w;
	while (cin >> h >> w)
	{
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
			{
				cin >> board[i][j];
			}
		for (int i = 0; i < h; i++)
			for (int j = 0; j < w; j++)
				dfs(i, j, h, w);
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (board[i][j] == '.')
					cout << dfs(i, j, h, w);
				else
					cout << board[i][j];
			}
			cout << endl;
		}
	}
	//system("pause");
}

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

using namespace std;

const unsigned long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % MOD;
       base = base * base % MOD;
    }
    return tot;
}

vector<pair<int, int>> red, blu;

vector<vector<int>> event;

int main(){

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    for(int i = 0; i < n; ++i){
        int a, b; cin >> a >> b;
        event.push_back({a, b, 0});
    }
    for(int i = 0; i < n; ++i){
        int a, b; cin >> a >> b;
        event.push_back({a, b, 1});
    }

    sort(event.begin(), event.end());

    set<int> pq;
    int cnt = 0;

    for(auto i : event){
        int x = i[0], y = i[1], t = i[2];
        if(t == 0){
            //cout << "INSERT " << x << " " << y << endl;
            pq.insert(y);
        } else if(!pq.empty()){

            if(pq.begin() == pq.upper_bound(y))
                continue;

            pq.erase((*--pq.upper_bound(y)));

            ++cnt;


            //if(!pq.empty() && pq.top() < y){
            //    pq.pop(); ++cnt;
            //}
        }
    }

    cout << cnt;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define INF 1e+10
#define MAX_V 10
 
 
// <最短距離, 頂点の番号>
using P = pair<int, int>;

 
 
signed main(){
    int n;
    cin >> n;
    int a[n][n];
    int b[n][n];
    int t=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];

            b[i][j]=a[i][j];
        }
     
    }
   
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            for(int k=0;k<n;k++){
                if(a[i][j] > a[i][k]+a[j][k]){
                    t=1;
                    break;
                }
                if(i!=k&&j!=k&&a[i][j] == a[i][k]+a[j][k]){b[i][j]=0;b[j][i]=0;}
            }
        }
        
    }
  
      int ans=0;
    if(t==1){ans = -1;
    }
    else{
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                ans+=b[i][j];
            }
        }
    }
   cout << ans;
     return 0;
    }
   




Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
	int n,x;
	while(cin >> n >> x,n){
		int ans = 0;
		loop(i,1,n+1)loop(j,i+1,n+1)loop(k,j+1,n+1){
			if(i+j+k == x){
				ans++;
			}
		}
		cout << ans << endl;
	}

}



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

using namespace std;

int main(){
  int s;
  int w;
  cin >> s >> w;
  cin.ignore();

  if(w >= s){
    cout << "unsafe" << endl;
    return 0;
  } else {
    cout << "safe" << endl;
    return 0;
  }
  return 0;
}


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

int main( void )
{
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H( N );
  double max = 100000;
  int maxi = 0;
  
  for( int i = 0; i < N; i++ ) {
    cin >> H.at( i );
    if( abs( (double)( T - H.at( i ) * 0.006 ) - (double)A ) < max ) {
      //cout << "TEST" << endl;
      max = abs( ( T - H.at( i ) * 0.006 ) - A );
      maxi = i;
    }
  }
  cout << maxi + 1 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
struct state{
  int n,lx,ly,ux,uy;
  state(int n=0,int lx=0,int ly=0,int ux=0, int uy=0):n(n),lx(lx),ly(ly),ux(ux),uy(uy){}
  bool operator < (const state &s) const {
    return lx == s.lx ? ly < s.ly : lx < s.lx;
  }
};
 
int n,a[10],cnt;
bool f[10];
vector<state> in;
 
void func(vector<state> v){
  int c;
  sort(v.begin(), v.end());
 
  for(int i=0;i<v.size();i++){
    if(f[v[i].n]) continue;
    vector<state> v2;
     
    a[v[i].n] = cnt++;
    f[v[i].n] = true;
 
    c = v.size();
    for(int j=i+1;j<v.size();j++){
      if(v[j].ly < v[i].uy && v[j].uy > v[i].uy){
        c = j;
        break;
      }
    }
    for(int j=i+1;j<c;j++){
      if(!f[v[j].n] && (c == v.size() || v[c].lx >= v[j].ux) && v[j].uy <= v[i].uy){
        v2.push_back(v[j]);
      }
    }
    if(v2.size() > 0) func(v2);
 
  }
 
}
 
void solve(){
  fill(a,a+10,0);
  fill(f,f+10,false);
  cnt = 1;
  func(in);
 
  for(int i=0;i<n;i++) cout << a[i] << endl;
}
 
int main(){
  bool f = false;
  while(cin >> n && n){
    in.clear();
    if(f) cout << endl;
    else f = true;
    for(int i=0;i<n;i++){
      int x,y,x2,y2;
      cin >> x >> y >> x2 >> y2;
      in.push_back(state(i,min(x,x2),min(y,y2),max(x,x2),max(y,y2)));
    }
    solve();
  }
}

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

int main () {
  string S , T ;
  cin >> S >> T ; 
  int j =0 ; 
  
  for (int i = 0 ; i < 3 ; i++){
    if ( S.at(i) == T.at(i)){
      j++ ; 
    }
    
  }
  
  cout << j << endl ;
  
}

Measured memory_bytes: 3624
import sys
import bisect
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
b_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls = [int(i) for i in sys.stdin.readline().split()]
a_ls.sort()
b_ls.sort()
c_ls.sort()
comb_a = []
comb_b = []
len_b = len(b_ls)
len_c = len(c_ls)
for a in a_ls:
    ind = len_b - bisect.bisect_right(b_ls, a)
    comb_a.append(ind)

prod_b = []
res = 0
for b in b_ls[::-1]:
    ind = len_c - bisect.bisect_right(c_ls, b)
    comb_b.append(ind)
    res += ind
    prod_b.append(res)
comb_b = comb_b[::-1]
_sum = 0
for a in comb_a:
    if a <= 0:
        continue
    _sum += prod_b[a-1]
print(_sum)

Measured memory_bytes: 105060
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 切り替えポイントで出せる速度：両側から見てminを取る
# あとは中を構成する

N = I()
t = LI()
v = [0] + LI() + [0]

L = [0]*(N+1)
for i in range(1,N+1):
    L[i] = min(v[i],v[i+1],L[i-1]+t[i-1])

R = [0]*(N+1)
for i in range(N)[::-1]:
    R[i] = min(v[i+1],v[i],R[i+1]+t[i])

A = [0]*(N+1)
for i in range(N+1):
    A[i] = min(L[i],R[i])

ans = 0
for i in range(1,N+1):
    if A[i-1] >= A[i]:
        x = (t[i-1]-A[i-1]+A[i])/2
        if A[i-1]+x <= v[i]:
            ans += (A[i-1]+x/2) * x \
                     + (A[i-1]+x+A[i])/2 * (x+A[i-1]-A[i])
        else:
            ans += (A[i-1]+v[i])/2 * (v[i]-A[i-1]) \
                     + v[i] * (t[i-1]-2*v[i]+A[i-1]+A[i]) \
                     + (v[i]+A[i])/2 * (v[i]-A[i])
    else:
        x = (t[i-1]-A[i]+A[i-1])/2
        if A[i]+x <= v[i]:
            ans += (A[i]+x/2) * x \
                     + (A[i]+x+A[i-1])/2 * (x+A[i]-A[i-1])
        else:
            ans += (A[i-1]+v[i])/2 * (v[i]-A[i-1]) \
                     + v[i] * (t[i-1]-2*v[i]+A[i-1]+A[i]) \
                     + (v[i]+A[i])/2 * (v[i]-A[i])

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 200005;

char s[N];
int main() {
    int n;
    LL ans = 0;
    int mx = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        mx = max(mx, x);
        ans += mx - x;
    }
    cout << ans << endl;
    return 0;
}


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

bool is_triangle(int a, int b, int c){
    if(a < b + c and b < a + c and c < a + b) return true;
    else return false;
}

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

    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    
    sort(a.begin(),a.end());
    
    int sum = 0;
    
    for(int i = 1; i < n; i++){
        for(int j = 0; j < i; j++){
            for(int k = n - 1; k > i; k--){
                if(is_triangle(a[i], a[j], a[k])) sum++;
                else continue;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = sum(a)

count = [0] * (100001)
for i in range(n):
  count[a[i]] += 1

q = int(input())
for i in range(q):
  b,c = map(int, input().split())
  ans += (c-b) * count[b]
  count[c] += count[b]
  count[b] = 0
  print(ans)


Measured memory_bytes: 21060
import java.util.*;

class Main{

    public static void main(String args[]) throws Exception{
        Main main = new Main();
    }

    public Main(){
        Scanner scanner = new Scanner(System.in);
        long A,B,K;
        A = scanner.nextLong();
        B = scanner.nextLong();
        K = scanner.nextLong();

        if(K>=A+B){
            A = 0L;
            B = 0L;
        } else if(K>=A){
            K -= A;
            A =0L;
            B -= K;
        } else {
            A -= K;
        }

        System.out.print(A + " " + B);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=1e5+10,Mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
#define inf 1e17
int n;
vector<int> G[N];
int dp[N][2];
void add(int &a,int b)
{
  a+=b;
  if(a>=Mod) a-=Mod;
}
void mul(int &a,int b)
{
  a=(1ll*a*b)%Mod;
}
void dfs(int u,int p)
{
  dp[u][0]=1,dp[u][1]=1;
  for(auto v:G[u])
  {
    if(v!=p)
    {
      dfs(v,u);
      mul(dp[u][1],dp[v][0]);
      mul(dp[u][0],(dp[v][0]+dp[v][1])%Mod);
    }
  }
}
int main()
{
  cin>>n;
  for(int i=1;i<n;i++)
  {
    int x,y;
    cin>>x>>y;
    G[x].pb(y);
    G[y].pb(x);
  }
  dfs(1,0);
  cout<<(dp[1][0]+dp[1][1])%Mod<<endl;
  return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(n,b-1);
    cout<<(a*x)/b el;
}

main()
{
//      fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3536