akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 300000 + 10000;

typedef pair<int, int> pii;

int lowbit(int x)
{
	return x & (-x);
}

struct BinaryIndexedTree
{
	int n, s[MAXN];
	void init(int _n)
	{
		n = _n;
		memset(s, 0, (n + 2) * sizeof(s[0]));
	}
	void add(int x, int v)
	{
		for(int i = x; i <= n; i += lowbit(i))
			s[i] += v;
	}
	int query(int x)
	{
		int ret = 0;
		for(int i = x; i >= 1; i -= lowbit(i))
			ret += s[i];
		return ret;
	}
}
bit;

int n, m;
pii seg[MAXN];

int cmp(const pii &a, const pii &b)
{
	return a.second - a.first < b.second - b.first;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> seg[i].first >> seg[i].second;
	sort(seg + 1, seg + n + 1, cmp);
	bit.init(m);
	int p = 1;
	for(int i = 1; i <= m; i++)
	{
		while(p <= n && seg[p].second - seg[p].first < i)
			bit.add(seg[p].first, 1), bit.add(seg[p].second + 1, -1), p++;
		// cerr << i << endl;
		int ans = n - p + 1;
		for(int j = i; j <= m; j += i)
			ans += bit.query(j);
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N = 2e5+5;
const int mod = 998244353;
int n,m,k;
ll Pow(int a,int b)
{
	if(a==0)return 1;
	ll res=Pow(a/2,b);
	res=res*res%mod;
	if(a%2==1)res=res*b%mod;
	return res;
}
ll fac[N];
void init()
{
	fac[0]=1;
	for(int i=1;i<=2e5;i++)fac[i]=fac[i-1]*i%mod;
}
ll ny(int x)
{
	return Pow(mod-2,x);
}
ll C(int a,int b)
{
	return ny(fac[b])*fac[a]%mod*ny(fac[a-b])%mod;
}
int main()
{
	init();
	ll ans=0;
	cin>>n>>m>>k;
	for(int i=0;i<=k;i++)
	{
		ans+=m*Pow(n-i-1,m-1)%mod*C(n-1,i)%mod;
		ans%=mod;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5196
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>
using namespace std;
static const int MAX=100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd()
{
  for(int k=0;k<n;k++)
    {
      for(int i=0;i<n;i++)
	{
	  if(d[i][k]==INFTY) continue;
	  for(int j=0;j<n;j++)
	    {
	      if(d[k][j]==INFTY) continue;
	      d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	    }
	}
    }
}

int main()
{
  int e,u,v,c;
  cin >> n >> e;
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  d[i][j]=((i==j) ? 0:INFTY);
	}
    }
  for(int i=0;i<e;i++)
    {
      cin >> u >> v >> c;
      d[u][v]=c;
    }
  floyd();
  bool negative=false;
  for(int i=0;i<n;i++) if(d[i][i] <0) negative = true;

  if(negative)
    {
      cout << "NEGATIVE CYCLE" << endl;
    }
  else
    {
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(j) cout << " ";
	      if(d[i][j] == INFTY) cout << "INF";
	      else cout << d[i][j];
	    }
	  cout << endl;
	}
    }
  return 0;
}

Measured memory_bytes: 3172
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				System.out.println(i + "x" + j + "=" + i*j);
			}
		}

	}

}

Measured memory_bytes: 16840
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut answers = vec![0; n + 1];
    for x in 1..101i64 {
        for y in 1..101 {
            for z in 1..101 {
                let temp = x * x + y * y + z * z + x * y + y * z + z * x;
                if temp <= n as i64 {
                    answers[temp as usize] += 1;
                }
            }
        }
    }

    for ans in answers.iter().skip(1) {
        println!("{}", ans);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2072
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_i
  s = [''] * n
  n.times{|i| s[i] = InputLine.to_s}
  
  h = {}
  n.times do |i|
    if h[s[i]] == nil then
      h[s[i]] = 1
    else
      h[s[i]] += 1
    end
  end

  m = 0
  h.each{|k, v| m = [m, v].max}
  
  t = []
  h.each do |k, v|
    if v == m then
      t.push(k)
    end
  end

  t.sort.each do |v|
    puts v
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

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

int main() {
//    freopen("in.txt", "r", stdin);
    int r, c, a[101][101] = {0};
    cin >> r >> c;

    for (int i = 0; i < r; ++i) {
        for (int j = 0; j < c; ++j) {
            cin >> a[i][j];
            a[i][c] += a[i][j];
        }
    }
    for (int j = 0; j < c; ++j) {
        for (int i = 0; i < r; ++i) {
            a[r][j] += a[i][j];
        }
    }

    for (int i = 0; i < r; ++i) {
        a[r][c] += a[i][c];
    }
//    for (int j = 0; j < c; ++j) {
//        a[r][c] += a[r][j];
//    }

    for (int i = 0; i <= r; ++i) {
        for (int j = 0; j <= c; ++j) {
            cout << a[i][j];
            if (j != c) {
                cout << " ";
            }
        }
//        if (i != r) {
            cout << endl;
//        }
    }
}

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

int main(){
  int N, H, W, i, count=0, x, y;
  cin >> N >> H >> W;
  int a[N], b[N];
  for(i=0; i<N; i++){
    cin >> a[i] >> b[i];
  }
  for(i=0; i<N; i++){
    x = a[i] / H;
    y = b[i] / W;
    if(x < y) count += x;
    else count += y;
  }
  cout << count << "\n";
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var array = new List<int>();
            for (var i = 0; i < n; i++)
            {
                array.Add(int.Parse(Console.ReadLine()));
                if(i != 0 && array[0]<array[i])
                {
                    int tmp = array[0];
                    array[0] = array[i];
                    array[i] = tmp;
                }
            }
            int sum = array[0] / 2;
            for (var i = 1; i < n;i++)
            {
                sum += array[i];
            }
            Console.WriteLine(sum);
        }

    }
}

