akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

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

        int dp[5][4005] = {};

        dp[0][0] = 1;
        for (int i = 1; i <= 4004; i++){
            dp[0][i] = 0;
        }

        rep(i, 4){
            for (int j = 0; j <= 4000; j++) {
                for (int k = 0; k <= min(j, 1000); k++) {
                    dp[i+1][j] += dp[i][j-k];
                }
            }
        }
        cout << dp[4][n] << endl;
        // printf("%d\n", N);
    }
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define ll long long
#define lli long long int
#define li long int
#define ld long double
#define vi vector<int>
#define vlli vector<lli>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define all(arr) arr.begin(), arr.end()
using namespace std;
const lli mod = 1e9 + 7;
const lli mod_ = 998244353;
const int INF = 1000000000;
const lli INF64 = (lli)1E18;
const int MAX = 1e5 + 5;

int main() {
	// ifstream cin("input.in");
	// ofstream cout("output.out");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, capacity, weight, value;
	cin >> n >> capacity;
	vlli dp(n*1000 + 1);
	fill(all(dp), INF64);
	dp[0] = 0;
	// dp[val] = minimum weights that can be taken to get value = val
	for(int item = 0; item < n; item++) {
		cin >> weight >> value;
		for(int val = dp.size()-1; val >= value; val--)
			dp[val] = min(dp[val], weight+dp[val-value]);
	}
	int ans = 0;
	for(int val = 0; val < dp.size(); val++) {
		if(dp[val] <= capacity)
			ans = val;
	}
	cout << ans;
	return 0;
}

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

int main(){
  int N;

  cin>>N;

  vector<int> v(N);
  vector<int> c(N);
  vector<int> a(N);

  int i;

  for(i=0;i<N;i++)
  cin>>v.at(i);

  for(i=0;i<N;i++)
  cin>>c.at(i);
  
  for(i=0;i<N;i++)
  a.at(i)=v.at(i)-c.at(i);

  int max=0;

  for(i=0;i<N;i++){
    if(a.at(i)>0)
    max+=a.at(i);
  }

  cout<<max<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i=0; i<(n); ++i)

int main() {
    int n,k; std::cin >> n >> k;
    int digits=0;
    while(n > 0){
        n /= k;
        ++digits;
    }
    std::cout << digits << std::endl;

    return 0;
}


Measured memory_bytes: 3564
H,W = map(int,input().split())
grid = []
vissible = []
for i in range(H):
  grid.append(input())
  vissible.append([True for i in range(W)])

cnt = 0
while True:
  flag = True
  for i in range(H):
    tmp = 0
    vis = 0
    for j in range(W):
      if vissible[i][j]:
        vis += 1
      if vissible[i][j] and grid[i][j] == '.':
        tmp += 1
    if vis and tmp == vis:
      for j in range(W):
        vissible[i][j] = False
      flag = False
  for j in range(W):
    tmp = 0
    vis = 0
    for i in range(H):
      if vissible[i][j]:
        vis += 1
      if vissible[i][j] and grid[i][j] == '.':
        tmp += 1
    if vis and tmp == vis:
      for i in range(H):
        vissible[i][j] = False
      flag = False
  if flag:
    break
  if cnt > 10:
    break
  cnt += 1
for i in range(H):
  flag = False
  for j in range(W):
    if vissible[i][j]:
      print(grid[i][j], end='')
      flag = True
  if flag:
    print()

Measured memory_bytes: 4724
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };

