akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>
#include <typeinfo>
#include <memory>

using namespace std;

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

#define fs first
#define sc second


class event{
public:
    int t;
    int type;
    int x;
    int id;
};


bool comp(event e1, event e2){
    return e1.t <= e2.t;
}


int main(){
    int N, Q;
    vector<ll> d;

    vector<event> s1;
    set<P> s2;

    cin >> N >> Q;
    for(int i = 0; i < N; i++){
        event e1, e2;
        int s, t, x;
        cin >> s >> t >> x;
        e1.t = s - x;
        e1.type = 1;
        e1.x = x;
        e1.id = i;

        e2.t = t - x;
        e2.type = -1;
        e2.x = x;
        e2.id = i;

        s1.emplace_back(e1);
        s1.emplace_back(e2);
    }
    for(int i = 0; i < Q; i++){
        int q;
        cin >> q;
        d.push_back(q);
    }

    sort(s1.begin(), s1.end(), comp);


    int index = 0;
    auto itr = s1.begin();
    while(true){
        event e = *itr;
        if(index >= Q || itr == s1.end()){
            break;
        }
        if(d[index] < e.t){
            if(s2.empty()){
                cout << -1 << endl;
            }
            else{
                cout << (*s2.begin()).fs << endl;
            }
            index++;
        }
        else{
            if(e.type == 1){
                s2.insert(P(e.x, e.id));
            }
            else{
                s2.erase(P(e.x, e.id));
            }
            itr++;
        }
    }

    for(int i = index; i < Q; i++){
        cout << -1 << endl;
    }


    return 0;
}


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

struct Card{
    char a;
    int b;
};

bool compare_as_ints(Card i,Card j){
    return (i.b<j.b);
}

int partition(Card a[],int p,int r){
    Card x = a[r];
    int i = p-1;

    for(int j=p;j<=r-1;j++){
        if(a[j].b<=x.b){
            i++;

            swap(a[i],a[j]);
        }
    }

    swap(a[i+1],a[r]);

    return i+1;
}


void quickSort(Card a[],int p,int r){
    if(p<r){
        int q = partition(a,p,r);
        quickSort(a,p,q-1);
        quickSort(a,q+1,r);
    }
}


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

    Card a[100000],b[100000];

    for(int i=0;i<n;i++){
        cin >> a[i].a >> a[i].b;
        b[i] = a[i];
    }

    quickSort(a,0,n-1);
    stable_sort(b,b+n,compare_as_ints);


    bool flg = true;

    for(int i=0;i<n;i++){
        if(!(a[i].a==b[i].a&&a[i].b==b[i].b)){
            flg = false;
            break;
        }
    }


    if(flg){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }

    for(int i=0;i<n;i++){
        cout << a[i].a << ' ' << a[i].b << endl;
    }

    return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n;
    int i;
    for(i=0;i<n;i++){
        cin >> s;
        if(s == "Y"){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

typedef long long ll;
int X, Y, Z, K;
std::vector<ll> A, B, C;


bool judge ( ll P ) {
  ll rtn = 0;
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      for(int k=0; k<Z; k++){
        if ( A[i]+B[j]+C[k] < P ) break;
        rtn++;
        if ( rtn > K ) return true;
      }
    }
  }
  return false;
}

ll binary_search(ll P1, ll P2){
  if ( P1 == P2 ) return P1;
  ll center = std::floor((double)(P1+P2)/2);
  if ( judge(center) ) return binary_search(P1, center+1);
  else return binary_search(center, P2);
}

void sol_4 () {
  ll boarder = binary_search(A[0]+B[0]+C[0], A[X-1]+B[Y-1]+C[Z-1]);

  std::vector<ll> ABCsum;
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      for(int k=0; k<Z; k++){
        if ( A[i]+B[j]+C[k] < boarder-1 ) break;
        ABCsum.push_back(A[i]+B[j]+C[k]);
      }
    }
  }

  std::sort(ABCsum.begin(), ABCsum.end(), std::greater<ll>() );
  for(int i=0; i<K ; i++) std::cout << ABCsum.at(i) << std::endl;
}



int main (void){
  std::cin >> X >> Y >> Z >> K;
  for(int i=0; i<X; i++) {
    ll t_; std::cin >> t_;
    A.push_back(t_);
  }
  for(int i=0; i<Y; i++) {
    ll t_; std::cin >> t_;
    B.push_back(t_);
  }
  for(int i=0; i<Z; i++) {
    ll t_; std::cin >> t_;
    C.push_back(t_);
  }


  std::sort(A.begin(), A.end(), std::greater<ll>() );
  std::sort(B.begin(), B.end(), std::greater<ll>() );
  std::sort(C.begin(), C.end(), std::greater<ll>() );
  sol_4();

  return 0;
}

Measured memory_bytes: 262884
n = gets.to_i

class Fixnum
  def bijective_s(base=nil, offset=nil)
    offset ||= 'a'.ord #65
    base ||= 26
    value = self
    result = []
    while value > 0
      value -= 1
      result << (value%base+offset).chr
      value /= base
    end
    result.reverse.join
  end
