akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	void set(ll arg_x1,ll arg_y1,ll arg_x2,ll arg_y2){
		x1 = arg_x1;
		y1 = arg_y1;
		x2 = arg_x2;
		y2 = arg_y2;
	}
	ll x1,y1,x2,y2;
};

Info info[2001];


int main(){

	int N;
	scanf("%d",&N);

	vector<ll> X,Y;

	X.push_back(-BIG_NUM);
	X.push_back(BIG_NUM);

	Y.push_back(-BIG_NUM);
	Y.push_back(BIG_NUM);

	for(int i = 0; i < N; i++){
		scanf("%lld %lld %lld %lld",&info[i].x1,&info[i].y1,&info[i].x2,&info[i].y2);
		X.push_back(info[i].x1);
		X.push_back(info[i].x2);
		Y.push_back(info[i].y1);
		Y.push_back(info[i].y2);
	}

	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());

	X.erase(unique(X.begin(),X.end()),X.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());

	map<ll,int> X_INDEX,Y_INDEX;

	for(int i = 0; i < X.size(); i++){
		X_INDEX[X[i]] = i;
	}
	for(int i = 0; i < Y.size(); i++){
		Y_INDEX[Y[i]] = i;
	}

	int H = (int)Y.size(),W = (int)X.size();

	bool** table = new bool*[H];
	for(int row = 0; row < H; row++){
		table[row] = new bool[W];
		for(int col = 0; col < W; col++){
			table[row][col] = false;
		}
	}

	ll new_x1,new_y1,new_x2,new_y2;

	for(int i = 0; i < N; i++){
		new_x1 = X_INDEX[info[i].x1];
		new_y1 = Y_INDEX[info[i].y1];
		new_x2 = X_INDEX[info[i].x2];
		new_y2 = Y_INDEX[info[i].y2];

		for(int row = new_y1; row < new_y2; row++){
			for(int col = new_x1; col < new_x2; col++){
				table[row][col] = true;
			}
		}
	}

	ll ans = 0;

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(table[row][col]){
				ans += (X[col+1]-X[col])*(Y[row+1]-Y[row]);
			}
		}
	}

	printf("%lld\n",ans);

	return 0;
}



Measured memory_bytes: 19600
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
const long long MAX=200005;
typedef long long ll;
const int INF=0x3f3f3f3f;
//int d[8][2]={-1,0,0,-1,0,1,1,0,1,1,-1,-1,-1,1,1,-1};
ll n,a[105][15],b[105][15],c[15],sum=-1e18;
void mmp()
{
    int p=0;
    for(int i=1;i<=10;i++)
    {
        if(c[i]==1)p++;
    }
    if(p==0) return ;
    ll num=0;
    for(int i=1;i<=n;i++)
    {
        ll k=0;
        for(int j=1;j<=10;j++)
        {
            if(a[i][j]&&c[j])k++;
        }
        num+=b[i][k];
    }
    if(num>sum)sum=num;
}
void fun(int k)
{
    if(k==10)
    {
        c[k]=0;
        mmp();
        c[k]=1;
        mmp();
        return ;
    }
    c[k]=0;
    fun(k+1);
    c[k]=1;
    fun(k+1);
}
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=10;j++)
            scanf("%lld",&a[i][j]);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=10;j++)
            scanf("%lld",&b[i][j]);
    }
    fun(1);
    printf("%lld\n",sum);
    return 0;
}



Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val k = sc.nextLong()
    println(problem108c(n, k))
}

fun problem108c(n: Long, k: Long): Long {
    var aCount = 0L
    for (i in 1..n) {
        if (i % k == 0L) aCount++
    }
    var bCount = 0L
    for (i in 1..n) {
        if (i % k == k / 2) bCount++
    }
    var ans = aCount * aCount * aCount
    if (k % 2 == 0L) {
        ans += bCount * bCount * bCount
    }
    return ans
}

Measured memory_bytes: 31268
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
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;}

string s;
int k;

int main(){
    cin >> s >> k;
    priority_queue<pair<string,int>,vector<pair<string,int>>,greater<>> q;
    REP(i,s.size()){
        q.push(make_pair(s.substr(i,1),i));
    }
    int cnt = 0;
    int size = 0;
    string pre;
    while(1){
        pair<string,int> ps = q.top();q.pop();
        string vs = ps.first;
        if(pre!=vs){
            pre = vs;
            cnt++;
            if(cnt==k){
                put(vs);
                break;
            }
        }
        if(ps.second+vs.size()<s.size()){
            q.push(make_pair(s.substr(ps.second,vs.size()+1),ps.second));
        }
    }
    return 0;
}


