akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<math.h>
#include<map>
#include <unordered_map> 
#include<vector>
#include<queue>
#include <bits/stdc++.h> 
#include<string>
#define ll long long int
#define N 1005
ll MOD =1e9+7;
using namespace std;

template <typename T> void max_self(T &a, T b){
	if(b>=a){
		a = b;
	}
}
int a[N][N];
int dp[N][N];
int vis[N][N];
int ans;
ll calc(int n, int m){
	if(n==0 && m==0)
	    return 1;
	if(n<0 || m<0)
	    return 0;
	if(vis[n][m] == 1)
	    return dp[n][m];
	else{
	    int ans =0;
	    if(n-1 >=0 && a[n-1][m] ==1){
	        ans +=calc(n-1,m)%MOD;
	    }
	    if(m-1 >=0 && a[n][m-1] == 1)
	        ans+=calc(n,m-1)%MOD;
	   
	   dp[n][m] = ans%MOD;
	   vis[n][m] = 1;
	   return ans;
	}

}
int main(){
	int n,m;
	cin>>n>>m;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		for(int j=0;j<s.length();j++){
			if(s[j] == '#')
				a[i][j] = 0;
			else
				a[i][j] = 1;
		}
	}
	calc(n-1,m-1);
	//for(int i=0;i<n;i++){
	  //  for(int j=0;j<m;j++){
	    //    cout<<dp[i][j]<<" ";
	    //}
	    //cout<<endl;
	//}
	cout<<dp[n-1][m-1]<<endl;

}


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

set<int> st;

int main() {
  for(int i = 0; i < 3; ++i) {
    int x;
    cin >> x;
    st.insert(x);
  }
  if(st.size() == 2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#define rg register
#define ll long long

using namespace std;
int n,num[100010];
bool f;

int main()
{
	cin>>n;
	for(rg int i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		if(num[i]&1) f=1;
	}
	if(!f) cout<<"second"<<endl;
	else cout<<"first"<<endl;
	
	return 0;
}


Measured memory_bytes: 640
main = do
	line <- getLine
	let a = read . (!! 0) . words $ line :: Int
	let b = read . (!! 1) . words $ line :: Int
	let c = read . (!! 2) . words $ line :: Int
	putStrLn $ ans a b c

ans a b c
	| a < b && b < c = "Yes"
	| otherwise = "No"

--main = do
--	line <- getLine
--	let a = read . head . words $ line :: Int
--	let b = read . last . words $ line :: Int
--	putStrLn (show (a * b) ++ " " ++ show (a * 2 + b * 2))

Measured memory_bytes: 3564
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class Main {

	/** 1000以下の素数の配列 */
	private static final int[] PRIMES = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
			73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
			191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
			311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
			439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571,
			577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701,
			709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853,
			857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997 };

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			int oneCount = (int) IntStream.range(0, n).map(i -> a[i] = scanner.nextInt()).filter(ai -> 0 == ai).count();
			boolean pairwiseCoprime = true;
			// 因数のセット
			Set<Integer> totalSet = getFactors(a[0]);
			main: for (int i = 1; i < n; i++) {
				Set<Integer> set = getFactors(a[i]);
				for (Integer j : set) {
					if (totalSet.contains(j)) {
						pairwiseCoprime = false;
						break main;
					}
				}
				totalSet.addAll(set);
			}
			if (pairwiseCoprime) {
				System.out.println("pairwise coprime");
				return;
			}
			boolean setwiseCoprime = true;
			if (0 == oneCount) {
				setwiseCoprime = false;
				int gcd = a[0];
				for (int i = 1; i < n; i++) {
					gcd = gcd(gcd, a[i]);
					if (1 == gcd) {
						setwiseCoprime = true;
						break;
					}
				}
			}
			if (setwiseCoprime) {
				System.out.println("setwise coprime");
			} else {
				System.out.println("not coprime");
			}
		}
	}

	/**
	 * nの素数となる因数のセットを計算
	 * 
	 * @param n
	 * @return nの素数となる因数のセット
	 */
	private static Set<Integer> getFactors(int n) {
		Set<Integer> set = new HashSet<>();
		int index = 0;
		while (n > 1) {
			if (index == PRIMES.length) {
				set.add(n);
				break;
			}
			while (0 == (n % PRIMES[index])) {
				n /= PRIMES[index];
				set.add(PRIMES[index]);
			}
			index++;
		}
		return set;
	}

	/**
	 * mとnの最大公約数を返す
	 * 
	 * @param m
	 * @param n
	 * @return mとnの最大公約数
	 */
	private static int gcd(int m, int n) {
		if (0 == n) {
			return m;
		}
		return gcd(n, m % n);
	}
}


