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

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

#define X real()
#define Y imag()

using D = double;
using P = complex<D>;

const D EPS = 1e-10;
namespace std {
  bool operator < (const P& a, const P& b) {
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
};

struct L : array<P, 2> {
  L () = default;
  L(const P& a, const P& b) {
    front() = a;
    back() = b;
  }
  P vec() const {
    return back() - front();
  }
};
D dot(const P& a, const P& b) {
  return (conj(a)*b).X;
}
D cross(const P& a, const P& b) {
  return (conj(a)*b).Y;
}
int ccw(P a, P b, P c) {
  b -= a;
  c -= a;
  if(cross(b, c) > 0) return +1; // ccw
  if(cross(b, c) < 0) return -1; // cw
  if(dot(b, c) < 0) return +2; // L c-a-b
  if(norm(b) < norm(c)) return -2; // L a-b-c
  return 0;
}

bool intersectLL(const L& l, const L& m) {
  return abs(cross(l.vec(), m.vec())) > EPS ||
    abs(cross(l[1] - l[0], m[0] - l[0])) < EPS;
}

vector<string> split(const string& s, char c = ' ') {
  stringstream ss(s);
  vector<string> ret;
  string t;
  while(getline(ss, t, c)) ret.push_back(t);
  return ret;
}
int main() {
  string s;
  while(getline(cin, s)) {
    auto v = split(s);
    vector<P> p(4);
    rep(i, 4) {
      D x, y;
      x = stof(v[i*2].c_str());
      y = stof(v[i*2+1].c_str());
      p[i] = {x, y};
    }
    if(ccw(p[0], p[1], p[2]) == -1) {
      swap(p[1], p[2]);
    }
    assert(ccw(p[0], p[1], p[2]) == 1);
    bool f = true;
    rep(i, 3) {
      int j = (i+1)%3;
      if(ccw(p[i], p[j], p[3]) != 1) f = false;
    }
    cout << (f? "YES" : "NO") << endl;
  }
  return 0;
}



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

using namespace std;

#define MAX 1002

int n;

double xs;
double ys;
double xt;
double yt;


struct st{
	double x;
	double y;
	double r;
	st(double x_,double y_,double r_){
		x = x_;
		y = y_;
		r = r_;
	}
};
vector<st> v;

double dist(double px, double py, double ppx, double ppy){
	double R = (px - ppx)*(px - ppx) + (py - ppy)*(py - ppy);
	R = sqrt(max(0.0, R));
	return R;
}
double dist(double px, double py, st &f){
	double R = (px - f.x)*(px - f.x) + (py - f.y)*(py - f.y);
	R = sqrt(max(0.0, R));
	return max(0.0,R-f.r);
}
double dist(st &a, st &b){
	return max(0.0, dist(a.x, a.y, b) - a.r);
}

double dp[1002];
bool used[1002];
int main(){
	cin >> xs >> ys >> xt >> yt;
	cin >> n;
	for (int i = 0; i < n; i++){
		int xx, yy, rr;
		scanf("%d%d%d", &xx, &yy, &rr);
		v.push_back(st(xx, yy, rr));
	}
	for (int i = 0; i < n; i++){
		dp[i] = dist(xs, ys, v[i]);
	}
	for (int i = 0; i < n; i++){
		double mx = LLONG_MAX;
		int id = -1;
		for (int j = 0; j < n; j++){
			if (mx>dp[j]&&used[j]==false){
				mx = dp[j];
				id = j;
			}
		}
		if (id == -1){
			break;
		}
		used[id] = true;
		for (int j = 0; j < n; j++){
			if (id != j&&used[j] == false){
				double nex = dp[id] + dist(v[id], v[j]);
				if (dp[j]>nex){
					dp[j] = nex;
				}
			}
		}
	}
	double ans = dist(xs, ys, xt, yt);
	for (int j = 0; j < n; j++){
		ans = min(ans, dp[j] + dist(xt, yt, v[j]));
	}
	printf("%.16f\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
  int j,i,n,q,C=0,mid=0,r=0,l=0,k=0;
  int S[100000],T[50000],c[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      mid=(l+r)/2;
      if(S[mid]==T[i]){
	C++;
        c[k]=S[mid];
        k++;
	break;
      }
      if(T[i]>S[mid]){
	l=mid+1;
      }
      else if(T[i]<S[mid]){
	r=mid;
      }
    }
  }
  printf("%d\n",C);
  return 0;
}

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

#define ll long long
using namespace std;

int main(){
	int n; cin>>n;
  	int min;
  	int c = 1;
	for(int i = 0; i < n; i++){
		int sayi; cin>>sayi;
      	if(i == 0) min = sayi;
      	else{
          if(sayi <= min){
            c++;
            min = sayi;
          }
        }
	}
  	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

  
  
int main(){
  int i,j,num,num2,num3,num4[101][101],num5[101];
    
  scanf("%d",&num);
  for(i=1;i<=num;i++){
    for(j=1;j<=num;j++){
      num4[i][j] = 0;
    }
  }
  for(i=1;i<=num;i++){
    scanf("%d",&num5[i]);
    scanf("%d",&num2);
    if(num2 == 0)continue;
     
  
    else{
      for(j=0;j<num2;j++){
    scanf("%d",&num3);
    num4[i][num3] = 1; 
      }
    }
      
  }
    
  for(i=1;i<=num;i++){
    for(j=1;j<num;j++){
      printf("%d ",num4[i][j]);
    }
    printf("%d\n",num4[i][num]);
  }
  
  
  return 0;
}
 

Measured memory_bytes: 636
#include <iostream>
#include <vector>
int main(void) {
	std::vector<int> a(3);
	std::cin >> a.at(0) >> a.at(1) >> a.at(2);
	int sev = 0, fiv = 0;
	for (int i = 0; i < 3; i++) {
		if (a. at(i) == 5) fiv++;
		if (a.at(i) == 7) sev++;
	}
	if (fiv == 2 && sev == 1) { std::cout << "YES" << std::endl; }
	else { std::cout << "NO" << std::endl; }
	return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d)
    cout << "Left" << endl;
  else if (a + b == c + d)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long int a,b,c;
long long int s[5];
int main()
{
    scanf("%lld%lld%lld",&a,&b,&c);
        if(c>=a&&c<=b)
            printf("Yes\n");
        else
            printf("No\n");
}


Measured memory_bytes: 256
# C - Otoshidama
def get_combi():

	for x in range(N + 1):
		for y in range(N + 1):
			if x + y > N:
				break
			else:
				z = N - x - y
				if 10000 * x + 5000 * y + 1000 * z == Y:	
					return x, y, z
	
	return -1, -1, -1


N, Y = map(int, input().split())
x, y, z = get_combi()

print(x, y, z)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class Main {
    
    int MOD = (int) 1e9 + 7;
    
    void solve() {
        int n = in.nextInt();
        char[] s = in.nextToken().toCharArray();
        
        int[] cnt = new int[26];
        for (int i = 0; i < n; i++) {
            cnt[s[i] - 'a']++;
        }
        
        long ans = 1;
        for (int i = 0; i < 26; i++) {
            ans = ans * (cnt[i] + 1) % MOD;
        }
        ans = (ans - 1 + MOD) % MOD;
        out.println(ans);
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new Main().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}


Measured memory_bytes: 24532
/*s1190073  Rina Sato
  File name: prog8a.c
  This is a binary search tree program.
*/

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

struct node{
  struct node *parent;
  struct node *left;
  struct node *right;
  int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;

void Insert(int k){
  Node y=NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else {
      x = x->right;
    }
  }
  z->parent = y;
  
  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else {
    y->right = z;
  }
}

void Inorder(Node u){
  if(u->left != NIL){
    Inorder(u->left);
  }
  printf(" %d",u->key);
  
  if(u->right != NIL){
    Inorder(u->right);
  }
}

void Preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL){
    Preorder(u->left);
  }
  if(u->right != NIL){
    Preorder(u->right);
  }
}

int main(void){
  int n,i,x;
  char com[20];
  
  scanf("%d",&n);
  
  root = malloc(sizeof(struct node));
  root = NIL;

  for(i = 0 ; i < n ; i++){
    scanf("%s",com);
    
    if(com[0] == 'i'){
      scanf("%d",&x);
     
      Insert(x);
    }
    else {  /*print inorder tree walk and preorder tree walk*/
            
      Inorder(root);
      printf("\n");
      Preorder(root);
      printf("\n");
    }

  }
  
  return 0;
}

Measured memory_bytes: 11000
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)