Measured memory_bytes: 640
import Data.Array
type Pos = (Int,Int)
type Field  = Array Pos Bool
type Size  = [Int]
type Range  = (Pos,Pos)
readsize :: String -> Range
readsize = (\[h,w] -> fieldrange h w ) . map read . words . head . lines
readfield :: Range -> String -> Field
readfield range  = listArray range . map onPath . concat . tail . lines
fieldrange h w = ((0,0),(h-1, w-1)) 
onPath :: Char -> Bool
onPath x
    | x == '#' = True
    | x == '.' = False
main = do
    str <- getContents
    let frange = readsize str
        field = readfield frange str
    putStrLn $ getAns $ and $ map (hasCorrectPath field) $ path field

right (x,y) = (x,y+1)
left  (x,y) = (x,y-1)
down  (x,y) = (x+1,y)
up    (x,y) = (x-1,y)
has :: (Pos->Pos) -> Field -> Pos -> Bool
has f field pos = field `el`  f  pos
hasCorrectPath :: Field -> Pos -> Bool
hasCorrectPath field pos = (has up field pos `nand` has left field pos) && (has down field pos `nand` has right field pos)
path = map (\(i,x)->i) . filter (\(i,x) -> x) . assocs

getAns True = "Possible"
getAns False = "Impossible"

nand a b = not $ a && b

el :: Field -> Pos -> Bool
el a i
    | inRange (bounds a) i  = a ! i
    | otherwise             = False


Measured memory_bytes: 508
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt();
        scanner.nextLine();
        for (char c: scanner.nextLine().toCharArray()) {
            if (c + N <= 'Z') {
                System.out.print((char) (c + N));
            } else {
                System.out.print((char) (c + N - 26));
            }
        }
        System.out.println();
    }

}



Measured memory_bytes: 28740
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main()
{
    double a, b, c;

    cin >> a >> b >> c;

    cout << min(ceil(c/a), ceil(c/b)) << endl;
}


Measured memory_bytes: 256
fun main(arr:Array<String>) {
    val (a,b) = readLine()!!.split(" ").map { it.toInt() }
    val listAll = readLine()!!.split(" ").map { it.toLong() }
    val listMinus = listAll.filter { it < 0 }.sortedDescending()
    val listPlus = listAll.filter { it > 0}.sorted()
    val hasZero = listAll.contains(0L)
    val ans = Math.min(getAns(listPlus, listMinus, hasZero, b), getAns(listMinus, listPlus, hasZero, b))
    println(ans)
}

fun getAns(list1:List<Long>, list2:List<Long>, hasZero:Boolean, fire:Int):Long {
    if(list1.size == 0) {
        if(list2.size == 0) {
            return 0
        }
        return Math.abs(list2.last() * 2)
    }
    var ans = Math.abs(list1.last())*2
    if(list2.size > 0) {
        ans += Math.abs(list2.last()) * 2
    }

    for(i in list1.indices) {
        val remain = Math.max(0, fire - (i + 1) - (if (hasZero) 1 else 0))
        var tmp = Math.abs(list1[i])
        if (remain > 0) {
            if(remain > list2.size) {
                continue
            }
            tmp += Math.abs(list1[i])
            tmp += Math.abs(list2[remain-1])
        }
        ans = Math.min(tmp, ans)
    }
    return ans
}


Measured memory_bytes: 52156
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a,b,ans;
	cin>>n>>a>>b;
	ans=max(a,b)-n-min(a,b);
	if(ans<=0){
		cout<<"0"<<endl;
	}
	else{
		ans=abs(ans);
		cout<<ans<<endl;
	}
  return(0);
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final String S = sc.next();
        sc.close();
        final int A = Integer.parseInt(S.substring(0, 1));
        final int B = Integer.parseInt(S.substring(1, 2));
        final int C = Integer.parseInt(S.substring(2, 3));
        final int D = Integer.parseInt(S.substring(3, 4));

        for (int i=8; i<Math.pow(2.0, 3.0)+8; i++) {
            int sum = A;
            StringBuilder sb = new StringBuilder(A + "+2+3+4=7");
            if ("1".equals(Integer.toBinaryString(i).substring(3, 4))) {
                sum += B;
                sb.replace(1, 3, "+" + B);
            } else {
                sum -= B;
                sb.replace(1, 3, "-" + B);
            }
            if ("1".equals(Integer.toBinaryString(i).substring(2, 3))) {
                sum += C;
                sb.replace(3, 5, "+" + C);
            } else {
                sum -= C;
                sb.replace(3, 5, "-" + C);
            }
            if ("1".equals(Integer.toBinaryString(i).substring(1, 2))) {
                sum += D;
                sb.replace(5, 7, "+" + D);
            } else {
                sum -= D;
                sb.replace(5, 7, "-" + D);
            }
            if (sum==7) {
                System.out.println(sb);
                return;
            }
        }
    }
}

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