Measured memory_bytes: 65948
#include<bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;

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

const int maxn=5e5+5;
const ll inf=0x3f3f3f3f;
const ll mod=1e9+7;

int a[maxn];
map<ll,int> vis;
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	printf("%lld",min(n%m,m-n%m));
	return 0;
}

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

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> b[i];
    }
    vector<ll> sumA(n + 1), sumB(m + 1);
    for (int i = 0; i < n; ++i) {
        sumA[i + 1] = sumA[i] + a[i];
    }
    for (int i = 0; i < m; ++i) {
        sumB[i + 1] = sumB[i] + b[i];
    }
    
    ll ans = 0;
    for (ll i = 0; i <= n; ++i) {
        ll cur = sumA[i];
        ll rest = k - cur;
        if (rest < 0) break;
        ans = max(ans, i + (ll)(upper_bound(sumB.begin(), sumB.end(), rest) - sumB.begin() - 1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 9496
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, k; string s;
  cin >> n >> k >> s;
  s[k-1] = s[k-1] - 'A' + 'a';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k,a[200001];
int main(){
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>k;
		a[k]++;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i];
		if(i!=n) cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4332
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<ll> A(N);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
    }
    ll sum = 0;
    for(size_t i=1;i<N; i++)
    {
        if(A[i-1] > A[i])
        {
            sum += A[i-1] - A[i];
            A[i] = A[i-1];
        }
    }
    cout << sum << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<int> ve;
typedef vector< vector < int> > vee;
typedef pair<int, int> pa;
typedef vector<pair<ll,ll> > vepa;
typedef set<int>se;
typedef map<string,int> mp;
const ll N=1e5+5;
ll arr[N],A[N],ARR[N];
bool visited[N]={};
ll cnt[N],freq[N];
bool f,ff;
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        puts("Yes");
    else
        puts("No");

go;
}


Measured memory_bytes: 256
#include<stdio.h>
#define size 115
int main()
{
	int N,max=-1,i,l[size],total=0;
	scanf("%d",&N);
	if(N>=3)
	{
	for(i=0;i<N;i++)
		{
			scanf("%d",&l[i]);
			total+=l[i];
		}
	for(i=0;i<N;i++)
		{
			if(l[i]>max&&l[i]>0)
				{
					max=l[i];
				}
			else
				{
					
				}
			
		}
		total-=max;
	if(max<total)
		{
			printf("Yes\n");
		}
	else
		{
			printf("No\n");
		}
	}
	else
		{
			printf("No\n");
		}
	return 0;
}

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

int main()
{
    ll t,i,j,k,l,n,m;
    cin>>n;
    ll A[n];
    ll B[n],sum=0;
    for(i=0;i<n;++i){
        cin>>A[i];
        B[i]=A[i];
    }
    map<ll,ll> M;
    ll ans=0;
    for(i=0;i<n;++i){
        sum+=A[i];
        if(sum==0){
            ans++;
        }
        ans+=M[sum];
        M[sum]++;
    }
    cout<<ans;


    return 0;
}


Measured memory_bytes: 15872
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    aa=LI()
    ans=n-sum(aa)
    if ans<0:print(-1)
    else:print(ans)

main()

Measured memory_bytes: 9976
// Problem : B - Crane and Turtle
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    long x, y;
    cin >> x >> y;
    
    long b = (y - 2 * x) / 2;
    if (y % 2 == 0 && b >= 0 && x - b >= 0) cout << "Yes\n";
    else cout << "No\n";
    
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
int main(void) {
    char str[1001], w[11];
    int ans;
    int i;
     
    scanf("%s", w);
     
    for (i = 0; str[i] != '\0'; i++) str[i] = tolower(str[i]);
     
    ans = 0;
    while (scanf("%s", str), strcmp(str, "END_OF_TEXT")) {
        for (i = 0; str[i] != '\0'; i++) str[i] = tolower(str[i]);
         
        if (strcmp(str, w) == 0) ans++;
    }
    printf("%d\n", ans);
     
    return 0;
}


Measured memory_bytes: 2056
import sys


def check(pay, like):
    str_pay = str(pay)
    like = ''.join(like)
    for p in str_pay:
        for lk in like:
            if p == lk:
                return False

    return True

N, K = map(int, input().split())

D = []
D = list(map(int, input().split()))
str_D = []

for s in D:
    str_D.append(str(s))

pay = N

while True:
    if check(pay, str_D):
        print(pay)
        sys.exit()
    pay += 1


Measured memory_bytes: 9036
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

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

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
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 << VECTOR_COUT_SEPARATOR; } 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; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N; cin >> N;
  vector<string> A(N);
  vector<int> B(N);
  map<string, int> m{};
  for (auto& a : A) {
    cin >> a;
    ++m[a];
  }
  for (int i = 0; i < N; ++i) {
    B[i] = m[A[i]];
  }
  auto cnt = *boost::max_element(B);
  map<string, int> res{};
  for (int i = 0; i < N; ++i) {
    if (B[i] == cnt) {
      // res.emplace(A[i]);
      res[A[i]];
    }
  }
  for (auto it = res.begin(); it != res.end(); ++it) {
    cout << it->first << CRLF;
  }
  return;
}

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

  solve();

  return 0;
}


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

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)round(x))<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

