akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout, marker::Usize1};

struct UnionFind {
    parents: Vec<isize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind { parents: vec![-1;n] }
    }

    fn root(&mut self, x: &usize) -> usize {
        let px = self.parents[*x];
        if px < 0 {
            return *x;
        } else {
            let pp = self.root(&(px as usize));
            self.parents[*x] = pp as isize;
            return pp;
        }
    }

    fn same(&mut self, x: &usize, y: &usize) -> bool {
        self.root(x) == self.root(y)
    }

    fn join(&mut self, x: &usize, y: &usize) {
        let rx = self.root(x);
        let cx = self.parents[rx];
        let ry = self.root(y);
        if rx == ry { return; }
        self.parents[rx] = ry as isize;
        self.parents[ry] += cx;
    }

    fn cnt(&mut self, x: &usize) -> usize {
        let rx = self.root(x);
        -self.parents[rx] as usize
    }
}


#[fastout]
fn main() {
    input! {
        n: usize, m: usize,
        arr: [(Usize1, Usize1); m],
    }

    let mut uf = UnionFind::new(n);
    for (a, b) in arr {
        uf.join(&a, &b);
    }
    let mut ans = 0;
    for i in 0..n {
        ans = std::cmp::max(uf.cnt(&i), ans);
    }
    println!("{}", ans)
}


Measured memory_bytes: 12252
N=int(input())
A= list(map(int, input().split()))

d=[0]*(N+1)

for i in range (0,N):
    c=A[i]
    d[c]+=1
    
z=0

for x in range (1,N+1):
    z+=d[x]*(d[x]-1)//2
    
for y in range (0,N):
    r=A[y]
    print(z+1-d[r])

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

int main(){
  int n,z,w;cin>>n>>z>>w;
  vector<int>a(n+5);
  for(int i=1;i<=n;++i){
    cin>>a[i];
  }
  if(n==1){
    cout<<abs(a[1]-w)<<endl;
    return 0;
  }
  cout<<max(abs(a[n]-w),abs(a[n]-a[n-1]))<<endl;
}