Measured memory_bytes: 11220
/**
 *
 * AtCoder Beginner Contest 106 - Problema B: 105 (https://beta.atcoder.jp/contests/abc106/tasks/abc106_b)
 *
 * Find the garden area excluding the roads.
 *
 * Math solution: the rectangle area is AB. One road has area A, the other one has area B. The
 * roads intersection has area 1.
 */
#include <iostream>

using namespace std;

const int MAX { 210 };

int ds[MAX], ps[MAX];

void precomp()
{
    for (int n = 1; n < MAX; ++n)
    {
        for (int d = 1; d * d <= n; ++d)
        {
            if (n % d == 0)
            {
                auto m = n / d;
                ds[n] += (d == m ? 1 : 2);
            }
        }
    }

    for (int i = 1; i < MAX; ++i)
        ps[i] = ps[i - 1] + (i % 2 and ds[i] == 8 ? 1 : 0);
}

void solve(int N)
{
    cout << ps[N] << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int N;
    cin >> N;

    solve(N);

    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split(' '))
mine = []
mine_result = []

def count(i, j):
    try:
        if i < 0 or j < 0:
            return None
        if mine[i][j] == '#':
            return 1
    except:
        return None

    return None

if __name__ == '__main__':
    for i in range(0, h):
        inp = list(input())
        mine.append(inp)
        mine_result.append(inp)

    for i in range(0, h):
        for j in range(0, w):
            if (mine[i][j] == '.'):
                mine_result[i][j] = sum(list(filter(None,
                    [
                        count(i + 1, j),
                        count(i - 1, j),
                        count(i, j + 1),
                        count(i, j - 1),
                        count(i + 1, j + 1),
                        count(i + 1, j - 1),
                        count(i - 1, j + 1),
                        count(i - 1, j - 1)
                    ])))
            else:
                mine_result[i][j] = '#'

    for i in range(0, h):
        for j in range(0, w):
            print(mine_result[i][j], end='')
        print()


Measured memory_bytes: 3572
#include <iostream>

using namespace std;
using ll = long long;

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

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

  rep(i, s.length()) {
    if (s[i] != t[i]) {
      cout << "No" << '\n';
      return 0;
    }
  }

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


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int n,t[101],m,p,x,k,i,j;
	scanf("%d", &n);
	for(i=1; i<=n; i++)
	scanf("%d", &t[i]);
	scanf("%d", &m);
	for(i=0; i<m; i++)
	{
		scanf("%d %d", &p, &x);
		k=0;
		for(j=1; j<=n; j++)
		{
			if(j==p)
			k+=x;
			else
			k+=t[j];
		}
		printf("%d\n", k);
	}
	
	return 0;
}

Measured memory_bytes: 128
from sys import stdin

n,m = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]

ball = [1]*(n+1)
red = [0]*(n+1)
red[1] = 1

for i in li:
    ball[i[0]] -= 1
    ball[i[1]] += 1
    if red[i[0]] == 1:
        if ball[i[0]] == 0:
            red[i[0]] = 0
        red[i[1]] = 1

print(sum(red))

Measured memory_bytes: 28836
#include<iostream>
#include<math.h>

using namespace std;

int n,mem[100],sum,ans;

void search(int max,int total,int now)
{
	if(now>max)
		return ;
	
	total+=mem[now];
	search(max,total,now+1);
	total-=mem[now];
	search(max,total,now+1);
	
	if(sqrt((total*2-sum)*(total*2-sum))<ans)
		ans=sqrt((total*2-sum)*(total*2-sum));
	
	return ;
}