static const int MAX = 100002;

int N;
ll C;
ll X[MAX], V[MAX];
ll x[2][MAX], v[2][MAX];
ll sum[2][MAX];
ll maxSum[2][MAX];

void calcSum(ll dist[MAX], ll cal[MAX], ll s[MAX], ll m[MAX]) {
  ll calSum = 0;
  for (int i = 0; i < N; i++) {
    calSum += cal[i];
    s[i] = calSum - dist[i];
    
    if (i == 0) {
      m[i] = s[i];
    } else {
      m[i] = max(s[i], m[i - 1]);
    }
  }
}

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

  while (cin >> N >> C) {
    for (int i = 0; i < N; i++) {
      cin >> X[i] >> V[i];
      
      x[0][i] = X[i];
      v[0][i] = V[i];
      x[1][N - i - 1] = C - X[i];
      v[1][N - i - 1] = V[i];
    }

    calcSum(x[0], v[0], sum[0], maxSum[0]);
    calcSum(x[1], v[1], sum[1], maxSum[1]);

    ll ans = 0;

    for (int first = 0; first < 2; first++) {
      for (int i = 0; i < N; i++) {
        ll cal = sum[first][i];

        if (cal <= 0) {
          continue;
        }

        if (i != N - 1) {
          int revFirst = !first;
          ll rev = maxSum[revFirst][N - i - 2];

          if (rev > x[first][i]) {
            cal = cal - x[first][i] + rev;
          }
        }

        ans = max(ans, cal);
      }
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n%10==9||n/10==9)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
return 0;
}



Measured memory_bytes: 256
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e5 + 5, mod = (int) 0;
int px[N], py[N], par[N];
pair<int, int> sx[N], sy[N];
int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
int unite(int u, int v) {
	u = find(u);
	v = find(v);
	if (u == v) return 0;
	par[u] = v;
	return 1;
}
	
int dist(int x, int y) {
	return min(abs(px[x] - px[y]), abs(py[x] - py[y]));	
}
int main() {
	int n;
	cin >> n;
	for (int j = 0; j < n; ++j) {
		cin >> px[j] >> py[j];
		par[j] = j;
		sx[j] = mp(px[j], j);
		sy[j] = mp(py[j], j);
	}
	sort(sx, sx + n);
	sort(sy, sy + n);
	set<pair<int, pair<int, int>>> st;
	for (int j = 0; j < n - 1; ++j) {
		st.insert(mp(dist(sx[j].second, sx[j + 1].second), mp(sx[j].second, sx[j + 1].second)));	
		st.insert(mp(dist(sy[j].second, sy[j + 1].second), mp(sy[j].second, sy[j + 1].second)));	
	}
	long long res = 0;
	while ((int) st.size()) {
		auto cur = *(st.begin());
		st.erase(cur);
		int u = cur.second.first, v = cur.second.second;
		res += (LL) unite(u, v) * dist(u, v);
	}
	cout << res << endl;
}




Measured memory_bytes: 15488
A, B, K = map(int, input().split())
a=[]
#b=[]
if A>=B:
  for i in range(1, A+1): # i = [1,2,3,4,....A]
    if A%i==0 and B%i==0:
      a.append( i )
      # b.append( B/i )
  
else:
  for i in range(1, B+1): # i = [1,2,3,4,....A]
    if A%i==0 and B%i==0:
      a.append( i )
      # b.append( B/i )

#print(a)
#print(b)

#c=[]
#for ea in a:
 # if ea in b:
  #  c.append( ea )
