akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

ll fpow(ll x, ll p, ll mod){ ll res=1; for (;p;p>>=1){ if (p&1) res=(res*x)%mod; x=(x*x)%mod;} return res;}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b); }

const int maxc=2000,mod=1000000007;

ll N,a[200100],b[200100],dp[2*maxc+10][2*maxc+10],cnt[maxc+10][maxc+10],f[4*maxc+10];

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

    int i,j;
    for (i=1; i<=N; i++){
        cin >> a[i] >> b[i];
        cnt[a[i]][b[i]]++;
    }

    for (i=maxc; i>=-maxc; i--)
        for (j=maxc; j>=-maxc; j--){
            dp[i+maxc][j+maxc]=(dp[i+maxc+1][j+maxc]+dp[i+maxc][j+maxc+1])%mod;
            if (i>0 && j>0) dp[i+maxc][j+maxc]=(dp[i+maxc][j+maxc]+cnt[i][j])%mod;
        }

    f[0]=1;
    for (i=1; i<=4*maxc; i++)
        f[i]=(i*f[i-1])%mod;

    ll res=0;
    for (i=1; i<=N; i++){
        res=(res+dp[-a[i]+maxc][-b[i]+maxc])%mod;

        ll val=f[2*(a[i]+b[i])]*fpow(f[2*a[i]],mod-2,mod)%mod*fpow(f[2*b[i]],mod-2,mod)%mod;
        res=(res-val+mod)%mod;
    }

    res=res*fpow(2,mod-2,mod)%mod;
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 160640
n = int(input())
import math
digit = int(math.log10(n))+1
ans = 0
if digit%2==0:
  for i in range(digit-1,0,-1):
    if i%2!=0: ans += (10**i-10**(i-1))
  print(ans)
else:
  ans = n-10**(digit-1)+1
  for i in range(digit-2,0,-1):
    if i%2!=0: ans += (10**i-10**(i-1))
  print(ans)


Measured memory_bytes: 3060
n=int(input())
d=[[int(i)for i in input().split()]for j in range(n)]
res="No"
for i in range(n-2):
    if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
        res="Yes"
        break
print(res)

Measured memory_bytes: 9184
a = list(map(int, input().split()))

if a[1] < a[0]:
    tmp = a[1]
    a[1] = a[0]
    a[0] = tmp

if a[2] < a[1]:
    tmp = a[2]
    a[2] = a[1]
    a[1] = tmp

if a[1] < a[0]:
    tmp = a[1]
    a[1] = a[0]
    a[0] = tmp
    
print(*a, sep=' ')


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

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

    ll a;
    cin >> a;
    long double b;
    cin >> b;
    ll ans = a * b;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3800
n,k,*a=map(int,open(0).read().split())
l=[]
for i in range(n):
    t=0
    for j in range(i,n):
        t+=a[j]
        l.append(t)
for i in range(40,-1,-1):
    j=2**i
    t=[]
    for x in l:
        if x&j:
            t.append(x)
    if len(t)>=k:
        l=t
a,*b=l
for t in b:
    a&=t
print(a)

Measured memory_bytes: 65916
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include<iomanip>

using namespace std;

