akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; //
typedef string str; //
//
typedef pair<int,int> pi;
typedef pair<ll,ll> pl; //
typedef pair<db,db> pd; //
//
typedef vector<int> vi; 
typedef vector<ll> vl; //
typedef vector<db> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi;
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
 
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
 
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back()
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //
 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; //
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); //
//
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { //
	return a < b ? a = b, 1 : 0; } //
constexpr int pct(int x) { return __builtin_popcount(x); } //
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) //
constexpr int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } // division of a by b rounded up, assumes b > 0 //
// IGNORE
int fstTrue(function<bool(int)> f, int lo, int hi) {
	hi ++; assert(lo <= hi); // assuming f is increasing
	while (lo < hi) { // find first index such that f is true 
		int mid = (lo+hi)/2; 
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}
template<class T> void remDup(vector<T>& v) { 
	sort(all(v)); v.erase(unique(all(v)),end(v)); }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// IGNORE
//
int a, b, c, d;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N;
	cin >> N;
	F0R(i, N){
		string s;
		cin >> s;
		if(s == "AC")
			a++;
		if(s == "WA")
			b++;
		if(s == "TLE")
			c++;
		if(s == "RE")
			d++;
	}
	cout << "AC x " << a << endl;
	cout << "WA x " << b << endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
string S;
  cin >>S;
string X;
  for(int i=0;i<S.length();i++){
  X.append("x");
  }
  
  
  cout<<X<<endl;
}


Measured memory_bytes: 256
#![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 v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut grid = vec![vec![]; h];
    for i in 0..h {
        grid[i] = read::<String>().chars().collect::<Vec<_>>();
    }
    let mut xs = BTreeSet::new();
    let mut ys = BTreeSet::new();
    for y in 0..h {
        for x in 0..w {
            if grid[y][x] == '#' {
                xs.insert(x);
                ys.insert(y);
            }
        }
    }
    for y in 0..h {
        if !ys.contains(&y) {
            continue;
        }
        for x in 0..w {
            if !xs.contains(&x) {
                continue;
            }
            print!("{}", grid[y][x]);
        }
        println!("");
    }
}

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: 4352
x, y = map(int, input().split())

a = max(0, y - x)
b = max(0, -1 * y - x + 1)
c = max(0, y + x + 1)
d = max(0, -1 * y + x + 2)

l = [a, b, c, d]

ans = 1000000000000

for i in l:
    if i != 0 and i < ans:
        ans = i

print(ans)



Measured memory_bytes: 9140
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
using namespace std;
using lint = long long;
template<class T> using grid = vector<vector<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
static const lint MOD = (lint)1e9+7;

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

    vector<int> A(Q);
    rep (i, Q) { cin >> A[i]; }

    map<int, int> mp;
    rep (i, Q)
    {
        mp[A[i]-1]++;
    }

    rep (i, N)
    {
        int point = K - (Q - mp[i]);
        if (point <= 0)
        {
            cout << "No" << endl;
        }
        else
        {
            cout << "Yes" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <string>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/




int main(void) {
  ll i, j, k;
  
  ll N, K;
  cin >> N >> K;
  double p[MAX*2];
  for(i=0; i<N; i++) {
    double t;
    cin >> t;
    p[i]=(t+1)/2;
  }
  
  double t=0;
  for(i=0; i<K; i++) t+=p[i];
  
  double ans=t;
  for(i=K; i<N; i++) {
    t+=p[i]-p[i-K];
    chmax(ans, t);
  }
  
  printf("%.10f\n", ans);
  
}



Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MAXN = 50000 + 10;

struct Edge {
  int u, v, w; 
  bool operator < (const Edge &rhs) const {
    return w < rhs.w;
  }
} E[MAXN];
int dsu[MAXN], n, m;

int get(int x) {
  if (x != dsu[x]) dsu[x] = get(dsu[x]);
  return dsu[x];
}

int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0; i < m; ++ i) {
      scanf("%d%d%d", &E[i].u, &E[i].v, &E[i].w);
    }
    sort(E, E + m);
    for (int i = 1; i <= n; ++ i) dsu[i] = i;
    vector<int> can;
    int cost(0);
    for (int i = 0; i < m; ++ i) {
      int u = get(E[i].u), v = get(E[i].v);
      if (u != v) {
        can.push_back(i);
        dsu[u] = v;
        cost += E[i].w;
      }
    }
    int ret(0), sum(0);
    for (auto &e: can) {
      for (int i = 1; i <= n; ++ i) dsu[i] = i;
      int tmp(0), cnt(0);
      for (int i = 0; i < m; ++ i) if (i != e) {
        int u = get(E[i].u), v = get(E[i].v);
        if (u != v) {
          dsu[u] = v;
          cnt ++;
          tmp += E[i].w;
        }
      }
      if (cnt != n - 1 || tmp > cost) {
        ret ++; sum += E[e].w;
      }
    }
    printf("%d %d\n", ret, sum);
  }
  return 0;
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,sum=0;
	long long c,s,a,b;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld %lld",&a,&b);
		c=a*b;
		s=(long long)sqrt(c);
		if(s*s==c)
		{
			if(a==b)
				printf("%lld\n",(s-1)*2);
			else
				printf("%lld\n",(s-1)*2-1);
		}
		else
		{
			if(s*(s+1)<a*b)
				printf("%lld\n",s*2-1);
			else
				printf("%lld\n",s*2-2);
		}
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int x = n;
    int digit = 0;
    while(1){
        digit += n%10;
        n /=10;
        if(n == 0){
            break;
        }
    }
    if(x%digit == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }
    return 0;
}

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