Measured memory_bytes: 256
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const X = parseInt(inputList[0].split(" ")[0]);
    const Y = parseInt(inputList[0].split(" ")[1]);

    const TURTLE = 4;
    const CRANE = 2;

    let isTrue = false;

    for (let i = 0; i <= X; i++) {
        const sum = (TURTLE * i) + (CRANE * (X - i));
        if (sum == Y) {
            isTrue = true;
            break;
        }
    }

    if (isTrue) {
        console.log("Yes");
    } else {
        console.log("No");
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29600
/*
    ABC 155 - A - Poor
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> mp;
    mp[a] = 1;
    mp[b] = 1;
    mp[c] = 1;
    if (mp.size() == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
    if cur==N:
        if a*b*c==0:
            return INF
        else:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
    ret0 = dfs(cur+1, a, b, c)
    ret1 = dfs(cur+1, a+L[cur], b, c) + 10
    ret2 = dfs(cur+1, a, b+L[cur], c) + 10
    ret3 = dfs(cur+1, a, b, c+L[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<std::pair<int64_t, int64_t>> c(n);

  for (int64_t i = 0; i < n; i++) {
    std::cin >> c[i].second >> c[i].first;
  }
  std::sort(c.begin(), c.end());

  int64_t t = 0;

  for (int64_t i = 0; i < n; i++) {
    t += c[i].second;
    if (c[i].first < t) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


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

int main(){
  int S;
  vector<int> N(4);
  cin >> S;
  N[0]=S/1000;
  N[1]=S%1000/100;
  N[2]=S%100/10;
  N[3]=S%10;
  for(int i=0; i<(1<<3); i++){
    int res=N[0];
    for(int j=0; j<3; j++){
      if(i&(1<<j)){
        res+=N[j+1];
      }
      else{
        res-=N[j+1];
      }
    }
    if(res==7){
      S=i;
      break;
    }
  }
  cout << N[0];
  for(int i=0; i<3; i++){
    if(S&(1<<i)){
      cout << '+';
    }
    else{
      cout << '-';
    }
    cout << N[i+1];
  }
  cout << "=7" << endl;
}

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

using namespace std;

int main()
{
    int a, b, c;
    
    set <int> s;

    cin >> a >> b >> c;

    s.insert(a);
    s.insert(b);
    s.insert(c);

    if (s.size() == 2)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

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

using namespace std;

bool solve(const string& S, const string& T){
  int n = S.size();
  for(int i=0;i<n;i++){
    bool ok = true;
    for(int j=0;j<n;j++){
      if(S[(i+j)%n] != T[j]) ok = false;
    }
    if(ok) return true;
  }
  return false;
}

int main(){
  string S, T; cin >> S >> T;
  cout << (solve(S, T) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, a, ans;
	ans = 100000000;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int j = 0;
		scanf("%d", &a);
		for (j = 0; a%2 == 0 ; j++)
		{
			a /= 2;
		}
		ans = (ans < j) ? ans : j;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>
#include <iomanip>
#include <map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 + 10, S2 = 1e7 * 2, MOD = 1e9 + 7, INF = 1e9 * 1e7;

vector<ll> vec;
vector<bool> graph[2];

int main() {
    fastInp;

    ll k, n = 1;
    cin >> k;

    ll lft = k;
    vector<ll> ans(50), mns(50);
    n = 50;
    ll addAll = lft / 50, add = 0;
    lft -= addAll * 50;
    for (int i = n - 1; i >= 0; i--) ans[i] = i;
    for (int i = 0; i < n; i++) {
        ans[i] += addAll * 50 - (addAll * (n - 1));
        if (lft > 0) {
            add++;
            mns[i] = 1;
            lft--;
            ans[i] += 50;
        }
    }
    for (int i = 0; i < n; i++) ans[i] -= add - mns[i];
    cout << 50 << "\n";
    for (int i = n - 1; i >= 0; i--) {
        cout << ans[i] << " ";
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        if (a < b && b < c) {
            System.out.println("Yes");

        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
int digit(int n){
	if(n<10) return 1;
	else return digit(n/10)+1;
}
signed main(){
	int n;
	cin>>n;
	int ans=INF;

	for(int a=1;a*a<=n;a++){
		if(n%a!=0) continue;
		int b=n/a;

		chmin(ans,max(digit(a),digit(b)));

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

Measured memory_bytes: 3660
#include <stdio.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
map<string, vector<pii>> mp;
int main(void) {
	int n; scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		string a; int b; cin >> a >> b;
		mp[a].push_back({ -b, i+1 });
	}
	for (auto& e : mp) {
		vector<pii>& x = e.second;
		sort(x.begin(), x.end());
		for (pii v : x) printf("%d\n", v.second);
	}
	return 0;
}

Measured memory_bytes: 256
# abc96d

import numpy as np
n = int(input())

def sosu(x):
    for i in range(2,int(np.sqrt(x))+1):
        if x%i == 0: return False
    return True

c = 2
ans = []
while 1:
    y = 20*c + 1
    if sosu(y):
        ans.append(y)
    c += 1
    if len(ans) == n: break

l = ""
for i in range(len(ans)):
    l += str(ans[i])
    l += " "

print(l[:len(l)-1])

Measured memory_bytes: 12488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const int siz = 1e5 + 7;
vector<pi>adj[siz];
bool vis[siz];
int dis[siz];
int n, m;
bool ok;
void dfs(int v) {
	vis[v] = true;
	for (auto k : adj[v]) {
		if (!vis[k.fi]) {
			dis[k.fi] = dis[v] + k.se;
			dfs(k.fi);
		}
		else {
			if (dis[k.fi] != dis[v] + k.se) {
				ok = true;
				return ;
			}
		}

	}
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l, r, m;
		cin >> l >> r >> m;
		adj[l].pb({r, m});
		adj[r].pb({l, -m});
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i])dfs(i);
	}
	if (ok)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 19504
#include<iostream>
#include<algorithm>
using namespace std;
inline int fib(int n){
    if(n==0||n==1){
        return 1;
    }
    return fib(n-1)+fib(n-2);
}
int main(){
    int x,y;
    cin >> x >> y;

    int xmin=0;
    int xmax=1;
    int ymin=0;
    int ymax=1;
    int c=0;

    while(1){
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }
        
        c++;
        xmin=xmax;
        xmax=xmin+fib(c);
        ymin=ymin;
        ymax=ymin+fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmax=xmax;
        xmin=xmax-fib(c);
        ymin=ymax;
        ymax=ymin+fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmax=xmin;
        xmin=xmax-fib(c);
        ymax=ymax;
        ymin=ymax-fib(c);
        if(xmin<=x&&x<xmax&&ymin<=y&&y<ymax){
            cout << c%3+1 <<endl;
            return 0;
        }

        c++;
        xmin=xmin;
        xmax=xmin+fib(c);
        ymax=ymin;
        ymin=ymax-fib(c);
    }
    return 0;
}


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

#define For(i,x,y) for (int i=x;i<y;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=100+3;
const int p=1e9+7;

int dp[N][N][N];
int A[N],vis[N];
int n,ans;

void upd(int &x,int y){
	x=(x+y)%p;
}

int main(){
	n=IN();
	For(i,1,2*n){
		A[i]=IN();
		vis[A[i]]=1;
	}
	sort(A+1,A+2*n);
	dp[n][1][1]=1;
	for (int i=n;i>1;i--)
		For(j,1,2*n) For(k,1,j+1)
			if (dp[i][j][k]){
				int x=(A[i]==A[i-1]),y=j+(A[2*n-i]!=A[2*n-i+1]);
				For(u,x,y+1){
					upd(dp[i-1][y-x+1-max(abs(k-u)-1,0)][u+(!x)-max(u-k-1,0)],dp[i][j][k]);
				}
			}
	For(i,1,2*n) For(j,1,i+1) upd(ans,dp[1][i][j]);
	printf("%d\n",ans);
}

Measured memory_bytes: 3456
h,w=map(int,input().split())
e=50000
for a,b in[(w,h),(h,w)]:
 for i in range(b):
  for c,d in[(a,b-i),(b-i,a)]:
   l=[i*a,c*(d//2),c*(d-d//2)]
   e=min(e,max(l)-min(l))
print(e)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*文字と文字の間に+を入れたものを総て列挙

*/
ll func(string S){
   vector<ll> v;//足し合わせる数字の列
   string kazu;//+の前後の数
   S.push_back('+');
   for(int i = 0;i<S.size();i++){
       
       if(S[i] >= '1' && S[i] <= '9'){
         kazu.push_back(S[i]);
       }
       if(S[i] == '+'){
           v.push_back(stol(kazu));
          kazu = "";
       }
    }
    ll sum = 0;
    for(int i = 0;i<v.size();i++){
        sum += v[i];
    }
    return sum;
   }

int main() {
 string S;
 cin >> S;
 ll ans = 0;
 //newSの奇数番目の要素をプラスにするかどうか

 for(int tmp = 0;tmp< (1<<9);tmp++){
     bitset<9> s(tmp);
     string newS(S.size()*2-1,'.');//+をいれる文字列
     for(int i = 0;i<S.size();i++){
         newS[i*2] = S[i];
     }

     for(int i = 0;i<S.size()-1;i++){
         if(s.test(i)){
             newS[i*2+1] = '+';
         }
     }
    //cout << newS << endl;
   ans += func(newS);
   if(s.count() == S.size()-1) break;
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  private static long INF = 100_000_000_000L;
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    int Z = sc.nextInt();
    int K = sc.nextInt();
    long[] A = inputAndSort(sc, X);
    long[] B = inputAndSort(sc, Y);
    long[] C = inputAndSort(sc, Z);
    
    Set<List<Integer>> checked = new HashSet<>();
    int count = 0;
    PriorityQueue<Cur> q = new PriorityQueue<>((a, b)-> {
      if (b.sum == a.sum) {
        return 0;
      }
      return a.sum < b.sum ? 1 : -1;
    });
    
    q.offer(new Cur(X-1, Y-1, Z-1, A[X-1]+B[Y-1]+C[Z-1]));
    while (!q.isEmpty() && count < K) {
      Cur c = q.poll();
      if (checked.contains(c.key)) {
        continue;
      }
      checked.add(c.key);
      count++;
      System.out.println(c.sum);
      if (c.x > 0) {
        q.offer(new Cur(c.x-1, c.y, c.z, A[c.x-1]+B[c.y]+C[c.z]));
      }
      if (c.y > 0) {
        q.offer(new Cur(c.x, c.y-1, c.z, A[c.x]+B[c.y-1]+C[c.z]));
      }
      if (c.z > 0) {
        q.offer(new Cur(c.x, c.y, c.z-1, A[c.x]+B[c.y]+C[c.z-1]));
      }
    }
  }
  private static long[] inputAndSort(Scanner sc, int n) {
    long[] ret = new long[n];
    for (int i = 0; i < n; i++) {
      ret[i] = sc.nextLong();
    }
    Arrays.sort(ret);
    return ret;
  }
  
  private static class Cur {
    final List<Integer> key;
    final int x;
    final int y;
    final int z;
    final long sum;
    Cur(int x, int y, int z, long sum) {
      this.key = asList(x, y, z);
      this.x = x;
      this.y = y;
      this.z = z;
      this.sum = sum;
    }
  }
  private static List<Integer> asList(int x, int y, int z) {
    List<Integer> ret = new ArrayList<>();
    ret.add(x);
    ret.add(y);
    ret.add(z);
    return ret;
  }
}

Measured memory_bytes: 32020
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from math import factorial 
def main():
    x, y = map(int, readline().split())
    if ((2*y-x)%3) or ((2*x-y)%3):
        print(0)
        return
    a = (2*y-x)//3
    b = (2*x-y)//3
    if a < 0:
        print(0)
        return
    if b < 0:
        print(0)
        return
    P = int(1e9)+7
    def c(n, m):
        ch = 1
        for i in range(m):
            ch *= (n-i)
            ch %= P
        b = factorial(m) 
        b = pow(b, P-2, P)
        return ch*b%P
    print(c(a+b, a)) 
if __name__ == '__main__':
    main()


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

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, int> p[n];
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        p[i] = {a, b};
    }
    sort(p, p + n);

    ll ans = 0;
    rep(i, n) {
        if (m <= p[i].second)
            ans += m * p[i].first, m = 0;
        else
            ans += p[i].first * p[i].second, m -= p[i].second;

        if (m == 0) break;
    }

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