end

puts n.bijective_s 

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

using namespace std;

#define U unsigned
#define L long
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define swap(a, b, tip) tip tempswap = a;a = b;b = tempswap;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);
	
int main(){
	char arr[4];

	cin >> arr;

	bool flag = false;

	if(arr[0] == '7'){
		flag = true;
	}
	if(arr[1] == '7'){
		flag = true;
	}
	if(arr[2] == '7'){
		flag = true;
	}

	if(flag){
		cout << "Yes";
		return 0;
	}
	cout << "No";
}


Measured memory_bytes: 3584
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
vector<LL> vq;
LL c1[100010], c2[100010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    vq.push_back(N);
    while (Q--) {
        LL qi;
        cin >> qi;
        while (!vq.empty() && qi <= vq.back()) vq.pop_back();
        vq.push_back(qi);
    }
    c2[vq.size() - 1] = 1;
    for (int i = vq.size() - 1; i > 0; i--) {
        LL q = vq.back(), w = c2[i];
        vq.pop_back();
        while (q > vq[0]) {
            int p = upper_bound(vq.begin(), vq.end(), q) - vq.begin() - 1;
            c2[p] += q / vq[p] * w;
            q %= vq[p];
        }
        c1[q] += w;
    }
    c1[vq[0]] += c2[0];
    for (int i = N - 1; i > 0; i--) c1[i] += c1[i + 1];
    for (int i = 1; i <= N; i++) cout << c1[i] << '\n';
    return 0;
}


Measured memory_bytes: 5708
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair< int, pair<int, int> >
#define plpll pair< ll, pair<ll, ll> >

using namespace std;

int32_t main(){
      int n;
      string s;
      cin >>n >>s;
      if(n >= 3200)
            cout <<s <<endl;
      else
            cout <<"red" <<endl; 
      return false;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
int N, M, a[100001];
long long x0[100002], x1[100002], O = 1LL << 60;
void add(int x, int y)
{
	if (x < y)
	{
		x0[1] += y - x;
		x0[x + 1] -= y - x;
		x0[y + 1] += y - x;
		x0[M + 1] -= y - x;
		x1[x + 1]--;
		x1[y + 1]++;
		x0[x + 1] += y + 1;
		x0[y + 1] -= y + 1;
	}
	else
	{
		x0[y + 1] += M + y - x;
		x0[x + 1] -= M + y - x;
		x1[x + 1]--;
		x1[M + 1]++;
		x0[x + 1] += M + y + 1;
		x0[M + 1] -= M + y + 1;
		x1[1]--;
		x1[y + 1]++;
		x0[1] += y + 1;
		x0[y + 1] -= y + 1;
	}
}
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	for (int i = 1; i < N; i++)
		add(a[i], a[i + 1]);
	for (int i = 2; i <= M; i++)
	{
		x0[i] += x0[i - 1];
		x1[i] += x1[i - 1];
	}
	for (int i = 1; i <= M; i++)
		O = std::min(O, x0[i] + x1[i] * i);
	printf("%lld\n", O);
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int a[200000];
int main ()
{
	long long ma=0,k,n,ba=0;
	cin>>k>>n;
	//cout<<k<<n;
	cin>>a[0];
	for(int t=1;t<n;t++)
	{ 
		cin>>a[t];
		a[t]=a[t]-ba-a[0];
		if(a[t]>ma) 
		{ 
			ma=a[t];
		} 
		ba=ba+a[t];
		//cout<<a[t]<<" "<<ba<<" "<<ma<<endl;
	} 
	if(k-ba>ma) 
	{ 
		ma=k-ba;
		//cout<<ma<<endl;
	} 
	cout<<k-ma;
	return 0;
} 

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

int main (){
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;
    if(a+b > c+d) std::cout << "Left";
    else if(a+b < c+d) std::cout << "Right";
    else std::cout << "Balanced";
    return 0;
}


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

int main() {
    char ch;
    cin >> ch;
    if(ch == 'a'){
        cout << 'b' << endl;
    } else if(ch == 'b'){
        cout << 'c' << endl;
    } else if(ch == 'c'){
        cout << 'd' << endl;
    } else if(ch == 'd'){
        cout << 'e' << endl;
    } else if(ch == 'e'){
        cout << 'f' << endl;
    } else if(ch == 'f'){
        cout << 'g' << endl;
    } else if(ch == 'g'){
        cout << 'h' << endl;
    } else if(ch == 'h'){
        cout << 'i' << endl;
    } else if(ch == 'i'){
        cout << 'j' << endl;
    } else if(ch == 'j'){
        cout << 'k' << endl;
    } else if(ch == 'k'){
        cout << 'l' << endl;
    } else if(ch == 'l'){
        cout << 'm' << endl;
    } else if(ch == 'm'){
        cout << 'n' << endl;
    } else if(ch == 'n'){
        cout << 'o' << endl;
    } else if(ch == 'o'){
        cout << 'p' << endl;
    } else if(ch == 'p'){
        cout << 'q' << endl;
    } else if(ch == 'q'){
        cout << 'r' << endl;
    } else if(ch == 'r'){
        cout << 's' << endl;
    } else if(ch == 's'){
        cout << 't' << endl;
    } else if(ch == 't'){
        cout << 'u' << endl;
    } else if(ch == 'u'){
        cout << 'v' << endl;
    } else if(ch == 'v'){
        cout << 'w' << endl;
    } else if(ch == 'w'){
        cout << 'x' << endl;
    } else if(ch == 'x'){
        cout << 'y' << endl;
    } else if(ch == 'y'){
        cout << 'z' << endl;
    }
}

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

using namespace std;

typedef long long ll;

int gcd(int a, int b) {
	return b? gcd(b, a % b): a;
}

const int maxn = 1e5 + 10;
int n, a[maxn];

int solve() {
	int cnt = 0;
	ll sum = 0;
	bool flag = false;
	for (int i = 0; i < n; ++i) {
		cnt += a[i] & 1;
		sum += a[i];
		if (a[i] == 1)
			flag = true;
	}
	if (flag)
		return ((sum - n) & 1);
	if (cnt >= 2) {
		if ((cnt & 1) == (n & 1))
			return 0;
		return 1;
	}
	if ((n + 1) & 1)
		return 1;
	int g = 0;
	for (int i = 0; i < n; ++i) {
		if (a[i] & 1)
			a[i]--;
		g = gcd(g, a[i]);
	}
	for (int i = 0; i < n; ++i)
		a[i] /= g;
	return solve() ^ 1;
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	if (n < 3) {
		if (n == 1)
			if (a[0] & 1)
				cout << "Second\n";
			else
				cout << "First\n";
		else
			if ((a[0] + a[1]) & 1)
				cout << "First\n";
			else
				cout << "Second\n";
		return 0;
	}
	if (solve())
		cout << "First\n";
	else
		cout << "Second\n";
	return 0;
}


Measured memory_bytes: 640
n = int(input())
txy = [[0, 0, 0]]

for i in range(n):
    txy.append(list(map(int, input().split())))

for j in range(1,n+1):
    t_diff = txy[j][0] - txy[j-1][0]
    x_diff = txy[j][1] - txy[j-1][1]
    y_diff = txy[j][2] - txy[j-1][2]
    if abs(x_diff) + abs(y_diff) <= t_diff and \
        (t_diff - abs(x_diff) - abs(y_diff))%2 == 0:
        continue
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 27300
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<(a*b)/2;
}

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


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