int main(){
    int n;
    cin >> n;
    map<string, int> goods;
    rep(i,0,n){
        string input;
        cin >> input;
        goods[input] = 0;
    }
    cout << goods.size() << endl;
    //--------------
    return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b > c + d) {
    cout << "Left" << endl;
  }
  else if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
Int extgcd(Int a,Int b,Int& x,Int& y){
  Int d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}
Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
}
//END CUT HERE
//INSERT ABOVE HERE

//extgcd
signed AOJ_NTL1E(){
  Int a,b;
  cin>>a>>b;
  Int x,y;
  extgcd(a,b,x,y);
  cout<<x<<" "<<y<<endl;
  return 0;
}
/*
  verified on 2017/12/31
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_E&lang=jp
*/

signed main(){
  AOJ_NTL1E();
  return 0;
}



Measured memory_bytes: 3104
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

      
N,M = map(int,input().split())
bridge = []
for i in range(M):
  a,b = map(int,input().split())
  bridge.append([a,b])
bridge.reverse()

uncomfortable = []
ans = N*(N-1)//2
union = UnionFind(N)

for i in range(M):
  uncomfortable.append(ans)
  a,b = bridge[i][0],bridge[i][1]
  n1,n2 = union.Count(a),union.Count(b)
  if(union.isSameGroup(a,b) == 0):
    ans = ans - n1*n2
  union.Unite(a,b) 