int n,ans = 0;
P r[100], b[100];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r[i].first >> r[i].second;
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i].second >> b[i].first;
	}
	sort(r, r + n);
	reverse(r, r + n);
	sort(b, b + n);
	bool used[100]{};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (!used[j] && r[j].first < b[i].second && r[j].second < b[i].first) {
				used[j] = true;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
#include <queue>
#define inf INT_MAX/2
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
struct office {
    int minl[100001], w, h, is, js, maps[500][500];
    bool used[500][500];
    office () {}
    office (int w, int h, int is, int js) : w(w), h(h), is(is), js(js) {
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
            used[i][j]=false;
        }
    }
    void calc(int r) {
        fill(minl, minl+(r+1), inf);
        if (maps[is][js]==0) return;
        minl[0]=0;
        draw(r);
    }
    bool isin(int x, int y) {
        return x>=0&&x<h&&y>=0&&y<w;
    }
    void draw(int r) {
        priority_queue<PP, vector<PP>, greater<PP> > que;
        que.push(make_pair(1,P(is,js)));
        int l=1, cnt=0;
        used[is][js]=true;
        while (!que.empty()) {
            PP p=que.top(); que.pop();
            l=max(l, p.first);
            int x=p.second.first, y=p.second.second;
            cnt++;
            if (cnt>=r) minl[r]=min(minl[r], l);
            else minl[cnt]=min(minl[cnt], l);
            for (int i=0; i<4; i++) {
                int nx=x+dx[i], ny=y+dy[i];
                if (isin(nx,ny)&&!used[nx][ny]) {
                    que.push(make_pair(maps[nx][ny],P(nx,ny)));
                    used[nx][ny]=true;
                }
            }
       }
    }
};
int main() {
    int r;
    while (scanf("%d",&r)) {
        if (!r) break;
        office o1, o2;
        int w, h, x, y;
        scanf("%d%d%d%d",&w,&h,&x,&y);
        o1=office(w,h,y-1,x-1);
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
            scanf("%d",&o1.maps[i][j]);
        }
        scanf("%d%d%d%d",&w,&h,&x,&y);
        o2=office(w,h,y-1,x-1);
        for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
            scanf("%d",&o2.maps[i][j]);
        }
        o1.calc(r); o2.calc(r);
        int res=inf;
        for (int i=r; i>=0; i--) {
            res=min(res, o1.minl[i]+o2.minl[r-i]);
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 7864
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
  tmp = ans
  if i == 0:
    for j in range(N):
      if j % 2 == 0:
        ans += A[j]
      else:
        ans -= A[j]
  else:
    ans = 2 * A[i - 1] - tmp

  tmp = ans
  print(ans, end = "")
  if i != N - 1:
    print(" ", end = "")
  else:
    print()

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

using namespace std;

const int maxn=1e3+5;
const int N=1e4+5;

int s[maxn],b[maxn],n,minn=N,book[maxn],weizhi[N];

int solve()
{
    int ans=0;
    for(int i=0;i<n;i++){
        b[i]=s[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++){
        weizhi[b[i]]=i;
    }
//    for(int i=1;i<=10;i++){
//        cout<<weizhi[i]<<" ";
//    }
//    cout<<endl;
    for(int i=0;i<n;i++){
        if(book[i]){
            continue;
        }
        int cnt=0,cixiao=N,cur=i,temp=0;
        while(1){
            book[cur]=1;
            int v=s[cur];
            temp+=v;
            cnt++;
            cixiao=min(cixiao,s[cur]);
            cur=weizhi[s[cur]];
            if(book[cur]){
                break;
            }
        }
        ans+=min(temp+(cnt-2)*cixiao,cixiao+temp+(cnt+1)*minn);
    }
    return ans;
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&s[i]);
        minn=min(s[i],minn);
    }
  //  cout<<minn<<endl;
    int ans=solve();
    cout<<ans<<endl;
    return 0;
}
/*
5
1 5 3 4 2
6
2 1 8 10 7 9
7
4 3 2 7 1 6 5
*/



Measured memory_bytes: 3240
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
#define INF 1000000001;