Measured memory_bytes: 5216
from collections import deque
H,W = map(int,input().split())
maze = []
for i in range(H):
    maze.append(input())
nl = [(1,0), (0,1), (-1,0),(0,-1)]
ans = 0

def bfs(sy,sx):
    dist = [[-1]*W for _ in range(H)]
    q = deque([])
    q.append((sy,sx))
    dist[sy][sx] = 0
    maxd = 0
    while len(q)>0:
        cy, cx = q.popleft()
        for ny, nx in nl:
            ny += cy
            nx += cx
            if (0 <= ny < H) and (0 <= nx < W):
                if dist[ny][nx] == -1 and maze[ny][nx] == ".":
                    q.append((ny,nx))
                    dist[ny][nx] = dist[cy][cx] +1
                    if maxd < dist[ny][nx]:
                        maxd = dist[ny][nx]
    return maxd

for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            maxn = bfs(i,j)
            if maxn > ans:
                ans = maxn
print(ans)

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

int main(){
	string s;
	cin >> s;
	int n=s.length();
	int m=INF;
	int cnt=0;
	rep(i,n){
		if(i%2 == 0){
			if(s[i] == '0'){
				cnt++;
			}
		}else{
			if(s[i] == '1'){
				cnt++;
			}
		}
	}
	m=min(m,cnt);
	cnt=0;
	rep(i,n){
		if(i%2 == 0){
			if(s[i] == '1'){
				cnt++;
			}
		}else{
			if(s[i] == '0'){
				cnt++;
			}
		}
	}
	m=min(m,cnt);
	cout << m << endl;
	return 0;




}