uncomfortable.reverse()

for i in range(M):
  print(uncomfortable[i])

Measured memory_bytes: 26384
#include<stdio.h>
#include<string.h>

int main(void){
    int n, l;
    scanf("%d%d", &n, &l);
    char s[n+1][l+1];
    for(int i=0;i<n;i++){
        scanf("%s", s[i]);
    }
    for(int i=0;i<n-1;i++){
        for(int j=0;j<n-1;j++){
            if(strcmp(s[j],s[j+1])>0){
                strcpy(s[n], s[j+1]);
                strcpy(s[j+1], s[j]);
                strcpy(s[j], s[n]);
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("%s", s[i]);
    }
    printf("\n");
}


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

num = 0
for i in range(n):
    if b[n-1-i] > a[n-i]:
        num += a[n-i]
        temp = b[n-1-i] - a[n-i]
        if temp <= a[n-i-1]:
            a[n-i-1] -= temp
            num += temp
        else:
            num += a[n-i-1]
            a[n-i-1] = 0
    else:
        a[n-i] -= b[n-1-i]
        num += b[n-1-i]
    
print(num)

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

using namespace std;

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

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

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

int N;
int C[600], S[600], F[600];

ll goFrom(int first){
    ll t = 0;
    
    while(first < N - 1){
        t = max<ll>(S[first], (t + F[first] - 1) / F[first] * F[first]);
        t += C[first];
        ++first;
    }

    return t;
}

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

    std::cin >> N;

    for(int i=0;i<N-1;++i){
        std::cin >> C[i] >> S[i] >> F[i];
    }

    for(int i=0;i<N;++i){
        std::cout << goFrom(i) << std::endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

S = input()
Q = int(input())
query = []
flag = 1
before = ""
after  = ""

for i in range(Q):
    query = input().split()
    if query[0] == "1":
        flag *= -1
    else:
        if (query[1] == "1" and flag == 1) or  (query[1] == "2" and flag ==-1):
            before += query[2]
        else:
            after += query[2]
        #print(before,after)
if flag == 1:
    print(''.join(list(reversed(before))) + S + after)
else:
    print(''.join(list(reversed(after))) + ''.join(list(reversed(S))) + before)


Measured memory_bytes: 4852
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

int main()
{
	int n;cin>>n;
	string s;cin>>s;
	int i=0,j=n-1;int ans=0;
	while(i<j){
		while(i<j&&s[i]!='W') i++;
		while(j>i&&s[j]!='R') j--;
		if(s[i]=='W'&&s[j]=='R') ans++;
		i++;j--;
	}
	cout<<ans;
	return 0;	
} 

Measured memory_bytes: 3428
#include<stdio.h>
#define N 100000
#define Q 50000

int main(){

  int i,j,x,y,b;
  int s[N],t[Q],a=0,mid,left,right;

  scanf("%d",&x);

  for(i=0;i<x;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&y);

  for(j=0;j<y;j++){
    scanf("%d",&t[j]);
  }


  for(b=0;b<y;b++){

  left=0;
  right=x;

  while(left<right){ 
    mid=(left+right)/2;
  if(s[mid]==t[b]){
    a++;
    break;
  }
  else if(t[b]<s[mid])
    right=mid;
  else if(t[b]>s[mid])
    left=mid+1;
  }
  }

  printf("%d\n",a);
  return 0;
}

Measured memory_bytes: 1184
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll N;
ll K;
ll A,B;

ll ltmp;
string stmp;
double dtmp;
vll steps[10];
ll SUMstep[10]={};

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    cin >> K;

    //N = 2 * base10_5;
    //K = 1;

    ll d[N+10]={};
    d[1]=1;
    rep(ni,K){
        cin >> A;
        cin >> B;

        //A = 1;
        //B = N;

        steps[ni].push_back(A);
        steps[ni].push_back(B);

    }

    for( ll ni = 2 ; ni <=N ; ni++ ){
        rep(ki,K){
            ll n0 = ni - steps[ki][1]-1;
            ll n1 = ni - steps[ki][0];
            if(n0>=1) SUMstep[ki]-=d[n0];
            if(n1>=1) SUMstep[ki]+=d[n1];

            d[ni] +=  SUMstep[ki];
            d[ni] = (d[ni] + MOD)% MOD;
        }
    }
    cout << d[N] << endl;

}

Measured memory_bytes: 5216
def solve():
    S=list(input())
    for i in range(8):
        ans=int(S[0])
        for j in range(3):
            if (i & (1 << j)) != 0:
                ans+=int(S[j+1])
            else:
                ans-=int(S[j+1])
        if ans==7:
            ans=S[0]
            for j in range(3):
                if (i & (1 << j)) != 0:
                    ans+='+'
                else:
                    ans+='-'
                ans+=S[j+1]
            return ans+'=7'

print(solve())


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		sc.close();

		if(B % A == 0) {
			System.out.println(A + B);
		}else {
			System.out.println(B - A);
		}

	}
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    string s;
    cin>>s;
    int flag=1;
    ffor(i,1,sz(s))
    {
        if(s[i]==s[i-1])
        {
            flag=0;
            break;
        }
    }
    if(flag) cout<<"Good";
    else cout<<"Bad";
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{ 
	public static int M = 1000000007;
    public static void main(String[] args)throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        String s1 = br.readLine();	
        String s2 = br.readLine();
        int f=0, len = s1.length();
        for(int i=0;i<len;i++)
        {
            if(checker(s1,s2,i,0))
            {
                f=1;
                break;
            }
        }
        if(f==1)
            out.println("Yes");
        else
            out.println("No");
        out.flush();
    }
    public static boolean checker(String s1, String s2, int pos1, int pos2)
    {
        int count=0,len = s1.length();

        while(count<len)
        {
            if(s1.charAt(pos1)==s2.charAt(pos2))
            {
                pos1=(pos1+1)%len;
                pos2=(pos2+1)%len;
                count++;
            }
            else
                return false;
        }
        return true;
    }
    /** Loops
    *	i: for(int i=0;i<n;i++)
    *	j: for(int j=0;j<n;j++)
    *	k: for(int k=0;k<n;k++)

    *	ArrayList<Integer> arr1 = new ArrayList<>();
    
    * 	HashMap
    *	HashMap<Integer, Integer> hm = new HashMap<>();
    * 	for (Map.Entry<String,String> entry : hm.entrySet()) 
    		out.println(entry.getValue());
    
    *	Count frequencies
    	for(int i=0;i<n;i++)
        {
            Integer c = hm.get(Integer.parseInt(s[i]));
            if(c==null)
                hm.put(Integer.parseInt(s[i]),1);
            else
                hm.put(Integer.parseInt(s[i]),++c);
        }
	**/		
    public static long modularExpo(long x,long n,int M)
	{
		long result=1;
		while(n>0)
		{
		    if(n%2==1)
		        result=(result*x)%M;
		    x=(x*x)%M;
		    n=n/2;
		}	
		return result;												
	}
	//FLT, only when a and M are co-prime
	public static long modInverse(int a,int M)
	{
		long g = gcd(a,M);
		if(g!=1)
			return -1;
	    return modularExpo(a,M-2,M);
	}
	public static long gcd(int a, int b) 
	{
	    if(b==0)
	        return a;
	    else
	        return gcd(b, a % b);
	}
}