c=len(a)
print(a[c-K])
    


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,ans=987654321;
char a[1010],b[1010];
int main()
{
    scanf("%s%s",a,b);
    n=strlen(a);
    m=strlen(b);
    for(int i=0;i<=n-m;i++)
    {
        int tem=0;
        for(int j=0;j<m;j++)
        {
            if(a[i+j]!=b[j])
            {
                tem++;
            }
        }
        ans=min(ans,tem);
    }
    printf("%d",ans);
}


Measured memory_bytes: 3824
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    map<long,long>mp;
    int N;
    cin >> N;
    long long K;
    cin >> K;
    long long A,B;
    long long num_max=0;
    for(int i=0;i<N;++i){
        cin >> A >> B;
        mp[A]+=B;
        num_max=max(num_max,A);       
    }
    long long ans=0;
    long long num=0;
    for(int i=0;i<=num_max;++i){
        num+=mp[i];
        if(num>=K){
            ans=i;
            break;
        }
    } 
    cout << ans << endl;
}

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

int dp[200002][3];
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  s = "  "+s;
  for (int i = 0; i < n; i++) {
    for (int j : {1,2}) {
      for (int k : {1,2}) {
	if (s.substr(i-k+2,k) != s.substr(i+2,j))
	  dp[i+j][j] = max(dp[i+j][j], dp[i][k]+1);
      }
    }
  }
  cout << max(dp[n][1], dp[n][2]) << endl;
}