int main()
{
  int A, B;
  string S;
  cin >> A >> B >> S;

  for (int i = 0; i < A + B + 1; ++i)
  {
    if (A == i)
    {
      if (S[i] != '-')
      {
        cout << "No" << endl;
        return 0;
      }
    }else{
      if (S[i] < '0' || S[i] > '9')
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1000000007;
//constexpr int64_t MOD = 1e9 + 7;

inline void swap(int64_t& a, int64_t& b) {
  int64_t tmp = a; a = b; b = tmp;
  return;
}

int64_t modinv(int64_t a, int64_t m) {
  int64_t b = m, u = 1, v = 0;
  while (b) {
    int64_t t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int64_t GCD(int64_t a, int64_t b) {
  if (b == 0) return a;
  else return GCD(b, a%b);
}

int64_t calc_lcm_(vector<int32_t>& A) {
  int64_t lcm = A[0];
  for (int i = 1; i < (int64_t)A.size(); i++) {
    int64_t gcd = GCD(lcm, (int64_t)A[i]);
    lcm = (lcm * (int64_t)A[i]) * modinv(gcd, MOD) % MOD;
    lcm %= MOD;
  }
  return lcm;
}

void get_primes(int32_t a, unordered_map<int32_t, int32_t>& res) {
  for (int div = 2; div * div <= a; div++) {
    while (a % div == 0) {
      res[div]++;
      a /= div;
    }
  }
  if (a != 1) res[a] = 1;
  return;
}

int64_t modpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
  int64_t res = 1;
  for (a %= mod; b; a = a * a % mod, b >>= 1)
    if (b & 1) res = res * a % mod;
  return res;
}

int64_t calc_lcm(vector<int32_t>& A) {
  unordered_map<int32_t, int32_t> lcm;
  for (auto a : A) {
    unordered_map<int32_t, int32_t> primes;
    get_primes(a, primes);
    for (auto prime : primes) {
      if (lcm[prime.first] < prime.second) lcm[prime.first] = prime.second;
    }
  }

  int64_t res = 1;
  for (auto x : lcm) {
    res = res * modpow(x.first, x.second) % MOD;
  }
  return res;
}

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

  int32_t N;
  cin >> N;
  vector<int32_t> A(N, 0);
  for (auto& a : A) {
    cin >> a;
  }
  int64_t lcm = calc_lcm(A);
  int64_t sum = 0;
  for (auto a : A) {
    sum += lcm * modinv(a, MOD) % MOD;
    sum %= MOD;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int x; cin >> x;
    if(x<=6){
        cout<<1<<endl;
        return 0;
    }
    if(x<=11){
        cout<<2<<endl;
        return 0;
    }
    int res=0;
    res=x/11*2;
    if(x%11==0) cout<<res<<endl;
    else if(x%11<=6)cout<<res+1<<endl;
    else cout<<res+2<<endl;
}

Measured memory_bytes: 3604
N, Y = map(int, input().split())
N+=1
ans = [-1, -1, -1]
for i in range(N):
    for j in range(N-i):
        k = N-i-j-1
        if i*10000+j*5000+k*1000 == Y:
            ans = [i, j, k]
print(" ".join(list(map(str, ans))))



Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(void) {
	string n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n.size(); i++) {
		sum = (sum + (n[i] - '0')) % 3;
	}
	if (sum == 0)cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    string s;
    int q;
    cin >> s >> q;
    vector<char> l, r, tt;
    int cnt=0;
    rep(i, q){
        int t; cin >> t;
        if(t==1){
            cnt++;
            tt = l;
            l = r;
            r = tt;
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f==1){
                l.emplace_back(c);
            }else{
                r.emplace_back(c);
            }
        }
    }

    rep(i, l.size()){
        cout << l[l.size()-1-i];
    }
    if(cnt%2==0){
        cout << s;
    }else{
        rep(i, s.size()){
            cout << s[s.size()-i-1];
        }
    }
    rep(i, r.size()){
        cout << r[i];
    }
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1152
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        s: Chars
    };
    let mut rs = String::new();
    for c in s {
        rs.push(match c {
            ',' => ' ',
            _ => c,
        });
    }
    println!("{}", rs);
}


Measured memory_bytes: 2116
#include <map>
#include <set>
#include <queue>
#include <iostream>

using namespace std;

int main() {
    long N, Q;
    cin >> N >> Q;
    priority_queue<vector<long>, vector<vector<long>>, greater<vector<long>>> tl;
    for (int i=0; i<N; i++) {
        long S, T, X;
        cin >> S >> T >> X;
        tl.push(vector<long> {T-X, 0, X});
        tl.push(vector<long> {S-X, 1, X});
    }
    for (int i=0; i<Q; i++) {
        long D;
        cin >> D;
        tl.push(vector<long> {D, 2, 0});
    }

    vector<long> ans {};
    multiset<long> Xset {};
    while (not tl.empty()) {
        vector<long> t = tl.top();
        tl.pop();
        long mode = t[1];
        long X = t[2];
        //cout << t[0] << ' ' << mode << ' ' << X << endl;
        if (mode == 0) {
            // T
            Xset.erase(X);
        } else if (mode == 1) {
            // S
            Xset.insert(X);
        } else {
            // D
            if (not Xset.empty()) {
                auto it = Xset.begin();
                ans.push_back(*it);
            } else {
                ans.push_back(-1);
            }
        }
    }

    for (auto it=ans.begin(); it!=ans.end(); it++) {
        cout << *it << endl;
    }
}


Measured memory_bytes: 45220
#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;i++)

int main()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	rep(i, n) cin >> h[i];
	ll ans = 0;
	rep(i, n)
	{
		if (k <= h[i]) ans++;
	}


	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 4028
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[][] map = new int[3][3];
			for (int i = 0; i < 3; i++) {
				for (int j = 0; j< 3; j++) {
					map[i][j] = scanner.nextInt();
				}
			}

			int temp2 = map[0][1] - map[0][0];
			int temp3 = map[0][2] - map[0][0];

			if (map[1][1] - map[1][0] == temp2 && map[2][1] - map[2][0] == temp2 && map[1][2] - map[1][0] == temp3 && map[2][2] - map[2][0] == temp3) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}


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