Measured memory_bytes: 22868
#include<stdio.h>
#define N 500000
#define SEN 1000000000

void Merge(int, int, int);
void Merge_Sort(int, int);

int S[N], count=0;

int main(void){
  int n, i;
  
  scanf("%d", &n);
  for(i=0; i < n; i++) scanf("%d", &S[i]);
  
  Merge_Sort(0, n);
  
  for(i=0; i < n; i++){
    printf("%d", S[i]);
    if(i < n-1)printf(" ");
  }
  
  printf("\n%d\n", count);
  return 0;
}


void Merge(int left, int mid, int right){
  int n1, n2, i, j, k;
  n1 = mid-left;
  n2 = right - mid;
  int l[n1], r[n2];
  
  for(i=0; i<n1; i++) l[i] = S[left + i];
  for(i=0; i<n2; i++) r[i] = S[mid + i];
  
  l[n1] = SEN;
  r[n2] = SEN;
  i=0;
  j=0;
  
  for(k=left; k<right; k++){
    if(l[i]<=r[j]){
      S[k] = l[i];
      i++;
    }
    else{
      S[k] = r[j];
      j++;
    }
    count++;
  }
}

void Merge_Sort(int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right) / 2;
    Merge_Sort(left, mid);
    Merge_Sort(mid, right);
    Merge(left, mid, right);
  }
}

Measured memory_bytes: 4504
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <assert.h>


using namespace std;


#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define MP(a,b) make_pair((a),(b))