for i in range(n):
    if i == 0:
        continue

    if arr[i] < arr[i - 1]:
        print("No")
        exit()

    if arr[i] > arr[i - 1]:
        arr[i] -= 1

print("Yes")


Measured memory_bytes: 63856
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a, b;
    int x;
    for(int i=0;i<n;i++){
        cin >> x;
        a.push_back(x);
    }
    copy(a.begin(), a.end(), back_inserter(b));
    sort(b.begin(), b.end());
    int left = b[n/2-1], right = b[n/2];
    
    for(int i=0;i<n;i++){
        if(a[i]<=left){
            cout << right << endl;
        } else {
            cout << left << endl;
        }
    }
}

Measured memory_bytes: 3828
import collections
n = int(input())
a = list(map(int, input().split()))
dd = collections.defaultdict(int)
ans = 0
for i in range(n):
    dd[str(a[i])] += 1
for k in dd.keys():
    v = dd[k]
    diff = int(k) - v
    if diff <= 0:
        ans += abs(diff)
    else:
        ans += v
print(ans)

Measured memory_bytes: 23796
# your code goes here
l=[]
n=int(input())
min=10000000
max=-1000000
sum=0
l=list(map(int,input().split()))
for i in range(n):
 sum+=l[i]
 if(min>l[i]):
  min=l[i]
 if(max<l[i]):
  max=l[i]
print(min,max,sum)


Measured memory_bytes: 6596
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 1000005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;

bool prime[MAX];
int lowFactor[MAX];
void SIEVE(void){  /// 10^6 lowest factors stored ; O(Nlog(log(N)))
    for(int i=1;i<MAX;i++){
        prime[i]=true;
        lowFactor[i]=i;
    }
    prime[1]=false;
    for(int i=2;i*i<MAX;i++){
        if(!prime[i]) continue;
        for(int j=i*i;j<MAX;j+=i){
            prime[j]=false;
            if(lowFactor[j]==j) lowFactor[j]=i;
        }
    }
}