c =0
for i in range(n):
    if b[i] < a[i]:
        c += b[i]
    else:
        d = min(a[i+1],b[i]-a[i])
        a[i+1] -= d
        c += a[i]+d
print(c)

Measured memory_bytes: 18624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();

        string answer = "";
        if (a + b <= 14)
        {
            answer = "Yay!";
        }
        if (a <= 8 && b <= 8)
        {
            answer = "Yay!";
        }
        else
        {
            answer = ":(";
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, k, q;
	cin >> n >> k >> q;
	ll a[n];
	zep(i, 0, n){cin >> a[i];}
	
	bool use[n+1];
	memset(use, 0, sizeof(use));
	use[n] = true;
	
	vector<P> pos;
	zep(i, 0, n){pos.push_back(P(a[i], i));}
	sort(pos.begin(), pos.end());
	
	ll ans = INF;
	zep(i, 0, n){
		priority_queue<ll> pq;	
		
		ll l = 0;	
		rep(r, 0, n){
			if(use[r]){
				if(r-l >= k){
					priority_queue<ll> tmp;
					zep(j, l, r){tmp.push(-a[j]);}
					rep(j, 1, r-l-k+1){pq.push(tmp.top()); tmp.pop();}
				}
				l = r+1;
			}
		}
		
		//print(pq.size())
		if(pq.size() >= q){
			ll buf = pq.top();
			rep(i, 1, q-1){pq.pop();}
			buf -= pq.top();
			ans = min(buf, ans);
		}
		else{
			break;
		}
		
		use[pos[i].second] = true;
	}
	print(ans)
	return 0;
}

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