Measured memory_bytes: 2896
#include<bits/stdc++.h>
#define M 500000
#define MAX 10000000000000010
#define mod 1000000007
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main()
{
	ll h,n;
	cin>>h>>n;
	ll sum = 0;
	for(int i=0;i<n;i++)
	{
		ll temp;
		cin>>temp;
		sum+=temp;
	}
	if(sum>=h)
		cout<<"Yes";
	else
	{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, X, L[101], D[101] = {};
    cin >> N >> X;
    for(int i = 0; i < N; ++i) {
        cin >> L[i];
        if((D[i + 1] = D[i] + L[i]) > X) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << N+1 << endl;
    return 0;
}

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

#define PI 3.14159265358979323846

// #define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 10000010
#define MOD 1000000007

int bexp(int a, int b)
{
    int res = 1;
    while(b)
    {
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n, k, d;
    cin >> n >> k >> d;

    if (n >= 0)
    {
        int l = min(k, n / d);
        n -=  l * d;
        k -= l;
        if (k)
            n -= d, k--;

        n = n + (k % 2) * d;
    }
    else
    {
        int l = min(k, abs(n) / d);
        n +=  l * d;
        k -= l;
        if (k)
            n += d, k--;

        n = n - (k % 2) * d;   
    }

    cout << abs(n);
    return 0;
}


Measured memory_bytes: 3684
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int m = sc.nextInt();
		Map<Integer, List<Integer>> yearsTable = new HashMap<>();
		int[] p = new int[m];
		int[] y = new int[m];
		for (int i = 0; i < m; ++i) {
			p[i] = sc.nextInt();
			y[i] = sc.nextInt();
			yearsTable.putIfAbsent(p[i], new ArrayList<>());
			yearsTable.get(p[i]).add(y[i]);
		}

		for (int key : yearsTable.keySet()) {
			Collections.sort(yearsTable.get(key));
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < m; ++i) {
			List<Integer> list = yearsTable.get(p[i]);
			int yearRank = find(list, y[i]) + 1;
			pw.printf("%06d%06d\n", p[i], yearRank);
		}
		pw.flush();
	}

	static int find(List<Integer> list, int key) {
		int left = -1;
		int right = list.size();
		while (right - left > 1) {
			int mid = left + (right - left) / 2;
			if (list.get(mid) == key) {
				return mid;
			} else if (list.get(mid) < key) {
				left = mid;
			} else {
				right = mid;
			}
		}
		return left;

	}

}


Measured memory_bytes: 113212
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <deque>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;

struct Bii {
  int d, a, b;

  bool operator > (const Bii& from) const
  {
     return d > from.d;
  }

  bool operator < (const Bii& from) const
  {
     return d < from.d;
  }
};

class UnionFind {
public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}

  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
  int size(int x) {
    return -data[find(x)];
  }
};

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

  cin >> n;
  vector<P> y;
  vector<P> x;

  REP(i, n) {
    int ty, tx;
    cin >> ty >> tx;

    y.push_back(P(ty, i));
    x.push_back(P(tx, i));
  }

  sort(y.begin(), y.end());
  sort(x.begin(), x.end());

  priority_queue<Bii, vector<Bii>, greater<Bii>> que;
  REP(i, n - 1) {
    Bii by = { y[i + 1].first - y[i].first, y[i].second, y[i + 1].second };
    que.push(by);

    Bii bx = { x[i + 1].first - x[i].first, x[i].second, x[i + 1].second };
    que.push(bx);
  }

  UnionFind uf(n);

  ll ans = 0;
  while(!que.empty()) {
    Bii bi = que.top(); que.pop();
    if(uf.find(bi.a) != uf.find(bi.b)) {
      uf.unite(bi.a, bi.b);
      ans += bi.d;
      if(uf.size(bi.a) == n) break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 7016
#include<stdio.h>
#include<math.h>
int main()
{
    long long int b,c,i,j,m=0,n=0;
    scanf("%lld",&i);
    long long int a[i-1];
    for(j=0;j<i;j++){
        scanf("%lld",&a[j]);
        m+=a[j];
        }
    b=llabs(m-2*a[0]);
    for(j=0;j<i-1;j++){
        n+=a[j];
        c=llabs(m-2*n);
        if(c<b) b=c;
    }
    printf("%lld",b);
    return 0;
}


Measured memory_bytes: 1664
import math

def main():
    N = int(input())
    A = list(map(int, input().split()))
    b = [None]*N
    
    for i in range(N, math.ceil(N/2), -1):
        b[i-1] = A[i-1]
    
    for i in range(math.ceil(N/2), 0, -1):
        s = sum([b[j-1] for j in range(2*i, N+1, i)])
        b[i-1] = (A[i-1] + s) % 2
        
    b_out = [str(i+1) for i in range(N) if b[i] == 1]
    print(sum(b))
    print(' '.join(b_out))

if __name__ == '__main__':
    main()

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

using namespace std;

struct node {
	node* l = nullptr, *r = nullptr;
	bool rev;
	int x;
	int y;
	int sz;
    vector<int> chars;
    node(int x): x(x){
       y = rand();
       chars.assign(26, 0);
       sz = 1;
       ++chars[x];
    }
};

node* root = nullptr;

int sz(node* curr)
{
    if (!curr)
        return 0;
    return curr->sz;
}

void upd(node* curr)
{
    if (!curr)
        return;
    curr->sz = 1 + sz(curr->l) + sz(curr->r);
    curr->chars.assign(26, 0);
    ++curr->chars[curr->x];
    if (curr->l)
    {
        for(int i = 0;i < 26; ++i)
        {
            curr->chars[i] += curr->l->chars[i];
        }
    }
    if (curr->r)
    {
        for(int i = 0;i < 26; ++i)
        {
            curr->chars[i] += curr->r->chars[i];
        }
    }
}

typedef pair<node*, node*> Pair;

node* Merge (node *l, node *r) {
    //push(l);
    //push(r);
    if (!l) return r;
    if (!r) return l;
    if (l->y > r->y) {
        l->r = Merge(l->r, r);
        upd(l);
        return l;
    }
    else {
        r->l = Merge(l, r->l);
        upd(r);
        return r;
    }
}

Pair split (node *p, int k) {
    //push(p);
    if (!p) return {0, 0};
    if (sz(p->l) + 1 <= k) {
        Pair q = split(p->r, k - sz(p->l) - 1);
        p->r = q.first;
        upd(p);
        return {p, q.second};
    }
    else {
        Pair q = split(p->l, k);
        p->l = q.second;
        upd(p);
        return {q.first, p};
    }
}

void Insert (int x, int k) {
    //push(root);
    Pair q = split(root, k);
    //cout << endl;
    node *t = new node(x);
    //cout << endl;
    root = Merge(q.first, Merge(t, q.second));
    upd(root);
}

void change (int newchar, int q_i) {
    Pair q1 = split(root, q_i);
    Pair q2 = split(q1.first, q_i - 1);
    --q2.second->chars[q2.second->x];
    q2.second->x = newchar;
    ++q2.second->chars[newchar];
    root = Merge(Merge(q2.first, q2.second), q1.second);
    upd(root);
}

int answer(int l, int r)
{
    Pair q1 = split(root, r);
    Pair q2 = split(q1.first, l - 1);
    int ans = 0;
    for(int i = 0;i < 26; ++i)
    {
        if (q2.second->chars[i] != 0)
        {
            ++ans;
        }
    }
    root = Merge(Merge(q2.first, q2.second), q1.second);
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n;
    string s;
    cin >> s;
    cin >> m;
    for(int i = 0;i < n; ++i)
    {
        Insert(s[i] - 'a', i);
    }
    for(int i = 0;i < m; ++i)
    {
        int q, l;
        cin >> q >> l;
        if (q == 1)
        {
            char r;
            cin >> r;
            //cout << r << endl;
            change(r - 'a', l);
        }
        else
        {
            int r;
            cin >> r;
            cout << answer(l, r) << '\n';
        }
        
    }
}

Measured memory_bytes: 88732
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int tmp;
		ArrayList<Integer> d = new ArrayList<Integer>();
		for(int i=0; i<N; i++) {
			tmp = sc.nextInt();
			d.add(tmp);
		}

		Collections.sort(d);

		int m = d.size()/2;
		int ans = d.get(m)-d.get(m-1);

		if(ans >= 1)System.out.println(ans);
		else System.out.println(0);
	}
}