int main(){
	int h, w, f, n, t, r;
	while(cin>>h>>w>>f,h||w||f){
		cin>>n;
		if(max({h,w,f})==f){
			t=h*h+w*w;
		}else if(max({h,w,f})==w){
			t=h*h+f*f;
		}else{
			t=w*w+f*f;
		}
		rep(i,n){
			cin>>r;
			if(4*r*r>t){
				cout<<"OK"<<endl;
			}else{
				cout<<"NA"<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
k = int(input())
RUNRUN_numbers = []

def RN(x,y):

    RUNRUN_numbers.append(y)

    if y > 10**9:
        return
    if x == 0:
        for i in range(0,2):
            
            yy = 10*y + i
            RN(i,yy)
    elif x == 9:
        for i in range(8,10):
            
            yy = 10*y + i
            RN(i,yy)
    else:
        for i in range(x-1,x+2,1):
            
            yy = 10*y + i
            RN(i,yy)


for i in range(1,10):
    RN(i,i)

RUNRUN_numbers.sort()
print(RUNRUN_numbers[k-1])
#print(RUNRUN_numbers)


Measured memory_bytes: 12748
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
  cin>>S;
  int ans=0;
  for(int i=0;i<4;i++){
  if(S.at(i)=='+')
    ans++;
    else
      ans--;
  }cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] a){
    	int d = 0;
    	
    	Scanner scan = new Scanner(System.in);
    	while (scan.hasNext()){
    	d = scan.nextInt();
    	int sum = 0;
    	for(int i = d;i < 600;i +=d){
    		sum += d*i*i;
    	}
    	System.out.println(sum);
    	}
    }
 }

Measured memory_bytes: 25884
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int prime[100010];
bool is_prime[100011];

void sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
}

int a[100010], b[100010];

int part_sum(int l, int r) {
	if (l > r) swap(l, r);
	if (l == 0) return b[r];
	return b[r] - b[l - 1];
}

int q;

int main(void){
	cin>>q;

	sieve(100000);
	for (int i = 0; i < 100005; i++) if (is_prime[i] && is_prime[(i + 1) / 2]) a[i]++;
	for (int i = 0; i < 100005; i++) {
		if (i > 0) b[i] = b[i - 1] + a[i];
	}

	while (q--) {
		int l, r; cin>>l>>r;

		cout<< part_sum(l, r) <<endl;
	}
	
	return 0;
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)

    return divisors
l=make_divisors(n)

print(l[-1]+l[-2]-2)

Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int n,T,cost=1001,ans;
    cin>>n>>T;
    REP(i,n){
        int c,t;
        cin>>c>>t;
        if(T>=t){
            cost=min(cost,c);
        }
    }
    if(cost!=1001)cout<<cost<<endl;
    else cout<<"TLE"<<endl;
}

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

int main(){
	int n;
	int ans = 0;
	cin >> n;
	rep(i, n){
		int a;
		cin >> a;
		if(a%2 == 0){
			if(a%3 != 0 && a%5 != 0){
				ans++;
			}
		}
	}

	if(0 < ans)
		cout << "DENIED" << endl;
	else
		cout << "APPROVED" << endl;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, K, w int
	fmt.Scan(&N, &K)
	var plus, minus []int
	plus = append(plus, 0)
	minus = append(minus, 0)
	for i := 0; i < N; i++ {
		fmt.Scan(&w)
		if w == 0 {
			continue
		}
		if w < 0 {
			minus = append(minus, w*-1)
		} else {
			plus = append(plus, w)
		}
	}
	sort.Ints(minus)
	max := 1000000000
	min := max
	for i := 0; i <= K; i++ {
		sum := 0
		if i > len(minus)-1 || K-i > len(plus)-1 {
			continue
		}
		if minus[i] > plus[K-i] {
			sum = minus[i] + plus[K-i]*2
		} else {
			sum = minus[i]*2 + plus[K-i]
		}
		if sum < min {
			min = sum
		}
	}
	if min == max {
		min = 0
	}
	fmt.Println(min)
}

Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadLineLongSpilit();

            var a = n[0];
            var b = n[1];
            var k = n[2];

            if ((a - k) >= 0) {
                Console.WriteLine($"{a - k} {b}");
                return;
            }

            if((b - (k-a)) < 0){
                b = 0;
            }
            else {
                b -= k-a;
            }

            Console.WriteLine($"0 {b}");
            ReadLine();
        }

        //メモ

        //配列
            //降順
            //var sort = array.OrderBy(x => -x).ToArray();

            //合計値
            //array.Sum();

        //kのn乗
        //(int) Math.Pow(k, n);


        //最大公約数
        static int gcd(int a, int b)
        {
            if (a > b) {
                return gcd(b, a);
            }

            while (b != 0) {
                var remainder = a % b;
                a = b;
                b = remainder;
            }

            return a;
        }

        //最小公倍数
        static int lcm(int a, int b) => a * b / gcd(a, b);

        /// <summary>
        /// コンビネーション
        /// </summary>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        public static string ReadLine() => Console.ReadLine();
        public static int ReadLineInt() => int.Parse(Console.ReadLine());
        public static long ReadLineLongInt() => long.Parse(Console.ReadLine());
        public static string[] ReadLineStringSplit(char a = ' ') => ReadLine().Split(a).ToArray();
        public static int[] ReadLineIntSpilit(char a = ' ') => ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        public static long[] ReadLineLongSpilit(char a = ' ') => ReadLine().Split(a).Select(x => long.Parse(x)).ToArray();
        static string[] GetAplhaLowerArray() => new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, (b)<(e)?1:-1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define FOR(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)(__VA_ARGS__)