typedef long long ll;

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

	int N, M;
	cin >> N >> M;

	vector<double> A(N);

	double count = 0;

	for(int i = 0; i < N; i++) {
		cin >> A[i];
		count += A[i];
	}

	sort(A.begin(), A.end(), greater<double>());

	double x = count / (4 * M);

	for(int i = 0; i < M; i++) {
		if(A[i] < x) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
using llong = long long;
 
int main(){
  int N;
  cin >> N;
  vector<llong> head(256);
  for(int i=0;i<N;++i){
    string s;
    cin >> s;
    head[s[0]]++;
  }
  
  vector<char> chars = { 'M','A','R','C','H' };
  int size = chars.size();
  llong pat = 0;
  for(int i=0;i<size;++i){
    for(int j=i+1;j<size;++j){
      for(int k=j+1;k<size;++k){
        pat += head[chars[i]]*head[chars[j]]*head[chars[k]];
      }
    }
  }
  cout << pat << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
// union by size + path having
class UF {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UF(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1ll);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<P>ab(m);
    rep(i,m){
        cin>>ab[i].first>>ab[i].second;
    }
    vector<ll>ans(m);
    UF uf(n);
    uf.init(n);
    ans[m-1]=((ll)n*(n-1)/2);
    for(int i=m-1;i>0;i--){

        int a=ab[i].first-1,b=ab[i].second-1;
        if(!uf.issame(a,b)){
            ans[i-1]=ans[i]-(ll)uf.size(a)*uf.size(b);
            uf.merge(a,b);
        }
        else ans[i-1]=ans[i];
        
        
    }
    rep(i,m)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 4480
#include<stdio.h>

int main() {
    //変数の宣言
    char hako[1200];
    char mozi[26];  //アルファベットの数
    int i=0, j, k; //処理用
    
    //初期化
    for (j=0; j<26; j++) {
        mozi[j] = 0;
    }
    
    
    //入力
    while (scanf("%c", &hako[i]) != EOF) {
        
//        if (hako[i] == '\0') {
//            break;
//        }
        i++; //カウンター回す
    }
    
    
    //処理
    for (j=0; j<i; j++) {  //入力のi全部
        for (k=0; k<26; k++) {
            if (hako[j] >= 'a' && hako[j] <= 'z') {
                if (hako[j] == 'a' + k) {
                    mozi[k] ++; //+1
                }
            }else if (hako[j] >= 'A' && hako[j] <= 'Z') {
                if (hako[j] == 'A' + k) {
                    mozi[k] ++; //+1
                }
                
            }
        }
    }
    
    //出力
    for (j=0; j<26; j++) {
        printf("%c : %d\n", 'a'+j, mozi[j]);
    }
    
    
    return 0;
}



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

int main(){
  int r; // current rating, 0 <= r <= 4500
  int g; // next rating, 0 <= g <= 4500
  
  cin >> r >> g;
  if (r >= 0 && r <= 4500 && g >= 0 && g <= 4500){
    cout << (2*g - r) << endl;
  }
}

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

int main(){
  
  int a,b,c;
  cin >> a >> b >> c;
  
  for(int i=b;i<=c;i++){
    if( i%a == 0 ){
    
      cout << "OK" << endl;
      return 0;
    }
  }
    
    cout << "NG" << endl;
  
}


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

using namespace std;

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

  int cnt = 0;
  int a = 0;
  int b = str.size() - 1;
  while (a <= b)
    if (str[a++] != str[b--])
      ++cnt;
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  ll n;
  cin >> n;
  map<ll,ll>mp;
  map<ll,ll>total;
  vector<ll>vec(n);
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
    total[a]++;
    vec[i]=a;
  }
  ll sum=0;
  for(auto p:mp){
    ll f=p.first;
    ll s=p.second;
    ll ns=s*(s-1)/2;
    mp[f]=ns;
    sum+=ns;
  }
  rep(i,n){
    cout << sum-total[vec[i]]+1<< endl;
  }
}


Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,x) memset(a,x,sizeof(a))
#define qwq (cerr<<"qwq"<<endl)
#define orz(x) (cerr<<#x": "<<x<<endl)
#define orzarr(a,n) {cerr<<#a": "; repeat(__,0,n)cerr<<(a)[__]<<" "; cerr<<endl;}
#define orzeach(a) {cerr<<#a": "; for(auto __:a)cerr<<__<<" "; cerr<<endl;}
#define fi first
#define se second
typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
typedef double lf; typedef long double llf; const lf err=1e-11; const lf pi=acos(-1); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;}
typedef pair<int,int> pii; template<typename A,typename B> ostream &operator<<(ostream &o,const pair<A,B> &x){return o<<'('<<x.fi<<','<<x.se<<')';}
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=3010;
const int mod=(0?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int n,s;
int dp[N],a[N];
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>s;
	dp[0]=1;
	repeat(i,0,n)cin>>a[i];
	repeat(i,0,n)
	repeat_back(j,0,s-a[i]+1){
		int delta=dp[j];
		if(j==0)delta*=i+1;
		if(j+a[i]==s)delta*=n-i;
		dp[j+a[i]]+=delta;
		dp[j+a[i]]%=mod;
	}
	cout<<dp[s]<<endl;
	return 0;
}