Measured memory_bytes: 61256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,x[100],y[100];
    cin >> n;
    for(int i = 0;i < n;i++)cin >> x[i];
    for(int i = 0;i < n;i++)cin >> y[i];
    double d[4];
    for(int i = 0;i < 4;i++)d[i] == 0.0;
    for(int k = 1;k <= 3;k++){
        for(int i = 0;i < n;i++){
            d[k] += pow(fabs(x[i] - y[i]), k);
        }
        d[k] = pow(d[k], 1.0/k);
    }
    
    for(int i = 0;i < n;i++){
        d[0] = (d[0] < fabs(x[i] - y[i])?fabs(x[i] - y[i]):d[0]);
    }
    cout << fixed << setprecision(8) << d[1] << endl;
    cout << fixed << setprecision(8) << d[2] << endl;
    cout << fixed << setprecision(8) << d[3] << endl;
    cout << fixed << setprecision(8) << d[0] << endl;
}


Measured memory_bytes: 3432
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	List<Integer>[] g;
	boolean[] seen;

	void dfs(int u) {
		seen[u] = true;
		for (int v : g[u]) {
			if (seen[v])
				continue;
			dfs(v);
		}
	}

	void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt(), m = in.nextInt();
		g = new ArrayList[n + 1];
		seen = new boolean[n + 1];
		for (int i = 0; i <= n; ++i) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; ++i) {
			int u = in.nextInt(), v = in.nextInt(), c = in.nextInt();
			g[u].add(v);
			g[v].add(u);
		}
		int ans = 0;
		for (int i = 1; i <= n; ++i) {
			if (!seen[i]) {
				dfs(i);
				++ans;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out)) {
			new Main().solve(in, out);
		}
	}
}


Measured memory_bytes: 111860
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include<regex>
#include <unordered_map>  

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)


//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int n, m, q, l[200009], r[200009], x[509][509], c[509][509];

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

	for (char c : s) {
		if (c == '1') {
			cout << 9;
		}
		else if (c == '9') {
			cout << 1;
		}
		else {
			cout << c;
		}
	}

	cout << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int i,count=0;
	char S[4], T[4];
	scanf("%s", &S);
	scanf("%s", &T);
	for (i = 0; i < 3; i++) {
		if (S[i] == T[i])
			count += 1;
	}
	printf("%d", count);
	return 0;
}






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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0;i<N;i++){
    cin >> d.at(i);
  }
  vector<int> div(N);
  for (int i= 0;i<N;i++){
    int count=N-1;
    for (int x=0;x<N;x++){
      if (i==x){
        continue;
      }
      else if (d.at(i) <d.at(x)){
        continue;
      }
      else if(d.at(i) > d.at(x)){
        count --;
      }
      else if(d.at(i) == d.at(x) && i <x){
        count --;
      }
    }
    div.at(count) = d.at(i);
  }
  int result=1 ;
  for (int i=1 ;i<N;i++){
    if (div.at(i-1)>div.at(i)){
      result += 1;
    }
    else{
      continue;
    }
  }
  cout << result <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

typedef vector<ll> vecll;
typedef vector<ld> vecld;
typedef vector<bool> vecbl;
typedef vector<vector<ll> > matll;
typedef vector<vector<ld> > matld;
typedef vector<vector<bool> > matbl;
#define mp make_pair;

const ll prime = 1000000000 + 7;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

bool my_comp(pll a, pll b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}

	return a.second < b.second;
}