Measured memory_bytes: 512
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

struct point
{
    double x = 0.0;
    double y = 0.0;
};

void koch(int depth, point p1, point p2)
{
    if (depth == 0)
        return ;
    point s, t, u;

    const double th = M_PI * 60.0 / 180.0;

    s.x = (2 * p1.x + p2.x) / 3.0;
    s.y = (2 * p1.y + p2.y) / 3.0;

    t.x = (p1.x + 2 * p2.x) / 3;
    t.y = (p1.y + 2 * p2.y) / 3;

    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(depth - 1, p1, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(depth - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(depth - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(depth - 1, t, p2);
}


int main()
{
    int n;
    point s;
    s.x = 0.0f;
    s.y = 0.0f;
    point t;
    t.x = 100.0f;
    t.y = 0.0f;
    while (cin >> n)
    {
        printf("%.8f %.8f\n", s.x, s.y);
        koch(n, s, t);
        printf("%.8f %.8f\n", t.x, t.y);
    }
    return 0;
}


Measured memory_bytes: 3164
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int ses[M];
 main()

{
    fast
    int n,q;
    cin>>n>>q;
    vector< tuple<double,int,int> >vec;
    f(i,1,n)
    {
        int s,t,x;
        cin>>s>>t>>x;
        double lft=s-0.5-x;
        double rgt=t-0.5-x;
        int p=1,q=-1;
        vec.pb(make_tuple(lft,p,x));
        vec.pb(make_tuple(rgt,q,x));
    }
    f(i,1,q)
    {
        int x;
        cin>>x;
        vec.pb(make_tuple(x,0,i));
    }
    sort(vec.begin(),vec.end());
    multiset<int>s;
    for(auto z:vec)
    {
        int typ=get<1>(z);
        double tym=get<0>(z);
        int x=get<2>(z);
        if(typ==1)
        {
           s.insert(x);
        }
        else if(typ==-1)
        {
            s.erase(x);
        }
        else
        {
            if(s.empty())ses[x]=-1;
            else ses[x]=*(s.begin());
        }
    }
    f(i,1,q)
    {
        cout<<ses[i]<<"\n";
    }
    return 0;

}





































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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int max = 0;
	for(int i = 1; i < n - 1; i++) {
		string chars = "";
		int count = 0;
		for(int k = 0; k < i; k++) {
			for(int l = i; l < n; l++) {
				bool flag = false;
				for(int j = 0; j < chars.size(); j++) {
					// cout << "chars :" << chars[j] << endl;
					if(s[k] == chars[j] || s[l] == chars[j]) flag = true;
				}
				// if(s[k] == s[l]) cout << "s[k] == s[l]: " << s[k] << endl;
				if(!flag && s[k] == s[l]) {
					chars += s[k];
					count++;
				}
			}
		}
		if(max < count) max = count;
		// cout << "count " << i << ": " << count << endl;
		// cout << "chars " << i << ": " << chars << endl;
	}
	cout << max << endl;
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ')
                .Select(__ => Int32.Parse(__));
        var a = Math.Min(input.ElementAt(0) , input.ElementAt(1));
        var b = Math.Max(input.ElementAt(0) , input.ElementAt(1));

        if ((b + a) % 2 != 0)
            Console.WriteLine("IMPOSSIBLE");
        else
            Console.WriteLine((b + a) / 2);
    }
}



Measured memory_bytes: 11348
let a, b = Scanf.scanf " %2d%2d" @@ fun a b -> a, b
let f x = x = 0 || x > 12
let _ = print_endline @@ match f a, f b with true, true -> "NA" | true, false -> "YYMM" | false, true -> "MMYY" | _ -> "AMBIGUOUS"

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  ll S = 0;
  rep(i,M) {
    ll A; std::cin >> A;
    S += A;
  }

  if ( S - N > 0 ) std::cout << -1 << std::endl;
  else std::cout << N - S << std::endl;
  return 0;
}



Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n;
	
	cin>>n;
	cout<<n/3<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