#ifdef LOCAL
#define dbg(x) cerr << '[' << #x << ":" << (x) << "]\n"
#else
#define dbg(x)
#endif
const int MOD=1e9+7;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,k;cin>>n>>k;
	int npos=0,nneg=0;
	vector<int> pos,neg;
	FOR(n){
		int a;cin>>a;
		if(a<0)neg.pb(a),nneg++;
		else pos.pb(a),npos++;
	}
	sort(rall(pos));
	sort(all(neg));
	auto mul=[&](vector<int>& v,int x){
		ll ans=1;
		FOR(x)(ans*=v[i])%=MOD;
		if(ans<0)ans+=MOD;
		return ans;
	};
	if(npos==0){
		if(k&1)reverse(all(neg));
		cout<<mul(neg,k);
		return 0;
	}
	int i=0,j=0;
	vector<int> chp,chn;
	FOR(z,k){
		if(j==nneg||(i<npos&&pos[i]>-neg[j]))chp.pb(pos[i]),i++;
		else chn.pb(neg[j]),j++;
	}
	if((j&1)^1){
		// dbg(i),dbg(j);
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
		return 0;
	}
	if(i==0||i<npos&&(j==nneg||(ll)chp.back()*pos[i]>(ll)chn.back()*neg[j])){
		chp.pb(pos[i]);
		chn.pop_back();
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}else if(j<nneg){
		chn.pb(neg[j]);
		chp.pop_back();
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}else{
		cout<<mul(chp,chp.size())*mul(chn,chn.size())%MOD;
	}
}

Measured memory_bytes: 5472
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    A, B = map(int, input().split())
    a[i], b[i] = A, B

a.reverse()
b.reverse()

ans = 0
for i in range(n):
    if (ans+a[i]) % b[i] == 0:
        cnt = 0
    else:
        cnt = b[i] - ((ans+a[i]) % b[i])
    ans += cnt
print(ans)

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