// nのk乗(mod p = prime)
ll power(ll n, ll k) {
	ll p = prime;
	if (k == 1) {
		return n;
	}
	ll m = n * n;
	m %= p;
	if (k % 2 == 0) {
		return power(m, k / 2);
	}
	m = power(m, k / 2);
	m *= n;
	m %= p;
	return m;
}

// nCk(mod p = prime)
ll com(ll n, ll k) {
	// nCk
	ll p = prime;

	ll ans = 1;
	for (ll i = 1; i <= n; i++)
	{
		ans *= i;
		ans %= p;
	}

	for (ll i = 2; i <= k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	for (ll i = 2; i <= n-k; i++)
	{
		ans *= power(i, p - 2);
		ans %= p;
	}

	return ans;
}


int main() {

	ll x, i, m;
	cin >> x;
	i = 0;
	m = 100;
	while (true) {
		m = m * 1.01;
		i++;
		if (m >= x) break;
	}
	cout << i << endl;

	return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


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

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

  int ans = 1;
  int cnt = 0;
  for (int i = 1; i <= N; i++) {
    int n = i;
    int c = 0;
    for (int j = 0; j < i / 2; j++) {
      if (n % 2 == 0) {
        n /= 2;
        c++;
      } else
        break;
    }
    if (cnt < c) {
      ans = i;
      cnt = c;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a[10000], b[10000];
	int sumA, sumB;
	int n;
	int i;
	
	sumA = 0;
	sumB = 0;
	
	while(1){
		scanf("%d", &n);
		
		if(n==0) break;
		
		for(i=0; i<n; i++){
			scanf("%d %d", a+i, b+i);
		}
		
		/*
		for(i=0; i<n; i++){
			printf("%d %d\n", a[i], b[i]);
		}
		*/
		
		for(i=0;i<n;i++){
			if(a[i] > b[i]) sumA += a[i]+b[i];
			if(a[i] < b[i]) sumB += a[i]+b[i];
			if(a[i] == b[i]){
				sumA += a[i];
				sumB += b[i];
			}
		}
		
		printf("%d %d\n", sumA, sumB);
		
		sumA = 0;
		sumB = 0;
		
	};
	
	return 0;
}

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

namespace abc123D
{
    class Program
    {
        static int cons = 3000;
        static long[] rank = new long[cons + 2];
        static void ReRank(long z)
        {
            long temp = rank[cons+1];
            rank[0] = 30000000001;

            if (z > temp)
            {
                for (int i = cons; i>=0;i--)
                {
                    if (z < rank[i])
                    {
                        for (int j = cons; j >= i; j--)
                        {
                            rank[j + 1] = rank[j];
                        }
                        rank[i + 1] = z;
                        break;
                    }

                }
            }
        }

        static void Main(string[] args)
        {
            //first line
            var d = Console.ReadLine();
            string[] f = d.Split(' ');
            var x = long.Parse(f[0]);
            var y = long.Parse(f[1]);
            var z = long.Parse(f[2]);
            var k = long.Parse(f[3]);
            if (k > cons)
            {
                k = cons;
            }
            long[] a = new long[x];
            long[] b = new long[y];
            long[] c = new long[z];     

            d = Console.ReadLine();
            f = d.Split(' ');
            for (int j = 0; j < f.Length; j++)
            {
                a[j] = Convert.ToInt64(f[j]);
            }

            d = Console.ReadLine();
            f = d.Split(' ');
            for (int j = 0; j < f.Length; j++)
            {
                b[j] = Convert.ToInt64(f[j]);
            }

            d = Console.ReadLine();
            f = d.Split(' ');
            for (int j = 0; j < f.Length; j++)
            {
                c[j] = Convert.ToInt64(f[j]);
            }

            Array.Sort(a);
            Array.Reverse(a);
            Array.Sort(b);
            Array.Reverse(b);
            Array.Sort(c);
            Array.Reverse(c);

            for (int i = 0;i<x;i++)
            {
                if (i>k)
                {
                    break;
                }
                for (int j = 0; j <y; j++)
                {
                    if (i*j > k)
                    {
                        break;
                    }
                    for (int l = 0; l <z; l++)
                    {
                        if (i * j * l > k)
                        {
                            break;
                        }
                        ReRank(a[i]+b[j]+c[l]);
                    }
                }
            }

            for (long i = 1; i <= k; i++)
            {
                Console.WriteLine(rank[i]);
            }
            Console.ReadKey();
        }
    }
}





Measured memory_bytes: 13780
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int h[maxn],f[maxn][2];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	f[0][1]=0;
	f[1][0]=0;
	f[1][1]=0;
	for(int i=2;i<=n;i++){
		f[i][0]=max(f[i-2][1],f[i-1][0]);
		if(h[i]<=h[i-1]){
			f[i][1]=f[i-1][1]+1;
		}
		else{
			f[i][1]=0;
		}
	}
	cout<<max(f[n][0],f[n][1])<<endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=1000000000000000;

vector<ll> pw2(51,1); vector<ll> pw10(19,1);
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll mid(ll x,ll y,ll z){return x>y?y>=z?y:min(z,x):x>=z?x:min(y,z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll myceil(ll x,ll y){if(x<=y) return 1;else if(x%y==0) return x/y;else return x/y+1;}
vector<ll> divisor(ll x){
	vector<ll> div;
	for(int i=1;i*i<=x;i++){
		if(i*i!=x && x%i==0){
			div.pb(i);
			div.pb(x/i);
		}
		else if(x%i==0) div.pb(i);
	}
	return div;
}
vector<ll> vectorprime(ll x){
	vector<bool> is_prime(x+1);
	vector<ll> prime;
	rep(i,x+1) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=x;i++){
		if(is_prime[i]){
			prime.pb(i);
		}
		for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
	}
	return prime;
}

//a,b x
int main(){
	ll N,K; cin>>N>>K;
	if(K%2==1){
		ll tmp=N/K;
		cout<<tmp*tmp*tmp;
	}
	else{
		ll tmp=N/(K/2);//0かK/2あまる
		ll tmp2=N/K;//0あまる
		tmp-=tmp2;//K/2あまる
		cout<<tmp*tmp*tmp+tmp2*tmp2*tmp2;
	}
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=100010;

vi graph[vmax],ord,low,scc,par;
stack<int>s;

void add_edge(int f,int t){ graph[f].pb(t);}
void add_both_edges(int f,int t){add_edge(f,t);add_edge(t,f);}

void dfs(int v,int p,int &k){
	ord[v]=k++;
	low[v]=ord[v];
	par[v]=p;
//	s.push(v);
	for(auto &i:graph[v]){
		if(ord[i]==-1){
			dfs(i,v,k);
			low[v]=min(low[v],low[i]);
		}else if(i!=p /*scc[i]==-1*/)
			low[v]=min(low[v],ord[i]);
	}
	/*if(ord[v]==low[v]){
		while(1){
			int u=s.top();s.pop();
			scc[u]=v;
			if(u==v) break;
		}
	}*/
}

void lowlink(int n){
	int k=0;
	ord.assign(n,-1),low.resize(n);
	scc.assign(n,-1),par.resize(n);
	rep(i,n) if(ord[i]==-1) dfs(i,-1,k);
}

int main(void){
	int v,e;
	cin >> v >> e;
	rep(loop,e){
		int a,b;
		cin >> a >> b;
		add_both_edges(a,b);// add_edge(a,b);
	}
	lowlink(v);

/*	rep(i,v){
		cout << "ord[" << i << "]=" << ord[i]  << endl;
		cout << "low[" << i << "]=" << low[i]  << endl;
	}
*/

// Bridge
/*	vector<pii> bridge;
	rep(i,v){
		int j=par[i];
		if(j==-1)
			continue;
		if(ord[i] < low[j] || ord[j] < low[i] ){
			pii in(i,j);
			if(in.second<=in.first) swap(in.first,in.second);
			bridge.pb(in);
		}
	}
	sort(bridge.begin(),bridge.end());
	for(auto &i:bridge)
		cout << i.first << " " << i.second << endl;
*/

// Articulation Points
	vi articulation_point;
	rep(i,v){
		if(i){
			bool ok=false;
			for(auto &j:graph[i]){
				if(i==par[j]&&ord[i]<=low[j])
					ok=true;
			}
			if(ok) articulation_point.pb(i);
		}else{
			int d=0;
			rep(j,v) if(par[j]==0) d++;
			if(d>=2) articulation_point.pb(i);
		}
	}
	sort(articulation_point.begin(),articulation_point.end());
	for(auto &i:articulation_point)
		cout << i << endl;

// Strongly Connected Components

/*	int q;
	cin >> q;
	rep(loop,q){
		int a,b;
		cin >> a >> b;
		cout << (scc[a]==scc[b]) << endl;
	}
*/
	return 0;
}

Measured memory_bytes: 4988