S=str(input())

ans='keyence'

if S[-7:]=='keyence':
    print('YES')
    exit()
   
for i in range(1,7):
    if S[:i]==ans[:i] and S[-7+i:]==ans[i:]:
        print('YES')
        exit()

if S[:8]=='keyence':
    print('YES')
    exit()

print('NO')


        







Measured memory_bytes: 2940
#   FizzBuzzSum

sum = 0
n = int(input())
for i in range(1, n + 1):
    if not ((i % 5 == 0) or (i % 3 == 0)):
        sum = sum + i
print(sum)
#   Fizz:(i%3==0)
#   Buzz:(i%5==0)
#   FizzBuzz:(i%3==0)and(i%5==0)
#   ベン図を描けば一目瞭然

Measured memory_bytes: 9172
if !ENV['RUBY_THREAD_VM_STACK_SIZE']
  exec({'RUBY_THREAD_VM_STACK_SIZE'=>'1000000000'}, '/usr/bin/ruby', $0)
end
begin
class Pqueue
  attr_accessor :heap, :sz

  def initialize
    @heap = Array.new
    @sz = 0
  end

  def add(x)
    i = @sz
    @sz += 1
    while i > 0
      p = (i - 1) / 2
      break if @heap[p][0] <= x[0]
      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end

  def dlt
    return nil if @sz <= 0
    ret = @heap[0]
    x = @heap[@sz -= 1]
    i = 0
    while i * 2 + 1 < @sz
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @heap[b][0] < @heap[a][0]

      break if @heap[a][0] >= x[0]
      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    @heap.pop
    return ret
  end

end

def dfs(v)
  res = 1
  # @to[v]&.each do |u|
  if @to[v]
    cnt = @to[v].size
    i = 0
    while i < cnt
      u = @to[v][i]
      res = res * dfs(u) % MOD
      i += 1
    end
  end
  res + 1
end

MOD = 998244353
N = gets.to_i
lists = []
N.times do
  s, t = gets.split.map(&:to_i)
  lists << [s, t]
end
lists.sort_by!{|x, y|x}

@to = {}
@s = Pqueue.new
(N-1).downto(0) do |i|
  x = lists[i][0]; d = lists[i][1]
  while @s.sz > 0 && @s.heap[0][0] < x + d
    (@to[i] ||= []) << @s.heap[0][1]
    @s.dlt
  end
  @s.add([x, i])
end

ans = 1
@s.heap.each do |x|
  v = x[1]
  ans = ans * dfs(v) % MOD
end
puts ans
rescue
  puts 2525
end

Measured memory_bytes: 71524
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(n);
    rep(i,m){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }    
    bool can = false;
    vector<bool> path1(n), path2(n);
    for(auto x: v[0]) path1[x] = true;
    for(auto x: v[n-1]) path2[x] = true;
    rep(i,n) if(path1[i] && path2[i]) can = true;
    cout << (can ? "POSSIBLE" : "IMPOSSIBLE") << endl;
    return 0;
}


Measured memory_bytes: 15868
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<stdlib.h>
#include<time.h>
#include<assert.h>
using namespace std;
int n,y;
int main(){
    cin>>n>>y;
    y/=1000;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int k=y-(10*i+5*j);
            if(k>=0&&i+j+k==n){
                return 0*printf("%d %d %d\n",i,j,k);
            }
        }
    }
    puts("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
AC = [0] * n
WA = [0] * n

for i in range(m):
    x = input().split()
    num = int(x[0]) - 1
    if x[1]=='AC':
        AC[num]=1
    elif x[1]=='WA' and AC[num]==0:
        WA[num]+=1
        
print(sum(AC), sum([w for i, w in enumerate(WA) if AC[i]]))

Measured memory_bytes: 51416
h,w=map(int,input().split())
n=int(input())
c=list(map(int,input().split()))
d=[]
for i in range(1,n+1):
  for j in range(c[i-1]):
    d.append(i)
ansl=[[0]*w for i in range(h)]
for i in range(h):
  if i%2==0:
    for j in range(w):
      ansl[i][j]=str(d[i*w+j])
  else:
    for j in range(w):
      ansl[i][w-j-1]=str(d[i*w+j])
for j in ansl:
  print(" ".join(j))


Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K , S , count;
  count = 0;
  cin >> K >> S;
  for(int x = 0; x < K+1 ;x++){
    for(int y = 0; y < K+1 ;y++){
      if(0 <= S - x - y && S - x - y <= K){
        count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

	int a[10],i,j,k;

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

	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++){
			if(a[i]<a[j]){
				k=a[i];
				a[i]=a[j];
				a[j]=k;
			}
		}
	}

	printf("%d\n%d\n%d\n",a[0],a[1],a[2]);

	return 0;
}

Measured memory_bytes: 600
(defun sum-d (k)
  (let ((ans 0))
    (loop while (/= k 0) do (incf ans (rem k 10)) (setf k (floor (/ k 10))))
    ans))

(let ((n (read))
      (flg nil))
  (loop for i from 0 while (>= n (expt 10 i)) do (if (= n (expt 10 i)) (setf flg t)))
  (format t "~A~%" (if flg 10 (sum-d n))))


Measured memory_bytes: 7520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    int n;
    cin >> n;
    ll min = LINF;
    vector<int> X(n);
    for(int i = 0; i < n; i++){
        cin >> X[i];
    }
    for(int i = 1; i <= 100; i++){
        ll sum = 0;
        for(auto x : X){
            sum += ((x - i) * (x - i));
        }
        if(min > sum) min = sum;
    }
    cout << min << endl;
    return 0;
}

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