int total_allocation(int W[], int n, int k, int P) {
    int total = 0;
    int truck_P = 0;
    for (int i = 0; i < n; i++) {
        if (truck_P + W[i] <= P) {
            truck_P += W[i];
            total++;
        } else {
            k--;
            if (k == 0) return total;
            truck_P = 0;
            if (W[i] <= P) {
                truck_P += W[i];
                total++;
            }
        }
    }
    return total;
}

int main() {
    int n, k;
    cin >> n >> k;
    int W[n];
    for (int i = 0; i < n; i++) cin >> W[i];

    int P_max = 1e9;
    int left = 0, right = P_max, mid;
    int allocation;

    while (left < right) {
        mid = (left + right) / 2;
        allocation = total_allocation(W, n, k, mid);
        if (allocation >= n) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    cout << right << endl;
}


Measured memory_bytes: 3468
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

S = input().rstrip()
N = len(S)

def dfs(num):
    if len(num) == N:
        return 1 if '3' in num and '5' in num and '7' in num and 1 <= int(num) <= int(S) else 0

    ret = 0
    if len(num) == 0 or '3' not in num and '5' not in num and '7' not in num:
        ret += dfs(num+'0')
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')
    else:
        ret += dfs(num+'3')
        ret += dfs(num+'5')
        ret += dfs(num+'7')

    return ret

def main():
    """ main """
    print(dfs(''))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007

long long GCD(long long A,long long B)
{
    return (B == 0) ? A : GCD(B , A % B);
}

void solve()
{
    long long N;
    cin >> N; 
    long long ans = 0;
    for(int i = 0;i < N;++i)
    {
        long long x;
        cin >> x;
        ans = GCD(ans,x);
    }
    cout << ans << '\n';
}

int main()
{
    solve();
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]

# 単調非減少か単調非増加
# 単調非減少 = 上昇 or 0
# 単調非増加 = 減少 or 0

up = False
down = False
count = 0
i = 1
while i < len(a):
    # print("\nup:{} down:{}".format(up, down))
    if a[i] - a[i - 1] > 0 and down:
        # print("+counted a[{}]:{} a[{}]:{}".format(i, a[i], i-1, a[i-1]))
        up = False
        down = False
        count += 1
    elif a[i] - a[i - 1] < 0 and up:
        # print("-counted a[{}]:{} a[{}]:{}".format(i, a[i], i - 1, a[i - 1]))
        up = False
        down = False
        count += 1
    elif a[i] - a[i-1] > 0:
        up = True
    elif a[i] - a[i-1] < 0:
        down = True
    i += 1
print(count + 1)


Measured memory_bytes: 14228
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long int N, A[100002], count = 0;
	cin >> N;
	A[0] = 0, A[N + 1] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		count += abs(A[i] - A[i - 1]);
	}
	count += abs(A[N]);
	for (int i = 1; i <= N; i++) {
		int before = abs(A[i + 1] - A[i]) + abs(A[i] - A[i - 1]);
		int after = abs(A[i + 1] - A[i - 1]);
		cout << count - before + after << endl;
	}
}

Measured memory_bytes: 2048
def main():
    S = list(input())
    accum = [0]
    for i in range(1,len(S)):
        tmp = accum[i-1] + 1 if S[i-1] == "B" else accum[i-1]
        accum.append(tmp)
    ans = 0
    for i in range(len(S)):
        tmp = 0 if S[i] == "B" else accum[i]
        ans += tmp
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61552
using System;

namespace abc150_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string Nstr = Console.ReadLine();
            int N = int.Parse(Nstr);
            string S = Console.ReadLine();

            int count = 0;
            for(int i = 0; i < N-2; i++)
            {
                if ('A' == S[i] && 'B' == S[i+1] && 'C' == S[i+2])
                {
                    count += 1;
                }
            }

            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 27536
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;


int main() {
  float t, x;
  cin >> t >> x;
  float ans;
  ans = t/x;
  cout << ans << endl;
  return 0;
}

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

#define ran 111

char s[ran];
int len;

int k;