int main(){
    int A,B,p=0,mina=101,minb=101;
    cin >> A >> B;
    p=int(A/0.08);
    for(int i = 10100; i > 0; i--){
        int a = i*0.08;
        int b = i*0.10;
        if(a==A && b==B){
            p=i;
            if(a <= mina) mina = a;
            if(b <= minb) minb = b;
        }
    }
    if(mina > 100 || minb > 100){
        cout << "-1" << endl;
    }else{
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 256
'''@masayoshi361   Qiita　　三重ループはTLE。要素固定⇒二分探索
こういういくつも要素が動く系の数え上げはいくつかを固定してあげると
うまくいくことがあります。今回、三角形に使う棒の長さをa<=b<=cとして、
b, cを固定すると、a>c-bとなるaの数え上げに帰着します。単調性から、
二分探索でlognで求められるので、全体ではO(N^2logN)です。
'''
from bisect import bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()#昇順ソート、小さいものから大きいものへ
ans = 0
for i in range(N):
    for j in range(i):#jはi未満
        m = L[i]-L[j]#上記c-aを計算
        k = bisect_right(L, m)#二分探索
        #aに相当するkは、mよりも大きい(つまり、右側)
        n = max(0, j-k)#j-kの区間の数は大丈夫
        ans+=n
print(ans)

Measured memory_bytes: 43228
from bisect import bisect_left, bisect_right
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

ans = 0
for b in B:
    a_val = bisect_left(A, b)
    c_val = N - bisect_right(C, b)
    ans += a_val * c_val
print(ans)



Measured memory_bytes: 23200
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
using namespace std;
 
const double PI = 3.14159265358979;
 
class Point {
public:
    double x, y;
    Point(double x = 0.0, double y = 0.0) :x(x), y(y) {}
};
 
class Wind {
public:
    double w, a;
};
 
bool include(double angle, double low, double high) {
    if(low < 0.0) {
        double l = low + 2.0 * PI;
        if(l <= angle) return true;
    }
    if(high > 2.0 * PI) {
        double h = high - 2.0 * PI;
        if(angle <= h) return true;
    }
    return low <= angle && angle <= high;
}
 
bool savor(const Point &home, const Wind &wind, const vector<Point> &blossom, double d) {
    d /= 2.0;
    for(const auto &b: blossom) {
        Point dif(home.x - b.x, home.y - b.y);
        double angle = atan2(dif.y, dif.x);
        double dist = hypot(dif.y, dif.x);
        if(angle < 0.0) angle = angle + 2.0 * PI;
        if(dist <= wind.a && include(angle, wind.w - d, wind.w + d)) return true;
    }
    return false;
}
 
double toRadian(double d) {
    return d * PI / 180.0;
}
 
int main() {
    int H, R;
    while(cin >> H >> R, H | R) {
        vector<Point> home(H);
        for(auto &i: home) cin >> i.x >> i.y;
 
        int U, M, S;
        double du, dm, ds;
        cin >> U >> M >> S >> du >> dm >> ds;
 
        du = toRadian(du);
        dm = toRadian(dm);
        ds = toRadian(ds);
 
        vector<Point> plum(U), peach(M), cherry(S);
        for(auto &i: plum) cin >> i.x >> i.y;
        for(auto &i: peach) cin >> i.x >> i.y;
        for(auto &i: cherry) cin >> i.x >> i.y;
 
        vector<Wind> wind(R);
        for(auto &i: wind) cin >> i.w >> i.a;
        for(auto &i: wind) i.w = toRadian(i.w);
 
        // solve
        vector<int> number(H, 0);
        int maxNumber = 0;
 
        for(int i = 0; i < H; ++i) {
            for(int day = 0; day < R; ++day) {
                bool ok = savor(home[i], wind[day], {Point(0.0, 0.0)}, du);
                bool ng = false;
                ng |= savor(home[i], wind[day], plum, du);
                ng |= savor(home[i], wind[day], peach, dm);
                ng |= savor(home[i], wind[day], cherry, ds);
 
                if(!ok || ng) continue;
 
                ++number[i];
                maxNumber = max(maxNumber, number[i]);
            }
        }
 
        if(maxNumber) {
            bool first = true;
            for(int i = 0; i < H; ++i) if(number[i] == maxNumber) {
                if(!first) cout << " ";
                first = false;
                cout << i + 1;
            }
            cout << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 1336
#include <stdio.h>

int main(void){
	int m_h, m_w, s_h, s_w, a, b, c, mas;

	scanf("%d %d", &m_h, &m_w);
	scanf("%d %d", &s_h, &s_w);

	a = s_h * m_w;
	b = s_w * m_h;
	c = s_h * s_w;

	mas = m_h * m_w - (a + b - c);

	printf("%d\n", mas);

	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

typedef long long ll;

ll N;
ll mod = 1e9 + 7;
unordered_map<string, ll> M[101];
char c[4] = {'A','C','G','T'};


bool isOK(string s,char c){
    if(c == 'A' || c == 'T') return true;
    if(c == 'C'){
        if(s[1] == 'A' && s[2] == 'G') return false;
        if(s[1] == 'G' && s[2] == 'A') return false;
        if(s[0] == 'A' && s[2] == 'G') return false;
        if(s[0] == 'A' && s[1] == 'G') return false;
        return true;
    }
    if(c == 'G'){
        if(s[1] == 'A' && s[2] == 'C') return false;
        return true;
    }
    return false;
}

ll dfs(ll n, string s){
    if(M[n].find(s) != M[n].end()){
        return M[n][s];
    }
    if(N == n) return 1;
    ll ret = 0;
    for(int i=0;i<4;i++){
        if(isOK(s,c[i])){
            ret += dfs(n+1,s.substr(1,2) + c[i]);
            ret %= mod;
        }
    }
    return M[n][s] = ret;
}

int main(){
    cin >> N;
    cout << dfs(0,"TTT") << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
#define double long double
#define vi vector<int>
#define vpi vector<pair<int,int> >
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define msi map<string,int>
#define set set<int>
#define u_set unordered_set<int>
#define pb push_back
#define mp make_pair
#define M 1000000007
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define endl "\n"
#define BRISK ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

signed main()
{
    BRISK;
    int n;
    cin>>n;

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

    int dp[n][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1;i<n;i++){
        dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=a[i][2]+max(dp[i-1][1],dp[i-1][0]);
    }

    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        for(int i=0;i<4;i++){
            int t,n;
            t=sc.nextInt();
            n=sc.nextInt();
            if(t==1){
                System.out.println(6000*n);
            }else if(t==2){
                System.out.println(4000*n);
            }else if(t==3){
                System.out.println(3000*n);
            }else{
                System.out.println(2000*n);
            }
        }
    }
}


Measured memory_bytes: 26164
use strict;
use warnings;

use constant MOD => 1000000007;

my ($n, $m) = split(/\s+/, <>);
my @fact = (1);
for(my $i = 1; $i <= $m; ++$i){
	push(@fact, $fact[-1] * $i % MOD);
}
my @ifact;
$ifact[$m] = powmod($fact[$m], MOD - 2);
for(my $i = $m; $i > 0; --$i){
	$ifact[$i - 1] = $ifact[$i] * $i % MOD;
}

my $ans = perm($m, $n);
for(my $i = 1; $i <= $n; ++$i){
	my $sgn = $i & 1 ? -1 : 1;
	my $t = cmb($n, $i) * perm($m - $i, $n - $i);
	$ans = ($ans + $sgn * $t) % MOD;
}
$ans = $ans * $fact[$m] % MOD * $ifact[$m - $n] % MOD;
print "$ans\n";

sub powmod{
	my ($x, $y) = @_;
	my $a = 1;
	while($y){
		$a = $a * $x % MOD if $y & 1;
		$y >>= 1;
		$x = $x * $x % MOD;
	}
	return $a;
}

sub perm{
	my ($n, $k) = @_;
	return $fact[$n] * $ifact[$n - $k] % MOD;
}

sub cmb{
	my ($n, $k) = @_;
	return $fact[$n] * $ifact[$n - $k] % MOD * $ifact[$k] % MOD;
}


Measured memory_bytes: 37148
//agc013_a.cpp
//Sat Oct 27 12:39:22 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int a[n];
	int ans = 0;
	int prevnum = 0;
	int flag = 0;
	for (int i=0;i<n;i++){
		int temp;
		cin >> temp;
		if (prevnum==0){
		}else if (flag ==0){
			if (prevnum > temp){
				flag = -1;
			}else if (prevnum < temp){
				flag = 1;
			}
		}else if (flag == 1){
			if (prevnum > temp){
				ans++;
				flag = 0;
			}
		}else if (flag == -1){
			if (prevnum < temp){
				ans++;
				flag = 0;
			}
		}
		prevnum = temp;
	}

	cout << ans + 1<< endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(true){
        c -= b;
        if(c<=0){
            cout << "Yes";
            break;
        }
        a -= d;
        if(a<=0){
            cout << "No";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include <vector>
#include <list>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <climits>
#include <map>
#include <math.h>
#include <stack>

using namespace std;

string strcut(string s, int f, int e) {
	string res = "";
	for (int i = f; i <= e; i++)
	{
		res += s[i];
	}
	return res;
}

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

	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] == 'B') { 
			str[i] = 'N';
			for (int s = i-1; s >= 0; s--)
			{
				if (str[s] != 'N') { str[s] = 'N'; break; }
			}
		}
	}

	for (int i = 0; i < str.size(); i++)
	{
		if (str[i] != 'N') { cout << str[i]; }
	}
	cout << endl;


	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<int,P>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int mypow(int a,int b){
	if(b==0) return 1;
	if(b%2) return mypow(a,b-1)*a%mod;
	int z=mypow(a,b/2);
	return z*z%mod;
}
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	string s;
	cin>>s;
	f(i,a){
		if(s[i]=='a'){
			if(b){
				cout<<"Yes"<<endl;
				b--;
			}
			else if(c){
				puts("Yes");
				c--;
			}
			else puts("No");
		}
		else if(s[i]=='b'){
			if(c){
				puts("Yes");
				c--;
			}
			else puts("No");
		}
		else puts("No");
	}
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int h, w,cnt;
	cin >> h >> w;
	vector<string> s(h+1), ans(h+1);
	rep(i, h) {
		cin >> s[i];
		ans[i] = s[i];
	}
	rep(i,h){
		rep(j, w) {
			if (s[i][j] == *"#") {
				ans[i][j] = s[i][j];
			}
			else {
				cnt = 0;
				rep(x, 3) {
					rep(y, 3) {
						int dx = x + i - 1, dy = y + j - 1;
						if (dx >= 0 && dx < h&&dy >= 0 && dy < w) {
							if (s[dx][dy] == *"#") {
								cnt++;
							}
						}
					}
				}
				ans[i][j] = cnt+'0';
			}
		}
	}
	rep(i, h) {
		cout << ans[i] << endl;
	}
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
use std::collections::HashMap;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    let mut cnts = vec![HashMap::<usize, usize>::new(); 2];
    for i in 0..n {
        seq[i] = read::<usize>();
        let mut entry = cnts[i % 2].entry(seq[i]).or_insert(0);
        *entry += 1;
    }
    let mut ans = 0;
    let mut cnts2 = vec![vec![]; n];
    for i in 0..2 {
        for (&v, &cnt) in cnts[i].iter() {
            cnts2[i].push((cnt, v));
            ans = std::cmp::max(ans, cnt);
        }
        cnts2[i].sort();
        cnts2[i].reverse();
    }
    for i in 0..std::cmp::min(4, cnts2[0].len()) {
        for j in 0..std::cmp::min(4, cnts2[1].len()) {
            if cnts2[0][i].1 == cnts2[1][j].1 {
                continue;
            }
            ans = std::cmp::max(ans, cnts2[0][i].0 + cnts2[1][j].0);
        }
    }
    println!("{}", n - ans);
}


Measured memory_bytes: 17772
#include<cstdio>
#include<cctype>

int main(){
    while(1){
        char ch;

        scanf("%c", &ch);
        if(isalpha(ch)){
            if(isupper(ch)) printf("%c", tolower(ch));
            else printf("%c", toupper(ch));
        } else printf("%c", ch);
        
        if(ch == '\n') break;
    }

    return 0;
}


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

int main(void){
  int n, temp;
  cin >> n;
  int a[100000];
  for(int i = 0; i < 100000; i++) a[i] = 0;
  for(int i = 0; i < n; i++){
    cin >> temp;
    a[temp]++;
  }
  int ans = 0;
  for(int i = 1; i < 100000 - 1; i++){
    temp = a[i - 1] + a[i] + a[i + 1];
    ans = max(ans, temp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import sys
from itertools import starmap
import math
readline = sys.stdin.readline
EPS = 1e-9
ONLINE_FRONT = -2
CLOCKWISE = -1
ON_SEGMENT = 0
COUNTER_CLOCKWISE = 1
ONLINE_BACK = 2
class Circle(object):
    __slots__ = ('c', 'r')
    def __init__(self, c, r):
        self.c = c
        self.r = r
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
Line = Segment
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
def getCrossPoint(s1, s2):
	base = s2.se - s2.fi
	d1 = abs(cross(base, s1.fi - s2.fi))
	d2 = abs(cross(base, s1.se - s2.fi))
	t = d1 / (d1 + d2)
	return s1.fi + (s1.se - s1.fi) * t
def getCrossPoints(c, l):
	pr = project(l, c.c)
	e = (l.se - l.fi) / abs(l.se - l.fi)
	base = math.sqrt(c.r * c.r - norm(pr - c.c))
	return Segment(pr + e * base, pr - e * base)
x, y, r = map(int, readline().split())
ci = Circle(complex(x, y), r)
n = int(readline())
for _ in [0] * n:
    p0, p1 = starmap(complex, zip(*[map(int, readline().split())] * 2))
    ppp = getCrossPoints(ci, Line(p0, p1))
    if ppp.se.real < ppp.fi.real or (ppp.se.real == ppp.fi.real and ppp.se.imag < ppp.fi.imag):
        ppp.fi, ppp.se = ppp.se, ppp.fi
    print(*map('{:.10f}'.format, [ppp.fi.real, ppp.fi.imag, ppp.se.real, ppp.se.imag]))

Measured memory_bytes: 7996
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let d: i32 = sc.read();
        let e: i32 = sc.read();
        if d == 0 { break; };
        let mut cur = d * d;
        let mut ans = 0;
        for i in 0..d/2 + 1 {
            if (i.pow(2) + (d - i).pow(2) - e.pow(2)).abs() < cur {
                ans = i;
                cur = (i.pow(2) + (d - i).pow(2) - e.pow(2)).abs();
            }
        }
        println!("{}", (e as f64 - ((ans.pow(2) + (d - ans).pow(2)) as f64).sqrt()).abs());
    }
}



Measured memory_bytes: 5048
N, A, B = map(int,input().split())

ans = 0
for val_int in range(1,N+1):
  num = 0
  val_str = str(val_int)
  for j in val_str:
    num += int(j)
  if A <= num and num <= B:
    ans += val_int

print(ans)

Measured memory_bytes: 3060
use std::io::*;
use std::io::Write;
use std::str::FromStr;

/// input macro
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
///
/// # Example
///
#[macro_export]
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_export]
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_export]
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")
    };
}

macro_rules! eprintln (
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);


fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}

