akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<cassert>
#include<cmath>
 
using namespace std;

typedef long long ll;

struct Point{
  ll x,y;
  Point operator - (const Point& p) const {
    Point res = *this;
    res.x -= p.x;
    res.y -= p.y;
    return res;
  }
};
typedef pair<ll,ll> P;

struct State{
  int now,pre;
  P t;
  bool operator < (const State& st) const {
    return t > st.t;
  }
};

ll cross(Point a, Point b){return a.x*b.y-a.y*b.x; }
 
// pre, now, next
bool isRight(Point p0, Point p1, Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  return cross(a,b) < 0;
}

const int MAX = 1050;
const ll INF = (1LL<<60);
map<string,int> idx;
vector<int> E[MAX];
Point pos[MAX];
int M,N;
P T[MAX][MAX];
 
 
void init(){
  idx.clear();
  for(int i = 0; i < MAX; i++) E[i].clear();
}
 
void input(){
 
  int cnt = 0;
  for(int i = 0; i < M; i++){
    string s;
    Point p;
    cin >> s >> p.x >> p.y;
    if(!idx.count(s)) idx[s] = cnt++;
    pos[idx[s]] = p;
  }
 
  for(int i = 0; i < N; i++){
    string p,q;
    cin >> p >> q;
    E[idx[p]].push_back(idx[q]);
    E[idx[q]].push_back(idx[p]);
  }
}

ll getDist(const Point& p1, const Point& p2){
  //return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
  return abs(p1.x-p2.x)+abs(p1.y-p2.y);
}
 
void solve(const int& src, const int& dst){
 
  fill(T[0], T[0]+MAX*MAX, P(INF,INF));
 
  priority_queue<State> Q;
  for(int i = 0; i < (int)E[src].size(); i++){
    ll d = getDist(pos[E[src][i]], pos[src]);
    T[E[src][i]][src] = P(d,2);
    Q.push((State){E[src][i],src,P(d,2)});
  }
 
  while(!Q.empty()){
    const State st = Q.top();
    Q.pop();
     
    if(T[st.now][st.pre] < st.t) continue;
 
    for(int i = 0; i < (int)E[st.now].size(); i++){
      if(st.pre == E[st.now][i]) continue;
      if(isRight(pos[st.pre], pos[st.now], pos[E[st.now][i]])) continue;
      State nex = st;
      nex.t.first += getDist(pos[st.now], pos[E[st.now][i]]);
      nex.t.second++;
      nex.now = E[st.now][i];
      nex.pre = st.now;
      if(T[nex.now][nex.pre] > nex.t){
	T[nex.now][nex.pre] = nex.t;
	Q.push(nex);
      }
    }
  }
  ll minDist = INF, res = INF;
  for(int i = 0; i < MAX; i++) minDist = min(minDist, T[dst][i].first);
  for(int i = 0; i < MAX; i++) if(T[dst][i].first == minDist) res = min(res, T[dst][i].second);
  if(res == INF) cout << "impossible" << endl;
  else cout << res << endl;
}
 
int main(){
 
  while(cin >> M >> N && M+N){
    init();
    input();
    string src, dst;
    cin >> src >> dst;
    solve(idx[src],idx[dst]);
  }
  return 0;
}

Measured memory_bytes: 18740
#include<stdio.h>
#define MODN 1000000007

static inline long mdadd(long a,long b){
    return (a + b) % MODN;
}

static inline long mdsum(long dest,long num){
    long res = (dest - num) % MODN;
    if(res < 0)res += MODN;
    return res;
}

static inline long mdml(long a,long b){
    long long res;
    res = (long long)a * b;
    return res % MODN;
}

static inline long mdpow(long num,long ind){
    unsigned long cnt = ind;
    long res = 1;
    while(cnt){
        if(cnt & 1ul)res = mdml(res,num);
        num = mdml(num,num);
        cnt >>= 1;
    }
    return res;
}

int main(void){
    register int i,j;
    int n,k;
    scanf("%d %d",&n,&k);

    long ml_num[k+1];
    for(i = 1;i <= k;i++)ml_num[i] = mdpow(k / i,n);

    long gcd_num[k+1];
    long tmp;
    for(i = k;i > 0;i--){
        tmp = 0;
        for(j = 2;i*j <= k;j++)tmp = mdadd(tmp,gcd_num[i*j]);
        gcd_num[i] = mdsum(ml_num[i],tmp);
    }
    long ans = 0;
    for(i = 1;i <= k;i++)ans = mdadd(ans,mdml(gcd_num[i],i));
    printf("%ld",ans);
}