int calc(int len, int todo) {
	if(len<todo) return 0;
	if(todo<0) return 0;
	
	int res = 1;
	for(int i=0;i<todo;i++)
		res = res * (len-i) / (i+1) * 9;
	//printf("%d %d %d\n", len, todo, res);
	return res;
}

int main() {
	scanf("%s", s);
	len = strlen(s);
	scanf("%d", &k);
	
	int done = 0;
	int ans = 0;
	for(int i=0;i<len && done<=k; i++) {
		if(s[i]=='0') continue;
		
		ans += calc(len-i-1, k-done);
		if(s[i]>'1') 
			ans += calc(len-i-1, k-done-1) * (s[i]-'0'-1);
		done++;
	}
	if(done==k) ans++;
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) x.begin(),x.end()
#define DEBUG

int money(int input)
{
	if(input == 1)
	{
		return 300000;
	}
	else if(input == 2)
	{
		return 200000;
	}
	else if(input == 3)
	{
		return 100000;
	}

	return 0;
}

int main()
{
	int x, y;
	cin >> x >> y;

	ll ans = money(x) + money(y);
	if(x == 1 && y == 1) ans += 400000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var mb = new ModBinom(10000);
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NK[0];
        var K = NK[1];
        var B = K;
        var R = N - K;
        for (int i = 1; i <= K; i++)
        {
            var c = mb.Binom(B - 1, i - 1);
            var r = R - (i - 1);
            var b = i + 1;
            var d = mb.Binom(b + r - 1, b - 1);
           // WriteLine(d);
            WriteLine(c*d % ((int)1e9 + 7));
        }
    }
}


class ModBinom
{
    long[] fac;
    long[] finv;
    int mod;

    public ModBinom(int N, int p = (int)1e9 + 7)//N < p  O(N)
    {
        N++;

        fac = new long[N];
        long[] inv = new long[N];
        finv = new long[N];

        fac[0] = fac[1] = 1;
        inv[1] = 1;
        finv[0] = finv[1] = 1;

        for (int i = 2; i < fac.Length; i++)
        {
            fac[i] = fac[i - 1] * i % p;
            inv[i] = p - inv[p % i] * (p / i) % p;
            finv[i] = finv[i - 1] * inv[i] % p;
        }

        mod = p;
    }

    public long Binom(int n, int k)// O(1)
    {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * finv[k] % mod * finv[n - k] % mod;
    }
}

Measured memory_bytes: 13408
#include <iostream>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  int c[N];

  for (int i = 0; i < N; i++){
    c[i] = 0;
  }
  

  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    c[a-1]++;
    c[b-1]++;
  }

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


Measured memory_bytes: 3752
#include<iostream>
using namespace std;
int N;
int flag[100005];
int main()
{
	for(int i=1;i<=9;i++)
		flag[i]=1;
	for(int i=100;i<=999;i++)
		flag[i]=1;
	for(int i=10000;i<=99999;i++)
		flag[i]=1;
	cin>>N;
	int ans=0;
	for(int i=1;i<=N;i++)
		ans+=flag[i];
	cout<<ans;
	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;


int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   int a, b, c;
   cin >> a >> b >> c;
   //for(int i = 0 ; i < n ; i++)  
   cout << min(min(a+b,a+c),b+c) << endl; 
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (auto i = 0; i < (n); i++)
#define rep2(i, s, n) for (auto i = (s); i < (n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    ll N, A; cin >> N >> A;
    vector<ll> x(N+1);
    ll tmp;
    rep2(i, 1, N+1) {
        cin >> x[i];
        x[i]-=A;
    }
    ll X = max(vmax(x), A);
    vector<vector<ll>> dp(N+1, vector<ll>(2*N*X+1));
    for (ll i = 0; i <= N; i++) {
        for (ll j = 0; j <= 2*N*X; j++) {
            if (i == 0 && j == N*X) dp[i][j] = 1;
            else if (i >= 1) {
                if (j-x[i] < 0 || j-x[i] > 2*N*X) dp[i][j] = dp[i-1][j];
                else dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i]];
            }
            else dp[i][j] = 0;
        }
    }
    cout << dp[N][N*X]-1 << endl;

}


Measured memory_bytes: 5340
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    int n, m, a, b, c, l, r;
    cin >> n;
    int x = n / 500;
    int y = n % 500;
    int ans = x * 1000 + (y / 5) * 5;
    cout << ans << endl;
}



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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const ll mod = (int)1e9 + 7;
// const ll mod = 998244353;

struct S{
    ll zeros, ones, inv;
};

using F = bool;

S op(S a, S b){
    return S{
        a.zeros+b.zeros, 
        a.ones+b.ones, 
        a.inv + b.inv + a.ones * b.zeros
    };
}

S e(){
    return S{0, 0, 0};
}

S mapping(F f, S x){
    if(f){
        return S{x.ones, x.zeros, x.ones*x.zeros-x.inv};
    }else{
        return x;
    }
}