use std::collections::HashMap;

fn main() {
    input! {
        s: chars,
    }

    let mut hashmap = HashMap::new();

    for x in &s {
        if !hashmap.contains_key(x) {
            hashmap.insert(x, 0);
        }
        *hashmap.get_mut(x).unwrap() += 1;
    }

    if hashmap.iter().map(|(k, v)| v).all(|x| *x == 2) {
        println!("Yes");
    } else {
        println!("No");
    }
}



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

int main() {
	long long N;
	string S;
	map<string, long long> mp;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		mp[S]++;
	}
	long long MAX = 0;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		MAX = max(MAX, it->second);
	}
	vector<string> ANS;
	for (auto it = mp.begin(); it != mp.end(); it++) {
		if (it->second == MAX) ANS.push_back(it->first);
	}
	sort(ANS.begin(), ANS.end());
	for (int i = 0; i < ANS.size(); i++) cout << ANS[i] << endl;
}

Measured memory_bytes: 26868
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as S
import Data.Array.IArray
import Data.Maybe
import Data.Monoid
 
type Vertex = Int
type Vertexes = S.IntSet
type Edge = (Vertex, Vertex)
type Graph = Array Vertex Vertexes

instance Monoid Int where
  mempty = 0
  mappend = (+)

buildG :: Int -> [Edge] -> Graph
buildG n = accumArray (flip S.insert) S.empty (1, n)
 