lint getFactorization(int a){ /// O(log(n)); n<10^6/10^7
    lint ans=1;
    while(a>1){
        int pre=lowFactor[a];
        int cong=0;
        while(lowFactor[a]==pre){
            pre=lowFactor[a];
            a/=pre;
            cong++;
        }
        if(cong) ans*=(cong+1);
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    SIEVE();
    lint n,sm=0;
    cin>>n;
    for(lint i=1;i<n;i++){
        sm+=getFactorization(n-i);
    }
    cout<<sm;
    return 0;
}


Measured memory_bytes: 8520
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n,a,b,c,t;
    double rate,ret;
    cin >> n >> a >> b >> c;
    int p = a, pr[n];
    for(int i=0;i<n;i++){
        cin >> pr[i];
    }
    sort(pr,pr+n);
    ret = (double)c/p;
    int tmpc = c, tmpp = p;
    for(int i=0;i<n;i++){
        tmpc = c;
        tmpp = p;
        for(int j=0;j<i;j++){
            tmpc += pr[n-1-j];
            tmpp += b;
        }
        ret = max(ret, (double)tmpc/tmpp);
    }
    cout << (int)floor(ret) << endl;
}

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

int main(){
   double pi = 3.141592653589793238;
   double a,b,h,m; cin>>a>>b>>h>>m;
   if(h==0) h=12.0;
   if(m==0) m=60.0;
   //double a1=1.0/12.0;
   //double a2=1.0/60.0;
   //cout<<a1<<" "<<a2<<endl;
   double c;
   if(m!=60.0) c=abs((h+m/60.0)/12.0-m/60.0);
   else c=abs((h)/12.0-m/60.0);
   //cout<<c<<endl;
   double co=cos(c*2*pi);
   //cout<<co<<endl;
   //cout<<c<<" "<<co<<endl;
   double ans=sqrt(a*a+b*b-2*a*b*co);
   printf("%.13f",ans);
   return 0;    
}


Measured memory_bytes: 4184
K = int(input().rstrip())
n = 1
if K%7==0:
    L = 9 * K / 7
else:
    L = 9 * K
R = 10 ** n
s = set()
if K == 1 or K == 7:
    print(1)
else:
    while R!=1:
        R = (10 * R) % L
        n += 1
        if R in s:
            print(-1)
            break
        else:
            s.add(R)
    else:
        print(n)

Measured memory_bytes: 77824
#!/usr/bin/env python3

import sys, heapq
sys.setrecursionlimit(300000)

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, S: "List[str]"):
    tmp = []
    for i in range(N):
        cur = 0
        mn = 0
        for c in S[i]:
            if c == '(':
                cur += 1
            else:
                cur -= 1
                mn = min(mn, cur)
        tmp.append((mn, cur))

    tmp.sort(key=lambda x: (x[1] < 0, (-x[0] if x[1] >= 0 else -(x[1] - x[0]))))
    #tmp.sort(key=lambda x: (x[1] < 0, -x[0], x[1]))
    #print(tmp)

    cur = 0
    for mn, cnt in tmp:
        #print(cur, mn, cnt)
        if abs(mn) > cur:
            print(NO)
            return
        cur += cnt

    if cur == 0:
        ret = YES
    else:
        ret = NO
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 229452
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // 入力受取
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String line1 = input.readLine();

        int N = Integer.parseInt(line1);
        int[] A = new int[N];
        int max1 = 0;
        int max2 = 0;
        for(int i=0;i<N;i++) {
            A[i] = Integer.parseInt(input.readLine());
            // 1番目に大きい値と2番目に大きい値を計算しておく
            if(max1<=A[i]) {
                max2 = max1;
                max1 = A[i];
            } else if(max2<=A[i]) {
                max2 = A[i];
            }
        }

        for(int i=0;i<N;i++) {
            // 1番目に大きい数と同じなら2番めに大きい数を出力する
            if(A[i]==max1) {
                System.out.println(max2);
            } else {
                System.out.println(max1);
            }
        }

    }
}


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

typedef long long ll;