int main()
{
    int n;cin>>n;
    for(int i=0;i<n;++i){
        int num[3];
        for(int j=0;j<3;++j)cin>>num[j];
        sort(num,num+3);
        if(pow(num[2],2)==pow(num[0],2)+pow(num[1],2))
            cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    char str[5] = { 0 };
    scanf("%s", str);
    int i;
    int ans = 0;
    int cnt = 0;
    for (i = 0; i < 3; i++) {
        if (str[i] == 'R') {
            cnt++;
        }
        else {
            cnt = 0;
        }
        ans = MAX(ans, cnt);

    }
    printf("%d\n", ans);


    return;
}

int main()
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for (t = 0; t < T; t++) {
        //printf("Case #%d: ", t + 1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 1736
N, M = map(int, input().split())
H = list(map(int, input().split()))
other_max_heights = [-1] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] < H[B]:
        other_max_heights[A] = max(other_max_heights[A], H[B])
    elif H[A] > H[B]:
        other_max_heights[B] = max(other_max_heights[B], H[A])
    else:
        other_max_heights[A] = max(other_max_heights[A], H[B])
        other_max_heights[B] = max(other_max_heights[B], H[A])

ans = 0
for h, omh in zip(H, other_max_heights):
    if h > omh:
        ans += 1
print(ans)


Measured memory_bytes: 84780
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 100011
#define ll long long
#define endl '\n'
ll dp[101][MAX],w;
int v[MAX],c[MAX];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n>>w;
	for(int i =0 ; i < n  ;i ++)cin>>c[i]>>v[i];
	for(int i = c[0] ; i <= w; i++)dp[0][i] = v[0];
	for(int i = 1; i < n ; i++){
		for(int j = 1 ; j <= w; j++){
			if(c[i] > j)dp[i][j]=dp[i-1][j];
            else dp[i][j]= max(dp[i-1][j], dp[i-1][j - c[i]]+v[i]);
		}
	}
	// for(int i = 0; i < n ;i++){
	// 	for(int j = 0; j <= w ; j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[n-1][w];
  	return 0; 
} 


Measured memory_bytes: 81712
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int N;
string s;

int main(){
    cin >> N;
    cin >> s;
    int le=0,lw=0,re,rw;
    int min = N + 1;
    re = count(s.begin(),s.end(),'E');
    rw = s.size() - re;
    for(int i=0;i<N;i++){
        if(s[i] == 'E') re--;
        else rw--;
        if(min > lw+re) min = lw + re;
        if(s[i] == 'E') le++;
        else lw++;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 900
while True:
    x = input().split()
    x_int = [int(i) for i in x]

    if x_int[0] == 0 and x_int[1] == 0:
        break
    for i in range(x_int[0]):
        for j in range(x_int[1]):
            if i % 2 == 0 :
                if j % 2 == 0:
                    print('#',end='')
                else:
                    print('.',end='')
            else:
                if j % 2 == 0:
                    print('.',end='')
                else:
                    print('#',end='')
        print()
    print()

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

int main() {
  int a, b, c;
  std::cin >> a >> b >> c;
  if (c <= a + b) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	String topping = sc.nextLine();
		switch (topping) {
          case "ooo":
            System.out.println("1000");
          	break;
          case "oox":
            System.out.println("900");
          	break;
          case "oxo":
            System.out.println("900");
          	break;
          case "xoo":
            System.out.println("900");
          	break;
          case "oxx":
            System.out.println("800");
          	break;
          case "xox":
            System.out.println("800");
          	break;
          case "xxo":
            System.out.println("800");
          	break;
          case "xxx":
            System.out.println("700");
          	break;
        }
	}
}

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

using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }


int main() {
	ll a, b;
	cin >> a >> b;
	if (a == 1) a = 100;
	if (b == 1) b = 100;
	if (a < b) cout << "Bob";
	if (a > b) cout << "Alice";
	if (a == b) cout << "Draw";

		
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
int N, M, root[100001], T[9000001], ls[9000001], rs[9000001], n;
std::vector < int > ins[100001];
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1, l, r; i <= N; i++)
	{
		scanf("%d%d", &l, &r);
		ins[l].push_back(r);
	}
	for (int i = 1; i <= M; i++)
	{
		root[i] = root[i - 1];
		for (int x : ins[i])
		{
			int p = root[i], nrt = ++n, l = 1, r = M;
			T[n] = T[p] + 1;
			while (l < r)
			{
				int m = l + r >> 1;
				if (x <= m)
					ls[n] = n + 1, rs[n] = rs[p], p = ls[p], r = m;
				else
					rs[n] = n + 1, ls[n] = ls[p], p = rs[p], l = m + 1;
				T[++n] = T[p] + 1;
			}
			root[i] = nrt;
		}
	}
	for (int i = 1; i <= M; i++)
	{
		int S = 0;
		for (int j = i; j <= M; j += i)
		{
			int pl = root[j - i], pr = root[j], l = 1, r = M;
			while (l < r)
			{
				int m = l + r >> 1;
				if (j <= m)
					S += T[rs[pr]] - T[rs[pl]], pl = ls[pl], pr = ls[pr], r = m;
				else
					pl = rs[pl], pr = rs[pr], l = m + 1;
			}
			S += T[pr] - T[pl];
		}
		printf("%d\n", S);
	}
	return 0;
}


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

int main() {
	int N, M,S=0;
	int A[10000];
	int i,j;
	cin >> N >> M;
	for (i = 0; i <= M - 1; i++) {
		cin >> A[i];
	}
	cout << '\n';
	for (j = 0; j <= M - 1; j++) {
		S += A[j];
	}
	if (N - S >= 0) cout << N - S << '\n';
	else cout << -1 << '\n';
	return 0;
}

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

typedef long long LL;
const int N = 605, mod = 1000000007;
 
int n, k, ans, dp[N][N], min[N], max[N], g[N], sum[N];

void down(int &x, int y) { x = std::min(x, y); }
void up(int &x, int y) { x = std::max(x, y); }
void reduce(int &x) { x += x >> 31 & mod; }

int dfs(int l, int r) {
	if (~dp[l][r]) return dp[l][r];
	int &ret = dp[l][r] = g[sum[r] - sum[l - 1]];
	for (int p = l + 1; p < r; p += 2)
		ret = (ret + (LL) (mod - dfs(l, p)) * g[sum[r] - sum[p]]) % mod;
	return ret;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::memset(dp, -1, sizeof dp);
	std::cin >> n >> k, g[0] = 1;
	for (int i = 2; i <= 2 * n; i += 2)
		g[i] = (LL) (i - 1) * g[i - 2] % mod;
	for (int i = 1; i <= 2 * n; ++i) min[i] = 2 * n, max[i] = 1;
	for (int i = 0; i < k; ++i) {
		int x, y; std::cin >> x >> y, sum[x] = sum[y] = 1;
		down(min[x], y), down(min[y], x), up(max[x], y), up(max[y], x);
	}
	for (int i = 1; i <= 2 * n; ++i) sum[i] = sum[i - 1] + !sum[i];
	for (int i = 1; i <= 2 * n; ++i) {
		int m = i, M = i;
		for (int j = i; j <= 2 * n; ++j) {
			m = std::min(m, min[j]), M = std::max(M, max[j]);
			if (m < i || M > j) dp[i][j] = 0;
		}
	}
	for (int i = 1; i <= 2 * n; ++i)
		for (int j = i + 1; j <= 2 * n; j += 2)
			ans = (ans + (LL) dfs(i, j) * g[sum[2 * n] - sum[j] + sum[i - 1]]) % mod;
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n);
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  ll s = 0;
  REP(i, n) s ^= a[i];
  REP(i, n) {
    if (i != 0) cout << " ";
    cout << (s ^ a[i]);
  }
  cout << endl;
}


Measured memory_bytes: 4700
n,m,c=map(int,input().split())
b=list(map(int,input().split()))

right=0

for i in range(n):
    a=list(map(int,input().split()))
    sum=0
    for j in range(m):
        sum+=a[j]*b[j]
    sum+=c
    if sum>0:
        right+=1

print(right)

Measured memory_bytes: 3060
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))

a.sort()
mc = sum(item<0 for item in a)
ans = []
if mc==1 or mc==0:
    val = a[0]
    for i in range(n-2):
        ans.append((val, a[i+1]))
        val = val - a[i+1]
    ans.append((a[n-1], val))
    value = a[n-1] - val
elif mc<n:
    val = a[-1]
    for i in range(mc-1):
        ans.append((val, a[i]))
        val -= a[i]
    val2 = a[mc-1]
    for i in range(mc, n-1):
        ans.append((val2, a[i]))
        val2 -= a[i]
    ans.append((val, val2))
    value = val-val2