from :: Graph -> Vertex -> Vertexes
from g = (g !)
 
readUndirectedEdge :: B.ByteString -> [Edge]
readUndirectedEdge = concatMap ((\[v,w] -> [(v,w),(w,v)]) . map readVertex . B.words) . B.lines
 
readVertex :: B.ByteString -> Vertex
readVertex = fst . fromJust . B.readInt

main :: IO ()
main = do
 [n,_] <- map read . words <$> getLine
 es <- readUndirectedEdge <$> B.getContents
 let g = buildG n es
 print (dfs g (\vs -> if S.size vs == n then 1 else 0) 1 :: Int)
 
dfs :: Monoid m => Graph -> (Vertexes -> m) -> Vertex -> m
dfs g p v = dfsCore g p v visited mempty
  where
    visited = S.empty

dfsCore :: Monoid m => Graph -> (Vertexes -> m) -> Vertex -> Vertexes -> m -> m
dfsCore g p v visited m
  | S.null next = p (S.insert v visited)
  | otherwise = S.foldr (\w acc -> acc <> dfsCore g p w (S.insert v visited) m) mempty next
  where
    next = S.difference (from g v) visited

Measured memory_bytes: 892
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	int a, b;
	string s;
	bool ok = true;

	cin >> a >> b >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if(i==a&&s[i]!='-')ok = false;
		if (i != a && s[i] == '-')ok = false;
	}

	if (ok)cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

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