int main() {
  int n;
  cin >> n;
  long long a[n];
  int num4 = 0;
  int num2 = 0;
  int num0 = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 4 == 0) {
      num4++;
    }
    if (a[i] % 2 == 0) {
      num2++;
    }
  }
  num2 -= num4;
  num0 = n - num2 - num4;
  //cerr << num0 << " " << num2 << " " << num4 << endl;
  bool ans = true;

  if (num0 == num4 + 1) {
    if (num2 > 0) {
      ans = false;
    }
  }else if(num0 > num4 + 1){
    ans = false;
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int len_array,num_query;
    int b,m,e;
    scanf("%d",&len_array);
    vector<int> int_array(len_array,0);
    
    for(int i = 0;i < len_array;i++){
        cin  >> int_array[i];
    }
    
    scanf("%d",&num_query);
    for(int i = 0;i < num_query;i++){
        scanf("%d %d %d",&b,&m,&e);
        rotate(int_array.begin()+b,int_array.begin()+m,int_array.begin()+e);
    }
    
    for(int i = 0;i < len_array;i++){
        cout  << int_array[i];
        if(i != len_array-1) cout << " ";
        else cout << "\n";
    }
    
    
    
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> S(n);
    for (int i = 0; i < n; i++)
    {
        cin >> S[i];
    }

    int m;
    cin >> m;
    vector<int> T(m);
    for (int i = 0; i < m; i++)
    {
        cin >> T[i];
    }

    int ans = 0;
    for (int i = 0; i < m; i++)
    {
        vector<int>::iterator it = lower_bound(S.begin(), S.end(), T[i]);
        if (*it == T[i])
        {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3300
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")


x,a = MI()

if x < a:
    print(0)
else:
    print(10)

Measured memory_bytes: 3064
#include <cctype>
#include <cstdio>
#include <cstring>

using namespace std;

char S[100][16]; int N, H, Q, R, T[100], P[100];

int main()
{
    scanf("%d %d", &N, &H);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%s %d", S[i], &T[i]);
    }
    
    char F[2];
    
    for(int i = 0; i < N; i++)
    {
        int ptr = 0;
        
        while(ptr != strlen(S[i]))
        {
            printf("? %s\n", S[i]); fflush(stdout);
            
            scanf("%s", F); R++;
            
            if(tolower(S[i][ptr]) == tolower(F[0]))
            {
                S[i][ptr] = '_'; ptr++; Q++;
            }
            else
            {
                P[i]++;
                
                if(P[i] > T[i])
                {
                    H--; break;
                }
            }
        }
        
        if(H == 0)
        {
            printf("! Game Over\n"); return 0;
        }
    }
    
    int r = Q * 1000 / R;
    
    printf("! Game Clear %d.%d\n", r / 10, r % 10);
    
    return 0;
}

Measured memory_bytes: 3368
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
int p[100005];
int xy[100005][2];
int par[100005]={0};
int r[100005]={0};

int ufind(int s){
    if(par[s] == s ) return s;
    else{
        par[s] = ufind(par[s]);
        r[par[s]] = 1; 
        return par[s];
    }
}

int main(){
    int n,m;
    int s,t, ps, pt;
    cin >> n >>m;
    for(int i=1; i<n+1; i++){ cin >> p[i]; par[i]=i; }
    for(int i=0; i<m; i++){
        cin >> s >> t;
        xy[i][0] =s;
        xy[i][1] =t;
    }
    for(int i=0; i<m; i++){
        s = xy[i][0];
        t = xy[i][1];
        pt = ufind(t);
        ps = ufind(s);

        if( r[ps] > r[pt] ){
           par[ps] = pt;
        }else{
            par[pt] = ps;        
            if( r[pt] == r[ps] ) r[pt]++;
       }
    }
    int count = 0;
    for(int i=1; i<n+1; i++){
        ps = ufind(i);
        pt = ufind(p[i]);
        if( ps == pt) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 2176
use scanner::Scanner;

fn main() {
    let mut sc = Scanner::new();
    let c: String = sc.read();

    println!("{}", if c == "a" || c == "e" || c == "i" || c == "o" || c == "u" { "vowel" } else { "consonant" });
}

mod scanner {
    pub struct Scanner<'a> {
        s: String,
        words: ::std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new() -> Scanner<'a> {
            let s = String::new();
            let words = unsafe { ::std::mem::transmute(s.split_whitespace()) };
            Scanner { s: s, words: words }
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T {
            match self.words.next() {
                Some(x) => x.parse().ok().unwrap(),
                None => {
                    self.load();
                    self.read()
                }
            }
        }

        fn load(&mut self) {
            self.s.clear();
            ::std::io::stdin().read_line(&mut self.s).unwrap();
            self.words = unsafe { ::std::mem::transmute(self.s.split_whitespace()) };
        }
    }
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int N, K;
    cin >> N >> K;
    if (2 * K - 1 <= N) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> s;
  for (int i = 0; i < n; i++) {
    string k;
    cin >> k;
    if (s.count(k) == 0) {
      s[k] = 0;
    } else {
      s[k]++;
    }
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 19180
# Code for A - Hitachi String
# Use input() to fetch data from STDIN
s = input()
def solve():
    if len(s) % 2 != 0:
        print("No")
        return

    for i, x in enumerate(s):
        if i % 2 == 0 and not x == "h":
            print("No")
            return
        if i % 2 == 1 and not x == "i":
            print("No")
            return

    print("Yes")

solve()



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a;cin>>n;
  map<ll,ll> mp;
  rep(i,n) {
    cin>>a;
    if(a%2==1) mp[1]++;
    else {
      if(a%4==0) mp[4]++;
      else mp[2]++;
    }
  }
  bool isok=false;
  if(mp[2]==0) {
    if(mp[1]-mp[4]<2) isok=true;
  }
  else {
    if(mp[1]>0) {
      if(mp[1]-mp[4]<1) isok=true;
    }
    else isok=true;
  }
  print((isok)?"Yes":"No");
  return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n+2];
    int b[n+2]={0};
    for(int i=2;i<=n;i++)
    {
        cin>>a[i];
        b[a[i]]++;

    }
    for(int i=1;i<=n;i++)
    cout<<b[i]<<endl;
}



Measured memory_bytes: 5200
import string
string.ascii_lowercase

H,W = map(int,input().split())
A = ''
for i in range(H):
  A += input()
#print(A)

S = {}
for s in string.ascii_lowercase:
  if A.count(s) > 0:
    S[s] = A.count(s)
#print(S)

h1 = H//2
w1 = W//2
h2 = H - h1*2
w2 = W - w1*2
for i in range(h1*w1):
  flag = True
  for s in S.keys():
    if S[s] >= 4:
      S[s] -= 4
      flag = False
      break
  if flag:
    print('No')
    exit()
for i in range(h1*w2+w1*h2):
  flag = True
  for s in S.keys():
    if S[s] >= 2:
      S[s] -= 2
      flag = False
      break
  if flag:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 3768
N = int(input())
A = [int(input()) for _ in range(N)]

A.sort()

if N % 2 == 0:
    ans = sum(A[N//2:]) + sum(A[N//2 + 1:]) - sum(A[:N//2]) - sum(A[:N//2-1])
else:

    ans = sum(A[N//2:]) + sum(A[N//2+2:]) - 2 * sum(A[:N//2])
    
    ans = max(ans, 2 * sum(A[N//2+1:]) - sum(A[:N//2+1]) - sum(A[:N//2-1]))
    
print(ans)
       

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

ans = 1
for i in range(n):
  ans *= a[i]
  if ans > 1000000000000000000:
    ans = -1
    break

for i in range(n):
  if a[i] == 0:
    ans = 0

print(ans)


Measured memory_bytes: 21652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i< (n);i++)
using namespace std;

int main() {
  int x,a,b,c,d,e;
  cin>>x;
 for(int i=1;i*i<=x;i++){
   a=i*i;
 }
 for(int i=1;i*i*i<=x;i++){
   b=i*i*i;
 }
 for(int i=1;i*i*i*i*i<=x;i++){
   c=i*i*i*i*i;
 }
  
  for(int i=1;i*i*i*i*i*i*i<=x;i++){
  d=i*i*i*i*i*i*i;
 }
  
  for(int i=1;i*i*i*i*i*i*i*i*i<=x;i++){
   e=i*i*i*i*i*i*i*i*i;
 }
  int f=max({a,b,c,d,e});
  cout<<f<<endl;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3

YES = "Yes"  # type: str
NO = "No"  # type: str


def is_palindrome(S: str):
    return S == S[::-1]


def solve(S: str):
    N = len(S)
    former = S[:((N-1)//2)]
    latter = S[(((N+3)//2)-1):]
    return all(map(is_palindrome, [S, former, latter]))


def main():
    S = input()  # type: str
    print(YES if solve(S) else NO)


if __name__ == '__main__':
    main()


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

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

Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)

#define mp make_pair
#define P pair<int,int>
#define ll __int64
int t[100];
int a,b,c,d,e;
int main(){
	cin>>a>>b>>c>>d>>e;
	int ans=0;
	if(a<0){ans+=c*-a;a=0;}
	if(a==0){ans+=d;}
	ans+=e*(b-a);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

double d,e;	
int main(){
	while(1){
		cin>>d>>e;
		double ans=INFd;
		if(d==0&&e==0)break;
		for(int i=0;i<=d;i++){
			double tans=abs(sqrt((double)(i*i+(d-i)*(d-i)))-e);
			ans=min(ans,tans);
		}
		printf("%.10f\n",ans);
	}
	return 0;
}


Measured memory_bytes: 3212
package main

import (
	"fmt"
)

func max(x, y int) int {
	if x < y {
		return y
	}
	return x
}
func min(x, y int) int {
	if x > y {
		return y
	}
	return x
}
func findSharp(m [][]byte, x, y, h, w int) int {
	ret := 0
	for i := max(0, x-1); i <= min(x+1, h-1); i++ {
		if i == x {
			for j := max(0, y-1); j <= min(y+1, w-1); j++ {
				if m[i][j] == '#' {
					ret += 1
				}
			}
		} else {
			if m[i][y] == '#' {
				ret += 1
			}
		}

	}
	return ret
}
func main() {
	var H, W int
	m := make([][]byte, 50)

	fmt.Scanf("%d %d", &H, &W)
	for i := 0; i < H; i++ {
		var s string
		fmt.Scanf("%s", &s)
		m[i] = []byte(s)
	}

	ans := true
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if m[i][j] == '#' {
				if findSharp(m, i, j, H, W) <= 1 {
					ans = false
					break
				}
			}
		}
		if !ans {
			break
		}
	}
	if ans {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    if(N==1){
        p(1);
        return 0;
    }

    if(N==2){
        p(1);
        return 0;
    }

    vector<ll> X(N);
    vector<ll> Y(N);
    FOR(i, 0, N){
        cin >> X[i] >> Y[i];
    }

    ll min_count = inf;
    FOR(i, 0, N){
        FOR(j, 0, N){
            if(i==j) continue;
            ll dx = X[i]-X[j];
            ll dy = Y[i]-Y[j];

            ll count = 0;
            FOR(k, 0, N){
                bool is_free = false;
                FOR(l, 0, N){
                    if(k==l) continue;
                    if(X[k]+dx==X[l] && Y[k]+dy==Y[l]){
                        is_free = true;
                    }
                }
                if(!is_free) count++;
            }
            chmin(min_count, count);
        }
    }
    p(min_count);
    
    return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Poisonous Cookies
 */

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

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll a, b, c;
  scanf("%lld%lld%lld", &a, &b, &c);

  ll d = min(b, c);
  b -= d, c -= d;
  ll ans = d * 2 + b;
  
  if (c > 0) {
    ll e = min(a, c);
    ans += e;
    a -= e, c -= e;
    if (c > 0) ans++;
  }

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


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            for (int i = 1; i < n; i++)
            {
                arr[i] = LCM(arr[i - 1], arr[i]);
            }
            Console.WriteLine(arr[n - 1]);
        }

        static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }

        static int GCD(int a, int b)
        {
            int x, y, r;
            x = Math.Max(a, b);
            y = Math.Min(a, b);

            while (y > 0)
            {
                r = x % y;
                x = y;
                y = r;
            }
            return x;
        }
    }
}

Measured memory_bytes: 9228
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    int x[N],y[N];
    for(int i=0;i<N;i++) cin>>x[i]>>y[i];
    int max=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            int sum=0;
            if(i==j) continue;
            int p=x[j]-x[i];
            int q=y[j]-y[i];
            for(int k=0;k<N;k++){
                for(int l=0;l<N;l++){
                    if(p==x[k]-x[l]&&q==y[k]-y[l]) sum++;
                }
            }
            if(sum>max) max=sum;
        }
    }
    cout<<N-max;
}


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

using namespace std;

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

  long long n;
  cin >> n;
  long long t = 0, f = 0;
  if (n & 1) {
    cout << 0;
    return 0;
  }
  long long x = n;
  while (x) {
    t += x / 2;
    x /= 2;
  }
  x = n / 2;
  while (x) {
    f += x / 5;
    x /= 5;
  }
  cout << min(t, f);

  return 0;
}

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

const int N = 1000 * 1000 + 5;
int n, k;

int a[N];
int b[N];
int indeg[N];
vector <int> vec;
vector <int> adj[N];
int ans[N];
int seg1[N * 4];
pair <int, int> seg2[N * 4];
int seg3[N * 4];

void update1(int p, int id = 1, int s = 1, int e = n + 1) {
	if (e <= p || p < s) {
		return;
	}	
	if (e - s == 1) {
		seg1[id]++;
		return;
	}
	int md = (s + e) / 2;
	update1(p, id * 2, s, md);
	update1(p, id * 2 + 1, md, e);
	seg1[id] = seg1[id * 2] + seg1[id * 2 + 1];
}
int get1(int l, int r, int id = 1, int s = 1, int e = n + 1) {
//	cout << "42 " << l << " " << r << endl;
	if (e <= l || r <= s) {
		return 0;
	}
	if (l <= s && e <= r) {
		return seg1[id];
	}
	int md = (s + e) / 2;
	int ans = get1(l, r, id * 2, s, md);
	ans += get1(l, r, id * 2 + 1, md, e);
	return ans;
	
}
void build(int id = 1, int s = 1, int e = n + 1) {
	if (e - s == 1) {
		seg2[id] = {indeg[s], -s};
		return;
	}
	int md = (s + e) / 2;
	build(id * 2, s, md);
	build(id * 2 + 1, md, e);
	seg2[id] = min(seg2[id * 2], seg2[id * 2 + 1]);
}
void update2(int l, int r, int val, int id = 1, int s = 1, int e = n + 1) {
	if (e <= l || r <= s) {
		return;
	}
	if (l <= s && e <= r) {
	//	cout << "48 " << l << " " << r << " " << s << " " << e << endl;
		seg3[id] += val;
		seg2[id].first += val;
		return;
	}
	int md = (s + e) / 2;
	update2(l, r, val, id * 2, s, md);
	update2(l, r, val, id * 2 + 1, md, e);
	seg2[id] = min(seg2[id * 2], seg2[id * 2 + 1]);
	seg2[id].first += seg3[id];
	
}


int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		b[a[i]] = i;
	}

	for (int i = n; i; i--) {
		int x = get1(max(0, b[i] - k + 1), min(n + 1, b[i] + k));
		indeg[b[i]] = x;
		update1(b[i]);
	}
//	for (int i = 1; i <= n; i++) {
//		cout << "41 " << indeg[i] << endl;
//	}
	build();
//	for (int i = 1; i <= 15; i++) {
//		cout << "43 " << i << " " << seg2[i].first << " " << seg2[i].second << endl;
//	}
	for (int i = 1; i <= n; i++) {
		pair <int, int> p = seg2[1];
		int v = -p.second;
	//	cout << "45 " << v << endl;
		update2(max(0, v - k + 1), min(n + 1, v + k), -1);
		update2(v, v + 1, N);
	//	for (int j = 1; j <= 15; j++) {
	//		cout << "47 " << j << " " << seg2[j].first << " " << seg2[j].second << " " << seg3[j] << endl;
	//	}
		vec.push_back(v);
	}
	for (int i = n - 1; i >= 0; i--) {
	//	cout << vec[i] << endl;
		ans[vec[i]] = n - i;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 67056
/*****And nothing else matters!******/

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

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define setbits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define sp(x) fixed << setprecision(10) << x
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 2e5 + 10;

int main()
{
    fast;
    int n;
    cin >> n;
    ll ans = 0;
    f(i,1,n+1)
    {
        if(i % 3 and i % 5)
            ans += i;
    }
    cout << ans;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define INF 100100100
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll left = min(a, b);
  ll right = max(a, b);
  ll ans = 0;

  	ll margin = right - left;
  	if(margin%2 == 0) ans += margin/2;
  	else{
  		ans += min(n - right, left - 1);
  		ans += (margin + 1)/2;
  	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            sS = System.Console.ReadLine().Trim().Split(' ');
            for (int i = 0; i < sS.Length; i++)
            {
                int iInp = int.Parse(sS[i]);
                if (iInp % 2 == 0) { lstInp.Add(iInp); }        // 偶数のみ保持
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "APPROVED";
            for (int i = 0; i < lstInp.Count; i++)
            {
                if (lstInp[i] % 3 != 0 && lstInp[i] % 5 != 0) { sOut = "DENIED"; break; }
            }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i,k) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

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

ii dp[405][405];
ll v[405];

int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    
    for(int i = 1; i <= n; i++)
        dp[i][i] = {0, v[i]};
    for(int i = 1; i+1 <= n; i++)
        dp[i][i+1] = {v[i] + v[i+1], v[i] + v[i+1]};
    
    for(int k = 3; k <= n; k++)
        for(int i = 1; i+k-1 <= n; i++){
            ii r1 = {1e18, 1e18};
            for(int j = i; j < i+k-1; j++){
                ll a = dp[i][j].first + dp[j+1][i+k-1].first;
                ll b = dp[i][j].second + dp[j+1][i+k-1].second;
                //printf("%d (%d %d) (%d %d) = %lld %lld\n", k, i, j, j+1, i+k-1, a+b, b);
                r1 = min(r1, ii(a+b, b));
            }
            dp[i][i+k-1] = r1;
        }
    // for(int k = 1; k <= n; k++)
    //     for(int i = 1; i + k -1 <= n; i++)
    //         printf("dp[%d][%d] = %lld %lld\n", i, i+k-1, dp[i][i+k-1].first, dp[i][i+k-1].second);
    cout << dp[1][n].first << endl;
    // cout << dp[1][n].second << endl;
    
    return 0;
}   

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#include <limits.h>
#include <algorithm>  
#include <numeric>
#include <sys/resource.h>
 
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
using ll = long long;
 
const int precision = 15;
const int modulo =  1000000007; // 10^9 + 7
const ll lmodulo =  1000000007; // 10^9 + 7
 
const double EPS = 1e-9;
const ll inf = 1e18;


void increaseStack() {
	const rlim_t kStackSize = 50 * 1024 * 1024;   // min stack size = 50 MB
	struct rlimit rl;
	int result;

	result = getrlimit(RLIMIT_STACK, &rl);
	if (result == 0) {
		if (rl.rlim_cur < kStackSize) {
			rl.rlim_cur = kStackSize;
		    result = setrlimit(RLIMIT_STACK, &rl);
		    if (result != 0) {
		    	fprintf(stderr, "setrlimit returned result = %d\n", result);
		    }
		}
	}
}


void solve() {
	int n, k; cin >> n >> k;
	vector<int> candies(n);
	for (auto &it : candies) {
		cin >> it;
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(k + 1, 0l));

	dp[0][0] = 1l;
	for (auto i = 1; i <= n; ++i) {
		auto candy = candies[i - 1];
		for (auto j = 1; j <= k; ++j) {
			dp[i - 1][j] += dp[i - 1][j - 1];
			dp[i - 1][j] %= lmodulo;
		}

		for ( auto v = 0; v <= k; ++v) {
			ll minV = v - candy - 1 >= 0 ? dp[i - 1][v - candy - 1] : 0;
			dp[i][v] += dp[i - 1][v] - minV + lmodulo;
			dp[i][v] %= lmodulo;
		}
	}
	cout << dp[n][k];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(precision);
  cout.setf(ios_base::fixed);
  solve();
  return 0;
}


Measured memory_bytes: 80256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    int           MAX        = 32769;
    boolean       isPrime[] = new boolean[MAX];
    int           prime[]    = new int[MAX];
    List<Integer> primeList  = new ArrayList<Integer>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main();
        m.calcPrime();
        while (true) {
            int ans = 0;
            int in = sc.nextInt();
            if (in == 0) {
                break;
            }
            for (int i = 2; i < in; i++) {
                if (m.isPrime[i]) {
                    int b = in - i;
                    if (i > b) {
                        break;
                    }
                    if (m.isPrime[b]) {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }

    public void calcPrime() {
        int p = 0;
        for (int i = 2; i < MAX; i++)
            isPrime[i] = true;
        for (int i = 2; i < MAX; i++) {
            if (isPrime[i]) {
                prime[p++] = i;
                for (int j = 2 * i; j < MAX; j += i)
                    isPrime[j] = false;
            }
        }
    }
}

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

using namespace  std;

typedef long long ll;

ll dp[100000+5];

int main() {
    int N, W;
    scanf("%d%d",&N, &W);
    for(int i = 0 ;i < N; ++i){
        int w,v;
        scanf("%d%d",&w,&v);
        for(int j = W ; j>=w; --j){
            dp[j] = max(dp[j], dp[j-w] + v);
        }
    }
    printf("%lld\n",dp[W]);
    return 0;
}

Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int dp[n+1][k+1];
    int sum[n+1][k+1];
    dp[0][0]=1;
    for(int i=1;i<=k;i++)
    dp[0][i]=0;
    for(int i=1;i<=n;i++)
    {
        sum[i-1][0]=dp[i-1][0];
        for(int j=1;j<=k;j++)
        sum[i-1][j]=(0LL+sum[i-1][j-1]+dp[i-1][j]+mod)%mod;
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=sum[i-1][j];
            if(j-arr[i-1]-1>=0)
            dp[i][j]=(0LL+dp[i][j]-sum[i-1][j-arr[i-1]-1]+mod)%mod;
        }
    }
    cout<<(0LL+dp[n][k]+mod)%mod<<"\n";
    return 0;
}

Measured memory_bytes: 79104
///*****************************************************///
///*.......//
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

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

    int a[n];
    forn(i, n)
    {
        cin >> a[i];
    }

    int ans=0;
    for(int i=0; i<n-1; i++)
    {
        if(a[i]>a[i+1])
        {
            ans += a[i]-a[i+1];
        }
    }
    ans+=a[n-1];
    cout << ans << "\n";

    return 0;
}




Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int q,n,i,l,r;
  cin>>n>>q;
  string s;
  cin>>s;
  vector<int>pre(n+1,0);
  int state=0;
  for(i=0;i<n;i++)
    {
    if(state==0)
      {
      if(s[i]=='A')
        state=1;
      }
    else if(state==1)
      {
      if(s[i]=='C')
        state=2;
      else
        state=(s[i]=='A'?1:0);
      }
    else
      {
      if(s[i]=='A')
        state=1;
      else
        state=0;
      }
    pre[i+1]=pre[i]+(state==2?1:0);
    }
  while(q--)
    {
    cin>>l>>r;
    cout<<pre[r]-pre[l]<<endl;
    }
  }


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for(int i=0;i<n;i++){
			String line = br.readLine();
			String[] str = line.split(" ");
			int[] m = new int[3];
			int max=0;
			for(int j=0;j<3;j++){
				m[j]=Integer.parseInt(str[j]);
				if(m[j]>max)max=m[j];
			}
			int tmp=0;
			for(int j=0;j<3;j++)if(m[j]!=max)tmp+=m[j]*m[j];
			if(max*max==tmp)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 25856
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""

from collections import deque
import math
from collections import deque, defaultdict
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def round_up(a, b):
    """ a/b の切り上げ """
    c = (a + b - 1) / b
    return c


def lcm(a, b):
    """a,bの最小公倍数"""
    return a * b // gcd(a, b)


def floor(a, b):
    """floor(a/b) 整数値を返す"""
    c = (a - a % b)/b
    return int(c)


def main():
    L = int(input())
    a = L/3
    print(a*a*a)


if __name__ == '__main__':
    main()


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

int main(){
    int n;
    cin>>n;
    vector<vector<int>>a(n,vector<int>(26));
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        for(int j=0;j<s.size();j++){
            a[i][s[j]-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        int minv=20000;
        for(int j=0;j<n;j++){
            minv=min(minv,a[j][i]);
        }
        for(int j=0;j<minv;j++){
            cout<<char(i+'a');
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#define mp std::make_pair
#define pr std::pair<int,int>
#define gc() getchar()
typedef long long LL;

inline int read()
{
	int now=0,f=1;register char c=gc();
	for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
	for(;isdigit(c);now=now*10+c-'0',c=gc());
	return now*f;
}

int main()
{
	int B=read(),A=read(),C=read(); LL ans=0;
	int mn=std::min(C,A+B+1);
	if(A+B+1>=C) ans=A+C;
	else ans=(LL)A+B+1+A;
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;
typedef struct restaurant {
    string city;
    int rank;
    int ans;
} restaurant1;
bool cmp(const restaurant &a, const restaurant &b){
    if(a.city==b.city) return a.rank>b.rank;
    else return a.city < b.city;
}


int main(){
    int n;
    cin >>n;
    vector<restaurant1> vec(n);
    for (int i=0;i<n;i++){
        cin >>vec.at(i).city>>vec.at(i).rank;
        vec.at(i).ans=i+1;
    }
    sort(vec.begin(),vec.end(),cmp);
    for (int i=0;i<n;i++) cout << vec.at(i).ans << endl;
    
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 2e9;

ll dist[505][505];
ll dist2[505][505];

void warchall_floyd(int N){
    rep(k,N)rep(i,N){
        if(dist[i][k] == INF) continue;
        rep(j,N){
            if(dist[k][j] == INF) continue;
	        chmin(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
}

void warchall_floyd2(int N){
    rep(k,N)rep(i,N){
        if(dist2[i][k] == INF) continue;
        rep(j,N){
            if(dist2[k][j] == INF) continue;
	        chmin(dist2[i][j], dist2[i][k]+dist2[k][j]);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    ll l;
    cin >> n >> m >> l;
    rep(i,n){
        rep(j,n){
            dist[i][j] = INF;
            dist2[i][j] = INF;
        }
        dist[i][i] = 0;
        dist2[i][i] = 0;
    }
    rep(i,m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }
    warchall_floyd(n);
    rep(i,n){
        rep(j,n){
            if(dist[i][j] <= l) dist2[i][j] = 1;
        }
    }
    warchall_floyd2(n);
    int q;
    cin >> q;
    rep(i,q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        if(dist2[s][t] == INF) cout << -1 << endl;
        else cout << dist2[s][t] - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include<iostream>
#include<vector>
using std::cin;
using std::cout;
using std::endl;
int main(void){
  int H,W;
  cin >> H >> W;
  char pic[H][W];
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> pic[i][j];
    }
  }

  char picp[H + 2][W + 2];
  for(int i = 0; i < W + 2; i++){
    picp[0][i] = '#';
    picp[H + 1][i] = '#';
  }
  for(int i = 0; i < H + 2; i++){
    picp[i][0] = '#';
    picp[i][W + 1] = '#';
  }
 
  for(int i = 1; i <= H; i++){
    for(int j = 1; j <= W ; j++){
      picp[i][j] = pic[i - 1][j - 1];
    }
  }

  for(int i = 0; i < H + 2; i++){
    for(int j = 0; j < W + 2; j++){
      cout << picp[i][j];
      if(j == (W + 1)){
        cout << endl;
      }
    }
  } 
}
  

Measured memory_bytes: 256