int main()
{
    int A, B, C, X, Y;
    int Xnum = 0;
    int Ynum  = 0;
    int Cnum = 0;
    cin >> A >> B >> C >> X >> Y;
    if((A + B) <= (2 * C)) {
        /* バラ売りを買う */
        Xnum = X; Ynum = Y;
    }
    else {
        /* ABとして買える分をすべて買う */
        if(X > Y) {
            Cnum = Y * 2;
            X = X - Y;
            if((2 * C) < A) {
                /* すべてABピザとなるパターン */
                Cnum += (X * 2);
            }
            else {
                Xnum = X;
            }
        }
        else {
            Cnum = X * 2;
            Y = Y - X;
            if((2 * C) < B) {
                /* すべてABピザとなるパターン */
                Cnum += (Y * 2);
            }
            else {
                Ynum = Y;
            }
        }
    }
    cout << (Xnum * A) + (Ynum * B) + (Cnum * C) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <tuple>
#include <cmath>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;


int main(void){
    int n;
    cin >> n;
    
    vector <double> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    /*降順*/
    
    for (int i = n-1 ; i > 0; i--)
    {
        v.at(i-1)=(v.at(i)+v.at(i-1))/2;
    }
    
    printf("%.6f\n",v.at(0));
}


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

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b, h;
    cin >> a;
    cin >> b;
    cin >> h;
    
    int answer = ((a+b)*h)/2;
    cout << answer << endl;
    
    
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	string s;
	cin >> s;
	map<char, int> mp;

	for (char c : s)
		mp[c]++;
	bool ok = true;
	for (auto p : mp)
		if (p.second != 2)
			ok = false;
	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

	solve();
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=2e5+5;

ll ans;
char st[N];

int main() {
	scanf("%s",st+1);
	int n=strlen(st+1),cnt=0;
	fo(i,1,n) if (st[i]=='W') ans+=i-(++cnt);
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
h,w=map(int,input().split())
c=[]
for i in range(10):
    c.append(list(map(int,input().split())))
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j]=min(c[i][j],c[i][k]+c[k][j])
ans=0
for i in range(h):
    s=list(map(int,input().split()))
    for j in s:
        if j!=1 and j!=-1:
            ans+=c[j][1]
print(ans)


Measured memory_bytes: 40684
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
 
// Remove GCC optimizer for codechef
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
using namespace std;
using namespace __gnu_pbds;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define endl "\n"
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const int INF = 1e16;
const double PI = acos(-1);
const int N = 1e6 + 7;
int mod = 1e9 + 7;

const int maxn = 3e6 + 7;
int dp[maxn];

int32_t main()
{
    IOS;
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    vector<vector<int>> mat(n, vector<int>(n));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> mat[i][j];
    dp[0] = 1;
    for(int mask = 0; mask < (1 << n) - 1; mask++)
    {
        int nxt = __builtin_popcount(mask);
        for(int j = 0; j < n; j++)
        {
            if(!mat[nxt][j] || ((1 << j) & mask))
                continue;
            int target = mask ^ (1 << j);
            dp[target] += dp[mask];
            dp[target] %= mod;
        }
    }
    cout << dp[(1 << n)-1] << endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int cou;

int mygcd(int a,int b){
    cou++;
    if(b==0)return a;
    else return mygcd(b,a%b);
}

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    while(cin >> a >> b,a){
        if(a<b)swap(a,b);
        int res = mygcd(a,b);
        cout << res << " " << cou-1 << endl;
        cou=0;
    }
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/



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

    int const inf = 1e9;

    int N, M; cin >> N >> M;
    vector<int> a(M, 0);
    vector<int> key(M, 0);
    rep(i, M) {
        int b; cin >> a[i] >> b;
        rep(j, b) {
            int c; cin >> c;
            --c;
            key[i] += 1<<c;
        }
    }

    vector<vector<int>> dp(M+1, vector<int>(1<<N, inf));
    dp[0][0] = 0;
    rep(i, M) rep(S, 1<<N) {
        // not use
        chmin(dp[i+1][S], dp[i][S]);
        // use
        chmin(dp[i+1][S | key[i]], dp[i][S]+a[i]);
    }
    
    cout << (dp[M][(1<<N)-1]==inf? -1:dp[M][(1<<N)-1]) << endl;

    return 0;
}


Measured memory_bytes: 16384
N = int(input())
H = list(map(int,input().split()))
H.reverse()

check = True

for i in range(N-1):
  if H[i] >= H[i+1]:
    continue
  else:
    if H[i+1] - H[i] > 1:
      check = False
      break
    else:
      H[i+1] -= 1
      
if check:
  print("Yes")
else:
  print("No")

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

int main(void){
    int a,b,a2,b2,k,check;
    check = 0;
    scanf("%d %d",&a,&b);
    for(int i = 0; i <= 1000000000; i++){
        a2 = abs(a-i);
        b2 = abs(b-i);
        if(a2==b2){
            k = i;
            check = 0;
            printf("%d\n",i);
            break;
        }else{
            check++;
        }
    }
    if(check != 0) printf("IMPOSSIBLE\n");
    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, m, t;
  cin >> n >> m >> t;
  map<int, int> row, col;
  set<ii> s;
  for (int i = 1; i <= t; i++) {
    int x, y;
    cin >> x >> y;
    row[x]++;
    col[y]++;
    s.insert(ii(x, y));
  }
  vector<int> r, c;
  for (auto &i : row) {
    if (r.empty()) {
      r.push_back(i.fi);
      continue;
    }
    int t = row[r.back()];
    if (i.sc > t) {
      r.clear();
      r.push_back(i.fi);
    } else if (t == i.sc) {
      r.push_back(i.fi);
    }
  }
  for (auto &i : col) {
    if (c.empty()) {
      c.push_back(i.fi);
      continue;
    }
    int t = col[c.back()];
    if (i.sc > t) {
      c.clear();
      c.push_back(i.fi);
    } else if (t == i.sc) {
      c.push_back(i.fi);
    }
  }
  for (auto &i : r)
  for (auto &j : c) {
    if (!s.count(ii(i, j))) {
      cout << row[r.back()] + col[c.back()] << '\n';
      return;
    }
  }
  cout << row[r.back()] + col[c.back()] - 1 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 67796
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S,T; cin>>S>>T;
    ll N=S.size();
    map<char,char> mp;
    map<char,char> mp2;
    rep(i,N){
        if(mp.find(S[i])!=mp.end() and mp[S[i]]!=T[i]) dame;
        mp[S[i]]=T[i];
    }
    rep(i,N){
        if(mp2.find(T[i])!=mp2.end() and mp2[T[i]]!=S[i]) dame;
        mp2[T[i]]=S[i];
    }
    cout<< "Yes"<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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


int main() {long N, K;
cin >> N >> K;
vector<long> d(K);
rep(i, K) cin >> d.at(i);
long x = 0;
long num; bool next = true; long ans;
while(1){
    num = N + x;
    next = false;
    while(num != 0){
      rep(i, K){
      if(num % 10 == d.at(i)){
        next = true;
        break;
      }
    }
    num = num / 10;
  }
  if(next == false){
    ans = N + x;
    break;
  }
  x++;
}



// cout << x << endl;

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



Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++) {
			a[i]=nextInt();
		}
		sc.close();
		int[] L = new int[N];
		int[] R = new int[N];
		L[N-1] = a[N-1];
		for(int i=0;i<N-1;i++) {
			L[i]+=a[i];
			L[i+1]+=L[i];
		}
		R[0] = a[0];
		for(int i=N-1;i>0;i--) {
			R[i]+=a[i];
			R[i-1]+=R[i];
		}
		int minabs = 100010;
		for(int i=0;i<N-1;i++) {
			minabs = Math.min(Math.abs(L[i]-R[i+1]),minabs);
		}
		out.println(minabs);
	}

	private static int nextInt() {
		return Integer.parseInt(next());
	}
	private static long nextLong() {
		return Long.parseLong(next());
	}
	private static String next() {
		return sc.next();
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
const int n = 100001;


int main(){
	string s;
	int K;
	cin >> s >> K;
	set<string> S;
	int N = s.length();
	for(int i = 0; i < N; ++i){
		for(int j = i; j < N && j-i < K; ++j){
			S.insert(s.substr(i, j-i+1));
		}
	}
	int i = 1;
	for(string st : S){
		if(i++ == K){
			cout << st << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int H,W,M; cin>>H>>W>>M;
  vector<int> LH(H,0),LW(W,0);
  set<pair<int,int>> SET;
  rep(i,M){
    int a,b; cin>>a>>b;
    a--;
    b--;
    SET.insert(make_pair(a,b));
    LH.at(a)++;
    LW.at(b)++;
  }
  int HM=0,WM=0;
  vector<int> HH,WW;
  rep(i,H){
    if(HM<LH.at(i)){
      HH={};
      HH.push_back(i);
      HM=LH.at(i);
    }
    else if(HM==LH.at(i)){
      HH.push_back(i);
    }
  }
  rep(i,W){
    if(WM<LW.at(i)){
      WW={};
      WW.push_back(i);
      WM=LW.at(i);
    }
    else if(WM==LW.at(i)){
      WW.push_back(i);
    }
  }
  int s=HH.size(),t=WW.size(),ans=WM+HM;
  bool c=false,finish=false;
  rep(i,s){
    rep(j,t){
      if(!SET.count(make_pair(HH[i],WW[j]))){
        c=true;
        finish=true;
        break;
      }
    }
    if(finish) break;
  }
  
  if(c) cout<<ans;
  else cout<<ans-1; 
}

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

int main(){
  int n,k;
  while( cin >> n >> k,n+k){
    
    int a[n];
    for(int i = 0;i < n;i++){
      cin >> a[i];
    }
    int sum = -500000;
    for(int i = 0;i < n-k+1;i++){
      //cout << i << endl;
      int s = 0;
      for(int j = i;j < i+k;j++){
	s += a[j];
      }
      sum = max(s,sum);
    }
    cout << sum <<  endl;
    
  }
  
}

Measured memory_bytes: 3360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
int n, m, x;
int ans = INF, C[20], A[20][20];
int tmp[20];
bool ck() {
	for (int i = 1; i <= m; i++) {
		if (tmp[i] < x)return false;
	}
	return true;
}
int main() {
	scanf("%d%d%d", &n, &m, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", &C[i]);
		for (int j = 1; j <= m; j++)scanf("%d", &A[i][j]);
	}
	for (int i = 0; i < (1 << n); i++) {
		int res = 0;
		memset(tmp, 0, sizeof(tmp));
		for (int j = 0; j < n; j++) {
			if (i&(1 << j)) {
				res += C[j];
				for (int k = 1; k <= m; k++)
					tmp[k] += A[j][k];
			}
		}
		if (ck())ans = min(ans, res);
	}
	printf("%d\n", ans == INF ? -1 : ans);
	return 0;
}

Measured memory_bytes: 3836
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        double[] a = new double[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextDouble();
        }
        
        double ans = 0;
        for(int i = 0; i < n; i++){
            ans += 1 / a[i];
        }
        
        ans = 1 / ans;
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

const int mod = 1e9 + 7;

vector<int> candidates;
vector<int> options = {3, 5, 7};


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

  int N, K;
  cin >> N >> K;

  vector<int> accs(N+1, 0);

  int acc = 0;
  rep(i, N){
    int tmp;
    cin >> tmp;
    accs[i+1] = (tmp+1 + accs[i]);
  }

  // rep(i, N) cout << accs[i] << " ";
  // cout << endl;

  int ans = 0;
  for(int k=K; k<=N; k++){
    int tmp_ans = accs[k] - accs[k-K];
    ans = max(ans, tmp_ans);
  }

  printf("%.10f\n", ans / 2.0);

  return 0;
}


Measured memory_bytes: 1792