int main() {
	int i, A, B, s, t, u, v, r = 0;
	cin >> A >> B;

	for (i = A; i <= B; ++i) {
		s = int(i / 10000);
		t = int((i % 10000) / 1000);
		v = i % 10;
		u = int((i % 100) / 10);
		if (s == v && t == u) ++r;
	}
	cout << r << endl;
	return 0;
}

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

class State
{
public:
	int n, k, d;
	State(int n, int k, int d)
		:n(n),k(k),d(d)
	{}

	bool operator<(const State& s) const
	{
		if(n!=s.n) return n > s.n;
		return d > s.d;
	}
};

int N, p[41], t[41];

pair<bool, int> solve()
{
	bool vis[40][4] = {0};

	int m = 0, res = (1<<24);
	priority_queue<State> q;
	q.push(State(0,0,0));

	while(!q.empty()) {
		State s = q.top(); q.pop();
		m = max(m, s.n);

		if(s.n == N) {
			res = min(res, s.d + p[s.n]);
			continue;
		}
		if(vis[s.n][s.k]) continue;
		vis[s.n][s.k] = true;

		int nt = (s.k + 1)*abs(p[s.n + 1] - p[s.n]) + t[s.n];
		if(nt <= t[s.n + 1] && s.k < 3) q.push(State(s.n + 1, s.k + 1, s.d + abs(p[s.n + 1] - p[s.n])));

		nt = (s.k + 1)*p[s.n] + p[s.n + 1] + t[s.n];
		if(nt <= t[s.n + 1]) q.push(State(s.n + 1, 1, s.d + p[s.n + 1] + p[s.n] ));
	}

	if(m == N) return make_pair(true, res);
	return make_pair(false, m + 1);
}


int main()
{
	while(cin >> N, N) {
		p[0] = t[0] = 0;
		for(int i=1; i<=N; i++)
			cin >> p[i] >> t[i];

		pair<bool, int> res = solve();

		cout << (res.first ? "OK" : "NG") << " ";
		cout << res.second << endl;
	}
}

Measured memory_bytes: 0
<?php

//----------------------------------------------------------------------------------
// Input
//----------------------------------------------------------------------------------
$sc = new Scanner();
$n = $sc->nextInt();

$h = array();
for ($i = 0; $i < $n; $i++) {
  $h[] = $sc->next();
}

//  $t = array();
//  $d = array();
//  for ($i = 0; $i < $n; $i++) {
//    $t[] = $sc->next();
//    $d[] = $sc->next();
//  }



//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$ans = $n;
foreach (range(0, $n-1) as $i) {
  foreach (range(0, $i-1) as $j) {
    if ($h[$i] < $h[$j]) { $ans--; break; }
  }
}



//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
$is_large_int_ans = 0;
$is_multi_ans = 0;

if ($is_multi_ans) {
  for ($i = 0; $i < count($ans); $i++) {
    out::println($ans);
  }
} else {
  out::println($ans);
}



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;

  private $fp = NULL;

  function __construct() {
    $folder = explode("\\", getcwd());
    if (end($folder) == 'AtCoder') {
      error_reporting(E_ERROR | E_WARNING | E_PARSE);
      $this->fp = fopen('./Input.dat' , 'r');
    } else {
      error_reporting(0);
    }
  }

  public function next() {
    if($this->pointer >= $this->count) {
      $folder = explode("\\", getcwd());
      if (end($folder) == 'AtCoder') {
        $str = trim(fgets($this->fp));
      } else {
        $str = trim(fgets(STDIN));
      }
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    global $is_large_int_ans;
    if ($is_large_int_ans) {
      echo sprintf("%d", $str) . PHP_EOL;
    } else {
      echo $str . PHP_EOL;
    }
  }
}

?>


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

