akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

class SegmentTree
{
public:
    ll N = 0;
    vector<ll> Data;

public:
    SegmentTree(ll n, ll x = 0)
    {
        for (N=1;N<n;N<<=1);
        Data.assign(N * 2 - 1, x);
    }

    template <typename Func> void update(ll k, ll x, Func func)
    {
        if (k < 0) { return; }

        k += N - 1;
        Data[k] = x;

        while (k)
        {
            k = (k - 1) >> 1;
            Data[k] = func(Data[k * 2 + 1], Data[k * 2 + 2]);
        }
    }

    template <typename Func> void add(ll k, ll x, Func func)
    {
        update(k, x + Data[k + N - 1], func);
    }

    template<typename Func> ll query(ll a, ll b, Func func) const
    {
        return query(a, b, 0, N, 0, func);
    }

    template<typename Func> ll query(ll a, ll b, ll l, ll r, ll k, Func func) const
    {
        if(r <= a || b <= l) { return 0; }
        if(a <= l && r <= b) { return Data[k]; }

        const auto mid = (l + r) >> 1;
        const auto lhs = query(a, b, l, mid, (k << 1) + 1, func);
        const auto rhs = query(a, b, mid, r, (k << 1) + 2, func);
        return func(lhs, rhs);
    }
};

struct Query
{
    ll ID, L, R;
};

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

    vector<ll> C(N);
    rep (i, N) { cin >> C[i]; --C[i]; }

    vector<Query> queries(Q);
    rep (i, Q)
    {
        auto& query = queries[i];
        query.ID = i;

        cin >> query.L >> query.R;
        --query.L;
        --query.R;
    }

    sort(queries.begin(), queries.end(), [](const auto& a, const auto& b)
    {
        return a.R < b.R;
    });

    vector<ll> ans(Q);
    vector<ll> last(N, -1);

    SegmentTree seg(N);
    const auto func = [](const auto& a, const auto& b) { return a + b; };

    ll index = 0;

    for (const auto& query : queries)
    {
        while (index <= query.R)
        {
            seg.update(last[C[index]], 0, func);
            seg.update(index, 1, func);

            last[C[index]] = index;
            ++index;
        }

        ans[query.ID] = seg.query(query.L, query.R + 1, func);
    }

    for (const auto& x : ans) { cout << x << endl; }

    return 0;
}


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

using namespace std;