F composition(F f, F g){
    return f^g;
}

F id(){
    return false;
}

int main(){

    ll N, Q;
    cin >> N >> Q;
    V<ll> A(N);
    REP(i, N) cin >> A[i];
    V<S> B(N);
    REP(i, N) B[i] = S{1-A[i], A[i], 0};

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(B);

    while(Q--){
        ll T, L, R;
        cin >> T >> L >> R;
        L--, R--;

        if(T==1){
            seg.apply(L, R+1, true);
        }else{
            cout << seg.prod(L, R+1).inv << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 21952
s=input()
n=len(s)
ans=0
a=[0]*n
for i in range(n):
    if s[i]=='R':
        ans+=1
        #print(i,ans)
    else:
        #print(i,ans)
        if ans!=0:
            a[i-1]+=(ans+1)//2
            a[i]+=ans//2
            #print(a)
            ans=0
ans=0
for i in range(n-1,-1,-1):
    if s[i]=='L':
        ans+=1
        #print(i,ans)
    else:
        #print(i,ans)
        if ans!=0:
            a[i+1]+=(ans+1)//2
            a[i]+=ans//2
            #print(a)
            ans=0
print(*a)

Measured memory_bytes: 6400
q = int(input())

for _ in range(q):
    c, a, n = map(int, input().split())

    if n <= c and n <= a:
        cnt = n
        c -= cnt
        a -= cnt

        if a <= c:
            if 2*a >= c:
                cnt += c >> 1
            else:
                cnt += a
                c -= 2 * a
                cnt += c // 3
        else:
            cnt += c >> 1
    elif a <= c and a <= n:
        cnt = a + (c-a) // 3
    else:
        cnt = c

    print(cnt)


Measured memory_bytes: 5592
n=int(input())
alist=list(map(int,input().split()))

allh=alist[0]^alist[1]
for i in range(n-2):
    allh = allh ^ alist[i+2]

outlist=[]
for a in alist:
    outlist.append(str(allh ^ a))
    outlist.append(" ")
outlist.pop()
print("".join(outlist))


Measured memory_bytes: 37760
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int dp[200005];
const int mod=1e9+7;
int lol[200005];
int pos[200005];
int z[200005];

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n;
    cin>>n;
    int a[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    vector<int>temp;
    temp.push_back(0);
    set<int>s;
    for(int i=1;i<=n;i++)
    {
        if(a[i]!=a[i-1])
            temp.push_back(a[i]);
        s.insert(a[i]);
    }
    map<int,int>mm;
    int cnt=0;
    for(auto i:s)
        mm[i]=++cnt;
    int sz=temp.size();
    for(int i=1;i<sz;i++)
    {
        temp[i]=mm[temp[i]];
        pos[i]=z[temp[i]];
        z[temp[i]]=i;
    }

    int ans=0;
    dp[0]=1;
    for(int i=1;i<sz;i++)
    {        
        if(pos[i]!=0)
            dp[i]=dp[pos[i]]+dp[i-1];
        else
            dp[i]=dp[i-1];
        dp[i]%=mod;
    }
    cout<<dp[sz-1];

} 


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

using namespace std;

#define MAX 26
 
int main()
{
    int n, a[MAX];
     
    while (cin >> n,n) {
        for (int i = 0; i < n; i++) cin >> a[i];
        int ohajiki = 32, j = 0, d = 0;
        while (1) {
            if (ohajiki == 1) break;
            if (j%2 == 0) {
                ohajiki -= (ohajiki-1)%5;
            } else {
                ohajiki -= a[d++];
                if (d == n) d = 0;
            }
            j++;
            cout << ohajiki << endl;
        }
        cout << '0' << endl;
    }
    return 0;
}

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

int min(int a,int b){
    if(a>b){
        return b;
    }else{
        return a;
    }
}

int max(int a,int b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}

int main(void){
    int X,Y,N,M;
    scanf("%d %d %d %d",&N,&M,&X,&Y);
    int x[N],y[M];
    int i;
    int M_x = -100;
    int m_y = 100;
    for(i=0;i<N;i++){
        scanf("%d",&x[i]);
        if(M_x<=x[i]){
            M_x = x[i];
        }
    }
    for(i=0;i<M;i++){
        scanf("%d",&y[i]);
        if(m_y>=y[i]){
            m_y = y[i];
        }
    }
    X = max(M_x,X);
    Y = min(Y,m_y);
    if(Y>X ){
        printf("No War\n");
    }else{
        printf("War\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <unordered_map>
#define M ((ll)1e9+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi acos(-1)
typedef long long ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t,n;
	cin>>t>>n;
	cout<<max(t-2*n,(ll)0);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int h, w;
    vector<string> s;
    string tmp;
    bool tate = true;
    bool kai = false;
     
    cin >> h >> w;

    for (int i = 0; i < h; i++) {
        cin >> tmp;
        s.push_back(tmp);
    }

    for (int i = 0; i < h; i++) {
        if ((int)s[i].find('#') == -1) {
          for (int j = 0; j < w; j++) {
              s[i][j] = 'A';
          }
        }
    }
    
  for (int j = 0; j < w; j++) {
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#') tate = false;
    }
    if (tate == true) {
      for (int i = 0; i < h; i++) {
        s[i][j] = 'A';
      }
    }
    tate = true;
  }

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
      	  if (s[i][j] != 'A') {
              cout << s[i][j];
              kai = true;
          }
      }
      if (kai == true) {
          cout << endl;
      }
      kai = false;
    }
}


Measured memory_bytes: 256
import sys
import math

def main():
    N = int(input())
    digit = int(math.log10(N))
    c = N // (10**digit)
    if N < int(str(c) + '9'*digit):
        print(9 * digit + c -1)
    else:
        print(9 * digit + c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int num, max = 0;
    vector<int> cnt(101);

    while(cin >> num)
        cnt[num]++;

    for(int i=0; i<101; i++)
        if(max < cnt[i]) max=cnt[i];
    for(int i=0; i<101; i++)
        if(max == cnt[i])
            cout << i << endl;

    return 0;
}

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

const ll INF = 1LL << 60;
const int MOD = 1e9 + 7;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": "; for (const auto& v: (a)) cout << v << endl

int a, b;
int main() {
    int tmp;
    cin >> tmp;
    a = tmp / 100;
    b = tmp % 100;

    if (a > 12) {
        // b が MM でなければNA
        if (b > 12 || b == 0) {
            cout << "NA" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else if (a == 0) {
        // b が MM でなければNA
        if (b > 12 || b == 0) {
            cout << "NA" << endl;
        } else {
            cout << "YYMM" << endl;
        }
    } else {
        if (b > 12 || b == 0) {
            cout << "MMYY" << endl;
        } else {
            cout << "AMBIGUOUS" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		
		if (a % 2 == 0 || b % 2 == 0)
			System.out.println("No");
		else
			System.out.println("Yes");

	}

}

Measured memory_bytes: 21844
import sys
from collections import deque
N,M=map(int,input().split())
table=[[] for i in range(N)]
for i in range(M):
    u,v,s=map(int,input().split())
    table[u-1].append((v-1,s))
    table[v-1].append((u-1,s))
L=[0]*N
T=[1]*N#checker
visit=[False]*N
h=deque()
h.append([0,1])
visit[0]=True
flag=True

K=[]

while h:
    x,t=h.popleft()
    for y,s in table[x]:
        if visit[y]:
            if T[y]==T[x]:
                flag=False
                K.append((x,y,s))
            else:
                if L[y]+L[x]!=s:
                    print(0)
                    sys.exit()
            continue
        T[y]=-t
        visit[y]=True
        L[y]=s-L[x]
        h.append([y,-t])
    
    
if not flag:
    x,y,s=K[0]
    t=T[x]
    u=L[x]+L[y]-s
    if u%2!=0:
        print(0)
        sys.exit()
    u=u//2
    for i in range(N):
        if T[i]==t:
            L[i]-=u
        else:
            L[i]+=u
    for x,y,s in K:
        if L[x]+L[y]!=s:
            print(0)
            sys.exit()
    for i in range(N):
        if L[i]<=0:
            print(0)
            sys.exit()
    print(1)
    sys.exit()
a=10**13
c=10**13
#b=-10**13
#d=-10**13
for i in range(N):
    if T[i]==1:
        a=min(a,L[i])
        #b=max(b,L[i])
    else:
        c=min(c,L[i])
        #d=max(d,L[i])
print(max(0,c+a-1))

Measured memory_bytes: 85720
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

const int MAX = 55;

vector<int> E[MAX];

bool bio[MAX];
int color[MAX];

bool dfs(int x, int col) {
  if (bio[x]) return color[x] == col;
  bio[x] = true;
  color[x] = col;
  for (int y: E[x]) {
    if (!dfs(y, col ^ 1)) return false;
  }
  return true;
}

int main(void) {
  int N;
  scanf("%d", &N);
  vector<int> d(N);
  REP(i, N) scanf("%d", &d[i]);

  auto can = [&] (int s) {
    REP(i, N) E[i].clear();
    REP(i, N) REP(j, i) {
      if (abs(d[i] - d[j]) < s) {
        int d2 = min(d[i] + d[j], 24 - (d[i] + d[j]));
        if (d2 < s) return false;
        E[i].push_back(j);
        E[j].push_back(i);
      }
    }

    REP(i, N) color[i] = 0, bio[i] = false;
    REP(i, N) if (!bio[i]) {
      if (!dfs(i, 0)) return false;
    }
    return true;
  };
  
  int ret = *min_element(d.begin(), d.end());
  while (!can(ret)) ret--;
  
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	//最大公約数gcd
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}

	public static void main(String[] args) {
		
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //都市の数
		int X = stdIn.nextInt(); //今いる座標
		int [] x = new int[n];
		
		for(int i = 0; i < n; i++) {
			x[i] = stdIn.nextInt();
		}
		int min = Integer.MAX_VALUE;
		if(n==1) {
			System.out.println(Math.abs(x[0]-X));
			System.exit(0);
		}
		
		for(int i = 0; i < n-1; i++) {
			min = Math.min(gcd(Math.abs(x[i]-X),Math.abs(x[i+1]-X)), min);
		}
		
		System.out.println(min);
		
		
		
		
		
	}

}


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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

int main(){
    fcin;
    int x;
    cin >> x;

    int d = 1000 * (x / 500);
    x %= 500;

    d += 5 * (x / 5);
    cout << d << endl;
    return 0;
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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;}

const double INF=1e12;
int M,N;
int X1[100],X2[100],Y1[100],Y2[100];

double f(int *X,int *Y,int n,double x){
    double l=INF,r=-INF;
    rep(i,n){
        double x1=X[i],y1=Y[i],x2=X[(i+1)%n],y2=Y[(i+1)%n];
        if((x1-x)*(x2-x)>0||x1==x2)continue;
        double y=y1+(y2-y1)/(x2-x1)*(x-x1);
        chmin(l,y);
        chmax(r,y);
    }
    return r-l;
}

void solve(){
    vint xs;
    rep(i,M)xs.pb(X1[i]);
    rep(i,N)xs.pb(X2[i]);
    sort(all(xs));
    int min1=*min_element(X1,X1+M),max1=*max_element(X1,X1+M);
    int min2=*min_element(X2,X2+N),max2=*max_element(X2,X2+N);
    double ans=0;
    for(int i=0;i+1<xs.size();i++){
        double a=xs[i],b=xs[i+1],c=(a+b)/2.0;
        if(c<min1||c>max1||c<min2||c>max2)continue;
        double fa=f(X1,Y1,M,a)*f(X2,Y2,N,a);
        double fb=f(X1,Y1,M,b)*f(X2,Y2,N,b);
        double fc=f(X1,Y1,M,c)*f(X2,Y2,N,c);
        ans+=(b-a)/6*(fa+fb+fc*4);
    }
    printf("%.20f\n",ans);
}

signed main(){
    while(cin>>M>>N,M||N){
        rep(i,M)cin>>X1[i]>>Y1[i];
        rep(i,N)cin>>X2[i]>>Y2[i];
        solve();
    }
}

Measured memory_bytes: 3072
/* ***************************
   
   aoj-1130
   
   *************************** */

#include<stdio.h>
#include<stdlib.h>

#define MAX 20

// ????????¨?????¨ ?§???????
typedef struct {
  int row;               // ?????????
  int col;               // ?????????
} Coord;

// ??????????????¨ ?§???????
typedef struct _stack {
  struct _stack *next;
  Coord point;
} *stack, stackelem;

char M[MAX+2][MAX+2];    // ?????¢?????°??????????????§???

// ????????????????????£?¨?
int solve (int W, int H);
int search_df (int W, int H, Coord start);
void display_map (int W, int H);

// ??????????????¨
stack  new_stack (void);
int is_empty (stack);
int push (stack, Coord);
Coord top (stack);
Coord pop (stack);

// main ??¢??°
int main () {
  int W, H;
  while(1){
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0) break;
    printf("%d\n", solve(W,H));
  }

  return 0;
}

// ?????£?????¢?´¢ 
int solve (int W, int H) {
  Coord start;             // ??????????????°???
  int i, j;

  //  ?£?????????????????¨???? 
  for (i=0; i<=W+1; i++) { M[0][i] = '#'; M[H+1][i] = '#'; }
  for (i=1; i<=H; i++) { M[i][0] = '#'; M[i][W+1] = '#'; }
  // ??????????????\??? 
  for (i=1; i<=H; i++) {
    for (j=1; j<=W; j++) {
      scanf(" %c", &M[i][j]);
      if (M[i][j]=='@') {
	start.row = i;
	start.col = j;
      }
    }
  }

  // ?????????????????°?????????
  return search_df(W, H, start);
}

int search_df (int W, int H, Coord start) {
  stack S = new_stack ();  // ?¨?????????????????????????????????????

  // ??????????????°???????¨????
  push(S,start);                               // ??????????????°?????? push
  int tilenum = 1;                             // ?????????????????°
  // ??¢?´¢
  while (!is_empty(S)) {
    Coord current = pop(S);                    // pop ???????????????
    int d;                                     // ??????
    int D1[]={1,0,-1,0}; int D2[]={0,-1,0,1};  // ????????¢?????¶?????¨

    for (d=0; d<4; d++) {
      Coord nc = current;                      // Next Cell
      nc.row += D1[d];
      nc.col += D2[d];
      if(M[nc.row][nc.col] == '.') {
        M[nc.row][nc.col] = '*';
        tilenum += 1;
        push(S,nc);
      }
    }
  }
  return tilenum;
}

/* ??°??????????????????????¢?????????????????????? */
stack new_stack (void) {
  stack s;
  s = (stack) malloc (sizeof (stackelem));
  if (s == NULL) return NULL;
  s->next = NULL;
  return s;
}
    
/* ???????????????????????????????????? */
int is_empty (stack s) {
  return (s && s->next == NULL);
}

/* ??°??????????´???????????????\ */
int push (stack s, Coord v) {
  stack p;
  if (s == NULL) return 0;
  p = (stack) malloc (sizeof (stackelem));
  if (p == NULL) return 0;
  p->point = v;
  p->next = s->next;
  s->next =  p;
  return 1;
}

/* ?????????????´?????????? */
Coord top (stack s) {
  if (s && s->next) 
    return s->next->point;
  exit (1);
}

/* ????????? */
Coord pop (stack s) {
  stack p;
  Coord v = top (s);
  p = s->next;
  s->next = p->next;
  free (p);
  return v;
}


Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  long long N,K;
  cin>>N>>K;
  if(N>K){
    N=N%K;
  }
  if(K-N<N){
    N=K-N;
  }
  cout<<N<<endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if (A+B > C+D){
  	cout << "Left" << endl;
  }
  else if (A+B < C+D){
  	cout << "Right" << endl;
  }
  else{
  	cout << "Balanced" << endl;
  }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll n,ans,i,x,y,d,z;
  ans=0;
  cin >> n >> d;
  d=d*d;
  for(i=0;i<n;i++){
    cin >> x >> y;
    z=x*x+y*y;
    if(z<=d){
      ans+=1;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
int main(){
	double a,b,C;
	double S,L,h,r,c;
	scanf("%lf %lf %lf",&a,&b,&C);
	r=C/180*M_PI;
	S=sin(r)*a*b/2;
	c=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(r));
	L=a+b+c;
	h=S*2/a;
	printf("%0.8f\n",S);
	printf("%0.8f\n",L);
	printf("%0.8f\n",h);
	return 0;
}


Measured memory_bytes: 2092
N = int(input())
from itertools import product
ans = 0
for n in range(3,10):
    for ptn in product('753', repeat=n):
        if '7' not in ptn: continue
        if '5' not in ptn: continue
        if '3' not in ptn: continue
        v = int(''.join(ptn))
        if v <= N:
            ans += 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, K);
    vector<int> count(N+1, 0);

    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        count[a]--;
    }
    sort(count.begin(),count.end());

    int ans = 0;
    for (int i = K; i < N; i++) {
        if (count[i] == 0) break;
        ans -= count[i];
    }

    cout << ans << "\n";
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))