int main(){
    vector<int> N(4);
    vector<int> hash_table(10, -1);
    hash_table[1] = 1;
    hash_table[9] = 1;
    hash_table[7] = 1;
    hash_table[4] = 1;
    int cnt = 4;
    for (int i=0;i<4;i++){
        cin >> N[i];
        if (hash_table[N[i]] > 0){
            hash_table[N[i]]--;
            cnt--;
        }
    }
    if (cnt == 0) cout << "YES";
    else cout << "NO";
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10) {
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

struct _f {
	ll v, l, r;
	_f() {}
	_f(ll v, ll l, ll r) :v(v), l(l), r(r) {}
};
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<ll> t(N), v(N);
	for (int i = 0; i < N;i++) cin >> t[i];
	for (int i = 0; i < N;i++) cin >> v[i];

	vector<_f> F; F.push_back(_f(0, 0, 0));
	ll t_sum = 0;
	for (int i = 0; i < N;i++) {
		F.push_back(_f(v[i], t_sum, t_sum + t[i]));
		t_sum += t[i];
	}
	F.push_back(_f(0, t_sum, t_sum));

	double res = 0.0;
	double pre_v = 0.0;
	for (double T = 0.5; T <= t_sum;T += 0.5) {
		double next_v = INF;
		for (auto _F : F) {
			if (T <= _F.l) {
				next_v = min(next_v, (double)(_F.v + (_F.l - T)));
			}
			else if (T >= _F.r) {
				next_v = min(next_v, (double)(_F.v + (T - _F.r)));
			}
			else {
				next_v = min(next_v, (double)_F.v);
			}
		}
		res += (pre_v + next_v)*0.5 / 2.0;
		pre_v = next_v;
	}
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main() {
	int h, w;
	while(true) {
		scanf("%d %d", &h, &w);
		if(h == 0 & w == 0) break;

		for(int i = 1; i <= h*w; i++) {
			if(i <= w | i % w == 0 | i > w*(h-1)+1) printf("#");
			else if(i % w == 1) {
				printf("\n");
				printf("#");
			}
				else printf(".");
		}
		printf("\n\n");
	}	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
  int a,b;
  P o(0,0);
  double nowang = 3.141592653589793238 / 2.0;
  P I(0,1);
  while(~scanf("%d,%d",&a,&b)){
    if(a==0 && b==0)break;
    double len = a;
    double ang = (double)b / 180.0 * 3.141592653589793238;
    ang *= -1.0;
    P angvec = exp(I*nowang);
    o += angvec * len;
    nowang += ang;
  }
  cout<<(int)real(o)<<endl;
  cout<<(int)imag(o)<<endl;
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
ll MOD=1e9+7;
ll MAX=1e17;

int tell[100002];
ll factorial[100002];

ll power(ll a, ll b){
    ll x = 1, y = a;
    while (b > 0){
        if (b%2){
            x = (x*y)%MOD;
        }
        y = (y*y)%MOD;
        b /= 2;
    }
    return x%MOD;
}   
 
ll modular_inverse(ll n){
    return power(n, MOD-2);
}
 
ll nCr(ll n, ll k){
    ll flag= ((factorial[n])*(modular_inverse(factorial[k])))%MOD;
    return (flag*modular_inverse(factorial[n-k]))%MOD;
}


int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    n++;
    factorial[0]=1;
    for (int i = 1; i < 100002; ++i)
    {
        factorial[i] = ((ll)i*factorial[i-1])%MOD;
    }
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    ll rep=0,counter=0;
    for (int i = 0; i < n; ++i)
    {
        if(tell[a[i]]==0) tell[a[i]]=1;
        else {
            rep=a[i];
            break;
        }
    }
    int help=0;
    for (int i = 0; i < n; ++i)
    {
        if(!help){
            if(a[i]!=rep) counter++;
            else help=1;
        }
        else if(help==1){
            if(a[i]==rep) help=-1;
        }
        else counter++;
    }
    cout<<n-1<<endl;
    for (int i = 2; i <= n; ++i)
    {
        ll ans=nCr(n,i);
        if(counter>=i-1) ans-=nCr(counter,i-1);
        cout<<(ans+MOD)%MOD<<endl;
    }
    return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <stdlib.h>
using namespace std;
int int_sort(const void * a, const void * b) {
	if (*(int *)a < *(int*)b) {
		return -1;
	}
	else if (*(int*)a == *(int*)b) {
		return 0;
	}
	return 1;
}

int max_array(int n[], int len)
{
	int i, tmp;
	tmp = n[0];
	for (int i = 1; i<len; i++) {
		if (tmp < n[i]) {
			tmp = n[i];
		}
	}
	return tmp;
}

int min_array(int n[], int len)
{
	int i, tmp;
	tmp = n[0];
	for (int i = 1; i<len; i++) {
		if (tmp > n[i]) {
			tmp = n[i];
		}
	}
	return tmp;
}
int main()
{
	int N = 0;
	cin >> N;
	int ai[1000];
	int counti = 0;
	while (counti != N) {
		cin >> ai[counti];
		counti++;
	}

	int ans = max_array(ai, N) - min_array(ai, N);
	
	cout << ans << endl;

    return 0;
}



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

int main(){
  int h,w;
  cin >> h >> w;
  std::vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  std::vector<bool> row(h,false),column(w,false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = true; column[j] = true;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i]) {
      for (int j = 0; j < w; j++) {
        if (column[j]) {
          std::cout << a[i][j];
        }
      }
      std::cout << '\n';
    }
  }
}


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

int main()
{
	int x, a, b,i,j;
	cin >> x >> a >> b;
	i = x - a;
	j = x - b;
	 if (i < 0&&j<0)
	{
	i = -(i);
	j = -(j);
	if (i < j)
		cout << "A";
	else
		cout << "B";
	}
	else if (i < 0)
	{
		i = -(i);
		//j = -(j);
		if (i < j)
			cout << "A";
		else
			cout << "B";

	}
	else if (j < 0)
	{
		j = -(j);
		if (i < j)
			cout << "A";
		else
			cout << "B";
	}
	
	else
	 {
		 if (i < j)
			 cout << "A";
		 else
			 cout << "B";
	 }
}