int main(void) {
	int N;
	char S[100000];
	cin >> N;
	cin >> S;
	char BeforeColor = S[0];
	int count = 1;
	for (int i=1; i<N; i++) {
		if (S[i] != BeforeColor) count++;
		BeforeColor = S[i];
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 384
#define MAX 1000000000
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    
    int n,m,i,j,t;
    long int a[100]={},b[100]={},c[100]={},d[100]={},min=MAX,ans;
    
    scanf("%d %d",&n,&m);
    
    for(i=0;i<n;i++){
        scanf("%ld %ld",&a[i],&b[i]);
    }
    for(i=0;i<m;i++){
        scanf("%ld %ld",&c[i],&d[i]);
    }
    for(i=0;i<n;i++){
        min=MAX;
        for(j=0;j<m;j++){
            ans=labs(a[i]-c[j])+labs(b[i]-d[j]);
            if(ans<min){
                min=ans;
                t=j+1;
            }
        }
        printf("%d\n",t);
    }
    return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const INFINITY = math.MaxInt64/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	q := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	x := 0
	diffs := []int{-1, 0, 1}
	for len(q) < Pow(10, 5) {
		a := q[x]
		b := a % 10
		for _, d := range diffs {
			if 0 <= b+d && b+d <= 9 {
				q = append(q, a*10+b+d)
			}
		}
		x++
	}

	k := stdin.ReadInt()
	stdout.Println(q[k-1])
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}


Measured memory_bytes: 5504
from collections import*
n,*v=map(int,open(0).read().split())
a,b=[Counter(i).most_common()+[(0,0)]for i in(v[::2],v[1::2])]
i,j=a[0][1],b[0][1]
print(min(n-i-b[1][1],n-a[1][1]-j)*(a[0][0]==b[0][0])or n-i-j)

Measured memory_bytes: 21032
#include<stdio.h>


int main(){
  
  int N, i, g1[210], g2[210], g3[210], p[210], j, c1, c2, c3;
  
  scanf("%d",&N);

  for(i=1;i<=N;i++){
    scanf("%d %d %d", &g1[i], &g2[i], &g3[i]);
  }
  for(i=1;i<=N;i++){
    p[i]=0;
    c1=0;
    c2=0;
    c3=0;
    for(j=1;j<=N;j++){
      if(g1[i]==g1[j]) c1++;
      if(g2[i]==g2[j]) c2++;
      if(g3[i]==g3[j]) c3++;
    }
    if(c1==1) p[i]+=g1[i];
    if(c2==1) p[i]+=g2[i];
    if(c3==1) p[i]+=g3[i];
  }

  for(i=1;i<=N;i++){
    printf("%d\n", p[i]);
  }
  
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		WriteLine((GetInt() + 1) / 2);
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll a, b, c;
    cin >> a >> b >> c;
    
    ll ans = INF;

    ans = min(ans, abs(a*b*(c/2) - a*b*(c-c/2)));
    ans = min(ans, abs(a*c*(b/2) - a*c*(b-b/2)));
    ans = min(ans, abs(c*b*(a/2) - c*b*(a-a/2)));

    cout << ans << endl;
    




    return 0;
}

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

int main() {
  int n, x; cin >> n >> x;
  vector<int> m(n); for(int i = 0; i < n;i++) cin >> m.at(i);
  
  for(int i = 0; i < n; i++) x -= m.at(i);
  int ans = n;
  sort(m.begin(), m.end());
  ans += x / m.at(0);
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define first F
#define second S
#define int ll

int32_t main(){
    FAST
    int a, b; cin >> a >> b;
    cout << (a*b)/__gcd(a, b);
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int N,A,B,C,D;
  cin >>N;
		A = N/1000 ; //1000		
        B = (N%1000 - N%100)/100 ; //100
  		C = (N%100 - N%10)/10 ; //10
  		D = N%10 ; //1

	if (A==B && A==C)
      cout <<"Yes"<<endl;
  
  	else if (B==C && B==D)
      cout <<"Yes"<<endl;
  
  	else
      cout <<"No"<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define PI 3.14159265359
using namespace std;

int main(){
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double ax, ay, bx, by;
  double long_angle = h * 30 + m * 30 / 60.0;
  double short_angle = m * 6;
  ax = cos(long_angle * M_PI / 180.0) * a;
  ay = sin(long_angle * M_PI / 180.0) * a;
  bx = cos(short_angle * M_PI / 180.0) * b;
  by = sin(short_angle * M_PI / 180.0) * b;
  double x_dis = ax - bx;
  double y_dis = ay - by;
  double ans = sqrtl(x_dis * x_dis + y_dis * y_dis);
  printf("%.15f\n", ans);
  return 0;
}

Measured memory_bytes: 4028
#include<iostream>
#include<string>
using namespace std;
int main(){
 string w;
 string t;
 cin >> w;
 int i;
 for(i=0;i<w.size();i++) {
   if('A'<=w[i]&&w[i]<='Z') w[i]+='a'-'A';
 }
 int o=0;
 cin >> t;
 while(t!="END_OF_TEXT"){

   for(i=0;i<t.size();i++) {
     if('A'<=t[i]&&t[i]<='Z') t[i]+='a'-'A';
   }
   if(w==t) o++;
   cin >> t;
 }
 cout << o << endl;
}


Measured memory_bytes: 3164
import java.util.*;

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

		boolean b = false;
		for (int i = 1; i <= 9 && !(b = n % i == 0 && n / i <= 9); i++) ;
		System.out.println(b ? "Yes" : "No");
	}
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 2 * 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
ll sqr(ll a)
{
    return ((a % MOD) * (a % MOD)) % MOD;
}
ll msub(ll a, ll b)
{
    return ((a - b) % MOD + MOD) % MOD;
}
ll madd(ll a, ll b)
{
    return (a + b) % MOD;
}
ll mmul(ll a, ll b)
{
    return ((a % MOD) * (b % MOD)) % MOD;
}
int t;
int a[N];
map <ll, ll> cnt;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    FOR(i, 1, n)
    {
        cin >> a[i];
        cnt[a[i] + i]++;
    }
    ll res = 0;
    FOR(i, 1, n)
    {
        res += cnt[-(a[i] - i)];
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 27136
using System;

class P{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int[] d = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
    int sum=0;
    for(int i=0;i<d.Length;i++){
      for(int j=i+1;j<d.Length;j++){
        sum+=d[i]*d[j];}}
    
    Console.WriteLine(sum);
  }
}


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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  int n, x, y;
  cin >> n >> x >> y;
  
  vector<int> k(n+1);	//k(i):距離kのペア数
  
  Graph G(n);
  rep(i,0,n-1){
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[x-1].push_back(y-1);
  G[y-1].push_back(x-1);
  
  for(int m = 0; m < n; m++){
  // BFS のためのデータ構造
  vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
  queue<int> que;
  
  // 初期条件 (頂点 m を初期ノードとする)
  dist[m] = 0;
  que.push(m); // m を橙色頂点にする
  
  // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
  rep(i,0,n){
      	k.at(dist[i])++;
  }
  }
  
  for(int i = 1; i < n; i++){
    cout << k.at(i)/2 << endl;
  }
  
  
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

/*
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int64> a(3);
	REP(i, 3) cin >> a[i];
	sort(all(a));
	if (a[0] == a[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}
*/

int main(void) {
	string s;
	int64 N;
	cin >> N;
	cin >> s;
	map<char, int64> cnt;
	REP(i, s.size()) {
		cnt[s[i]]++;
	}
	if (cnt['R'] > cnt['B']) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(" ".join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


n = int(data())
initial = 100
i = 1
while True:
    initial += initial//100
    if initial >= n:
        out(i)
        exit()
    i += 1


Measured memory_bytes: 72832
#include <cstdio>
#include <cmath>

struct Point{ double x, y;};

void koch(int n, Point a, Point b){
  if (n == 0) return;

  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

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

int main(){
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}



Measured memory_bytes: 2740
#include<stdio.h>
#define N 100
#define INFTY 1000000000

int main(){
    int n,i,j,k,l,q, p[N + 1], m[N + 1][N + 1];

    scanf("%d", &n);

    for(i = 1; i <= n; i++){
        scanf("%d %d", &p[i-1], &p[i]);
    }

    for(i = 1; i <= n; i++) {
      m[i][i] = 0;
    }

    for(l = 2; l <= n; l++){
        for(i = 1; i <= n-l+1; i++){
            j = i + l - 1;
            m[i][j] = INFTY;
            for(k = i; k <= j-1; k++){
                q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
                if(m[i][j] > q) m[i][j] = q;
            }
        }
    }

    printf("%d\n", m[1][n]);

    return 0;
}



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

using namespace std;

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

    long N, X; cin>>N>>X;
    struct Data {
        long b, l, u;
        Data() {
            cin>>b>>l>>u;
        }
        long value(long x) {
            return b*l+(x-b)*u;
        }
    };
    vector<Data> datas(N);
    sort(datas.begin(), datas.end(), [X](auto l, auto r) {return l.value(X) > r.value(X);});
    vector<long> cvalue(N);
    cvalue[0] = datas[0].value(X);
    for (int i = 1; i < N; i++) {
        cvalue[i] = cvalue[i-1] + datas[i].value(X);
    }
    long B = 0;
    for (auto& data : datas) {
        B += data.b*data.l;
    }

    auto solve = [&](long k) {
        if (k == N*X)
            return cvalue.back() >= B;
        for (int n = 0; n < N; n++) {
            auto q = k/X;
            long sum = q > 0 ? cvalue[q-1] : 0;
            if (n < q)
                sum = sum - datas[n].value(X) + datas[q].value(X);
            auto r = k%X;
            auto& data = datas[n];
            if (r <= data.b) {
                sum += data.l*r;
            } else {
                sum += data.l*data.b + data.u*(r-data.b);
            }
            if (sum >= B)
                return true;
        }
        return false;
    };

    long l = 0, r = N*X;
    long ans = r;
    while (l <= r) {
        auto c = (l+r)/2;
        if (solve(c)) {
            r = c-1;
            ans = c;
        } else {
            l = c+1;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3456
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
struct inp{int x, y, id;};
struct edge{int u, v, cost;};
vector<inp> inputs;
vector<edge> edges;
bool xsort(const inp& left, const inp& right){
    return left.x == right.x ? left.y < right.y : left.x < right.x;
}
bool ysort(const inp& left, const inp& right){
    return left.y == right.y ? left.x < right.x : left.y < right.y;
}
bool costs(const edge& left, const edge& right){
    return left.cost == right.cost ? left.u < right.u : left.cost < right.cost;
}

int par[101010];
int ranki[101010];

void init(int n){
    rep(i, n){
        par[i] = i;
        ranki[i] = 0;
    }
}
int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(ranki[x] < ranki[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ranki[x] == ranki[y]) ranki[x]++;
    }
}

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

int kruskal(){
    init(n);
    int res = 0;
    rep(i, edges.size()){
        edge e = edges[i];
        if(!same(e.u, e.v)){
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main(){
    cin >> n;
    inp in;
    int a, b;
    rep(i, n){
        cin >> a >> b;
        in.id = i;
        in.x = a;
        in.y = b;
        inputs.pb(in);
    }
    /*
    rep(i,n){
        cout << inputs[i].x << " " << inputs[i].y << " " << inputs[i].id << endl;
        }*/
    sort(inputs.begin(), inputs.end(), xsort);
    edge inedge;
    rep(i, n){
        if(i == n-1){
            continue;
        }
        else{
            inedge.u = inputs[i].id;
            inedge.v = inputs[i+1].id;
            inedge.cost = inputs[i+1].x - inputs[i].x;
            edges.pb(inedge);
        }
    }
    sort(inputs.begin(), inputs.end(), ysort);
    rep(i, n){
        if(i == n-1){
            continue;
        }
        else{
            inedge.u = inputs[i].id;
            inedge.v = inputs[i+1].id;
            inedge.cost = inputs[i+1].y - inputs[i].y;
            edges.pb(inedge);
        }
    }
    sort(edges.begin(),edges.end(),costs);
    cout << kruskal() << endl;
    return 0;
}


Measured memory_bytes: 6132
N=list(input())
MM=["01","02","03","04","05","06","07","08","09","10","11","12"]
YY=["00","01","02","03","04","05","06","07","08","09"]

for i in range(10,100):

        YY.append(str(i))

if str(N[0])+str(N[1]) in YY and str(N[0])+str(N[1]) in MM and str(N[2])+str(N[3]) in YY and str(N[2])+str(N[3]) in MM:
    print("AMBIGUOUS")

elif str(N[0])+str(N[1]) in MM and str(N[2])+str(N[3]) in YY:
    print("MMYY")

elif str(N[0])+str(N[1]) in YY and str(N[2])+str(N[3]) in MM:
    print("YYMM")

else:
    print("NA")


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

// 素数判定
bool isPrime(int p) {
  if(p == 1) return false;
  else if(p == 2) return true;
  else if(p % 2 == 0) return false;
  
  double x = sqrt(p);
  for(int i = 3; i <= x; i += 2){
    if(p % i == 0) return false;
  }
  return true;
}

int main() {
  int n, i, count = 0;
  cin >> n;
  
  for(i = 19; i <= 55555; i += 5){
    if(isPrime(i)){
      cout << i << endl;
      count++;
    }
    
    if(count == n) break;
  }
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){

    string s; int n,k;
    cin >> n >> k >> s ;
    vi p0(n+1,0),p1(n+1,0);
    n = 1;
    if (s[0] == '0') p1[1] = 0, n++;
    for (int i=1,c=1;i<sz(s);i++){
    	if (s[i] != s[i-1]) {
    		p1[n++] = c; 
    		c = 1; 
    	}
    	c += (s[i]==s[i-1]);
    	if (i==sz(s)-1) p1[n] = c;
    }
    for (int i=1;i<=n;i++) p1[i] += p1[i-1] ; 
    int ans=0;
	for (int i=min(k*2+1,n);i<=n;i++){
		if (i&1) 
			ans = max(ans,p1[i]-p1[max(0LL,i-(k*2+1))]);
		else 
			ans = max(ans,p1[i]-p1[max(0LL,i-(k*2))]);
	}
	if(ans == 0) ans = n ; 
	cout << ans << endl;
    /// 110011001100
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

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

    int N, K, S;
    cin >> N >> K >> S;

    for (int i = 0; i < N; ++i) {
        if (i) cout << ' ';
        if (K) {
            cout << S;
            K--;
        } else {
            cout << int(1e9 - (S == 1e9));
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s, t;

	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());

	if (s < t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
# D submit
from math import sqrt
def sieve(n):
    if n<2:
        return [False]*(n+1)
    is_prime = [True]*(n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(sqrt(n))+1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return is_prime

n = int(1e5)
is_prime = sieve(n)

cnt = [0]*(n+1)
for i in range(1, n+1):
    cnt[i] += cnt[i-1]
    if is_prime[i] and is_prime[(i+1)//2]:
        cnt[i] += 1
q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cnt[r] - cnt[l-1])

Measured memory_bytes: 7156
def abc115_d():
    n, x = map(int, input().split())
    l = [1] * 51
    p = [1] * 51
    for i in range(50):
        l[i + 1] = 2 * l[i] + 3
        p[i + 1] = p[i] * 2 + 1

    ans = 0
    while n:
        if x == l[n]:
            ans += p[n]
            break
        elif x > (l[n] // 2):
            ans += p[n - 1] + 1
            x -= (l[n - 1] + 2)
            n -= 1
        else:
            x -= 1
            n -= 1
    if x == 1:
        ans += 1

    print(ans)


abc115_d()

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

//---------- ソート用 ----------
struct St
{
	int n;
	string s;
	int p;

	bool operator < (const St& st) const
	{
		if (s == st.s)
		{
			return p > st.p;
		}
		return s < st.s;
	}
};

int N;
St s[101];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		s[i].n = i + 1;
		cin >> s[i].s >> s[i].p;
	}
	ARY_SORT(s, N);

	REP(i, N)
	{
		cout << s[i].n << endl;
	}
}



Measured memory_bytes: 3568
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

const int M=1000006;
ll f[M],inv[M];
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M){
        f[i]=(1LL*i*f[i-1])%hell;
    }
    inv[M-1]=expo(f[M-1],hell-2,hell);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%hell;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%hell)*inv[n-r])%hell;
}
bool cmp(pii a,pii b)
{
    return a.F+a.S<b.F+b.S;
}
void solve()
{
    ll n,h,w,x,y;
    cin>>h>>w>>n;
    vector<pii>v;
    rep(i,0,n)
    {
        cin>>x>>y;
        v.pb({x,y});
    }
    compute();
    sort(all(v),cmp);
    v.pb({h,w});
    vi dp(n+1,0);
    rep(i,0,n+1)
    {
        ll t=C(v[i].F+v[i].S-2,v[i].F-1);
        for(int j=0;j<i;j++)
        {
            if(v[i].F>=v[j].F&&v[i].S>=v[j].S)
            {
                ll x=C(v[i].F+v[i].S-v[j].F-v[j].S,v[i].F-v[j].F);
                x=(x*dp[j])%hell;
                t=(t+hell-x)%hell;
            }
        }
        dp[i]=t;
    }
    cout<<dp[n]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 19424
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		long n = Long.parseLong(st.nextToken());
	 		long m = Long.parseLong(st.nextToken());
	 		ArrayList<Integer> array = new ArrayList<Integer>();
	 		StringTokenizer st2 = new StringTokenizer(bf.readLine());
	 		long sum = 0;
	 		for(int j=0;j<m;j++){
	 			array.add(Integer.parseInt(st2.nextToken()));
	 			sum+=(long)(array.get(j));
	 		}
	 		if (sum > n)
	 			out.println(-1);
	 		else
	 			out.println(n-sum);
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 27636
#include<stdio.h>
#include<stdlib.h>

typedef struct {
	char num[11];
	int time;
} Data;

typedef struct {
	Data data;
	Data *bef_p, *aft_p;
} Process;
int main(void){
	int n, last, total = 0, q, i, cnt = 0;
	Process *p_arr, *po, *bef, *aft;
	
	scanf("%d %d\n", &n, &q);
	last = n-1;
	p_arr = (Process*)malloc(sizeof(Process)*n);
	for(i = 0; i < n; i++){
		scanf("%s %d\n", p_arr[i].data.num, &p_arr[i].data.time);
	}
	po = &p_arr[0];
	p_arr[0].bef_p = &p_arr[last];
	p_arr[0].aft_p = &p_arr[1];
	p_arr[last].bef_p = &p_arr[last-1];
	p_arr[last].aft_p = &p_arr[0];
	for(i = 1; i < last; i++){
		p_arr[i].bef_p = &p_arr[i-1];
		p_arr[i].aft_p = &p_arr[i+1];
	}
	po = &p_arr[0];
	while(cnt != n){
		
		if(po->data.time <= q){
			total += po->data.time;
			printf("%s %d\n", po->data.num, total);
			bef = po->bef_p;
			aft = po->aft_p;
			bef->aft_p = po->aft_p;
			aft->bef_p = po->bef_p;
			cnt++;
		}else{
			total += q;
			po->data.time -= q;
		}
		po = po->aft_p;
	}
	return 0;
}



Measured memory_bytes: 3248
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//  cout <<  s.at(1)-'0'-49  <<endl;
int main() {
  int k;
  vector<int>suu(3);
  rep(i,3) cin >> suu.at(i);
  cin >> k;
  int ma=0;
  rep(i,3) ma = max(ma,suu.at(i) );
  int sum=0;
  rep(i,3) sum += suu.at(i);
  cout << sum - ma + ma*pow(2,k) <<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    if(c>b && b>a)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        while(k)
        {
            if(b>a)
            {
                break;
            }
            else
            {
                b=b*2;
            }
            k--;
        }

        while(k--)
        {
            if(c>b)
            {
                break;
            }
            else
            {
                c*=2;
            }
        }

        if(c>b && b>a)
        {
           cout<<"Yes"<<endl;

        }
        else
        {
           cout<<"No"<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3648
import java.util.*

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)

    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    var bool = false
    if(a == b && a != c)bool = true
    if(a == c && a != b)bool = true
    if(b == c && b != a)bool = true

    if(bool){
        println("Yes")
    }else{
        println("No")
    }

    sc.close()
}

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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;


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

    for (int i = 0; i < int(s.size()); i++) {
        s[i] = ((s[i] - 'A' + n) % 26) + 'A'; 
    }
    cout << s << endl;
    return 0;
}



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

using namespace std;

#define ll long long

void solve() {
	int n;
	cin >> n;
	int mx = 0, mx2;
	int a, b;
	while(n--) {
		cin >> a >> b;
		if (a > mx) {
			mx = a;
			mx2 = b;
		}
	}
	cout << mx + mx2 << "\n";
}

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

	int t = 1, i = 1;
	//cin >> t;
	while(t--) {
		//cout << "Case #" << i << ": ";
		solve();
		//i++;
	}
	return 0;
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
	int N,K;
	cin >> N >> K;
	vector<int> H(N);
	rep(i,N) cin >> H[i];
	sort(H.begin(),H.end());
	long long sum = 0;
	rep(i,N-K) sum += H[i];
	cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
  int h, w, x=0, i, j, k;
  while(1)
    {
      scanf("%d %d", &h, &w);
      if ( h == 0 && w == 0 ) break;
      x=0;
      if( w % 2 == 0)  /*1行目*/
	{
	  for( i = 0; i < (w/2); i++)
	    {
	      printf("#.");
	    }
	  printf("\n");
	}
      else if( w % 2 != 0)
	{
	  for( i = 0; i < (w/2); i++)
	    {
	      printf("#.");		    
	    }
	  printf("#\n");
	}
 
      for( j = 0; j < h-1; j++)
	{
	 
	  if(x % 2 == 0)                                /*偶数行*/
	    {
	      printf(".");
	      if( w % 2 != 0) /* w が奇数 */
		{
		  for(i = 0; i < (w/2); i++)
		    {
		      printf("#.");
		    }
		  printf("\n");
		  x += 1;
		}
	      else if( w % 2 == 0) /* w が偶数 */
		{
		  for( k = 0; k < (w/2)-1; k++)
		    {
		      printf("#.");
		    }
	          printf("#\n"); 
		  x += 1;
		}
	    }
	  else if( x % 2 != 0)                               /*奇数行*/
	    {
	      if( w % 2 == 0)  /* w が偶数*/
		{
		  for( i = 0; i < (w/2); i++)
		    {
		      printf("#.");
		    }
		  printf("\n");
		  x += 1;
		}
	      else if( w % 2 != 0)
		{
		  for( k = 0; k < (w/2); k++)
		    {
		      printf("#.");
		    }
		  printf("#\n");
		  x += 1;
		}
	    }
	}
      printf("\n");
    }
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int T,n,m,i,u[N],v[N];
vector<int>e[N];
int dfn[N],xb,id[N],dad[N],de[N],ans[N];
bool vi[N],ind[N];
void dfs(int x,int fa){
	vi[x]=1;dfn[id[x]=++xb]=x;
	for(int i=0;i<e[x].size();++i){
		int j=e[x][i],y=u[j]^v[j]^x;
		if(ans[j]==-1)ans[j]=x==v[j];
		if(vi[y] && id[y]<id[x] && y!=fa)ind[y]^=1;
		if(!vi[y])dad[y]=x,de[y]=j,dfs(y,x);
	}
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;xb=0;for(i=1;i<=n;++i)e[i].clear();
	memset(ind+1,0,n);memset(ans+1,-1,m<<2);memset(id+1,0,n<<2);memset(vi+1,0,n);
	for(i=1;i<=m;++i){
		cin>>u[i]>>v[i];
		e[u[i]].push_back(i);e[v[i]].push_back(i);
	}
	if(m&1){cout<<"-1\n";return 0;}
	dfs(1,0);
	for(i=n;i>1;--i){
		int x=dfn[i];
		if(ind[x])ind[x]^=1;else ans[de[x]]^=1,ind[dad[x]]^=1;
	}
	for(i=1;i<=m;++i){
		if(!ans[i])swap(u[i],v[i]);
		cout<<u[i]<<' '<<v[i]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<char, int>;
typedef pair<int,int> pii;
typedef long long ll;

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


char field[2010][2010];
bool mark[2010][2010];
int spaces[2010][2010];
int H, W;

int main(){

    fastStream();
    cin >> H >> W;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> field[i][j];

    for(int i = 0; i <= H; i++){
        for(int j = 0; j <= W; j++){
            const int dy[]= {0, 0, -1, -1};
            const int dx[]= {0, -1, -1, 0};
            bool in = true;
            int cnt = 0;
            for(int k = 0; k < 4; k++){
                int ni = i + dy[k];
                int nj = j + dx[k];
                if(ni >= 0 && nj >= 0 && ni < H && nj < W){
                    if(field[ni][nj] == '#') cnt++;
                }
                else{
                    in = false;
                }
            }
            if(in && cnt % 2){
                mark[i][j] = true;
            }
        }
    }

    int ans = max(H, W);

    for(int j = 1; j < W; j++){
        for(int i = 1; i <= H; i++){
            if(mark[i-1][j]){
                spaces[i][j] = 1;
            }
            else{
                spaces[i][j] = spaces[i-1][j] + 1;
            }
        }
    }

    // 各行ごとに、ヒストグラムの最大値を計算する
    for(int i = 2; i <= H; i++){
        stack<pii> stk;
        for(int j = 1; j <= W; j++){
            if(stk.size() == 0 || stk.top().second < spaces[i][j]){
                stk.push(pii(j, spaces[i][j]));
            }
            else if(stk.top().second > spaces[i][j]){
                int last_pos = -1;
                // スタックの先頭から順番に処理する
                while(stk.size() > 0 && stk.top().second > spaces[i][j]){
                    pii p = stk.top(); stk.pop();
                    ans = max(ans, p.second * (j - p.first + 1));
                    last_pos = p.first;
                }
                stk.push(pii(last_pos, spaces[i][j]));
            }
        }
    }

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 23936
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String[] s = in.nextLine().split(" ");
        final BigDecimal first = new BigDecimal(s[0]);
        final BigDecimal second = new BigDecimal(s[1]);
        System.out.println(first.multiply(second).setScale(0, RoundingMode.FLOOR));
    }
}


Measured memory_bytes: 36084
import sys
input = sys.stdin.readline
def 解():
    iN,iM = [int(_) for _ in input().split()]
    a1 = [0]*iN
    aN = [0]*iN
    for i in range(iM):
        a,b = [int(_) for _ in input().split()]
        if a == 1:
            a1[b] = 1
        if b == iN:
            aN[a] = 1
    for i in range(iN):
        if a1[i] and aN[i]:
            print("POSSIBLE")
            exit()
    print("IMPOSSIBLE")
解()


Measured memory_bytes: 6132
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n,l;
  cin >> n >> l;
  ll ans = (l+(l+n-1))*n/2;
  if(l>=0) ans -= l;
  else if(l<1-n) ans -= l+n-1;
  cout << ans << endl;
  return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  int c, d, e;
  e = 0;
  for(int i = a; i < b + 1; i++){
    if(i / 10000 == i % 10){
      c = i / 1000 - (i / 10000) * 10;
      d = i % 100 - i % 10;
      if(10 * c == d){
        e++;
      }
    }
  }
  cout << e << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int n,k;
ll a[200005];
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>a[i];
ll l=0,r=1e9+5;
while(r-l>1)
{
ll mid=(l+r)/2;
ll t=0;
for(int i=0;i<n;i++)
t=t+(a[i]-1)/mid;

if(t<=k)r=mid;
else l=mid;

}
cout <<r;
}

Measured memory_bytes: 5116
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
int main()
 {
  string s, t;
  cin >> s >> t;
  map<char, char> m1;
  map<char, char> m2;
  for (int i = 0; i < s.size(); ++i) 
{
    if (m1.find(t[i]) != m1.end()) 
{
      if (m1[t[i]] != s[i])
 {
        cout << "No" << endl;
        return 0;
      }
    } else {
      m1[t[i]] = s[i];
    }
    if (m2.find(s[i]) != m2.end())
 {
      if (m2[s[i]] != t[i])
 {
        cout << "No" << endl;
        return 0;
      }
    } else 
{
      m2[s[i]] = t[i];
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define ll long long
#define pp push_back
#define fr first
#define sc second

using namespace std;

int n , m;
int h[1000200];
vector<int>v[200020];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0) ,cout.tie(0);
    cin >> n >> m;
    for(int i = 1;i <= n;i++)
        cin >> h[i];
    for(int i = 1;i <= m;i++)
    {
        int a , b; cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++){
        bool ok = 1;
        for(auto j : v[i]){
            ok &= h[j] < h[i];
        }
        ans += ok;
    }
    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 11480
N,M=map(int,input().split())
l=[]
m=[]
for _ in range(M):
    a,b=map(int,input().split())
    if a==1:
        l.append(b)
    elif b==N:
        m.append(a)
o=set(l)&set(m)

if len(o):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>

int main(void){
	int N;
	scanf("%d",&N);
	//fprintf(stderr,"N = %d",N);
	int i,j,master = 0, count = 0;
	for(i = 1; i <= N; i += 2){
		count = 0;
		for(j = 1; j <= i; j += 2){
			if(i % j == 0){count++;}
			}
		if(count ==  8){master++;}
		}
	printf("%d\n",master);
return 0;
}




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

# define ll long long
ll mod=pow(10,9)+7;

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

    int n;
    cin>>n;
    map<string,int> mp;
    string s;
    while(n--){
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;

}


Measured memory_bytes: 3664
import sys

input = sys.stdin.readline


def main():
    a, b, c = map(int, input().split())

    ans = 3
    if a == b == c:
        ans = 1
    else:
        if a == b:
            ans -= 1
        if b == c:
            ans -= 1
        if c == a:
            ans -= 1
    print(ans)


if __name__ == "__main__":
    main()


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

int main(int, char**) {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int x;
    cin >> x;
    cout << ((x/500) *1LL* 1000 + ((x%500)/5)*1LL*5) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int A[100001];
int root(int x){
    if(A[x]==x) return x;
    else return A[x]=root(A[x]);
}
int main(){
    int n,m,p[100001],x,y;
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<=n;i++) A[i]=i;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        x=root(x),y=root(y);
        if(x!=y) A[y]=x;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(root(p[i])==root(i+1)) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 1024