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

#include<bits/stdc++.h>
using namespace std;
 
typedef vector<vector<int> > mat;
 
mat mul(mat A, mat B, int M){

    if(A[0].size() != B.size())return mat();
    int n = A.size(), m = B[0].size();
    mat C(n,vector<int> (m));
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k < A[0].size(); k++){
                C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
            }
        }
    }
    return C;
}
 
mat pow(mat A, int n, int M){
    mat res(A.size(),vector<int> (A[0].size()));
    for(int i = 0; i < A.size(); i++) res[i][i] = 1;
    while(n > 0){
        if(n & 1) res = mul(res, A, M);
        A = mul(A, A, M);
        n >>= 1;
    }
    return res;
}

int main(){

    while(1){
        int n, m, a, b, c, t; cin >> n >> m >> a >> b >> c >> t;
        if(!n) break;
        mat s(n, vector<int> (1));
        for(int i = 0; i < n; i++) cin >> s[i][0];

        mat A(n, vector<int> (n));
        for(int i = 0; i < n; i++){
            if(i != 0) A[i - 1][i] = c;
            A[i][i] = b;
            if(i != n - 1) A[i + 1][i] = a;
        }
        
        A = pow(A, t, m);    
        s = mul(A, s, m);
        for(int i = 0; i < n; i++){
            if(i != n - 1) cout << s[i][0] << " ";
            else cout << s[i][0] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

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

	ll sizeS = argS.size();

	ll ret0 = 0;
	for (ll i = 0; i < sizeS; ++i) {
		if (i % 2 == 0 && argS.at(i) == '0') {
			ret0++;
		}
		if (i % 2 == 1 && argS.at(i) == '1') {
			ret0++;
		}
	}

	ll ret1 = 0;
	for (ll i = 0; i < sizeS; ++i) {
		if (i % 2 == 1 && argS.at(i) == '0') {
			ret1++;
		}
		if (i % 2 == 0 && argS.at(i) == '1') {
			ret1++;
		}
	}

	cout << min(ret0, ret1) << endl;
}

Measured memory_bytes: 512
h,w=map(int,input().split())
g=[[c=='.'for c in input()] for _ in range(h)]
a=[[-3]*w for _ in range(h)]
for i in range(h):
  l=r=0
  for j in range(w):
    l=-~l*g[i][j]; a[i][j]+=l
    r=-~r*g[i][-1-j]; a[i][-1-j]+=r
for i in range(w):
  d=u=0
  for j in range(h):
    d=-~d*g[j][i]; a[j][i]+=d
    u=-~u*g[-1-j][i]; a[-1-j][i]+=u
print(max(a[i][j] for i in range(h) for j in range(w)))

Measured memory_bytes: 111836
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <queue>
#include <cmath>
#include <set>



using namespace std;
typedef long long ll;


int main () {
    ios_base::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<=m;i++)
        for(int j=0;j<=n;j++)
        {
            ll sum=i*n;
            sum+=(j*(m-2*i));
            if(sum==k)
            {
                cout<<"Yes";
                return 0;
            }
        }
    cout<<"No";
    
    return 0;

    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  if(a>b&&a>c)printf("%lld",b*c/2);
  else if(b>a&&b>c)printf("%lld",a*c/2);
  else printf("%lld",a*b/2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

const long INF = LLONG_MAX / 3;

template<typename T>
class SegTree {
private:
  int n;
  vector<T> segMin, segAdd;
  void _add(int a, int b, T x, int k, int l, int r){
    if(r<=a || b<=l) return;
    if(a<=l && r<=b){ segAdd[k]+=x; return; }
    int cl = k*2+1, cr = k*2+2;
    _add(a,b,x,cl,l,(l+r)/2);
    _add(a,b,x,cr,(l+r)/2,r);
    segMin[k] = min(segMin[cl]+segAdd[cl], segMin[cr]+segAdd[cr]);
  }
  T _min(int a, int b, int k, int l, int r) const {
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return segMin[k]+segAdd[k];
    return min(_min(a,b,k*2+1,l,(l+r)/2), _min(a,b,k*2+2,(l+r)/2,r)) + segAdd[k];
  }
public:
  SegTree(){}
  SegTree(int n_){
    n=1;
    while(n<n_) n*=2;
    segMin.resize(2*n-1, 0);
    segAdd.resize(2*n-1, 0);
  }
  SegTree(const vector<T> &v){
    int n_ = v.size();
    n=1;
    while(n<n_) n*=2;
    segMin.resize(2*n-1);
    segAdd.resize(2*n-1, 0);
    rep(i,n_) segMin[n+i-1] = v[i];
    for(int i=n-2; i>=0; i--) segMin[i] = min(segMin[2*i+1], segMin[2*i+2]);
  }
  inline void add(int a, int b, T x){ _add(a,b,x,0,0,n); } // add x in [a,b)
  inline T getMin(int a, int b) const { return _min(a,b,0,0,n); } // range min in [a,b)
};


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

  vector<vector<pair<int,int>>> v(n); // <start, value>
  rep(i,m){
    int l,r,a;
    cin>>l>>r>>a;
    l--;r--;
    v[r].push_back({l,a});
  }

  SegTree<long> st(n);
  rep(i,n){
    st.add(i, i+1, min(0L, st.getMin(0,i)));
    for(auto &p : v[i]){
      st.add(p.first, i+1, -p.second);
    }
  }

  cout << max(0L, -st.getMin(0,n)) << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	long long N;
	cin >> N;

	long long ans = N;
	double sqrtNum = sqrt(N);
	for (int i = 1; i <= sqrtNum; ++i) {
		if (N % i == 0) {
			long long result = (N / i) - 1 + i - 1;
			if (ans > result) {
				ans = result;
			}
			else {
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,ans=0;
  string S;
  cin >> N >> S;
  ll i=0,j=N-1;
  while(i<j){
    while(i<N&&S.at(i)=='R'){
      i++;
    }
    while(j>=0&&S.at(j)=='W'){
      j--;
    }
    if(i>=j){
      break;
    }
    ans++;
    i++;
    j--;
  }
  cout << ans << endl;
}
   

Measured memory_bytes: 3760
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

class Node implements Cloneable {
	int h, w;
	List<List<Integer>> route = new ArrayList<>();

	public Node clone() {
		Node newNode = new Node();
		newNode.h = h;
		newNode.w = w;
		for (int i = 0; i < route.size(); i++) {
			newNode.route.add(new ArrayList<>(route.get(i)));
		}
		return newNode;
	}

}

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int H = sc.nextInt();
		int W = sc.nextInt();

		int[][] s = new int[H + 1][W + 1]; // 1オリジン。0は使わない

		for (int i = 1; i <= H; i++) {
			String x = sc.next();
			for (int j = 1; j <= W; j++) {
				s[i][j] = x.charAt(j - 1) == '.' ? 0 : 1; // 0は白、1は黒。
			}
		}

		sc.close();

		boolean[][] visited = new boolean[H + 1][W + 1];

		Queue<Node> que = new ArrayDeque<>();
		Node st = new Node();
		st.h = 1;
		st.w = 1;
		st.route.add(Arrays.asList(1, 1)); // 初期地点を登録
		que.add(st);

		boolean noSolution = false;
		Node n;
		// 経路を探索
		while (true) {
			n = que.poll();

			// 調べるべきノードがない場合は、解がない場合
			if (n == null) {
				noSolution = true;
				break;
			}

			// 範囲外ならとばす
			if (n.h <= 0 || n.h > H || n.w <= 0 || n.w > W) {
				continue;
			}

			// 黒のマスならとばす
			if (s[n.h][n.w] == 1) {
				continue;
			}

			// ゴールならループを抜ける
			if (n.h == H && n.w == W) {
				break;
			}

			// すでに訪問済みなら、queに登録ずみなのでとばす
			if (visited[n.h][n.w]) {
				continue;
			}

			// 訪問済みにマーク
			visited[n.h][n.w] = true;

			Node right = n.clone();
			right.w++;
			right.route.add(Arrays.asList(right.h, right.w));
			que.add(right);

			Node down = n.clone();
			down.h++;
			down.route.add(Arrays.asList(down.h, down.w));
			que.add(down);

			Node left = n.clone();
			left.w--;
			left.route.add(Arrays.asList(left.h, left.w));
			que.add(left);

			Node top = n.clone();
			top.h--;
			top.route.add(Arrays.asList(top.h, top.w));
			que.add(top);

		}

		if (noSolution) {
			out.println("-1");
			return;
		}

		// n.routeが最短経路なので、そこを通り道としてマークする
		for (List<Integer> r : n.route) {
			s[r.get(0)][r.get(1)] = 2;
		}

		// 黒でもなく最短経路でもないマスを数える。
		int ans = 0;
		for (int i = 1; i <= H; i++) {
			for (int j = 1; j <= W; j++) {
				if (s[i][j] == 0) {
					ans++;
				}
			}
		}

		out.println(ans);
	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 40748
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<List<Edge>> edge = new ArrayList<>();
		for (int i = 0;i < N;++ i) edge.add(new ArrayList<>());
		for (int i = 1;i < N;++ i) {
			int u = sc.nextInt() - 1, v = sc.nextInt() - 1, w = sc.nextInt();
			edge.get(u).add(new Edge(v, w));
			edge.get(v).add(new Edge(u, w));
		}
		int[] color = new int[N];
		Arrays.fill(color, -1);
		color[0] = 0;
		Queue<Integer> queue = new ArrayDeque<>();
		queue.add(0);
		while (!queue.isEmpty()) {
			int tmp = queue.poll();
			for (Edge i : edge.get(tmp)) {
				if (color[i.edge] >= 0) continue;
				color[i.edge] = color[tmp] ^ (i.weight & 1);
				queue.add(i.edge);
			}
		}
		for (int i = 0;i < N;++ i) System.out.println(color[i]);
	}
	public static class Edge {
		int edge;
		int weight;
		public Edge(int edge, int weight) {
			this.edge = edge;
			this.weight = weight;
		}
	}
}

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

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

    int n;
    cin >> n;
    string input = to_string(n);
    if(input[input.length()-1]=='2' || input[input.length()-1]=='4' || input[input.length()-1]=='5' || input[input.length()-1]=='7' || input[input.length()-1]=='9')
        cout << "hon" << endl;
    else if(input[input.length()-1]=='0' || input[input.length()-1]=='1' || input[input.length()-1]=='6' || input[input.length()-1]=='8')
        cout << "pon" << endl;
    else if(input[input.length()-1]=='3')
        cout << "bon" << endl;
    return 0;
}

Measured memory_bytes: 3720
#include<cstdio>
typedef long long ll;
int tot=0;
ll p[10005],sum[100005];
int main() {
	ll cnt=0,n,tmp;
	scanf("%lld",&n);
	tmp=n;
	for(register ll i=2;i*i<n;++i) {
		if((n-1)%i==0) {
			++cnt;
			if(i!=(n-1)/i) ++cnt;
		}
	}
	for(register ll i=2;i*i<=n;++i) {
		if(n%i==0) {
			tmp=n;
			while(tmp%i==0) tmp/=i;
			if(tmp%i==1) ++cnt;
			if(i*i==n) continue;
			tmp=n;
			while(tmp%(n/i)==0) tmp/=(n/i);
			if(tmp%i==1) ++cnt;
		}
	}
	if(n!=2) ++cnt;
	printf("%lld\n",cnt+1);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        var n = sc.nextInt();
        var a = sc.nextInt();
        var b = sc.nextInt();

        Console.WriteLine(Math.Min(a * n, b));
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
from collections import Counter
n = int(input())
a = []
for i in range(n):
    a.append(Counter(input()))
for i in range(97, 97+26):
    m = 100
    for j in range(n):
        m = min(a[j][chr(i)], m)
    print(chr(i)*m, end='')
print()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}
int v[200001];
int main()
{
    int x, n;
    cin >> x >> n;
    US<int> s;
    FOR(i, n)
    {
        int t;
        cin >> t;
        s.insert(t);
    }
    for (int l = x, r = x;; --l, ++r)
    {
        if (not s.count(l))
        {
            cout << l;
            return 0;
        }
        if (not s.count(r))
        {
            cout << r;
            return 0;
        }
    }
}

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

int main()
{
  int K;
  cin >> K;
  string S;
  cin >> S;

  if (S.size() <= K)
  {
    cout << S << endl;
  }
  else
  {
    cout << S.substr(0, K) << "..." << endl;
  }
}


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

int main(){
	int n, a, b, mx = 0, mxb;
	cin >> n;
	rep(i, n){
		cin >> a >> b;
		if(mx < a){
			mx = a;
			mxb = b;
		}
	}
	
	cout << mx + mxb << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b;
    int sum = 0;
    cin >> a >> b;
    if(a > b) {
        sum = a;
        a--;
    }
    else {
        sum = b;
        b--;
    }
    if(a > b) {
        sum += a;
    }
    else {
        sum += b;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from itertools import accumulate


N = int(input())
A1 = [0] + list(accumulate(map(int, input().split())))
A2 = [0] + list(accumulate(map(int, input().split())))
ans = 0
for i in range(1, N + 1):
    cur = A1[i - 1]
    if i < N:
        cur += A2[N] - A2[i]
    ans = max(ans, cur + A1[i] - A1[i - 1] + A2[i] - A2[i - 1])
print(ans)


Measured memory_bytes: 3064
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    n,a,b = map(int, input().split())
    i = n//(a+b)
    j = n%(a+b)
    if j<=a:
        print(a*i+j)
    else:
        print(a*(i+1))



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
list_S = list(input())
ans = "WA"
if list_S[0] == "A":
    list_S.remove("A")
    if "C" in list_S[1:-1]:
        list_S.remove("C")
        for c in list_S:
            if c not in ["q","a","z","w","s","x","e","d","c","r","f","v","t","g","b","y","h","n","u","j","m","i","k","o","l","p"]:
                ans = "WA"
                break
            else:
                ans = "AC"

print(ans)


Measured memory_bytes: 3060
object Main extends App {
  import scala.io.StdIn._
  val c = readInt()
  println(
    c match {
      case _ if (65 to 90).contains(c) ⇒ 1
      case _ if (97 to 122).contains(c) ⇒ 2
      case _ ⇒ 0
    }
  )
}



Measured memory_bytes: 43680
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;

int main(){
	int num[4];
	for(int i=0;i<4;i++) num[i] = 0;

	for(int i=0;i<3;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		num[a]++;
		num[b]++;
	}
	int n1 = 0;
	int n2 = 0;
	for(int i=0;i<4;i++){
		if(num[i]==1)n1++;
		if(num[i]==2)n2++;
	}
	if(n1==n2){
		printf("YES\n");
	}else{
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ans += 2 * min(x, k - x);
  }
  cout << ans << endl;
}

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

/* i の平方根が整数であるか */
bool isPowerd(int i){
  
  int cur = 2;
  int counter = 0;
  while (i > 1){
    if (i % cur == 0) {
      // cout << cur << ":" << counter << ":" << i << endl;
      counter++;
      i /= cur;
      // cout << i << endl;
    } else {
      if (counter % 2 != 0){
        return false;
      } else if (cur < i){
        counter = 0;
        cur++;
      } else {
        return false;
      }
    }
  }
  if (counter % 2 == 0) return true;
  else return false;
  return true;
}

int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> p(N, vector<int>(D));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < D; j++){
    	cin >> p[i][j];
    }
  }
  
  int cnt = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
		long long dis = 0;
    	for (int dim = 0; dim < D; dim++){
      		dis += pow(p[i][dim] - p[j][dim],2);
    	}
      	if (isPowerd(dis)){
          cnt++;
        }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.second>secondElof.second;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll a,p;cin>>a>>p;
    p+=a*3;
    cout<<p/2<<endl;
}


Measured memory_bytes: 256
// aoj-0000.c

#include <stdio.h>

int main() {
	int i, j;
	
	for (i = 1; i < 10; i++) {
		for (j = 1; j < 10; j++) {
			printf("%dx%d=%d\n", i, j, (i * j));
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
 
using namespace std;
 
int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	long long res = 0, hs1 = n/(a+b), hs2 = n%(a+b);
	if(hs2 > a) hs2 = a;
	res = hs1*a+hs2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# abc109_c.py
# https://atcoder.jp/contests/abc109/tasks/abc109_c

# C - Skip /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 数直線上に N個の都市があり、i 番目の都市は座標 xiにあります。
# あなたの目的は、これら全ての都市を 1度以上訪れることです。
# あなたは、はじめに正整数 Dを設定します。
# その後、あなたは座標 Xから出発し、以下の移動 1、移動 2を好きなだけ行います。
#     移動 1: 座標 y から座標 y+Dに移動する
#     移動 2: 座標 y から座標 y−Dに移動する
# 全ての都市を 1度以上訪れることのできる Dの最大値を求めてください。
# ここで、都市を訪れるとは、その都市のある座標に移動することです。

# 制約
#     入力はすべて整数である
#     1≤N≤10^5
#     1≤X≤10^9
#     1≤xi≤10^9
#     xiはすべて異なる
#     x1,x2,...,xN≠X

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N X
# x1 x2 ... xN

# 出力
# 全ての都市を 1度以上訪れることのできる Dの最大値を出力せよ。

# 入力例 1
# 3 3
# 1 7 11

# 出力例 1
# 2

# D=2と設定すれば次のように移動を行うことですべての都市を訪れることができ、これが最大です。

#     移動 2を行い、座標 1に移動する
#     移動 1を行い、座標 3に移動する
#     移動 1を行い、座標 5に移動する
#     移動 1を行い、座標 7に移動する
#     移動 1を行い、座標 9に移動する
#     移動 1を行い、座標 11に移動する

# 入力例 2
# 3 81
# 33 105 57

# 出力例 2
# 24

# 入力例 3
# 1 1
# 1000000000

# 出力例 3
# 999999999


def calculation(lines):
    # N = int(lines[0])
    N, X = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    values.append(X)
    mi = min(values)
    # 最小値を起点とする
    values = [value - mi for value in values]

    for _ in range(10):
        # 解の候補として最小値を取得する
        values = [value for value in values if value > 0]
        mi = min(values)
        # 最小値単位のあまりを取得する
        values = list(set([value % mi for value in values]))
        if values == [0]:
            return [mi]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3 3', '1 7 11']
        lines_export = [2]
    if pattern == 2:
        lines_input = ['3 81', '33 105 57']
        lines_export = [24]
    if pattern == 3:
        lines_input = ['1 1', '1000000000']
        lines_export = [999999999]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 21284
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  map<char,int> A;
  for(int i=0;i<s.length();i++){
    A[s[i]]++;
  }
  bool flag=true;
  for(char t='a';t<='z';t++){
    if(A[t]==0){
      cout<<t<<endl;
      flag=false;
      break;
    }
  }
  if(flag)cout<<"None"<<endl;

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  ll N;
  cin >> N;

  vvi a(N, vi(N, -1));

  for (ll i = 0; i < N - (N % 2); i++) {
    for (ll j = 0; j < N - (N % 2); j++) {
      if (i == j)
        continue;
      if (abs(i - j) == 1 || abs(i - j) == (N - (N % 2)) - 1)
        a[i][j] = 1;
      else
        a[i][j] = 2;
    }
  }

  queue<tuple<ll, ll, ll>> q;
  q.emplace(0, N - 1, 1);

  while (q.size()) {
    ll l, r, x;
    tie(l, r, x) = q.front();
    q.pop();

    if (l >= r) {
      continue;
    }

    if (r - l == 1) {
      a[l][r] = a[r][l] = x;
      continue;
    }

    ll mid = (r + l) / 2;
    for (ll i = l; i <= mid; i++) {
      for (ll j = mid + 1; j <= r; j++) {
        a[i][j] = a[j][i] = x;
      }
    }

    q.emplace(l, mid, x + 1);
    q.emplace(mid + 1, r, x + 1);
  }

  for (ll i = 0; i < N; i++) {
    for (ll j = i + 1; j < N; j++) {
      cout << a[i][j];
      if (j == N - 1)
        cout << endl;
      else
        cout << ' ';
    }
  }
}

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

int main(){
    int s, k, x, y, z, count=0;
    cin >> k>> s;
    for (x=0; x <=k; x++) {
        for (y=0; y<=k; y++) {
            z=s-x-y;
            if (z>=0&&z<=k) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

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

	long long  sum=0;
	for(long long i=1;i<=n;i++)
	{
		if(i%3==0 || i%5==0)
			continue;
		else sum=sum+i;
	}

	cout<<sum;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,A;
vector<ll> enumdiv(ll n) {
	vector<ll> S;
	for(ll i=1;i*i<=n;i++) if(n%i==0) {S.push_back(i); if(i*i!=n) S.push_back(n/i); }
	sort(S.begin(),S.end());
	return S;
}

vector<ll> V;

ll dp[1010101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A;
	
	ll mi=N;
	// once;
	ll X;
	for(X=1;X*(X-1)<=N;X++) {
		mi=min(mi,X+A+(N+(X-1))/X);
	}
	// morethan 2
	for(X=2;X*(X-1)*(X-2)<=N;X++) {
		FOR(x,40) {
			ll pace=1;
			ll tot=0;
			ll t=X;
			FOR(y,40) {
				if(y<x) {
					pace=pace*X;
					tot+=X+A;
				}
				else {
					pace=pace*(X-1);
					tot+=(X-1)+A;
				}
				mi=min(mi,tot+(N+(pace-1))/pace);
				if(pace>N) break;
			}
		}
		
	}
	
	cout<<mi<<endl;
	return;
	
	dp[1]=1;
	for(i=1;i<=N;i++) dp[i]=i;
	for(i=2;i<N;i++) {
		for(j=i*2;j<=2*N;j+=i) {
			if(j>N) {
				dp[N]=min(dp[N],dp[i]+A+(j/i));
				break;
			}
			else {
				dp[j]=min(dp[j],dp[i]+A+(j/i));
			}
		}
	}
	for(i=1;i<=N;i++) _P("%d %lld\n",i,dp[i]);
	
	cout<<dp[N]<<endl;
	
#if 0
	FOR(i,N+1) FOR(j,N+1) dp[i][j]=1LL<<60;
	dp[0][1]=0;
	for(i=1;i<=N;i++) {
		for(j=0;j<=N;j++) if(dp[j][i]<1LL<<60) {
			_P("%d %d : %lld\n",j,i,dp[j][i]);
			//bake
			dp[min(j+i,(int)N)][i] = min(dp[min(j+i,(int)N)][i],dp[j][i]+1);
			//eat
			dp[0][j] = min(dp[0][j],dp[j][i]+A);
		}
	}
	for(j=1;j<=N;j++) {
		int mi=1;
		for(i=2;i<=N;i++) if(dp[j][i]<dp[j][mi]) mi=i;
		_P("%d %d %lld\n",j,mi,dp[j][mi]);
	}
	FOR(x,100) {
		V=enumdiv(N);
		dp[0]=0;
		for(i=1;i<V.size();i++) {
			dp[i]=1LL<<60;
			FOR(j,i) if(V[i]%V[j]==0) {
				dp[i]=min(dp[i],(V[i]/V[j])+dp[j]+A);
			}
			//_P("%d %lld %lld\n",i,V[i],dp[i]);
			mi=min(mi,dp[i]+N/V[j]);
		}
		N++;
	}
	cout<<mi<<endl;
#endif
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-val for val in A]

heapq.heapify(A)

for _ in range(M):
    val = heapq.heappop(A)
    val = -val // 2
    heapq.heappush(A, -val)

A = [-val for val in A]

print(sum(A))


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<char> ch(N+2, '#');
  
  for (int i = 0; i < N+2; i++)
    cout <<  ch.at(i);
  cout << endl;
  
  for (int j = 0; j < H; j++){
    cout << '#';
    string str;
    cin >> str;
    cout << str << '#' << endl;
  }

  for (int i =0; i < N+2; i++)
    cout <<  ch.at(i);
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 300 + 7;

int main()
{
    int a, b;
    cin>>a>>b;
    int arr[5];
    arr[0] = a+b;
    arr[1] = a-b;
    arr[2] = a*b;
    sort(arr,arr+3);
    cout<<arr[2]<<endl;


    return 0;
}


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


int main(){
  int n, m;

  cin >> n >> m;

  lli l[m], r[m];
  lli max_l, min_r;

  for(int i = 0; i < m; i++)
    cin >> l[i] >> r[i];

  max_l = l[0];
  min_r = r[0];

  for(int i = 1; i < m; i++){
    if(max_l < l[i])
      max_l = l[i];
    if(min_r > r[i])
      min_r = r[i];
  }

  if(min_r - max_l < 0)
    cout << 0 << endl;
  else
    cout << min_r - max_l + 1 << endl;

}


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

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int ans=1e5;
    int flag=0;
    for(int i=0;i<(int)s.size();i++){
        int curr=0;
        for(int j=0;j<(int)t.size();j++){
            if(i+j>=(int)s.size()){
                flag=1;
                break;
            }
            if(s[i+j]!=t[j]){
                curr++;
            }
        }
        if(flag==1){
            break;
        }
        ans=min(ans,curr);
    }
    cout<<ans;
}

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

const int inf = 1e9;
const ll linf = 1e18;

template<typename T = int>
class WeightedUnionFind
{
public:
    WeightedUnionFind(int n = 0, T unity = 0) : m_data(n, -1), m_weight(n, unity), m_count(n) {}

    int find(int x)
    {
        if (m_data[x] < 0) return x;

        int root = find(m_data[x]);
        m_weight[x] += m_weight[m_data[x]];
        return m_data[x] = root;
    }

    T weight(int x)
    {
        find(x);
        return m_weight[x];
    }

    bool unite(int x, int y, T w)
    {
        w += weight(x), w -= weight(y);
        x = find(x), y = find(y);
        if (x == y) return false;

        if (m_data[x] > m_data[y]) {
            swap(x, y);
            w = -w;
        }
        m_data[x] += m_data[y];
        m_data[y] = x;
        m_weight[y] = w;
        m_count--;
        return true;
    }

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

    T diff(int x, int y) { return weight(y) - weight(x); }

    int size(int x) { return -m_data[find(x)]; }

    int count(void) const { return m_count; }

private:
    vector<int> m_data;
    vector<T>   m_weight;
    int m_count; 
};

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

    int n, m; cin >> n >> m;
    WeightedUnionFind<int> uf(n);
    for (int i = 0; i < m; i++) {
        int l, r, d; cin >> l >> r >> d; l--, r--; // 0-indexed
        if (!uf.same(l, r)) {
            uf.unite(l, r, d);
        } else {
            if (d != uf.diff(l, r)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

ll attack(ll h){
  if(h==1){
    return 1;
  }
  return 1 + 2 * attack(h / 2);
}

int main()
{
  ll h;
  cin >> h;
  cout << attack(h) << endl;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
num = 0
for i in range(1, N - 1):
    tmp = [P[i - 1], P[i], P[i + 1]]
    tmp = sorted(tmp)
    if tmp[1] == P[i]:
        num += 1

print(num)



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

int main() {
  string s;
  cin>>s;
  int a;
  if (s=="SUN") a=7;
  else if (s=="MON") a=6;
  else if (s=="TUE") a=5;
  else if (s=="WED") a=4;
  else if (s=="THU") a=3;
  else if (s=="FRI") a=2;
  else a=1;
  cout<<a;
  return 0;
}

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

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


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

int main() {
  while(1) {
    int K;
    cin >> K;
    if(K == 0) break;

    int num = K*(K-1)/2;
    int temp = 0;
    for(int i = 0; i < num; i++) {
      int in;
      cin >> in;
      temp += in;
    }

    if(K == 1) cout << temp << endl;
    else       cout << temp / (K - 1) << endl;
  }
  return 0;
}

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

int main() 
{
    ll n,W;
    cin>>n>>W;

    vector<ll> weight(n), value(n);

    for(ll i=0; i<n; i++)
        cin>>weight[i]>>value[i];

    ll sum_value = 0;

    for(ll x : value)
        sum_value += x;

    vector<ll> dp(sum_value+1, INT_MAX);

    dp[0] = 0;

    for(ll item=0; item<n; item++)
    {
        for(ll value_already = sum_value-value[item]; value_already>=0; --value_already)
            dp[value_already + value[item]] = min(dp[value_already + value[item]], dp[value_already] + weight[item]);
    }

    ll answer = 0;

    for(ll i=0; i<=sum_value; i++)
    {
        if(dp[i]<=W)
            answer = max(answer,i);
    }

    cout<<answer<<endl;

    return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod=1e9+7;
const int nax= 1005;
char mat[nax][nax];
int dp[nax][nax];

#undef int
int main() {
#define int long long
    int H,W;
    cin >> H >> W;
    int ans=0;

    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            cin >> mat[i][j];
        }
    }

    dp[0][0]=1;
    for(int i=1;i<H;i++)
        if(mat[0][i]=='#')
           dp[0][i]=0;
        else
           dp[0][i]=dp[0][i-1];

    for (int i = 1; i < H; i++)
        if (mat[i][0] == '#')
            dp[i][0] = 0;
        else
            dp[i][0] = dp[i-1][0];

    
    for(int i=1;i<H;i++)
    {
        for(int j=1;j<W;j++)
        {
            if(mat[i][j]=='#')
               dp[i][j]=0;
            else
               dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
        }
    }
    ans=(dp[H-1][W-1]%mod);
    cout << ans << endl;
}

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long)(1e15)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');
    cerr.write(names, name-names) << " = " << arg1 << endl;
    _F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){
    in >> q.F >> q.S; return in;
}template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}


void solve(){
    int n, m;
    cin >> n >> m;
    int a[m];
    int sum = 0;
    for(int i = 0; i < m ; i++){
        cin >> a[i];
        sum += a[i];
    }
    if(n < sum){
        cout <<-1 << endl;
    }else{
        cout << n-sum << endl;
    }
}

signed main(){

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

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(12);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif

    //cin >> t;

    for(int i = 1; i <= t; ++i){
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 3660
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    ll a, b , k;
    cin >> a >> b >> k;
    ll newa, newb;

    newa = max(0ll, a-k);
    newb = max(0ll, min(b, a + b -k));
    cout << newa << " " << newb << endl;
}


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

int main(){
  vector<int>time(5);
  for(int i=0;i<5;i++)
    cin>>time.at(i);
  vector<int>mod(5);
  for(int i=0;i<5;i++){
    mod.at(i)=10-time.at(i)%10;
    if(mod.at(i)==10)
      mod.at(i)=0;
  }
  sort(mod.begin(),mod.end());
  int res=0;
  for(int i=0;i<5;i++)
    res+=time.at(i);
  for(int i=0;i<4;i++)
    res+=mod.at(i);
  cout<<res;
}

Measured memory_bytes: 256
#include <iostream>
//#include <map>
//#include <iterator>
//#include <fstream>
//#include <iomanip>
//#include <omp.h>
#include <vector>
//#include <string>
#include <algorithm>
//#include <stdlib.h>
//#include <thread>
//#include <chrono>
#include <cmath>
using namespace std;
typedef long long LL;

LL hp[100000];
int N, A, B, diff;
int* monsters;
int* countAttack;

bool isAttackCompleted(LL T)
{
	LL center = 0;
	for (LL i = 0; i < N; i++) {
		LL tmp = hp[i] - B*T;
		if (tmp > 0) {
			LL count = (tmp + (diff - 1)) / diff;
			center += count;
		}
	}
	return center <= T;
}

int main()
{
	cin >> N >> A >> B;
	diff = A - B;

	LL maxHp = 0;
	for (LL i = 0; i < N; i++)
	{
		cin >> hp[i];
		if (hp[i] > maxHp) maxHp = hp[i];
	}

	sort(hp, hp + N);

	LL left = 0;
	LL right = (maxHp + (B - 1)) / B + 1;
	LL mid;
	//int index;
	//int answer = 0;
	//vector<int> v;
	//chrono::milliseconds mil(1000);
	//std::chrono::system_clock::time_point  start, end;
	//start = std::chrono::system_clock::now();
	while (left + 1 < right)
	{
		mid = (left + right) / 2;
		bool flag = isAttackCompleted(mid);
		if (flag)
			right = mid;
		else
			left = mid;
		//this_thread::sleep_for(mil);
	}
	cout << right << endl;
	//end = std::chrono::system_clock::now();
	//double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
	//cout << "Time : " << elapsed << " [ms]\n";
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,t,min=INT_MAX,a,x; cin >> n >> t;
	//bool bl = 1;
	while(n--){
		cin >> a >> x;
		if(x <= t && min > a){
			min = a;
		}
		
	}
	if(min==INT_MAX) cout << "TLE" << endl;
	else{
	cout << min << endl;}	
	return 0;
}


Measured memory_bytes: 256
# input
N = int(input())
T = list(map(int, input().split()))
M = int(input())
P = list()
X = list()
res = [0]*M

for _ in range(M):
    p, x = map(int, input().split())
    res[_] = sum(T) - (T[p-1] - x)

for e in res:
    print(e)


Measured memory_bytes: 3060
#include <stdio.h>

int linearSearch(int *,int,int);

#define N 10000
#define Q 500
#define FOUND 1
#define NOT_FOUND 0

int main()
{
	int i,n,q,f,count=0,S[N],T[Q];

	scanf("%d",&n);
	for(i = 0;i < n;i++) scanf("%d",&S[i]);

	scanf("%d",&q);
	for(i = 0;i < q;i++) scanf("%d",&T[i]);

	for(i = 0;i < q;i++)
	{
		f = linearSearch(S,T[i],n);
		if(f == FOUND)count++;
	}

	printf("%d\n",count);

	return 0;

}

int linearSearch(int *A,int key,int n)
{
	int i=0;

	A[n] = key;

	while(A[i] != key)
	{
		i++;
	}

	if(i == n)return NOT_FOUND;
	else return FOUND;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    int duration = (h2*60+m2) - (h1*60+m1);
    int ans = duration-k;
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int D[200005];
int main() {
  ios::sync_with_stdio(false);
  int N, A;
  cin >> N;
  for (int i=2; i<=N; i++) {
    cin >> A;
    D[A]++;
  }
  for (int i=1; i<=N; i++) {
    cout << D[i] << '\n';
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

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

    ll res = 0;
    ll idxF = 0;
    ll idxB = s.size()-1;
    while(true){
        if(s[idxF] == s[idxB]){
            idxF++;
            idxB--;
            continue;
        }
        while(idxF<idxB && s[idxB] == 'x'){
            idxB--;
            res++;
        }
        while(idxF<idxB && s[idxF] == 'x'){
            idxF++;
            res++;
        }
        if(idxF >= idxB){
            cout<<res<<endl;
            return 0;
        }
        if(s[idxF] != s[idxB]){
            cout<<"-1"<<endl;
            return 0;
        }
    }

    return 0;
}

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

using namespace std;
vector<int>v[100005],vb[100005];
int dp[100005],visit[100005];
vector<int>vv;
void dfs(int x){
	visit[x]=1;
	for(int i=0;i<v[x].size();i++){
		if(!visit[v[x][i]])dfs(v[x][i]);
	}
	vv.push_back(x);
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		v[x].push_back(y);
		vb[y].push_back(x);
	}
	for(int i=0;i<n;i++)if(!visit[i])dfs(i);
	reverse(vv.begin(),vv.end());
	dp[vv[0]]=0;
	for(int i=1;i<n;i++){
		for(int j=0;j<vb[vv[i]].size();j++)
		    dp[vv[i]]=max(dp[vv[i]],dp[vb[vv[i]][j]]+1);
	}
	int res=0;
	for(int i=0;i<n;i++)res=max(res,dp[i]);
	cout<<res;
	return 0;
}

Measured memory_bytes: 13820
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
	int a, b, c, d;
	while (cin >> a >> b >> c >> d,a||b||c||d) {
		a = max(0, b*c-a);
		b = a / d;
		if (a%d)b++;
		cout << b << endl;
	}
}

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

int main(){
    for(int i = 0; ; i++){
        int x,y;
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }
        for(int j = 0; j < x; j++){
            for(int k = 0; k < y; k++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
//

const int MAX = 1000010;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
  int N,K;cin>>N>>K;
  vector<ll> a(N,0);
  rep(i,N) cin>>a[i];
  sort(a.begin(),a.end());

  ll min = 0, plu = 0;
  rep(i,N-K+1) {
    min = (min - (a[i] * COM(N-i-1,K-1)) % MOD + MOD) % MOD;
  }
  rep(i,N-K+1) {
    plu = (plu + (a[N-1-i] * COM(N-i-1,K-1)) % MOD) % MOD;
  }
  cout<< (plu + min + MOD) % MOD << endl; 
}


Measured memory_bytes: 27492