Measured memory_bytes: 3516
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n ,t;
    cin >> n >> t;
    int mi = pow(10,6);
    pair <int,int> a;
    rep(i,0,n) {
        cin >> a.first >> a.second;
        if (a.second <= t) {
            mi = min(mi, a.first);
        }
    }
    if (mi == pow(10,6)) {
        cout << "TLE" << endl;
        return 0;
    }
    cout << mi << endl;
}

Measured memory_bytes: 3204
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<string> w = {"Sunny", "Cloudy", "Rainy"};
    string s;
    cin >> s;
    REP(i,3){
        if(s==w[i]){
            cout << w[(i+1)%3] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MIN_M = 2;
const int MAX_M = 16;

/* typedef */

/* global variables */

/* subroutines */

int ten2m(int n, int m) {
  //if (m == 10) return -1;
  int tm = 0, base = 1;
  while (n > 0) {
    int d = n % m;
    if (d >= 10) return -1;
    tm += d * base;
    base *= 10;
    n /= m;
  }
  return tm;
}

/* main */

int main() {
  int a, b, c;
  for (;;) {
    cin >> a >> b >> c;
    if (a < 0) break;
    //printf("a=%d, b=%d, c=%d\n", a, b, c);

    int mm;
    for (mm = MAX_M; mm >= MIN_M; mm--)
      if (ten2m(a, mm) == b) break;
    if (mm < MIN_M) {
      cout << -1 << endl;
      continue;
    }

    int prev = b;

    for (int ag = a + 1; ag <= c; ag++) {
      int bg;
      for (mm = MAX_M; mm >= MIN_M; mm--)
	if ((bg = ten2m(ag, mm)) >= prev) break;

      if (mm < MIN_M) {
	prev = -1;
	break;
      }
      prev = bg;
    }

    cout << prev << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
n.times{
    r, t = gets.chomp.split.map(&:to_i)
    type = ([100, 200, 300, 400, 500].include? r) ? 1 : 0
    type += ([0, 30, 60, 90, 120, 150, 180].include? t) ? 2 : 0
    points = []
    case type
    when 3
        points << (t / 30) * 5 + (r / 100)
    when 2
        points << (t / 30) * 5 + (r / 100)
        points << (t / 30) * 5 + (r / 100) + 1
    when 1
        points << (t / 30) * 5 + (r / 100)
        points << (t / 30 + 1) * 5 + (r / 100)
    else
        points << (t / 30) * 5 + (r / 100)
        points << (t / 30) * 5 + (r / 100) + 1
        points << (t / 30 + 1) * 5 + (r / 100)
        points << (t / 30 + 1) * 5 + (r / 100) + 1
    end
    puts points.join(" ")    
}



Measured memory_bytes: 6884
input = gets.strip
sx,sy,tx,ty = input.split(' ').map(&:to_i)

dx = tx - sx
dy = ty - sy

U = 'U'
R = 'R'
D = 'D'
L = 'L'

output = []
dy.times { output << U }
dx.times { output << R }
dy.times { output << D }
dx.times { output << L }

output << 'L'

(dy+1).times { output << U }
(dx+1).times { output << R }
output << 'D'

output << 'R'
(dy+1).times { output << D }
(dx+1).times { output << L }
output << 'U'

puts output.join


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

struct Data {
    int p, len, state;
};

const int INF = 1e9;

int main() {
    int n, m; cin >> n >> m;
    vector< vector<int> > graphlist(n, vector<int>());
    for(int i = 0; i < m; ++i) {
        int u, v; cin >> u >> v;
        u--; v--;
        graphlist[u].emplace_back(v);
    }
    int s, t; cin >> s >> t;
    s--; t--;
    vector< vector<int> > graph(3, vector<int>(n, INF));

    graph[0][s] = 0;
    Data first;
    first.p = s; first.len = 0; first.state = 0;
    queue<Data> que;
    que.push(first);

    while(!que.empty()) {
        Data now = que.front();
        que.pop();
        for(int i = 0; i < (int)graphlist[now.p].size(); ++i) {
            int np = graphlist[now.p][i];
            int nlen = now.len+1;
            int nstate = nlen%3;
            if(graph[nstate][np] > nlen) {
                graph[nstate][np] = nlen;
                Data next;
                next.p = np; next.len = nlen; next.state = nstate;
                que.push(next);
            }
        }
    }

    if(graph[0][t] == 1e9) cout << -1 << endl;
    else cout << graph[0][t]/3 << endl;
}

Measured memory_bytes: 10360
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=[ int(sys.stdin.readline().strip()) for _ in range(N) ]
max_A=max(A)

# 処理する区間の長さmax_A
N0 = 2**(max_A).bit_length()
data = [0]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k > 0:
        k = (k - 1) / 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最大値
def query(l, r):
    L = l + N0; R = r + N0
    s = float("-inf")
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i,a in enumerate(A):
    update(a,query(max(a-K,0),min(a+K+1,max_A+1))+1)

print query(0,max_A+1)


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

int main(){
  int n;
  cin >> n;
  
  int wari = n / 1.08;
  int wariwari = n / 1.08 + 1;
  int wada = wari * 1.08;
  int wadawada = wariwari * 1.08;
  
  queue<int> q;
  if(n == wada)q.push(wari);
  if(n == wadawada)q.push(wariwari);
  
  if(q.size() == 0)cout << ":(" << endl;
  else cout << q.front() << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,a=0,b=0,c=0,t=0;
    cin>>n;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=="AC")
        {
            a++;
        }
        if(s=="TLE")
        {
            t++;
        }
        if(s=="WA")
        {
            b++;
        }
        if(s=="RE")
        {
            c++;
        }
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<c<<endl;
    return 0;
}


Measured memory_bytes: 3572
import java.util.Scanner;

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

		n = sc.nextInt();
		t = sc.nextInt();

		for(int i = 0; i < n; ++i) {
			int ci = sc.nextInt();
			int ti = sc.nextInt();
			if(ti <= t) {
				minCost = Math.min(minCost, ci);
			}
		}

		if(minCost == 1001) {
			System.out.println("TLE");
		} else {
			System.out.println(minCost);
		}
	}
}


Measured memory_bytes: 23252
x = input()
# x = x.replace(1,14)
# replaceは，文字列しか使えない．
ls_x = x.split()

# xに入力した文字列たちを整数化

for i in range(len(ls_x)):
    ls_x[i] = int(ls_x[i])

if ls_x[0] == ls_x[1]:
    print("Draw")

elif ls_x[0] == 1:
    print("Alice")

elif ls_x[1] == 1:
    print("Bob")

elif ls_x[0] > ls_x[1]:
    print("Alice")

elif ls_x[0] < ls_x[1]:
    print("Bob")

Measured memory_bytes: 3060
#https://abc010.contest.atcoder.jp/tasks/abc010_4
#http://kmjp.hatenablog.jp/entry/2014/06/08/0900

#よくわからない最大フロー用のdfs---------------------------------

num=201 #今回のnの最大値100*2+1

def dfs(cur):
	global vis
	global EE
	vis[cur] = 1

	if cur==num:
		return 1

	for i in range(num+1):
		if vis[i]==0 and EE[cur][i]>0 and dfs(i) > 0:
			EE[cur][i] -= 1
			EE[i][cur] += 1
			return 1
	return 0
#--------------------------------------------------------------

#今回の問題分（インプット～隣接リストの作成）------------------

n=int(input())
s=[]
ss=[]
for i in range(n):
    s.append([int(i) for i in input().split()])
for i in range(n):
    ss.append([int(i) for i in input().split()])
#s.sort(key=lambda x:(x[0],x[1]))
#ss.sort(key=lambda x:(x[0],x[1]))

pair=[]
for i in range(len(s)):
    right=[]
    for j in range(n):    
        if s[j][0]<ss[i][0] and s[j][1]<ss[i][1]:
            right.append(j)
    pair.append(right)
#pair.sort(key=lambda x:len(x))

#print(pair)

#------------------------------------------------------------

#BFSにぶち込む用のグラフ作成---------------------------------

EE = [[0 for x in range(num+1)] for y in range(num+11)]
vis = [0] * (num+1)

for i in range(len(pair)): #1から最大100　始点s（番号0）から青い点への辺
	EE[0][i+1] = 1
	EE[i+1][0] = 1

for i in range(n): #101から最大200　赤い点から終点t（番号201）への辺
	EE[i+101][num] = 1

for i in range(len(pair)): #青い点（番号1～100に振り直し）から　赤い点（番号101～200）への辺
    for j in range(len(pair[i])):
        node1, node2 = i+1,pair[i][j]+101
#        EE[node1][node2] = EE[node2][node1] = 1　なんでこれダメなんだろう
        EE[node1][node2] = 1

#風呂～～--------------------------------------------------

flow=0
while 1:
    for i in range(0, num+1):
        vis[i] = 0
    if dfs(0) == 0:
        break
    flow += 1

print (flow)

#----------------------------------------------------------




Measured memory_bytes: 3572
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

const long long inf = 1'000'000'000'000'000'000;

inline long long mul(long long a, long long b) {
  return a <= inf / b ? a * b : inf;
}

inline long long add(long long a, long long b) {
  a += b;
  return a <= inf ? a : inf;
}

const int N = 200'009;

int n;
int a[N];

long long calc(int s) {
  long long res = 0;
  for (int i = 0; i < s; ++i) {
    res = add(res, a[i]);
  }
  for (int from = 0; from < n; from += s) {
    for (int k = 0; k < s; ++k) {
      int i = from + k;
      if (i >= n) {
        continue;
      }
      int j = from + s + k;
      int v = from / s + 2;
      if (j < n) {
        res = add(res, mul(a[i] - a[j], mul(v, v)));
      } else {
        res = add(res, mul(a[i], mul(v, v)));
      }
    }
  }
  return res;
}

int main() {
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  reverse(a, a + n);
  int ll = 0, rr = n + 1;
  while (rr - ll > 1) {
    int ss = (ll + rr) / 2;
    if (calc(ss) == inf) {
      ll = ss;
    } else {
      rr = ss;
    }
  }
  int l = ll + 1, r = n;
  while (l < r) {
    int s = (l + r) / 2;
    if (calc(s) + (long long)m * s > calc(s + 1) + (long long)m * (s + 1)) {
      l = s + 1;
    } else {
      r = s;
    }
  }
  printf("%lld\n", calc(l) + (long long)m * (l + n));
}


Measured memory_bytes: 1024