typedef struct{
    int min;
    int ymm;
} Food;

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,T;
    cin >>N>>T;

    vector<Food> X(N);
    int dp[N+1][T],ans=0;// eat / time
    rep(i,N) cin >> X[i].min>>X[i].ymm;

    sort(X.begin(),X.end(),[&](Food a,Food b){
        return a.min<b.min;
    });

    rep(i,N+1)rep(j,T)dp[i][j]=0;
    rep(i,N)rep(j,T){
        chmax(dp[i+1][j],dp[i][j]);
        if(j+X[i].min<T){
            chmax(dp[i+1][j+X[i].min],dp[i][j] + X[i].ymm);
        }else{
            chmax(ans,dp[i][j] +X[i].ymm);
        }
    }

    cout << ans <<endl;
    return (0);
}

Measured memory_bytes: 35456
import math
while True:
    n,x = list(map(int,input().split()))
    if n*n + x*x == 0:
        break
    count = 0
    for a in range(1,n+1):
        if a >= x - a - n:
            add = max(math.floor((x-a-0.1)/2) - a,0)
        else:
            add = max(math.floor((x-a-0.1)/2) - (x-a-n) + 1,0)
        count += add
    print(count)


Measured memory_bytes: 5676
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, ll> P; 
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

P v[3333];
ll dp[3333][3333];