Measured memory_bytes: 256
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    main(input)
});

function main(input){
    console.log(input.trim().split('').reverse().join(''));
}

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

int main(void){
  int N, T, i, x = 0, cost;
  cin >> N >> T;
  int a[N], b[N];
  for(i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  for(i=0; i<N; i++){
    if(b[i] <= T){
      if(x == 0){
        cost = a[i];
        x = 1;
      }
      else{
        if(cost > a[i]) cost = a[i];
      }
    }
  }
  if(x == 0) cout << "TLE\n";
  else cout << cost << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it;
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}, M{}; std::cin >> N >> M;
  const std::vector<ui> HONSUU{ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  vector<ui> A(M);
  rep(0, A.size()) cin >> A[i];
  boost::sort(A, std::greater<ui>());

  vector<ll> dp(N + 1, -1);
  dp[0] = 0;
  rep(1, N + 1)
  {
    vector<ll> tmp(A.size(), -1);
    rep_uj(0, A.size())
    {
      int it = i - HONSUU[A[j]];
      if(it < 0) continue;
      if(dp[it] >= 0)
        tmp[j] = dp[it] + 1;
    }
    dp[i] = *boost::max_element(tmp);
  }

  assert(dp[N] > 0);
  vector<ui> ans(dp[N]);
  ui num{N};
  rep(0, ans.size())
  {
    rep_uj(0, A.size())
    {
      if(num >= HONSUU[A[j]]
      && dp[num - HONSUU[A[j]]] == dp[num] - 1)
      {
        ans[i] = A[j];
        num -= HONSUU[A[j]]; 
        break;
      }
    }
    assert(ans[i]);
  }

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

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

  solve();

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<set> 
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,k,i,j,l,ans[15],x[100005],y[100005];
int dx[9]={0,-1,-1,-1,0,0,1,1,1},dy[9]={0,-1,0,1,-1,1,-1,0,1};
set<pair<int,int>/**/> s,vis;
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m>>k;
	for (i=1;i<=k;i++)
	{
		cin>>x[i]>>y[i];
		s.insert(make_pair(x[i],y[i]));
	}
	ans[0]=(n-2)*(m-2);
	for (i=1;i<=k;i++)
	{
		for (j=0;j<=8;j++)
		{
			int xx=x[i]+dx[j],yy=y[i]+dy[j];
			if (xx<2||xx>=n||yy<2||yy>=m) continue;
			if (vis.count(make_pair(xx,yy))) continue;
			vis.insert(make_pair(xx,yy));
			int now=0;
			for (l=0;l<=8;l++)
			{
				int xxx=xx+dx[l],yyy=yy+dy[l];
				now+=s.count(make_pair(xxx,yyy));
			}
			//cerr<<xx<<' '<<yy<<' '<<now<<endl;
			/*if (now==1)
			{
				cerr<<xx<<' '<<yy<<endl;
			}*/
			ans[0]--;
			ans[now]++;
		}
	}
	/*int xx,yy;
	for (xx=2;xx<n;xx++)
	{
		for (yy=2;yy<m;yy++)
		{
			int now=0;
			for (l=0;l<=8;l++)
			{
				int xxx=xx+dx[l],yyy=yy+dy[l];
				now+=s.count(make_pair(xxx,yyy));
			}
			//cerr<<xx<<' '<<yy<<' '<<now<<endl;
			if (now==1)
			{
				cerr<<xx<<' '<<yy<<endl;
			} 
		}
	}*/
	for (i=0;i<=9;i++) cout<<ans[i]<<endl;
	return 0;
}

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

int main(){
  int D;
  cin>>D;
  if(D==25){
    cout<<"Christmas"<<endl;
  }
  else if(D==24){
    cout<<"Christmas Eve"<<endl;
  }
  else if(D==23){
    cout<<"Christmas Eve Eve"<<endl;
  }
  else if(D==22){
    cout<<"Christmas Eve Eve Eve"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scan = new Scanner(System.in)) {
            String str = scan.nextLine();
            int len = str.length();
            for (int i = len - 1; 0 <= i; i--) {
                if (i == 0) {
                    System.out.println(str.charAt(i));
                } else {
                    System.out.print(str.charAt(i));
                }
            }
        } catch (Exception e) {
            System.exit(0);
        }
    }
}