else:
    val = a[-1]
    for i in range(n-1):
        ans.append((val, a[i]))
        val -= a[i]
    value = val
        
print(value)
write("\n".join(" ".join(map(str, item)) for item in ans))

Measured memory_bytes: 102196
#include <bits/stdc++.h>
using namespace std;
 
main(){
  int N, M ;
  cin >> N >> M ;
  int ans = 0 ;
  int count ;
  if(N > 1){
    ans += N * (N-1) / 2 ;
  }
  if(M > 1){
    ans += M * (M-1) / 2 ;
  }
  cout << ans ;
  return 0 ;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a<b){
    printf("a < b\n");
  }
  else if(a>b){
    printf("a > b\n");
  }
  else if(a==b){
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
s = input().replace("BC", "D")
n = len(s)
ans = 0
l = r = 0
while l < n:
    if s[l] != 'A':
        l += 1
        continue
    r = l + 1
    a = 1
    while r < n:
        if s[r] == 'A':
            a += 1
            r += 1
        elif s[r] == 'D':
            ans += a
            r += 1
        else:
            break
    l = r
print(ans)

Measured memory_bytes: 3500
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 5001


int main(){
	vector<int>a;
	vector<int>b, c;
	bool used[N];
	int n, k;
	int x, y, l, r, m;
	scanf("%d %d", &n, &k);
	f(i, N)used[i] = false;
	f(i, n){
		scanf("%d", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	b.push_back(0);
	used[0] = true;
	l = 0;
	r = n + 1;
	while (l + 1 < r){
		m = (l + r) / 2;
		m--;
		y = 0;
		b.clear();
		c.clear();
		memset(used, 0, sizeof(used));
		b.push_back(0);
		used[0] = true;
		f(i, n){
			if (i != m){
				f(j, b.size()){
					if (b[j] + a[i] <= k){
						if (!used[b[j] + a[i]]){
							c.push_back(b[j] + a[i]);
							used[b[j] + a[i]] = true;
							if (y < b[j] + a[i])y = b[j] + a[i];
						}
					}
				}
				b = c;
			}
		}
		if (y + a[m] < k)l = m + 1;
		else r = m + 1;
	}
	printf("%d\n", l);


	return 0;
}

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

int main(){
	int a,n,min=1000000,max=-1000000;
	long long int s=0;
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> a;
		s += a;

		if(a>max) max=a;
		if(a<min) min=a;
	}
	
	cout << min << " " << max << " " << s << "\n";
	return 0;
}

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

using namespace std;

const int NMAX = 100 + 5;

int n;
int v[2 * NMAX];

int main() {
    cin >> n;
    for (int i = 1; i <= 2 * n; ++ i)
        cin >> v[i];
    sort(v + 1, v + 2 * n + 1);

    int ans = 0;
    for (int i = 1; i <= 2 * n; i += 2)
        ans += v[i];

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll=long long;  
using pLL = std::pair<ll, ll>;

#define SORT(v) std::sort(v.begin(), v.end())
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    vector<int> like(b);
    for(int i=0;i<a;++i){
        int k;
        cin >> k;
        for(int j=0;j<k;++j){
            int temp;
            cin >> temp;
            like[temp-1]++;
        }
    }
    int count=0;
    for(int i=0;i<b;++i){
        if(a==like[i]) count++;
    }
    cout << count << endl;
    return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			String a = scanner.next();
			String b = scanner.next();
			int alen = a.length();
			int blen = b.length();
			int dp[][] = new int[alen + 1][blen + 1];

			int best = 0;
			for (int i = 1; i <= alen; i++)
				for (int j = 1; j <= blen; j++) {
					if (a.charAt(i - 1) == b.charAt(j - 1)) {
						dp[i][j] = dp[i - 1][j - 1] + 1;
						best = Math.max(best, dp[i][j]);
					}
				}
			System.out.println(best);
		}
	}
}

Measured memory_bytes: 184404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); 
    ll N; cin >> N;
    int ans = 0;
    FOR(i, 2, 1000010) {
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        FOR(j, 1, 10000) {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int n;
int a[222222];
int l[222222], r[222222], st[222222], cur;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	for(int i = 1; i <= n; ++i) scanf("%d",&a[i]);
	for(int i = 1; i <= n + 1; ++i){
		while (cur && a[i] < a[st[cur]]) r[st[cur]] = i - 1, --cur;
		st[++cur] = i;
	}
	cur = 0;
	for(int i = n; i >= 0; --i){
		while (cur && a[i] < a[st[cur]]) l[st[cur]] = i + 1, --cur;
		st[++cur] = i;		
	}
	long long an = 0;
	for(int i = 1; i <= n; ++i){
		an += 1ll * (r[i] - i + 1) * (i - l[i] + 1) * a[i];
	}
	printf("%lld",an);
	return 0;
}

Measured memory_bytes: 3328