int main(){
    int X;

    int ans = 0;    

    cin>>X;

    ans += 1000*(X/500);
    X -= (X/500)*500;

    
    ans += 5*(X/5);
    X -= (X/5)*5;
    

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4e5+5;
int a[maxn],b[maxn];
int nex[maxn],n;
queue<int>q;
void getnext()
{
	int i=0,j=-1;
	nex[0]=-1;
	while(i<n)
	{
		while(j!=-1&&b[i]!=b[j])j=nex[j];
		nex[++i]=++j;
	}
}
void solve()
{
	int i=0,j=0;
	while(j<n&&i<n*2-1)
	{
		if(j==-1||b[j]==a[i])i++,j++;
		else j=nex[j];
		if(j>=n)
		{
			q.push(i-n);
			i--,j--;
			j=nex[j];
		}
	}
}
int main()
{
	int i,aa[maxn]={0},bb[maxn]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&aa[i]),aa[i+n]=aa[i];
	for(i=0;i<n;i++)scanf("%d",&bb[i]),bb[i+n]=bb[i];
	for(i=0;i<n;i++)a[i]=a[i+n]=aa[i]^aa[i+1];
	for(i=0;i<n;i++)b[i]=bb[i]^bb[i+1];
	getnext();
	solve();
	while(!q.empty())
	{
		int num=q.front();q.pop();
		printf("%d %d\n",num,aa[num]^bb[0]);
	}
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

ll s2sum(string s){
	stringstream ss(s);
	ll curr = 0LL, res = 0LL;
	while(ss >> curr){
		res += curr;
	} // end while
	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string S; cin >> S;
	int n = (int)S.length();

	ll res = 0LL;
	for (int i = 0; i < (1<<(n-1)); ++i){
		string s = "";
		rep (j, n){
			s += S[j];
			if (i & (1<<j)){
				s += ' ';
			} // end if
		} // end rep
		ll curr = s2sum(s);
		res += curr;
//		cerr << s << endl;
	} // end for
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
    $ac = 0;
    $wa = 0;
    $tle = 0;
    $re = 0;

    $count = (int)fgets(STDIN);
    
    for($i = 0; $i < $count; $i++) {
        $J = trim(fgets(STDIN));
        if($J == "AC")
            $ac++;
        elseif ($J == "WA")
            $wa++;
        elseif ($J == "TLE")
            $tle++;
        else
            $re++;
    }
    
    echo "AC x $ac\n";
    echo "WA x $wa\n";
    echo "TLE x $tle\n";
    echo "RE x $re\n";
?>

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

int main(){
    int N, A;
    int flg_ap = 1;

    std::cin >> N;

    for(int i = 0; i < N; i++){
        std::cin >> A;
        if(A%2 == 0){
            if(A%3 !=0 && A%5 !=0){
                flg_ap = 0;
            }
        }
    }

    if(flg_ap == 1){
        std::cout << "APPROVED";
    }else{
        std::cout << "DENIED";
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N){
    ll ans = 0;
    return ans;
}

int main(){
    ll N,M; cin >> N >> M;
    if(N==M) print("Yes");
    else print("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		float a = sc.nextInt();
		
    		for(float i = 1; i < 10; i++){
    		    
    		    float b = a/i;
    		    
    		    if(b <= 9.0 && a % i == 0.0) {
    		        System.out.println("Yes");
                  	break;
    		    } else if(i == 9.0){
    		        System.out.println("No");
                    break;
    		    } else {
    		        continue;
    		    }
    		}



	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
vector<bool> seen;
vector<int> ans(3000, 0);
int d[3000][3000];
vector<vector<int>> G(3000);

void bfs(int s) {
  queue<int> q;
  q.push(s);
  seen[s] = true;

  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto next_v : G[v]) {
      if (seen[next_v]) continue;
      seen[next_v] = true;
      q.push(next_v);
      d[s][next_v] = d[s][v] + 1;
      ans[d[s][next_v]]++;
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, X, Y;
  cin >> N >> X >> Y;
  X--;
  Y--;
  FOR(i, N - 1) {
    G[i].push_back(i + 1);
    G[i + 1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);
  FOR(i, N) FOR(j, N) d[i][j] = 0;

  FOR(i, N) {
    seen.assign(N, false);
    bfs(i);
  }

  for (int i = 1; i < N;i++) cout << ans[i] / 2 << endl;
  return 0;
}

Measured memory_bytes: 25088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=1e5+5;
int n,val[N];
lint m,pos[N],gain[N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline lint nxi(){
		lint x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

lint solve(){
	static lint qsum[N];
	for(int i=1; i<=n; ++i){
		qsum[i]=qsum[i-1]+val[i]-pos[i]+pos[i-1];
	}
	for(int i=1; i<=n; ++i){
		apx(qsum[i],qsum[i-1]);
	}
	lint ss=0,ans=qsum[n];
	for(int i=n; i; --i){
		ss+=val[i];
		apx(ans,ss-(m-pos[i])*2+qsum[i-1]);
	}
	return ans;
}

int main(){
	n=nxi(),m=nxi();
	for(int i=1; i<=n; ++i){
		pos[i]=nxi(),val[i]=nxi();
	}
	lint ans=solve();
	for(int i=1; i<=n; ++i)
		pos[i]=m-pos[i];
	std::reverse(pos+1,pos+n+1);
	std::reverse(val+1,val+n+1);
	apx(ans,solve());
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 5688
#ITP_1_2_D
W, H, x, y, r = input().split()
W, H, x, y, r = int(W), int(H), int(x), int(y), int(r)

r_nouth = y + r
r_south = y - r
r_east = x + r
r_west = x - r

if H < 0:
  if r_south >= H and r_nouth <= 0:
    height = True
  else:
    height = False
else:
  if r_nouth <= H and r_south >= 0:
    height = True
  else:
    height = False

if W < 0:
  if r_west >= W and r_east <= 0:
    weith = True
  else:
    weith = False
else:
  if r_east <= W and r_west >= 0:
    weith = True
  else:
    weith = False

if height == True and weith == True:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 5600
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define Read_Fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
using namespace std;
using ll=long long;
const int N=2e5+5;
//ll cum[N+4];
int main()
{
    string str;
    cin>>str;
    int l=str.size();
    if(str[l-1]=='2' || str[l-1]=='4' || str[l-1]=='5' || str[l-1]=='7' || str[l-1]=='9')
    {
         cout<<"hon"<<endl;
    }
    else if(str[l-1]=='0' || str[l-1]=='1' || str[l-1]=='6' || str[l-1]=='8')
    {
         cout<<"pon"<<endl;
    }
    else
    {
        cout<<"bon"<<endl;
    }
    return 0;

}


Measured memory_bytes: 3568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>
#include <cassert>
#include <climits>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
void print() { std::cout << std::endl; }
template <typename T, typename... A> void print(const T& first, const A&... rest) { cout << sizeof...(rest) << endl; std::cout << first; if (sizeof...(rest)) std::cout << " "; print(rest...); }
template <typename... A> void print(const A&... rest) { print(rest...); }
template <typename A> void print(const std::vector<A>& v) { std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; }); std::cout << std::endl; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    priority_queue<ll> q;
    rep(i, n){
        ll a; 
        cin >> a;
        q.push(a);
    }
    rep(i, m){
        ll maxn = q.top();
        q.pop();
        q.push(maxn / 2);
    }
    ll ans = 0;
    rep(i, n){
        ll x = q.top(); q.pop();
        ans += x;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s, t; cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			if(i==s.size()-1) t.push_back('B');
			else if (s[i + 1] == 'C') t.push_back('D');
			else t.push_back('B');
		}
		else if (s[i] == 'C') {
			if (i == 0) t.push_back('C');
			else if (s[i - 1] != 'B') t.push_back('C');
		}
		else t.push_back('A');
	}
	ll count = 0, ans = 0;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] == 'A') count++;
		else if (t[i] == 'D') ans += count;
		else count = 0;
	}
	cout << ans << endl;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

int dp[1 << 18][51];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int n;
    cin >> n;

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

    vector <int> per;
    for (int i = 0; i < n; ++i)
        per.app(i);

    const int INF = 1e9;
    for (int i = 0; i < (1 << 18); ++i)
        for (int j = 0; j < 51; ++j)
            dp[i][j] = INF;

    dp[0][0] = 0;
    for (int mask = 0; mask < (1 << 18); ++mask) {
        int to = bp(mask);
        for (int r = 0; r < 51; ++r) {
            if (dp[mask][r] == INF)
                continue;


            for (int i = 0; i < n; ++i) {
                if (!((mask >> i) & 1)) {
                    
                    int x = a[i];
                    if ((i^to)&1)
                        x = b[i];
                    if (r <= x) {

                        int add = 0;
                        for (int j = 0; j < n; ++j)
                            if ((mask >> j) & 1)
                                add += i < j;
                         dp[mask | (1 << i)][x] = min(dp[mask | (1 << i)][x], dp[mask][r] + add);
                        
                    }   
                    
                }   
            }   
            
        }   
    }    

    int ans = INF;
    for (int i = 0; i < 51; ++i)
        ans = min(ans, dp[(1 << n) - 1][i]);

    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;            
}

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

int n;
long long int a[2*100000 + 10];
map<long long int,long long int> m;

int main() {

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    long long int ans = 0;

    long long int _sum = 0;

    for(int i=0; i<n; i++){

        _sum += a[i];

        m[_sum]++;

    }

    for(auto i : m){
        if(i.second > 1){
            ans += i.second * (i.second - 1) / 2;
        }
        if(i.first == 0){
            ans += i.second;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14336
// Daniel Grzegorzewski
// while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}

const int N = (int)1e5 + 3;

int x, y, a, b, c, res, p[N], q[N], r[N];
VII v;

signed main() {
  init_ios();
  cin >> x >> y >> a >> b >> c;
  for (int i = 1; i <= a; ++i) {
    cin >> p[i];
    v.PB({p[i], 1});
  }
  for (int i = 1; i <= b; ++i) {
    cin >> q[i];
    v.PB({q[i], 2});
  }
  for (int i = 1; i <= c; ++i) {
    cin >> r[i];
    v.PB({r[i], 0});
  }
  sort(v.begin(), v.end());
  int cnt1 = 0, cnt2 = 0;
  int wsk1 = -1, wsk2 = -1;
  for (int i = (int)v.size()-1; i >= 0; --i) {
    if (v[i].ND == 1)
      ++cnt1;
    if (v[i].ND == 2)
      ++cnt2;
    if (cnt1 == x && wsk1 == -1)
      wsk1 = i;
    if (cnt2 == y && wsk2 == -1)
      wsk2 = i;
  }
  cnt1 = cnt2 = 0;
  for (int i = (int)v.size()-1; i >= 0; --i) {
    if (v[i].ND == 1) {
      if (cnt1 == x)
        continue;
      ++cnt1;
      res += v[i].ST;
    }
    else if (v[i].ND == 2) {
      if (cnt2 == y)
        continue;
      ++cnt2;
      res += v[i].ST;
    }
    else {
      if (cnt1 == x && cnt2 == y)
        continue;
      if (cnt1 == x) {
        ++cnt2;
        res += v[i].ST;
        continue;
      }
      if (cnt2 == y) {
        ++cnt1;
        res += v[i].ST;
        continue;
      }
      res += v[i].ST;
      if (wsk1 < wsk2) {
        ++cnt1;
        ++wsk1;
        while (wsk1 < v.size() && v[wsk1].ND != 1)
          ++wsk1;
      }
      else {
        ++cnt2;
        ++wsk2;
        while (wsk2 < v.size() && v[wsk2].ND != 2)
          ++wsk2;
      }
    }
  }
  cout<<res<<"\n";
}

Measured memory_bytes: 12652
#include<stdio.h>
int main(void)
{
    int a[11];
    int z=0,y=0,x=0;
    int i;
    for(i=1;i<=10;i++){
        scanf("%d",&a[i]);
        if(x<a[i]){
            z=y;
            y=x;
            x=a[i];
        }
        else if(y<a[i]){
            z=y;
            y=a[i];
        }
        else if(z<a[i]){
            z=a[i];
        }
    }
    printf("%d\n%d\n%d\n",x,y,z);
    return 0;
}

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

using namespace std;

int main()
{

    int N, count;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++)
    {
        cin >> d[i];
    }
    sort(d, d + N);
    for (int i = 0; i < N - 1; i++)
    {
        if (d[i] != d[i + 1])
        {
            count++;
        }
    }
    cout << count+1 << endl;

}


Measured memory_bytes: 3624
c1x, c1y, c1r = map(int, input().split())
c2x, c2y, c2r = map(int, input().split())

dx,dy = c2x- c1x, c2y-c1y
s2 = dx**2 +dy**2
a = (s2+c1r**2 - c2r**2)/2
df =(s2 * c1r **2 -a **2)**0.5
ix1,ix2 = (a*dx+dy*df) /s2, (a*dx -dy * df)/s2
iy1,iy2 = (a*dy-dx*df)/s2, (a*dy+dx*df)/s2

if(ix1, iy1) > (ix2,iy2):
  ix1,ix2 = ix2, ix1
  iy1, iy2 = iy2, iy1
print(ix1 + c1x, iy1 + c1y, ix2 + c1x, iy2 + c1y)



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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n){
		cin >> s[i];
	}
	vector<vector<ll>> a(n,vector<ll>(14,0));

	rep(i,n){
		int dot = s[i].size();
		rep(j,s[i].size()){
			if(s[i][j] == '.'){
				dot = j;
			}
		}
		int k = 4;
		for(int j = dot - 1; j >= 0; j--){
			a[i][k] = s[i][j] - '0';
			k--;
		}
		k = 5;
		For(j,dot+1,s[i].size()){
			a[i][k] = s[i][j] - '0';
			k++;
		}
	}
	vector<vector<int>> count(19,vector<int>(19,0));
	ll ans = 0;
	rep(i,n){
		ll ten = 1;
		ll tmp = 0;
		for(int j = 13; j >= 0; j--){
			tmp += ten * a[i][j];
			ten *= 10;
		}
		int ni = 0, go = 0;
		while(tmp % 2 == 0){
			ni ++;
			tmp /= 2;
		}
		while(tmp % 5 == 0){
			go++;
			tmp /= 5;
		}
		ni = min(18,ni);
		go = min(18,go);
		for(int N = 18 - ni; N < 19; N++){
			for(int G = 18 - go; G < 19; G++){
				ans += count[N][G];
			}
		}
		count[ni][go]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 39068
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define FOR(i,k,n) for(int (i) = (k); (i) < (n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x,y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
template<class T> using vv=vector< vector<T> >;
typedef deque<int> di;
typedef deque< deque<int> > ddi;


int main() {
    while(1) {
        map<string, i_i> M;
        int n,q;
        cin >> n >> q;
        if(n==0) break;
        rep(i,n) {
            string s;
            int e,w;
            cin >> s >> e >> w;
            M[s] = make_pair(w-e, max(M[s].second,e));
        } 

        rep(i,q) {
            int w;
            bool f = false;
            cin >> w;
            for(auto itr = M.begin(); itr != M.end(); ++itr) {
                if(itr->second.first < w && (itr->second.first + itr->second.second) >= w) {
                    cout << itr->first << " " << w - itr->second.first << endl;
                    f = true;
                    break;
                } 
            }
            if(!f) cout << "Unknown" << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000000007
#define MOD 1000000007
#define ARRAY_MAX 3005


//重み付きUnion-Find
struct Potential_UnionFind{

    vector<int> par;//親
    vector<int> rank;//高さ
    vector<int> diff_weight;//根からの重み

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        REP(i,n){
            par[i] = i;
            rank[i] = 0;
            diff_weight[i] = 0;
        }
    }

    int root(int x) {//親を探す
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    int weight(int x) {
        //親からの重みを返す
        root(x);
        return diff_weight[x];
    }

    bool issame(int x,int y) {
        //同じ親を持つ要素かどうか
        return root(x) == root(y);
    }

    void merge(int x, int y,int w) {
        //weight(y) - weight(x) = wとなるようにつなげる
        int rx = root(x);
        int ry = root(y);
        
        if(rank[rx] < rank[ry]){
            diff_weight[rx] = -w - weight(x) + weight(y);
            par[rx] = ry;
        }else{
            diff_weight[ry] = w + weight(x) - weight(y);
            par[ry] = rx;
            if(rank[rx] == rank[ry]){
                rank[rx]++;
            }
        }
    }

    int diff(int x, int y) {
        //weight(y) - weight(x)を返す
        return weight(y) - weight(x);
    }
};


int main(){

    
    int n,m;
    while(cin >> n >> m,n|m){
        Potential_UnionFind tree;
        tree.init(n);
        bool ans = true;

        for(int i = 0;i < m;i++){

            char ch;
            int a,b,w;
            cin >> ch;
            if(ch == '?'){
                cin >> a >> b;
                a--;
                b--;
                if(tree.issame(a,b)){
                    cout << tree.diff(a,b) << endl;
                }else{
                    cout << "UNKNOWN" << endl;
                }
            }else{
                cin >> a >> b >> w;
                a--;
                b--;
                tree.merge(a,b,w);
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4004
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define gcd __gcd
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数 __builtin_popcount bitの個数

int main() {
  int N;
  ci(N);
  ve<ve<pair<int, int>>> A(N);
  rep(i, N){
    int a;
    ci(a);
    rep(j, a){
      int x, y;
      ci(x, y);
      A.at(i).pb(mp(x, y));
    }
  }
  int ans = 0, cnt = 0;
  rep(i, 1 << N){
    bool f = 1;
    rep(j, N){
      if(i >> j & 1){
        cnt++;
        each(k, A.at(j)){
          if((i >> (k.ft - 1) & 1) ^ k.sc){
            f = 0;
          }
        }
      }
    }
    if(f){  
      ans = max(cnt, ans);
    }
    cnt = 0;
  }
  co(ans);
}

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

using namespace std;

class DisjointSet {
    public:
        vector<int> rank, p;

        DisjointSet() { }
        DisjointSet(int size) {
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size; i++) makeSet(i);
        }

        void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

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

        void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        void link(int x, int y) {
            if (rank[x] < rank[y]) {
                p[x] = p[y];
            } else {
                p[y] = p[x];
                if (rank[x] == rank[y]) {
                    rank[x]++;
                }
            }
        }

        int findSet(int x) {
            while (x != p[x]) {
                x = p[x];
            }
            return p[x];
        }
};

int main(int argc, char const *argv[])
{
    int n, a, b, q;
    int t;

    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;
        if (t == 0) ds.unite(a, b);
        else if (t == 1) {
            if (ds.same(a, b)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3132
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

ll ans = 0;

int main(void){
	int h, n; cin >> h >> n;
	vint a(n);
	ll sum = 0;
	rep(i, n){
		ll a; cin >> a;
		sum += a;
	}
	if(h <= sum) cout << "Yes" << endl;
	else cout << "No" << endl;

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

Measured memory_bytes: 1024
#include <stdio.h>

int main(){

  int tmp,i,j,A[100],n,k,count=0;

  scanf("%d",&n);
    for(k=0;k<n;k++){
      scanf("%d",&A[k]);
    }
  for(i=1;i<=n;i++){
    for(j=n-1;j>=1;j--){

      if(A[j]<A[j-1]){
	tmp=A[j];
      A[j]=A[j-1];
      A[j-1]=tmp;
          count++;
      }
  
    }
  }
  
      for(i=0;i<n-1;i++){
	printf("%d ",A[i]);
	  }
      printf("%d\n",A[n-1]);
      printf("%d\n",count);
      return 0;
      
	}



Measured memory_bytes: 2140
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<bitset>
using namespace std;

#if 0
typedef long long ll;
#define WID 30 //10**9の場合
#define MOD 1000000007
//WID=int(log(l)/log(2))+1;で求める
//mのn乗を求める、lはnの最大値
ll power(int m,int n){
  bitset<WID> b(n);
  vector<ll> v(WID,0);v[0]=m;
  for(int i=0;i<WID-1;i++){
    v[i+1]=v[i]*v[i];v[i+1]%=MOD;
  }
  ll ans=1;
  for(int i=0;i<WID;i++){
    if(b[i]==1){ans=ans*v[i];ans%=MOD;}
  }
  return ans;
}
#endif

#if 1
typedef long long ll;
#define MOD 1000000007

ll power(int m,int n){
  ll ans=1;
  if(n>0){
    ans=power(m,n/2);
    if(n%2==0) ans=(ans*ans)%MOD;
    else ans=(((ans*ans)%MOD)*m)%MOD;
  }
  return ans;
}

#endif

int main(){
  int m,n;cin >> m >> n;
  cout << power(m,n) << endl;
}



Measured memory_bytes: 3084
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define xx first
#define yy second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int inf=0x3f3f3f3f;
const LL INF=0x3f3f3f3f3f3f3f3f;
const int N=3e5+10;
const int M=1e6+10;
char s[N];
int n=6;

int main(){
	scanf("%s",s+1);
	if(s[3]==s[4]&&s[5]==s[6]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256