Measured memory_bytes: 25804
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	int x, y;
	cin >> x >> y;
	rep(i, 0, x + 1) {
		int l2 = i, l4  = x - i;
		// trace(l2, l4)
		int ans = l2 * 2 + l4 * 4;
		if (ans == y) {
			// trace(l2, l4)
			cout << "Yes";
			return;
		}
	}
	cout << "No";
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void mul(T &a, T b) { a = (a * b) % MOD; }

int main() {
    int N; cin >> N;
    using P = pair<int, int>;
    vector<P> A(2 * N);
    rep(i, 0, N) {
        int a; cin >> a;
        A[i] = {a, 0};
    }
    rep(i, 0, N) {
        int a; cin >> a;
        A[i + N] = {a, 1};
    }
    sort(A.begin(), A.end());
    vector<long long> cnt(2);
    long long ans = 1;
    rep(i, 0, 2 * N) {
        cnt[A[i].second]++;
        if(cnt[A[i].second ^ 1]) {
            mul(ans, cnt[A[i].second ^ 1]);
            cnt[A[i].second]--;
            cnt[A[i].second ^ 1]--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
def main():
    N,M = map(int,input().split())
    pos = [0 for _ in range(N)]
    for i in range(M):
        a,b = map(int,input().split())
        pos[a-1] += 1
        pos[b-1] += 1

    for i in range(N):
        if pos[i]%2 != 0:
            print("NO")
            exit()

    print("YES")

if __name__ == "__main__":
    main()

Measured memory_bytes: 4008
#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    long i,j;
    long n;
    long q;
    long cnt = 0;
    long h;
    long left,right,mid;
    static long S[100001];
    static long T[50001];

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

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

    for (i = 0; i < q; i++) {
        left = 0; right = n;
        while(left < right) {
            mid = (left+right)/2;
            if (S[mid] > T[i])
                right = mid;
            else if(T[i] > S[mid])
                left = mid+1;
            else {
                cnt++;
                break;
            }
        }
    }
    printf("%ld\n",cnt);

    return 0;
}

Measured memory_bytes: 2200
from string import ascii_lowercase
import sys


def input():
    return sys.stdin.readline().strip()


def sum_b(data, i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s


def add_b(data, i, x):
    while i <= n:
        data[i] += x
        i += i & -i


n = int(input())
s = input()
q = int(input())

bits = {c: [0] * (n + 1) for c in ascii_lowercase}
[add_b(bits[c], i, 1) for i, c in enumerate(s, 1)]

for q_type, *q in (input().split() for _ in range(q)):
    if q_type == '1':
        iq = int(q[0])
        cq = q[1]
        for b in bits.values():
            if sum_b(b, iq) - sum_b(b, iq - 1) == 1:
                add_b(b, iq, -1)
                break
        add_b(bits[cq], iq, 1)
    else:
        l, r = map(int, q)
        print(sum([bool(sum_b(b, r) - sum_b(b, l - 1) > 0) for b in bits.values()]))


Measured memory_bytes: 175604
#include<iostream>

using namespace std;

int main()
{
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  int k;
  cin >> k;
  
  cout << a[k - 1];
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
s=input().strip()
if len(s)==2:
    if s[0]==s[1]:
        print(1,2)
        exit()
for i in range(len(s)-2):
    if len(set(s[i:i+3]))<3:
        print(i+1,i+3)
        exit()
print(-1,-1)


Measured memory_bytes: 41196
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var S = ReadLine();
            var kaibun = S.Replace("x", "");
            for (int s = 0, e = kaibun.Length - 1; s < kaibun.Length / 2; ++s, --e)
            {
                if (kaibun[s] != kaibun[e])
                {
                    WriteLine(-1);
                    return;
                }
            }
            var ans = 0L;
            for (int s = 0, e = S.Length - 1; ;)
            {
                if (e <= s)
                    break;
                if (S[s] == 'x' && S[e] != 'x')
                {
                    ++s;
                    ++ans;
                }
                else if (S[s] != 'x' && S[e] == 'x')
                {
                    --e;
                    ++ans;
                }
                else
                {
                    ++s;
                    --e;
                }
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13536
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int,int> pii;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define present(c,x) (c.find(x) != c.end())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define INF 1000000007 
#define MOD 998244353
#define INF64 1e18

void solve(){
	int n;
	cin>>n;

	vector<int> adj[n+1];
	vector<int> visited(n+1,false);
	vector<int> white(n+1,1);
	vector<int> black(n+1,1);

	rep(i,0,n-1){
		int u,v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}

	function<void(int)>DFS=[&](int i){
		visited[i]=true;
		
		if(adj[i].size()==1&&i!=1)
			return;

		for(auto it:adj[i]){
			if(!visited[it]){
				DFS(it);
				black[i]*=white[it];
				black[i]%=INF;
				white[i]*=(white[it]+black[it]);
				white[i]%=INF;
			}
		}
	};

	rep(i,0,n){

	}

	DFS(1);
	cout<<(white[1]+black[1])%INF;

}	
 
int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int T;
	// cin>>T;
	T=1;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 19220
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[210000];
vector<int>v[20];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		for(int j=0;j<20;j++){
			if(p[i]&(1<<j))v[j].push_back(i);
		}
	}
	long long ret=0;
	int left=0;
	for(int i=0;i<a;i++){
		for(int j=0;j<20;j++){
			int at=lower_bound(v[j].begin(),v[j].end(),i)-v[j].begin();
			if(at<v[j].size()&&v[j][at]==i){
				if(at){
					left=max(left,v[j][at-1]+1);
				}
			}
		}
		ret+=(i-left+1);
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 9024
n=gets.to_i
monsters=gets.split.map(&:to_i)
monsters.sort!
min=monsters[0]
def unchi(monsters,min)
	for i in 1..monsters.count - 1
		monsters[i]= monsters[i] % min
	end
	monsters.delete(0)
	monsters.sort!
	min=monsters[0]
	return [monsters,min]
end
while monsters.count > 1
	monsters,min = unchi(monsters,min)
end
puts monsters

Measured memory_bytes: 9216
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;

bool bellmanford(int N, vector<vector<pair<int, int>>>& graph, vector<int>& d){
  for(int i = 0; i < N; i++){
    for(int v = 0; v < N; v++){
      for(int k = 0; k < (int)graph[v].size(); k++){
        pair<int, int> e = graph[v][k];
        if(d[v] != INF && d[e.first] > d[v] + e.second){
          d[e.first] = d[v] + e.second;
          if(i == N-1) return true;
        }
      }
    }
  }
  return false;
}

signed main() {
  int N, M, P;
  cin >> N >> M >> P;

  vector<vector<pair<int, int>>> graph(N);
  vector<int> dist(N, INF);
  dist[0] = 0;

  int a, b, c;
  REP(i, M){
    cin >> a >> b >> c;
    a--; b--;
    c -= P;
    c *= -1;
    graph[a].push_back(make_pair(b, c));
  }

  bellmanford(N, graph, dist);

  vector<bool> negative(N, false);
  REP(_, N) REP(i, N) REP(j, (int)graph[i].size()){
    if(dist[i] == INF) continue;
    pair<int, int>p = graph[i][j];
    if(dist[p.first] > dist[i]+p.second){
      dist[p.first] > dist[i]+p.second;
      negative[p.first] = true;
    }
    if(negative[i] == true) negative[p.first] = true;
  }
  
  if(negative[N-1]) cout << -1 << endl;
  else cout << max(0LL, -dist[N-1]) << endl;

  return 0;
}

Measured memory_bytes: 512
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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


int main()
{
  // input & declare
  int n;
  cin >> n;
  std::vector<int> v1;
  std::vector<int> v2;
  int tmp;
  for(int i = 0; i < n; i++){
    cin >> tmp;
    v1.push_back(tmp);
  }
  for(int i = 0; i < n; i++){
    cin >> tmp;
    v2.push_back(tmp);
  }

  int maxv = 0;
  for(int i = 0; i < n; i++)
  {
    int sum = 0;
    for(int j = 0; j < n; j++){
      if (j <= i) {
        sum += v1[j];
      }
      if (j >= i) {
        sum += v2[j];
      }
    }
    if (sum > maxv) {
      maxv = sum;
    }
  }

  std::cout << maxv << '\n';

}


Measured memory_bytes: 256
s = list(input())
x, y = map(int, input().split())
dir, move, dx, dy = 0, 0, [], [abs(y)]
s.append('E')
first = True
fmove = 0
for i in s:
    if i == 'F':
        move += 1
    else:
        if first:
            fmove = move
            first = False
        else:
            if dir % 2 == 0:
                dx.append(move)
            else:
                dy.append(move)
        move = 0
        dir += 1
temp = (-x + fmove)
for i in sorted(dx, reverse=True):
    if temp < 0:
        temp += i
    else:
        temp -= i
adx = temp
temp = 0
for i in sorted(dy, reverse=True):
    if temp < 0:
        temp += i
    else:
        temp -= i
ady = temp
if adx == ady == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3188