int main()
{
	int i,j;
	
	for(;;)
	{
		cin >> n;
		if(n==0)
			break;
		
		sum=0;
		for(i=0;i<n;i++)
		{
			cin >> mem[i];
			sum+=mem[i];
		}
		ans=sum;
		
		search(n-1,0,0);
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      _s: [String; n]
   }
   let mut x = vec![50; 26];
   for s in _s {
      let b = s.as_bytes().iter().map(|&a| (a - b'a') as usize);
      let mut y = vec![0; 26];
      for i in b {
         y[i] += 1;
      }
      for i in 0..26 {
         x[i] = std::cmp::min(x[i], y[i]);
      }
   }
   for i in 0..26 {
      for _ in 0..x[i] {
         print!("{}", (b'a' + i as u8) as char);
      }
   }
   println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int N;

void dfs(string s,char mx){
    if(s.size() == N){
        cout << s << endl;
    }
    else{
        for(char c = 'a';c <= mx;c++){
            dfs(s + c,((c == mx) ? mx + 1 : mx));
        }
    }
}

int main(){
    cin >> N;
    dfs("",'a');
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	if (s.size() == a + b + 1) {
		int i = 0;
		while (i < a+b+1) {
			if (i<a || i>a) {
				if (s.at(i) < '0' || s.at(i) >' 9') {
					cout << "No" << endl;
					return 0;
				}
			}
			else{ 
				if (s.at(i) != '-') {
					cout << "No" << endl;
					return 0;
				}
			}
			i++;
		}
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3596
#include <algorithm>
#include <sstream>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using namespace std;

#define rep(i,n) for(int i = 0;i<n;i++)
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;


map<string,set<string> > M;
set<string> S;
map<string,bool> dp;
void searchMemb(string request){
	if(dp[request])return;
	dp[request] = true;
	if(S.count(request) == 1)return;
	FORIT(itr,M[request]){
		if(M.find(*itr) != M.end() && M[*itr].size() != 0){
			searchMemb(*itr);
		}else{
			if(S.count(*itr) == 0){
				S.insert(*itr);
			}
		}
	}
}

int main() {
	while(true){
		M.clear();
		S.clear();
		dp.clear();
		ll n;
		cin >> n;
		if(n == 0)break;
		char request[16];
		rep(l,n){
			char in[180];
			cin >> in;
			int in_size = strlen(in);
			//parse
			rep(i,in_size){
				if(in[i] == ',' || in[i] == '.' || in[i] == ':'){
					in[i] = '\0';
				}
			}
			char parent[20];
			strcpy(parent,in);
			if(l == 0) strcpy(request,parent);
			FOR(i,strlen(in) + 1,in_size){
				char child[20];
				strcpy(child,in+i);
				M[parent].insert(child);
				i += strlen(in+i);
			}
		}

//		FORIT(itr,M){
//			cout << itr->first << endl;
//			FORIT(veci,itr->second.children){
//				cout << *veci << " ";
//			}
//			cout << endl;
//		}
		searchMemb(request);
		cout << S.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1060
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

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

	string s;
	cin >> s;

	string t;
	cin >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

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

	return 0;
}

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

typedef long long ll;
ll a, b, c, t;
int main()
{
	cin >> a >> b >> c;
	if (a > b) swap(a, b);
	if (b > c) swap(b, c);
	if (a & b & c & 1) cout << a * b;
    else cout << '0';
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

int n, m, k;

int main() {
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i ++)
		for (int j = 0; j <= m; j ++) {
			if (i*(m-j)+j*(n-i) == k) {
				puts ("Yes");
				exit(0);
			}
		}
	puts ("No");
	return 0;
}

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

long long n, x, cur = 0;
vector<vector<long long>> tests;

long long check(long long k){

    long long best, complete = k / x, other = k % x, cursum = 0;

    if(complete >= n)
        return cur + 1;

    for(int i = 0; i < complete; ++i)
        cursum += tests[i][0];

    best = cursum;

    for(int i = 0; i < n; ++i){
        if(i < complete){
            best = max(best, tests[complete][0] + (cursum - tests[i][0]) + tests[i][3] * other - tests[i][1] * (tests[i][3] - tests[i][2]));
            best = max(best, tests[complete][0] + (cursum - tests[i][0]) + tests[i][2] * other);
        } else {
            best = max(best, cursum + tests[i][3] * other - tests[i][1] * (tests[i][3] - tests[i][2]));
            best = max(best, cursum + tests[i][2] * other);
        }
    }
    return best;
}

int main(){

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

    long long b, l ,u; cin >> n >> x;

    for(int i = 0; i < n; ++i){
        cin >> b >> l >> u;
        cur += b * l;
        tests.push_back({(x - b) * u + b * l, b, l, u});
    }

    sort(tests.begin(), tests.end(), greater<vector<long long>>());

    long long mid, lef = -1, rig = n * x;
    for(;lef < rig - 1;){
        mid = lef + rig >> 1;
        if(check(mid) >= cur)
            rig = mid;
        else
            lef = mid;
    }
    cout << rig << "\n";
    return 0;
}

Measured memory_bytes: 7984
#include <stdio.h>
int main(void){
    int n,m,L,i,j,k;
    scanf( "%d %d %d" , &n, &m, &L );
    int a[101][101] = {};
    int b[101][101] = {};
    long int sum = 0;
    
    for( i = 0; i < n; i++ ){
        for( j = 0; j < m; j++ ){
            scanf( "%d" , &a[i][j] );
        }
    }
    
    for( i = 0; i < m; i++ ){
        for( j = 0; j < L; j++ ){
            scanf( "%d" , &b[i][j] );
        }
    }
    
    for( i = 0; i < n ; i++ ){
        for( j = 0; j < L ; j++ ){
            for( k = 0; k < m ; k++ ){
                sum += a[i][k] * b[k][j];
            }
            if( j == 0 ){
                printf( "%ld" , sum );   
            }else{
                printf( " %ld" , sum );  
            }
            sum = 0;
        }
        printf("\n");
    }

}


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

using Graph=vector<vector<int>>;

int main()
{
    int N; cin>>N;
    Graph G(N);
    vector<int> a(N-1),b(N-1);
    for(int i=0;i<N-1;i++){
        cin>>a[i]>>b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }

    int mx=0;
    for(int i=0;i<N;i++) mx=max(mx,(int)G[i].size());

    map<pair<int,int>,int> color;
    function<void(int,int,int)> dfs=[&](int v,int p,int used)
    {
        int col=0;
        for(int u:G[v]) if(u!=p){
            if(col==used) col++;
            color[minmax(v,u)]=col;
            dfs(u,v,col++);
        }
    };

    dfs(0,-1,-1);
    cout<<mx<<endl;
    for(int i=0;i<N-1;i++){
        cout<<color[minmax(a[i],b[i])]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <ctype.h>

#define STACK_SIZE 110

int stack[STACK_SIZE];
int stack_pos = 0;

int pop() {
  return stack[--stack_pos];
}

void push(int a) {
  stack[stack_pos++] =a;
}

int empty() {
  return stack_pos;
}

int main() {
  char str[128];
  int a, b;
  while(scanf("%s", str) != EOF) {
    if(isdigit(str[0])) {
      push(atoi(str));
    } else {
      b = pop();
      a = pop();
      switch(str[0]) {
      case '+':
        push(a+b);
        break;
      case '-':
        push(a-b);
        break;
      case '*':
        push(a*b);
        break;
      }
    }
  }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    bool ok = 1;
    vector<int> T(N);
    vector<pair<int,int>> C(N);
    REP(i,N){
        T[i] = in();
        C[i].F = in();
        C[i].S = in();
    }
    pair<int,int> A;
    A.F = 0;
    A.S = 0;
    int time = 0;
    REP(i,N){
        int dist = 0;
        dist = abs(C[i].F - A.F) + abs(C[i].S - A.S);
        if(T[i] - time < dist){
            ok = 0;
        }else if((T[i] - time)%2 == dist%2){
            ok = 1;
        }else{
            ok = 0;
        }
        if(ok == 0)break;
        A.F = C[i].F;
        A.S = C[i].S;
        time = T[i];
    }
    cout << (ok ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 1408
S = str(input())
T = str(input())

max_len = 0
for i in range(len(S) - len(T) + 1):
    tmpS = S[i: i + len(T)]
    tmp_cnt = 0
    for j in range(len(T)):
        if tmpS[j] == T[j]:
            tmp_cnt += 1
    max_len = max(tmp_cnt, max_len)

print(len(T) - max_len)

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"


int main()
{
    int n = 0;
    cin >> n;
    string ans = "Yes";

    map<string, int> chk;
    string before = "";
    string word = "";
    REP(i, n)
    {
        cin >> word;
        chk[word]++;
        if (chk[word] > 1)
        {
            ans = "No";
        }
        if (before != "")
        {
            if (word[0] != before[before.size() - 1])
            {
                ans = "No";
            }
        }
        before = word;
    }

    COUT(ans);

    return 0;
}

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

int main()
{
    int64_t h = 0, c = 1;
    cin >> h;

    while (h > 1) {
        h /= 2;
        ++c;
    }

    int64_t ans = 0, d = 1;

    for (int i=0; i<c; ++i) {
        ans += d;
        d *= 2;
    }

    cout << ans << endl;

    return 0;
}


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

typedef pair<int, string> P;
bool comp(P a, P b){
	return a.first > b.first;
}

int main(){
	string s;
	int n, w, l, d, f = 0;
	while(cin >> n, n){
		if(f)cout << endl;f = 1;
		vector<P> v;
		for(int i = 0;i < n;i++){
			cin >> s >> w >> l >> d;
			int x = w*3 + d;
			v.push_back(P(x, s));
		}
		stable_sort(v.begin(), v.end(), comp);
		for(int i = 0;i < n;i++){
			cout << v[i].second << "," << v[i].first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3136
import math

K = int(input())
con = 0
con2 = 0
con3 = 0

for i in range(K):
    for k in range(i, K):
        tmp = math.gcd(i+1, k+1)
        for l in range(k, K):
            pre = math.gcd(tmp, l+1)
            con += pre
            if i == k == l:
                con3 += pre
                continue
            elif i == k or k == l or l == i:
                con2 += pre
                continue
            

print(con*6 - con2*3 - con3*5)


Measured memory_bytes: 9132
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

char s[MAXN];

int main(void)
{
	scanf("%s",s+1);
	int n = strlen(s+1);
	for(int i=1; i<=n; ++i)
		if(s[i] == '?')
			s[i] = 'D';
	printf("%s",s+1);
	return 0;
}

Measured memory_bytes: 3908
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		//??£??????????????????????????????????????°
		String strLine = "";
		boolean isContinue = true;
		while(isContinue){

			
			if(scan.hasNext()){
				String strScan = scan.nextLine();
				strLine += strScan;
				
			}else{
				scan.close();
				break;
			}



		}
		//System.out.println("strLine:" + strLine);

		//str???????§£??????char[]???????´?
		char[] aryLine= strLine.toCharArray();

		char x = 'a';
		//a???z?????§?????°?????????
		for(int j = 'a'; j <= 'z'; j++){
			//??¢????????????????????????????????????????????°
			int intCount = 0;



			for(int i = 0; i < aryLine.length; i++){

				//??§???????????£?????´???????°????????????????
				if(Character.isUpperCase(aryLine[i])){
					aryLine[i] = Character.toLowerCase(aryLine[i]);
				}
				//??¢???????????????????????????????????¢??????
				if( j == aryLine[i]){
					intCount++;
				}
			}
			String az = String.valueOf(j);
			System.out.print(x++);
			System.out.println(" : " + intCount);

		}
	}

}

Measured memory_bytes: 18888
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
 
const int MAXN=40010;
int n;
struct Line {
  int a,b,c;
  int sequence=1;
  double getY(double x) const{
    double cc=c-(double)a*x;
    return cc/(double)b;
  }
  double getX(double y) const{
    double cc=c-(double)b*y;
    return cc/(double)a;
  }
}l[MAXN];
 
class tenka_e {
  bool chose;
  int BITa[MAXN];
  void add(int p) {
    for (int i=p; i<=n; i+=i&-i)
      BITa[i]++;
  }
  int sum(int p) {
    int result=0;
    for (int i=p;i>0;i-=i&-i)
      result+=BITa[i];
    return result;
  }
 
  static double cc;
  static bool cmpY (const Line &a, const Line &b) {
    if (a.getY(cc) < b.getY(cc))
      return true;
    else if (a.getY(cc) == b.getY(cc))
      return a.sequence<b.sequence;
    return false;
  }
  static bool cmpX (const Line &a, const Line &b) {
    if (a.getX(cc) < b.getX(cc))
      return true;
    else if (a.getX(cc) == b.getX(cc))
      return a.sequence<b.sequence;
    return false;
  }
 
public:
  tenka_e(bool _chose) {
    this->chose = _chose;
    arrage(-200000000.0);
    for (int i=0;i<n;i++)
      l[i].sequence = i+1;
  }
  int arrage(double _cc) {
    cc = _cc;
    if (chose)
      sort(l,l+n,&cmpY);
    else
      sort(l,l+n,&cmpX);
    int result = 0;
    memset(BITa,0,sizeof(BITa));
    for (int i=n-1;i>=0;i--) {
      add( l[i].sequence );
      result += sum(l[i].sequence-1);
    }
    return result;
  }
};
double tenka_e::cc;
inline double abs (double a) {
  return a>=0?a:-a;
}
int main() {
  cin>>n;
  for (int i=0;i<n;i++)
    cin>>l[i].a>>l[i].b>>l[i].c;
  tenka_e* problem1 = new tenka_e(true);
  //X;
  //cout<<"left -> right"<<endl;
  double left=-1000000000.0,right=1000000000.0;
  while (right-left>1e-9 && abs((right-left)/left)>1e-9) {
    double middle = (left+right)/2.0;
    int leftnode = problem1->arrage(middle);
    int targetnode = ((n-1)*n/2 + 1)/2;
    if (leftnode >= targetnode)
      right = middle;
    else
      left = middle;
  }
  double res_x = (left+right)/2.0;
  //y;
  //cout<<"bottom -> up"<<endl;
  tenka_e* problem2 = new tenka_e(false);
  left=-1000000000.0,right=1000000000.0;
  while (right-left > 1e-9 && abs((right-left)/left)>1e-9) {
    double middle = (left+right)/2.0;
    int leftnode = problem2->arrage(middle);
    int targetnode = ((n-1)*n/2 + 1)/2;
    if (leftnode >= targetnode)
      right = middle;
    else
      left = middle;
  }
  double res_y = (left+right)/2.0;
  cout<<setiosflags(ios::fixed)<<setprecision(11)<<res_x<<" "<<res_y<<endl;
  return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int[] a = new int[3];
            for (int i = 0; i < 3; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);
            out.println((a[2] - a[1]) + (a[1] - a[0]));
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 111;

int C[26];

char buf[MAX];

int A[MAX][MAX];
int S[MAX * MAX];

int D[10];

void NO()
{
	cout<<"No"<<endl;
	exit(0);
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);

	FOR (i, 0, n)
	{
		scanf("%s", buf);
		FOR (j, 0, m)
		{
			C[buf[j] - 'a']++;
		}
	}

	FILL(A, -1);
	int sz = 0;
	FOR (i, 0, n)
	{
		FOR (j, 0, m)
		{
			if (A[i][j] != -1) continue;

			A[i][j] = sz;
			A[i][m-j-1] = sz;
			A[n-i-1][j] = sz;
			A[n-i-1][m-j-1] = sz;
			sz++;
		}
	}

	FOR (i, 0, n)
	{
		FOR (j, 0, m)
		{
			S[A[i][j]]++;
		}
	}

	FOR (i, 0, sz)
	{
		D[S[i]]++;
	}

	while(D[1])
	{
		bool ok = false;
		FOR (i, 0, 26)
		{
			if (C[i] & 1)
			{
				C[i]--;
				D[1]--;
				ok = true;
				break;
			}
		}

		if (!ok)
		{
			NO();
		}
	}

	while(D[2])
	{
		bool ok = false;
		FOR (i, 0, 26)
		{
			if (C[i] % 4 == 2)
			{
				C[i] -= 2;
				D[2]--;
				ok = true;
				break;
			}
		}

		if (!ok) break;
	}

	if (D[2] & 1) NO();
	FOR (i, 0, 26)
	{
		if (C[i] % 4 != 0) NO();
	}

	cout<<"Yes"<<endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define EPS (1e-10)
using namespace std;

typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment


namespace std {
  bool operator < (const P& a, const P& b){
    return fabs(real(a)-real(b)) < EPS ? imag(a) < imag(b) : real(a) < real(b);
  }
  bool operator ==(const P& a, const P& b){
    return abs(a.real()-b.real())<EPS&&abs(a.imag()-b.imag())<EPS;
  }
}

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){  
  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}

bool onEdge(P a){return a.real()==-100||a.real()==100||a.imag()==-100||a.imag()==100;}

int Unique(vector<P> &p){
  int res=0;
  for(int i=0;i<(int)p.size();i++){
    int flg=1;
    for(int j=i+1;j<(int)p.size();j++) if(p[i]==p[j]) flg=0;
    res+=flg;
  }  
  return res;
}

int main(){
  int n;
  while(cin>>n,n){
    int ans=1;
    vector<L> v;
    
    for(int i=0;i<n;i++){
      int sx,sy,gx,gy;
      cin>>sx>>sy>>gx>>gy;
      L l=L(P(sx,sy),P(gx,gy));
      
      vector<P> p;
      for(int i=0;i<v.size();i++){
	if(!isIntersect(l,v[i]))continue;
	P cp=crossPoint(l,v[i]);
	if(!onEdge(cp))p.push_back(cp);
      }
      ans+=1+Unique(p);
      v.push_back(l);
    }  
    cout<<ans<<endl;
  }
  return 0;
}

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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX


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

	int n,k,i,ret=0,ch=0;
	cin>>n>>k;
	inp(p,n,1);
	inp(cost,n,1);
	for(i=1;i<=n;i++)
		if(cost[i]<=0)
			ch++;
	if(ch==n)
	{
		ret=-1000000009;
		for(i=1;i<=n;i++)
			ret=max(ret,cost[i]);
		cout<<ret;
		return 0;
	}
	for(i=1;i<=n;i++)
	{
		int node=i,sz=0,res=0;
		int h[n+1]={0};
		while(h[node]==0)
		{
			h[node]++;
			sz++;
			node=p[node];
		}
		if(sz>k)
		{
			int cnt=0,ans=0;
			node=i;
			while(cnt!=k)
			{
				ans+=cost[p[node]];
				res=max(res,ans);
				node=p[node];
				cnt++;
			}
		}
		else
		{
			int cnt=0,ans=0;
			node=i;
			while(cnt!=sz)
			{
				ans+=cost[p[node]];
				res=max(res,ans);
				node=p[node];
				cnt++;
			}
			if(ans>=0)
			{
				int anss=0,mx=0;
				int ans1=ans*(k/sz);
				int kk=k%sz;
				cnt=0;
				node=i;
				while(cnt!=kk)
				{
					anss+=cost[p[node]];
					mx=max(mx,anss);
					node=p[node];
					cnt++;
				}
				ans1+=mx;
				res=max(res,ans1);
				cnt=0,node=i,anss=0,mx=0;
				int ans2=ans*max(0LL,k/sz-1);
				while(cnt!=sz)
				{
					anss+=cost[p[node]];
					mx=max(mx,anss);
					node=p[node];
					cnt++;
				}
				ans2+=mx;
				res=max(res,ans2);
			}
		}
		ret=max(ret,res);
	}
	cout<<ret;
	return 0;
}


Measured memory_bytes: 3672
N = int(input())
A = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
A.sort()


def solve(i, num):
    while i < len(A):
        if A[i] == num:
            if A[i + 1] == num:
                i += 2
                num += 2
            else:
                break
        else:
            break
    if i >= len(A):
        print(2 ** (N // 2) % mod)
    else:
        print(0)


if len(A) % 2 is 0:
    solve(0, 1)
else:
    if A[0] is 0:
        solve(1, 2)
    else:
        print(0)


Measured memory_bytes: 13880
#include <stdio.h>
#include <string.h>
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#define P pair<int,int>
#define int long long 
using namespace std;

int ans[10];
signed main() {
	int a, b, c; cin >> a >> b >> c;
	ans[0] += (a - 2)*(b - 2);
	map<P, bool>U;
	for (int d = 0; d < c; d++) {
		int e, f; scanf("%lld%lld", &e, &f); e--; f--;
		for (int i = -1; i < 2; i++) {
			for (int j = -1; j < 2; j++) {
				int sum = 0;
				int n = e + i, m = f + j;
				for (int x = -1; x < 2; x++) {
					for (int y = -1; y < 2; y++) {
						if (n + x < 0 || n + x >= a || m + y < 0 || m + y >= b)goto l;
						if (U[{n + x, m + y}])sum++;
					}
				}
				ans[sum]--;
				ans[sum + 1]++;
			l:;
			}
		}
		U[{e, f}] = true;
	}
	for (int i = 0; i < 10; i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 156544
#include <stdio.h>
int main(void){
int A,B,C,ans;
scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);
if((C-(A-B))>0)
{
	ans=C-(A-B);
}
else
{
	ans=0;
}
printf("%d",ans);

return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll GCD(vl &v) {  // vの全要素のgcd
    ll res = v[0];
    rep(i, (ll)v.size()) {
        res = gcd(res, v[i]);
    }
    return res;
}

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    if(GCD(a) > 1) {
        out("not coprime");
        re0;
    }

    vl v(1000010);
    rep(i, n) {
        map<ll, ll> mp = primefactor(a[i]);
        for(auto p : mp) {
            if(v[p.first]) {
                out("setwise coprime");
                re0;
            }
            v[p.first] = 1;
        }
    }

    out("pairwise coprime");
    re0;
}

Measured memory_bytes: 18804
<?php


fscanf(STDIN, "%d", $num);

for($i=1; $i<=$num; ++$i){

    fscanf(STDIN, "%s %d", $name, $point);
    $list[$name][$point] = $i;
}

ksort($list);

foreach($list as $name => $list){
    krsort($list);
    foreach($list as $number){
        echo $number.PHP_EOL;
    }
}



Measured memory_bytes: 4728
X = int(input())
A = [False]*1001
A[1] = True
for i in range(2,1001):
    j = 2
    while i**j < 1001:
        A[i**j] = True
        j += 1

ans = 1
for i in range(X,-1,-1):
    if A[i]:
        ans = i
        break

print(ans)



Measured memory_bytes: 3060
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210000;
const ll Mod = 1e9+7;

int n;
struct Taka{int p,v;}p[maxn];
inline bool cmpv(const Taka x,const Taka y){return x.v<y.v;}
struct node
{
	int l,r;
	node(){}
	node(const int _l,const int _r){l=_l,r=_r;}
}a[maxn];
inline bool cmpr(const node x,const node y){return x.r==y.r?x.l<y.l:x.r<y.r;}

struct segment{int mx,mn;}seg[maxn<<2];
void build(const int x,const int l,const int r)
{
	if(l==r) {seg[x].mx=seg[x].mn=p[l].p; return;}
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	build(lc,l,mid); build(rc,mid+1,r);
	seg[x].mx=max(seg[lc].mx,seg[rc].mx);
	seg[x].mn=min(seg[lc].mn,seg[rc].mn);
}
int lx,rx,c;
int qleft(const int x,const int l,const int r)
{
	if(rx<l||seg[x].mx<c) return -1;
	if(l==r) return l;
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	int re=qleft(lc,l,mid);
	return re==-1?qleft(rc,mid+1,r):re;
}
int qright(const int x,const int l,const int r)
{
	if(r<lx||seg[x].mn>c) return -1;
	if(l==r) return l;
	int mid=l+r>>1,lc=x<<1,rc=lc|1;
	int re=qright(rc,mid+1,r);
	return re==-1?qright(lc,l,mid):re;
}

ll f[maxn],sum[maxn],al;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&p[i].p,&p[i].v);
	sort(p+1,p+n+1,cmpv);
	build(1,1,n);
	
	for(int i=1;i<=n;i++)
	{
		lx=rx=i; c=p[i].p;
		a[i]=node(qleft(1,1,n),qright(1,1,n));
	}sort(a+1,a+n+1,cmpr);
	
	al=sum[0]=f[0]=1ll; int pos=1;
	for(int i=1;i<=n;i++)
	{
		while(pos<=n&&a[pos].r==i)
		{
			ll tmp=al-(a[pos].l-2>=0?sum[a[pos].l-2]:0);
			(f[i]+=tmp)%=Mod;
			(al+=tmp)%=Mod;
			pos++;
		}
		sum[i]=(sum[i-1]+f[i])%Mod;
	}
	printf("%lld\n",(f[n]+Mod)%Mod);
	
	return 0;
}


Measured memory_bytes: 13184
n = int(input())
a, b = [list(map(int, input().split())) for _ in range(2)]

a_sum = a[0]
b_sum = sum(b)

maxer = a_sum + b_sum

for i in range(1, n):
    a_sum += a[i]
    b_sum -= b[i-1]
    if a_sum + b_sum > maxer:
        maxer = a_sum + b_sum

print(maxer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);
int main(){
    string a,b;cin>>a;
    int ans =0;
    rep(i,3)if(a[i]=='R')ans=1;
    if(a[0]=='R'&&a[1]=='R')ans=2;
    if(a[1]=='R'&&a[2]=='R')ans=2;
    if(a[1]=='R'&&a[2]=='R'&&a[0]=='R')ans=3;
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3624
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dd(int n){
	if(n>=0) return n;
	else return -n;
}
int main() {
int a,b;
cin>>a>>b;
if((a*b)%2==0) cout<<"Even";
else cout<<"Odd";
cout<<endl;
	return 0;
}

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

/*Starry Sky Tree*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RSUQ{
public: 
  
  //遅延用の型  
  struct T{
    int type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(int type,int value):type(type),value(value){}
  };

  //マージ可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  int n;
  vector<D> dat;
  vector<T> td;
  D returnD = D(0); // 範囲外の時に返す値。
  
  RSUQ(){n=-1;}
  RSUQ(int n_){
    n=1;
    while(n < n_) n *= 2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  inline D merge(D a,D b){return a.value + b.value;}
  
  void delay(int k,int len){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    len /= 2;
    int l = k*2+1,r = k*2+2;
    dat[l].value = v * len; td[l].type = 1; td[l].value = v;
    dat[r].value = v * len; td[r].type = 1; td[r].value = v;
  }

  D write(int k,int x, int len){
    dat[k].value = x * len;
    td[k].type = 1;
    td[k].value = x;
    return dat[k];
  }
  
  //[a,b)の値をx変更　query(a,b,x)
  D update(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1) r=n, assert(a <= n && b <= n);
    if(r <= a||b <= l) return flg? dat[k]:returnD;
    if(a <= l && r <= b) return flg? write(k, x, r - l):dat[k];
    
    delay(k, r - l);
    D vl = update(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = update(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl, vr);
    return merge(vl, vr);
  }
  
  //[a,b)の合計値を得る　find(a,b);
  int find(int a,int b){
    D res = update(a,b,0,false);
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RSUQ rsuq(n);

  while(q--){
    int cmd;
    cin>>cmd;
    if(cmd == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rsuq.update(s,t+1,x);
    }
    if(cmd == 1){
      int s,t;
      cin>>s>>t;
      cout<<rsuq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



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

int N;
int x[110], y[110], h[110];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> h[i];
  }
  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int last = -1;
      bool no = false;
      for (int i = 0; i < N; i++) {
        if (h[i] > 0) {
          int tmp = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
          if (last < 0 || tmp == last) {
            last = tmp;
          } else {
            no = true;
          }
        }
      }
      if (no) continue;
      for (int i = 0; i < N; i++) {
        int tmp = last - abs(x[i] - cx) - abs(y[i] - cy);
        if (h[i] != max(tmp, 0)) no = true;
      }
      if (no) continue;
      cout << cx << " " << cy << " " << last << endl;
      return 0;
    }
  }

  return 0;
}

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

int main() {
  double p,n;
  while(cin >> p >> n) {
    if(p==0 && n==0) break;
    p=sqrt(p);
    int x=0,y=0,u=0,v=0;
    double a2=MAX,b2=MAX;
    for(int i=1; i<=n; i++) {
      int a=(int)(p*i);
      int b=a+1;
      if(a>n) break;
      if(__gcd(a,i)==1 && p-(double)a/i<a2) {
	a2=p-(double)a/i;
	u=a;v=i;
      }
      if(b>n) continue;
      if(__gcd(b,i)==1 && (double)b/i-p<b2) {
	b2=(double)b/i-p;
	x=b;y=i;
      }
    }
    printf("%d/%d %d/%d\n",x,y,u,v);
  }
  return 0;
}


Measured memory_bytes: 1200
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (100010)
int N;
ll A[MAX_N];

int search_zero(int from)
{
    for ( int i = from; i < N; i++ ) {
	if ( A[i] == 0 ) return i;
    }

    return N;
}

int search_non_zero(int from)
{
    for ( int i = from; i < N; i++ ) {
	if ( A[i] != 0 ) return i;
    }

    return N;
}

ll count_pair( int f, int t )
{
    ll ret = 0;
    bool check = false;
    for ( int i = f; i < t; i++ ) {
	ret += ( A[i] >> 1 );
	A[i] = A[i] % 2;
	if ( ( A[i] == 1 ) && ( i+1 < t ) ) { // 次のものとペアを作る
	    A[i+1]--;
	    ret++;
	}
    }

    return ret;
}

int main()
{
    ll ans = 0;
    int cur = 0;
    scanf("%d", &N);
    for ( int i = 0; i < N; i++ ) scanf("%lld", &A[i]);
    
    while ( true ) {
	int f = search_non_zero( cur ); // 
	int t = search_zero( f ); //
	if ( f == N ) break;
	ll add = count_pair( f, t );
	ans += add;
//	printf("(%d, %d): %lld\n", f, t, add);
	cur = t;
    }

    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 1024