int main(void){
	int n,t,i,j;
	ll ans = 0ll, tmp = 0ll;
	cin >> n >> t;
	for(i=0; i<n; ++i){
		cin >> v[i].first >> v[i].second;
	}
	sort(v,v+n);
	for(i=0; i<n; ++i){
		for(j=0; j<t; ++j){
			dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
			if(j+v[i].first<t){
				dp[i+1][j+v[i].first] = max(dp[i+1][j+v[i].first],dp[i][j]+v[i].second);
			}
		}
	}
	for(i=n; i>=0; --i){
		tmp = max(tmp,v[i].second);
		for(j=0; j<t; ++j){
			ans = max(ans,dp[i][j]+tmp);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, m;
    cin >> n >> m;
    vi c(m);
    rep(i, m) cin >> c[i];
    vl dp(n+1, INF);
    dp[0] = 0;
    rep(i, m) {
        for(int j = 0; j + c[i] < n+1; ++j) chmin(dp[j+c[i]], dp[j]+1);
    }
    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3124
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using ull = unsigned long long;

int main() {
	size_t N;
	std::cin >>N;
	
	std::vector<size_t> v;
	v.reserve(N);
	for (size_t i{ 0 }; i < N; i++) {
		size_t u;
		std::cin >> u;
		v.emplace_back(u-1);
	}

	size_t count_{0};
	for (size_t i{ 0 }; i < N ; i++) {
		size_t num = v[i];
		if (num != i) {//self 
			if(v[num ]  == i){//
				count_++; 
			}
		}
	}

	std::cout << count_/2 << "\n";

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>

using namespace std;

struct four {
	int a, b, c, d;
	four(int _a, int _b, int _c, int _d) : a(_a) , b(_b) , c(_c) , d(_d) {}
	four(){a=b=c=d=0;}
};

four operator + (const four &x, const four &y){
	return four(x.a+y.a, x.b+y.b, x.c+y.c, x.d+y.d);
}

four operator * (const four &x, const four &y){
	four ret;

	ret.a = x.a * y.a - x.b * y.b - x.c * y.c - x.d * y.d;
	ret.b = x.a * y.b + x.b * y.a + x.c * y.d - x.d * y.c;
	ret.c = x.a * y.c - x.b * y.d + x.c * y.a + x.d * y.b;
	ret.d = x.a * y.d + x.b * y.c - x.c * y.b + x.d * y.a;

	return ret;
}

int main() {
	int n;
	while (cin >> n, n) {
		for (int i = 0; i < n; ++i) {
			four f[2];
			for (int j = 0; j < 2; ++j) {
				int a, b, c, d; cin >> a >> b >> c >> d;
				f[j] = four(a, b, c, d);
			}

			four ans = f[0] * f[1];

			cout << ans.a << " " << ans.b << " " << ans.c << " " << ans.d << endl;
		}
	}
}

Measured memory_bytes: 0
import math
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(reverse=True)
k=ab[0][0]
ab.sort(reverse=True,key=lambda x:x[1])
ans=0
while h>0:
    if ans==n:
        break
    if k<=ab[ans][1]:
        h-=ab[ans][1]
        ans+=1
    else:
        break
if h<=0:
    print(ans)
else:
    print(ans+math.ceil(h/k))


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

using namespace std;

int main(){
	string s1;
	int k[10][10];
	while(cin>>s1){
		
		for(int i=0;i<10;i++)k[0][i]=s1[i]-'0';
		for(int i=1;i<10;i++){
			for(int j=0;j<10-i;j++){
				k[i][j]=(k[i-1][j]+k[i-1][j+1])%10;
				//cout<<k[i][j]<<" ";
			}
			//cout<<endl;
		}
		cout<<k[9][0]<<endl;
		
	}

}

Measured memory_bytes: 1180
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    auto S = new string[](H);
    foreach (i; 0 .. H)
        S[i] = sread();

    auto visited = new bool[][][](H, W, 2);

    PQueue!(Tuple!(long, long, long, long), "b<a") PQ;
    PQ.insert(Tuple!(long, long, long, long)(0, 0, 0, 0));
    long ans = long.max;
    while (!PQ.empty)
    {
        auto t = PQ.front();
        PQ.popFront();
        long d = t[0];
        long y = t[1];
        long x = t[2];
        long f = t[3];
        if (H <= y)
            continue;
        if (W <= x)
            continue;
        if (visited[y][x][f])
            continue;
        visited[y][x][f] = true;
        bool b = S[y][x] == '#';
        // writeln(t);
        if (y == H - 1 && x == W - 1)
        {
            ans = ans.min(d + (f != b && b));
        }
        PQ.insert(Tuple!(long, long, long, long)(d + (f == 0 && b), y + 1, x, b));
        PQ.insert(Tuple!(long, long, long, long)(d + (f == 0 && b), y, x + 1, b));
        // PQ.insert(Tuple!(long, long, long, long)(d + (f == 0 || !b), y + 1, x, 1));
        // PQ.insert(Tuple!(long, long, long, long)(d + (f == 0 || !b), y, x + 1, 1));
    }
    writeln(ans);
}


Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  string s; cin >> s;
  int n = s.size();

  char x[] = {'A', 'T', 'G', 'C'};
  int ans = 0, cnt = 0;
  for (int i = 0; i < n; i ++) {
    bool ok = false;
    for (int j = 0; j < 4; j ++) {
      if (s[i] == x[j]) ok = true;
    }

    if (ok) {
      cnt ++;
      ans = max(ans, cnt);
    } else {
      ans = max(ans, cnt);
      cnt = 0;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256