Measured memory_bytes: 3292
#include <stdio.h>
#include <math.h>

int main(void)
{
	double x1;
	double x2;
	double x3;
	double y1;
	double y2;
	double y3;
	double xp;
	double yp;
	double z1;
	double z2;
	double z3;
	
	while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF){
		z1 = (x3 - x2) * (yp - y2) - (y3 - y2) * (xp - x2);
		z2 = (x1 - x3) * (yp - y3) - (y1 - y3) * (xp - x3);
		z3 = (x2 - x1) * (yp - y1) - (y2 - y1) * (xp - x1);
		
		if ((z1 > 0 && z2 > 0 && z3 > 0) || (z1 < 0 && z2 < 0 && z3 < 0)){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

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

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

  bool yes = (a < b && a < c && c < b) || (a > b && a > c && c > b);
  if (yes)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
import sys
h, n = map(int, input().split())
# A = [0] * n
# B = [0] * n
# for i in range(n):
#     A[i], B[i] = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]
min_hp = h
max_hp = h + max(a for a, b in (AB))
 
dp = [sys.maxsize] * (max_hp + 1)
dp[0] = 0
 
for i in range(1, max_hp + 1):
    # dp[i] = min(dp[i - A[j]] + B[j] for j in range(n))
    dp[i] = min(dp[i - a] + b for a, b in AB)
print(min(dp[h:]))

Measured memory_bytes: 46812
#include<iostream>
#define ll long long
using namespace std;
int a[200000+5];
int main(){
	ll n,max1,sum=0;
  	cin>>n;
  	for(int i=1;i<=n;i++){
      	cin>>a[i];
    }
  	max1=a[1];
  	for(int i=2;i<=n;i++){
    	if(a[i]<max1)
          	sum+=max1-a[i];
      	else
          	max1=a[i];
    }
  	cout<<sum<<endl;
  	return 0;
}

Measured memory_bytes: 3924
s=input()
for c in s:
	a=(ord(c))
	if a>=65 and a<=90:
		a+=32
		print(chr(a),end='')
	elif a>=97 and a<=97+25:
		a-=32
		print(chr(a),end='')
	else:
		print(c,end='')
print()


Measured memory_bytes: 5716
N=int(input())
s=[0]*N
s_nz=[101]*N
res=0
for i in range(N) :
  s[i]=int(input())
  if s[i]%10!=0 :
    s_nz[i]=s[i]
  res+=s[i]
if res%10==0 :
  if min(s_nz)==101 :
    res=0
  else :
    res-=min(s_nz)
print(res)



Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;
    vector<P> red(n),blue(n);
    for(int i = 0; i < n; i++) cin >> red[i].first >> red[i].second;
    for(int i = 0; i < n; i++) cin >> blue[i].first >> blue[i].second;

    sort(red.begin(),red.end()),sort(blue.begin(),blue.end());

    int mark = 0,ans = 0;
    vector<int> v;
    for(int i = 0; i < n; i++){
        while(mark < red.size() && red[mark].first < blue[i].first){
            v.emplace_back(red[mark].second);
            mark++;
        }
        sort(v.begin(),v.end());
        for(int j = v.size()-1; j >= 0; j--){
            if(v[j] < blue[i].second){
                v.erase(v.begin()+j);
                ans++;
                break;
            }
        }
    }
  
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> as(N), cs(N);
  for (int i = 0; i < N; i++) {
    cin >> as.at(i);
  }
  
  bool stoppable = true;
  int index = 0;
  while (stoppable) {
    if (index == 1) break;
    cs.at(index)++;
    
    if (cs.at(index) <= 1) {
      index = as.at(index) - 1;
    } else {
      stoppable = false;
    }
  }
  
  if (stoppable) {
    int c = 0;
    for (int i = 0; i < N; i++) {
      c += cs.at(i);
    }
    cout << c << endl;
  } else {
    cout << -1 << endl;
  }
}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N, K;
  cin >> N >> K;
  map<int, int> mp;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    mp[A]++;
  }
  vector<int> c;
  for (auto x : mp) {
    c.push_back(x.second);
  }
  sort(c.begin(), c.end());
  int ans = 0;
  int SIZE = c.size() - K;
  for (int i = 0; i < max(0, SIZE); i++) {
    ans += c[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 10748
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	Info(ll arg_base,ll arg_add){
		base = arg_base;
		add = arg_add;
	}
	bool operator<(const struct Info &arg) const{

		return base > arg.base;
	}
	ll base,add;
};

int N;
vector<Info> P,M;

bool check(vector<Info> info){

	int tmp = 0;

	for(int i = 0; i < info.size(); i++){

		if(tmp+info[i].base < 0)return false;

		tmp += info[i].add;
	}

	return true;
}

int main(){

	scanf("%d",&N);

	int sum = 0;

	string tmp_str;

	for(int loop = 0; loop < N; loop++){

		cin >> tmp_str;

		int base = 0;
		int add = 0;

		for(int i = 0; i < tmp_str.length(); i++){
			if(tmp_str[i] == '('){

				add++;

			}else{

				add--;
				base = min(base,add);
			}
		}

		sum += add;

		if(add >= 0){

			P.push_back(Info(base,add));

		}else{

			M.push_back(Info(base-add,-add));
		}
	}

	if(sum != 0){

		printf("No\n");
		return 0;
	}

	sort(P.begin(),P.end());
	sort(M.begin(),M.end());

	if(check(P) && check(M)){

		printf("Yes\n");
	}else{

		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 34584
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
int N,L;
string S[100];
int main(){
  cin>>N>>L;
  for(int i=0;i<N;i++) cin>>S[i];
  sort(S, S+N, [](string &a, string &b) {
    return a < b;
  });
  for(int i=0;i<N;i++) cout<<S[i];
  cout<<"\n";
  return 0;
}

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

namespace ABC123
{
    class C
    {
        static void Main(string[] args)
        {
            double N = double.Parse(Console.ReadLine());

            long[] alpha = new long[5];

            for(long i = 0; i < alpha.Length; i++)
            {
                alpha[i] = long.Parse(Console.ReadLine());
            }
            
            double min = alpha.Min();
            double a = 4+Math.Ceiling(N/min);

            long aa = (long)a;

            Console.WriteLine(aa);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  rep(i, n) if (s[i] == '?') s[i] = 'D';
  cout << s << endl;
}

Measured memory_bytes: 3728
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
def md(x):
    u = sorted(x)
    if len(u) % 2 == 0:
        return u[len(u) // 2] + u[len(u) // 2 - 1]
    else:
        return u[len(u) // 2]
u, v = md(a), md(b)
print(v - u + 1)

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

int main() {
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n < k){
    cout << n*x << endl;
  }
  if(n >= k){
    cout << k*x+(n-k)*y << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> vec(N),height(N);
  for(int i=0;i<N;i++){
    cin >> height.at(i);
  }
  
  for(int i=0;i<M;i++){
    int A,B;
    cin >> A >> B;
    
    if(height.at(A-1) < height.at(B-1)){
      vec.at(A-1) = 1;
    }
    else if(height.at(A-1) > height.at(B-1)){
      vec.at(B-1) = 1;
    }
    else{
      vec.at(A-1) = 1;
      vec.at(B-1) = 1;
    }
  }
  
  int counter=0;
  for(int i=0;i<N;i++){
    if(vec.at(i)==0){
      counter++;
    }
    else{
    }
  }
  cout << counter << endl;
}

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

namespace Array
{
    class Official_House
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var data = new int[4,3,10];
            for (int i = 0; i < n; i++)
            {
                var array = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                data[array[0] - 1, array[1] - 1, array[2] - 1] += array[3];
            }

            for (int i = 0; i < data.GetLength(0); i++)
            {
                for (int j = 0; j < data.GetLength(1); j++)
                {
                    for (int k = 0; k < data.GetLength(2); k++)
                    {
                        Console.Write(" "+data[i,j,k]);
                    }
                    Console.WriteLine();
                }
                if(i!=data.GetLength(0)-1)Console.WriteLine("####################");
            }
        }
    }
}

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

int main(void)
{
    for (int x = 1; x <= 9; x++)
    {
        for (int y = 1; y <= 9; y++)
        {
            cout << x << "x" << y << "=" << x*y << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
cin >> N >> K;
int count = 0;
for(int i = 0; i < N;i++){
 int h;
 cin >> h;
 if(h >= K){
     count++;
 }
 }
 cout << count << endl ;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;
 
typedef long long ll;


#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }
 
template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll a, b, k;
  cin >> a >> b >> k;
  if (a <= k) {
    k -= a;
    cout << 0 << " " << max<ll>(b - k, 0) << endl;
  } else {
    cout << a - k << " " << b << endl;
  }
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(100010)
n,k = inpl()
a = inpl()
a.sort()
mx = 0
for i in range(n):
    if n-i-1 < k-1: continue
    tmp = comb(n-i-1,k-1)
    # print(tmp)
    mx += tmp*a[-i-1] - tmp*a[i]
    mx %= mod
print(mx) 

Measured memory_bytes: 96232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) \
    SORT(a);     \
    reverse(a.begin(), a.end())
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

typedef pair<ll, ll> ii;
typedef vector<ii> vp;
#define OUTA2(a, n) \
    REP(i, n) { cout << (a[i]).first << " " << (a[i]).second << endl; }

ll N;
vi X, L;

int main()
{
    cin >> N;
    X = vi(N);
    L = vi(N);
    REP(i, N)
    {
        cin >> X[i] >> L[i];
    }

    vp A = vp(N);
    REP(i, N)
    {
        A[i] = ii(X[i] + L[i], X[i] - L[i]);
    }
    SORT(A);
    ll prev = -INF;
    ll ans = 0;
    REP(i, N)
    {
        if (prev <= A[i].second)
        {
            ++ans;
            prev = A[i].first;
        }
    }

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

Measured memory_bytes: 3328
def reachable(es, source):
	ret = {source}
	Q = [source]
	while Q:
		cur = Q.pop()
		for nxt in es[cur]:
			if nxt not in ret:
				Q.append(nxt)
				ret.add(nxt)
	return ret

def BellmanFord(V:int, es:list, source=0):
	INF = float("inf")
	D = [INF]*V
	D[source] = 0
	for _ in range(V):
		upd = False
		for f, t, c in es:
			tmp = D[f] + c
			if D[t] > tmp:
				D[t] = tmp
				upd = True
		if not upd:
			return D[-1]
	else:
		return None
	
def main():
	N,M,P,*L=map(int,open(0).read().split())
	fwd = [[] for _ in range(N)]
	bwd = [[] for _ in range(N)]
	for a,b in zip(L[::3],L[1::3]):
		fwd[a-1].append(b-1)
		bwd[b-1].append(a-1)
	judge = reachable(fwd,0) & reachable(bwd,N-1)
	G = [(a-1,b-1,P-c) for a,b,c in zip(*[iter(L)]*3) if a-1 in judge and b-1 in judge]
	ans = BellmanFord(N,G)
	if ans==None:
		print(-1)
	else:
		print(max(0,-ans))

if __name__=="__main__":
	main()

Measured memory_bytes: 5472
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,m;
  cin >> n>>m;
  int a[m],b[m];
  vector <int> v,l;
  for(int i=0;i<m;i++){
    cin >> a[i]>>b[i];
    if(a[i]==1) v.push_back(b[i]);
    if(b[i]==n) l.push_back(a[i]);
  }
  sort(l.begin(),l.end());
  for(int i=0;i<v.size();i++){
        if(binary_search(l.begin(),l.end(),v[i])){
            cout <<"POSSIBLE"<<endl;
            return 0;
          }
     }
  cout << "IMPOSSIBLE"<<endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  int num = 0;
  int sum = 0;
  
  for (int x : a) {
    sum += x;
  }
  //cout << sum << endl;
  for (int x : a) {
    if (x*4*M >= sum) {
      num++;
    }
  }
  //cout << num << endl;
  if (num >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int cost;
    cin>>cost;
    if(cost % 1000 == 0) {
		cout<<0<<endl;
		return 0;
	}
	int change = (cost/1000 + 1)*1000 - cost;
	cout<<change<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int read()
{int x=0;
char c=getchar();
while (c<'0'||c>'9') c=getchar();
while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
return x;
}
int n,a[100005];
int main (){
	int i;
	n=read();
	for (i=1;i<=n;i++)
	{a[i]=read();}
	int pos=1,ans=0;
	while (pos<=n)
	{int st=pos;
	while (pos<=n&&a[pos]==pos) {pos++;}
	ans+=(pos+1-st)/2;pos++;
	}
	printf ("%d\n",ans);
	return 0;
}
	

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

int main(){
  int N;
  cin >> N;
  vector<string> word(N);
  for (int i=0; i<N; i++) {
    cin >> word.at(i) ;
  }
  int x=0;
  int y=0;
  for (int i=0; i<N-1; i++) {
    if ( word.at(i+1).at(0) == word.at(i).at(word.at(i).size()-1) ) {
      x++;
    }
  }
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++){
      if ( (i != j) && (word.at(i) != word.at(j)) ){
        y++;
      }
    }
  }
  if(x == N-1 && y == (N-1)*N){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
       

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            double a = sc.nextDouble();
            double b = sc.nextDouble();
            double e = sc.nextDouble();
            double c = sc.nextDouble();
            double d = sc.nextDouble();
            double f = sc.nextDouble();
            double[] res = simultaneousEquation(a, b, c, d, e, f);
            System.out.printf("%.3f %.3f\n", res[0], res[1]);
        }
    }

    public static double[] simultaneousEquation(double a, double b, double c, double d, double e, double f) {
        double t = a * d - c * b;
        double x = (d * e - b * f) / t;
        double y = (a * f - c * e) / t;
        x += 0.0f;
        y += 0.0f;
        return new double[]{ x, y };
    }
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号
  vector<int> siz;  //葉の値を持つ

  UnionFind(int n)
      : par(n),
        siz(n, 1)  //初期化
  {
    for (int i = 0; i < n; i++) par[i] = i;
  }

  int root(int x)  //データxが属する木の根を再帰で得る
  {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }

  int size(int x) { return siz[root(x)]; }

  bool same(int x, int y) { return root(x) == root(y); }

  bool unite(int x, int y)  // xとyの木を併合
  {
    if ((x = root(x)) == (y = root(y)))  // xとyの根が同じ時はそのまま
      return false;
    if (siz[y] > siz[x]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;  // yの根にxをつける
    return true;
  }
};

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

  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<int> ans(n, 0);
  rep(i, 0, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
    --ans[a], --ans[b];
  }

  rep(i, 0, n) ans[i] += uf.size(i) - 1;

  rep(i, 0, k) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    if (uf.same(a, b)) --ans[a], --ans[b];
  }

  arep(i, ans) cout << i << ' ';
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3200
// ABC132-C
#include <iostream>
#include <algorithm>
using namespace std;

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

    if(n % 2 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int d[n];

    for(int i = 0; i < n; i++)  cin >> d[i];

    sort(d, d + n);

    int ans = d[n/2] - d[n/2 - 1];
    cout << ans << endl;

    return 0;
}

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

int cnt;

void insertionSort(int* a, int n, int g){

    int i, j, v;

    for(i = g; i < n; i++){
        v = a[i];
        j = i - g;
        while((j >= 0) && (a[j] > v)){
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        };
        a[j + g] = v;
    }
}

void shellsort(int* a, int n)
{
    cnt = 0;
    int i, p;
    int m;
    int G[15];

    p = 1;
    for(i = 1; i < 20; i++){
        p = p * 3;
        if(p - 1 > 2 * n) break;
    }
    if(i > 1) i = i - 1;
    m = i;

    p = 1;
    for(i = 0; i < m; i++){
        p = p * 3;
        G[m - 1 - i] = (p - 1) / 2;
    }
    cout << m << endl;
    for(i = 0; i < m - 1; i++) cout << G[i] << " ";
    cout << G[m - 1] << endl;

    for(int i = 0; i < m; i++){
        insertionSort(a, n, G[i]);
    }
}

int main()
{
    int i, A[1000000], n;
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];

    shellsort(A, n);
    cout << cnt << endl;
    for(i = 0; i < n; i++) cout << A[i] << endl;

    return 0;
}

Measured memory_bytes: 5064
import java.util.Scanner;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int[] a={1,3,5,7,8,10,12};
		int[] b={4,6,9,11};
		int x=0,y=0,flag=0;
		x=in.nextInt();y=in.nextInt();
		if(x==y) System.out.println("Yes");
		else {
			for(int i=0;i<a.length;i++)
			{
				for(int j=0;j<a.length;j++)
				{
					if(x==a[i]&&y==a[j])
					{
							flag=1;
							break;
					}
					
				}
			}
			for(int i=0;i<b.length;i++)
			{
				for(int j=0;j<b.length;j++)
				{
					if(x==b[i]&&y==b[j])
					{
							flag=1;
							break;
					}
					
				}
			}
			
			if(flag==1)System.out.println("Yes");
			else System.out.println("No");
			
		}
		
		

	}

}


Measured memory_bytes: 20948
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _n = read::<usize>();
    let input = read_vec::<usize>();

    for i in input.iter() {
        if i % 2 == 0 && i % 3 != 0 && i % 5 != 0 {
            println!("DENIED");
            return;
        }
    }
    println!("APPROVED");
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>

using namespace std;
int solve(){
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  if (N % 2 != 0 || N == 0){
    return 0;
  }
  
  int S_len = N / 2;
  string S_rep = S.substr(0, S_len);
  
  if(S_rep + S_rep == S){
    return 1;
  }
  
  return 0;
}


int main(){
   if(solve() == 1){
     cout << "Yes" << endl;
   }else{
     cout << "No" << endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl

ll n,a,b;

int main()
{
    SPEED;   
    cin>>n>>a>>b;
    if((a-b)%2==0)
        cout<<abs(a-b)/2<<endl;
    else
        cout<<min(a+(b-a-1)/2,n-b+1+(b-a-1)/2)<<endl;
    return 0;
}

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

namespace AOJHelloWorld1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            int d = a / b;
            int r = a % b;
            double f = (double)a / b;

            Console.WriteLine("{0} {1} {2}", d,r,f.ToString("f5"));
        }
    }
}


Measured memory_bytes: 18004
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_double
  gets.chop.to_f
end

def get_str
  gets.chop
end

def get_strs
  gets.chop.split
end

def main
  n = get_int
  if n % 2 == 0
    puts (n/2 -1)
  else
    puts (n / 2)
  end
end

if __FILE__ == $0
  main
end



Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1; i<=n; i++){
		if(i%3!=0 && i%5!=0) ans+=i;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, x;

int main()
{
    cin >> n >> x;
    if(n < 10) x += 100*(10-n);
    cout << x << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

s = input()
s = s[::-1]
ans = 0
a = -1
s = (s.replace('CB', 'D').replace('C', '\t').replace('B', '\t')).split()
for i in range(len(s)):
    for j in range(s[i].count('A')):
        a = s[i].find('A',a+1)
        ans += a-j
    a = -1
print(ans)

Measured memory_bytes: 5224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] H = new int[10000];
		int[] W = new int[10000];
		int i = 0;
		while(true) {
			H[i] = scan.nextInt();
			W[i] = scan.nextInt();
			if(H[i] == 0 && W[i] == 0) break;
			i++;
		}
		for(int k = 0; k < i; k++) {
			for(int h = 0; h < H[k]; h++) {
				for(int w = 0; w < W[k]; w++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}



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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p;

int n;
vector<int> v,c;

int main(){
  cin >> n;
  rep(i,0,n){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  rep(i,0,n){
    int tmp;
    cin >> tmp;
    tmp = v[i]-tmp;
    c.push_back(tmp);
  }
  int ans = 0;
  for(int i=0; i<n;i++){
    if(c[i]>0)ans+=c[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int n,k,a,i,j=0;
int s;
int main()
{
    scanf("%d %d %d",&n,&k,&s);
    for(i=0;i<n;i++)
    {
        if(i>=k)
            a=999999999;
        else
            a=s;
        if(i==0)
            printf("%d",a);
        else
            printf(" %d",a);
    }
    printf("\n");
    return 0;
}

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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 200500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

int moved[N], a[N];

void no() {
	printf("-1");
	exit(0);
}

int main() {
	FREOPEN();
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) moved[i] = i - a[i];
	for (int i = 1; i <= n; i++) if (moved[i] < 0) no();
	vector<int> ans;
	while (true) {
		bool update = 0;
		for (int i = n; i >= 1; i--) {
			if (moved[i] < 0) continue;
			if (moved[i] == 0) {
				update = 1;
				ans.pb(a[i]);
				for (int j = i; j <= n; j++) moved[j]--;
				break;
			}
		}
		if (!update) break;
	}
	for (int i = 1; i <= n; i++) if (moved[i] >= 0) no();
	while (!ans.empty()) {
		printf("%d\n", ans.back());
		ans.pop_back();
	}
	return 0;
}


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

namespace ProblemC
{
    class Program
    {
        // Beg 85 C
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var Y = read[1];
            int i = N;
            int j = 0;
            bool find = false;
            for (; i >= 0; i--)
            {
                var C = Y - 10000 * i;
                j = (C - 1000 * (N - i)) / 4000;
                if (C >= 0 && (C - 1000 * (N - i)) % 4000 == 0 && j >= 0 && N - i - j >= 0)
                {
                    find = true;
                    break;
                }
            }
            if (find)
                Console.WriteLine(i + " " + j + " " + (N - i - j));
            else
                Console.WriteLine(-1 + " " + -1 + " " + -1);
        }
    }
}


Measured memory_bytes: 28000
#include <stdio.h>

int next(int A, int B, int C, int X){
    return (A*X+B)%C;
}

int main(void){
    int N,A,B,C,X,i,j,k,Y,count;
    while(scanf("%d %d %d %d %d",&N,&A,&B,&C,&X),N||A||B||C||X){
        //printf("N:%d A:%d B:%d C:%d X:%d\n",N,A,B,C,X);
        count=0;
        for(i=0;i<N;i++){
            scanf("%d",&Y);
            //printf("Y%d:%d\n",i,Y);
            while(~count){
                count++;
                if(Y==X){
                    X=next(A,B,C,X);
                    break;
                }else{
                    X=next(A,B,C,X);
                }
                if(count>10000) count=-1;
            }
        }
        if(~count)count--;
        printf("%d\n",count);
    }
    
    return 0;
}

Measured memory_bytes: 600
from operator import itemgetter
N, M = map(int, input().split())
AB = sorted([list(map(int, input().split())) for i in range(N)], key=itemgetter(0))
ans, tmp = 0, 0
for ab in AB:
    if ab[1] + tmp < M:
        tmp += ab[1]
        ans += ab[0] * ab[1]
    else:
        ans += (M - tmp) * ab[0]
        break
print(ans)

Measured memory_bytes: 29864
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n,l; cin >>n>>l;
    vector<string> s(n); REP(i,n) cin >> s[i];
    sort(s.begin(), s.end());

    string ans = "";
    for (int i = 0; i < n; i++) {
        ans += s[i];
    }

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



Measured memory_bytes: 888
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  string s;
  cin >> s;
  int n = 0, l = s.length(), h = l/2+l%2;
  for(int i=0;i<h;i++){
    if(s[i]!=s[l-i-1]){
      n++;
    }
  }
  cout << n << endl;
  return 0;
}


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

h.reverse()

for i in range(n - 1):
    if(h[i+1] == h[i]+1):h[i+1] -= 1
    elif(h[i+1] <= h[i]):continue
    else:
        print('No')
        exit()
print('Yes')

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(1) {
    int n, x;
    cin >> n >> x;
    if(n == 0 && x == 0) { break; }
    int ans = 0;
    for(int i = 1; i <= n - 2; i++) {
      for(int j = i + 1; j <= n - 1; j++) {
        for(int k = j + 1; k <= n; k++) {
          int sum = i + j + k;
          if(sum == x) { ans++; }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[100010];
ll berat[100010];
ll dp[110][100010];

ll ks(int a, int sisa){
	if(sisa < 0) return -3e12;
	if(a == 0) return 0;
	if(dp[a][sisa] != -1) return dp[a][sisa];
	
	dp[a][sisa] = ks(a - 1, sisa);
	if(berat[a] <= sisa){
		dp[a][sisa] = max(dp[a][sisa], ks(a - 1, sisa - berat[a]) + v[a]);
	}
	//cout << a << " " << sisa << " " << dp[a][sisa] << endl;
	return dp[a][sisa];
}

int main (){
	memset(dp,-1,sizeof dp);
	ll n,w;
	cin >> n >> w;
	for(int i = 1; i <= n; i++){
		cin >> berat[i] >> v[i];
	}
	
	cout << ks(n,w) << endl;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

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

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int N;
int D[105];

int main()
{
    cin >> N;
    REP(i, N)
    {
        cin >> D[i];
    }
    sort(D, D + N);
    int m = D[0];
    int n = 1;
    REP(i, N)
    {
        if (m == D[i])
            continue;
        m = D[i];
        n++;
    }
    cout << n << endl;
    return 0;
}

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

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

	if ((n.at(0) == n.at(1) && n.at(1) == n.at(2)) || (n.at(1) == n.at(2) && n.at(2) == n.at(3))) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int> a(n);
  int even=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==0) even++;
  }
  cout<<(pow(3,n)-pow(2,even));
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int l;
	cin>>l;

	vector<int> vec;
	int f[101]={};
	for(int i=1; i<l+1; i++){
		int x;
		cin>>x;
		if(x>0){
			if(f[x]==1){
				cout<<i<<endl;
				return 0;
			}
			f[x]=1;
			vec.push_back(x);
		}else{
			if(f[abs(x)]==0){
				cout<<i<<endl;
				return 0;
			}
			if(vec[vec.size()-1]!=abs(x)){
				cout<<i<<endl;
				return 0;
			}
			vec.pop_back();
			f[abs(x)]=0;
		}
	}
	cout<<"OK"<<endl;

	return 0;
}



Measured memory_bytes: 3148
def examB():
    A = S()
    B = S()
    if len(A)>len(B):
        ans = "GREATER"
    elif len(A)<len(B):
        ans = "LESS"
    else:
        i = 0; k = 0; cur = 0; loop = len(A)
        while i==k:
            if cur==loop:
                ans = "EQUAL"
                break
            i = int(A[cur])
            k = int(B[cur])
            if i>k:
                ans = "GREATER"
                break
            elif i<k:
                ans = "LESS"
                break
            cur +=1
    print(ans)

import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


Measured memory_bytes: 3572
T=int(input())

def standardize(x,base_set):
  base_list=sorted(base_set,reverse=True)
  for base in base_list:
    x=min(x,x^base)    
  return x

for _ in range(T):
  N=int(input())
  alist=list(map(int,input().split()))
  slist=list(map(int,input()))
  
  base_set=set()
  for index in reversed(range(N)):
    norm_a=standardize(alist[index],base_set)
    if slist[index]==0:
      base_set.add(norm_a)
    else:
      if norm_a>0:
        print(1)
        break
    #print(index,base_set)
  else:
    print(0)

Measured memory_bytes: 68652
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		int N=sc.nextInt();
		int K=sc.nextInt();
		Map<String, Integer> map = new HashMap<String, Integer>(N);

		for(int i=0;i<N;i++) {
			String a=sc.next();
			
			if(map.containsKey(a)) {
				map.replace(a, map.get(a)+1);
			}else {
				map.put(a, 1);
			}
		}
		ArrayList<Integer> cc = new ArrayList<>(N);
		int sum=0;
		for(String a:map.keySet()) {
			cc.add(map.get(a));
			sum++;
		}
		Collections.sort(cc);
		int ans=0;
		for(int i=1;sum-i>=K;i++) {
			ans+=cc.get(i-1);
		}
		p(ans);
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

using namespace std;

int main () {
	string s;
	cin >> s;
	int a=0,b=0,c=0;
	for (int i=0;i<s.size();i++) {
		if (s[i]=='a') a++;
		else if (s[i]=='b') b++;
		else c++;
	}
	while (a>0&&b>0&&c>0) {
		a--;
		b--;
		c--;
	}
	if ((a==0&&b==0&&c==0)||(a==1&&b==0&&c==0)||(a==1&&b==1&&c==0)||(a==0&&b==1&&c==0)||(a==0&&b==1&&c==1)||(a==0&&b==0&&c==1)||(a==1&&b==0&&c==1)) cout << "YES" << endl; 
	else cout << "NO" << endl;
	return 0;
}

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

namespace atcoder_BegginerContest93_Question3
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var max = input.Max();
            var dif = 3 * max - input[0] - input[1] - input[2];

            Console.WriteLine(dif % 2 == 0 ? dif / 2 : (dif + 1) / 2 + 1);

        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
bool inrange(int x,int y,int z,int n)
{
  return 1<=x && x<=n && 1<=y && y<=n && 0<=z && z<n;
}
int main(void)
{
  int dx[27],dy[27],dz[27];
  REP(i,3) REP(j,3) REP(k,3){
    dx[i*9+j*3+k]=i-1;
    dy[i*9+j*3+k]=j-1;
    dz[i*9+j*3+k]=k-1;
  }
  for(;;){
    int n,m,p;
    cin >> n >> m >> p;
    if(!n&&!m&&!p) return 0;
    int field[8][8][8];
    int fh[8][8];
    REP(i,8) REP(j,8) REP(k,8) field[i][j][k]=8;
    REP(i,8) REP(j,8) fh[i][j]=0;
    string answer="Draw";
    REP(i,p){
      int turn=i%2+1;
      int x,y,z;
      cin >> x >> y;
      z=fh[x][y];
      if(answer!="Draw") continue;
      field[x][y][z]=turn;
      REP(j,13){
	int seq=1,tmpx,tmpy,tmpz;
	tmpx=x;tmpy=y;tmpz=z;
	while(tmpx+=dx[j],tmpy+=dy[j],tmpz+=dz[j],inrange(tmpx,tmpy,tmpz,n) && field[x][y][z]==field[tmpx][tmpy][tmpz]) ++seq;
	tmpx=x;tmpy=y;tmpz=z;
	while(tmpx-=dx[j],tmpy-=dy[j],tmpz-=dz[j],inrange(tmpx,tmpy,tmpz,n) && field[x][y][z]==field[tmpx][tmpy][tmpz]) ++seq;
	if(seq>=m){
	  answer=(turn==1)?"Black ":"White ";
	  answer+=to_string(i+1);
	}
      }
      fh[x][y]++;
    }
    cout << answer << endl;
  }
}

Measured memory_bytes: 1240
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=sorted(list(map(int,input().split())))
c=sorted([abs(i-x) for i in p])
for i in range(200):
  if c.count(i)==0:
    print(x-i)
    exit()
  elif c.count(i)==1 and i!=0:
    if p.count(x-i)==0:
      print(x-i)
    else:
      print(x+i)
    exit()
  else:
    pass

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

int main(){
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;
  
  int all = 0, cntb = 0;
  for(int i = 0; i < n; i++){
    if(all < a+b){
      if(s.at(i) == 'a'){
        cout << "Yes" << endl;
        all++;
      }
      else if(s.at(i) == 'b'){
        if(cntb < b){
          cout << "Yes" << endl;
          all++, cntb++;
        }
        else cout << "No" << endl;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 896