akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define dbg(x) cout << #x"="<< (x) << endl
typedef long long ll;

int main(){
  ll n,a,b;cin>>n>>a>>b;
  string temp;
  ll sum,ans=0;
  rep(i,n){
    sum=0;
    temp= to_string(i+1);
    rep(j,temp.size()){
      sum+=stoi(temp.substr(j,1));
    }
    if(sum>=a&&sum<=b){
      ans+=i+1;
    }
  }
  cout<<ans<<endl;

}

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

# define ll long long

int frequency[26];

const int mod = 1e9 + 7;
ll kali(ll a, ll b){
  return ((a%mod) * (b%mod)) % mod;
}

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

  for(int i=0; i<s.size(); i++){
    frequency[s[i] - 'a']++;
  }

  ll ans = 1;
  for(int i=0; i<26; i++){
    ans = kali(ans, frequency[i]+1);
  }

  ans = (ans - 1 + mod) % mod;
  cout << ans << endl;
}

Measured memory_bytes: 512
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1
z = int((x**2 + y**2) ** (1/2))
x3 = x2 - y
y3 = y2 + x
x4 = x1 - y
y4 = y1 + x
print(x3, y3, x4, y4)


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

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

  int n,m;
  while(cin >> n >> m) {
    if((n|m) == 0) break;

    int a[n][m];
    for(int i=0;i<n;i++) {
      for(int j=0;j<m;j++) {
        cin >> a[i][j];
      }
    }
    vector< pair<int,int> > q_res;
    for(int j=0;j<m;j++) {
      int place_id = j+1;
      int popular = 0;
      for(int i=0;i<n;i++) {
        if(a[i][j]==1)
          popular++;
      }
      q_res.push_back(make_pair(-popular,place_id));
    }

    sort(q_res.begin(),q_res.end());

    for(int j=0;j<m;j++) {
      cout << q_res[j].second << (j+1 == m ? "\n" : " ");
    }
    q_res.clear();

  } // end while
}

Measured memory_bytes: 1596
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  LL k,n; cin>>k>>n;
  vector <LL> v(n);
  forn(i,n) cin>>v[i];
  LL an = 1e18;
  forn(i,n-1){
    an = min(an, k - v[i+1] + v[i]);
  }
  an = min(an, k - (v[0] + k - v[n-1]));
  cout<<an<<endl;
  return 0;
}



Measured memory_bytes: 1792
#include<algorithm>
#include<vector>
#include<list>
#include<iostream>
#include<utility>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<iterator>
#include<map>
#include<limits>
#include<iomanip>
#include<ctime>
#include<cmath>
 
const int INF=2147483647;
const long long MOD=1e9+7;
 
using namespace std;

bool canExchange(long long &a, long long &b, long long &c){
    if(a%2 || b%2 || c%2) return false;
    
    long long at=b/2+c/2;
    long long bt=a/2+c/2;
    long long ct=a/2+b/2;
    
    a=at;
    b=bt;
    c=ct;
    return true;
}


int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    long long a,b,c;
    cin>>a>>b>>c;
    int ct=0;
    for(int i=0; i<1000000; i++){
        //cout<<a<<" "<<b<<" "<<c<<endl;
        
        if(!canExchange(a,b,c)){
            cout<<ct;
            return 0;
        }
        ct++;
        
    }
    cout<<-1;
    
    
    return 0;
    
    
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from copy import deepcopy


def main():
    n, k, q = map(int, input().split())
    a = []
    for _ in range(q):
        a.append(int(input()))

    if k > q or k > 100000:
        for i in range(n):
            print('Yes')
        return

    a_point = [0] * n
    for i in a:
        a_point[i - 1] += 1

    for i in a_point:
        if k - (q - i) > 0:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9104
import numpy as np
from itertools import product
H, W, K = map(int, input().split())
G = np.array([list(map(int, list(input()))) for _ in range(H)])
 
ans = float('inf')
for pattern in product([0, 1], repeat=H - 1):
    # スライスで横方向への割り方を表現する
    div = [0] + [i for i, p in enumerate(pattern, start=1) if p == 1] + [10]
 
    # 横方向へ割った後、各ブロックについて縦方向にホワイトチョコの数を修正
    rows = []
    for i in range(len(div) - 1):
        rows.append(np.sum(G[div[i]: div[i + 1]], axis=0))
 
    # 縦方向にすでにK個より多いホワイトチョコが含まれている場合はどうにもならない
    if [r for r in rows if np.any(r > K)]:
        continue
 
    # 縦方向に貪欲に割っていく
    rows = [r.tolist() for r in rows]
    tmp_ans = 0
    counts = [0] * len(rows)
    w = 0
    while w < W:
        for r in range(len(rows)):
            counts[r] += rows[r][w]
        if any([c > K for c in counts]):
            counts = [0] * len(rows)
            w -= 1
            tmp_ans += 1
        w += 1
 
    # 横に割った分を加算
    tmp_ans += len(div) - 2
    ans = min(ans, tmp_ans)
 
print(ans)

Measured memory_bytes: 14600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s = r.readLine();
    int n = s.length();
    
    int[][] a = {{0, -1}, {1, 0}};
    int p = 0;
    
    for(int i = 0; i < n; i++)
    {
      p += a[i % 2][s.charAt(i) == 'g' ? 0 : 1];
    }

    System.out.println(p);

  }
}


Measured memory_bytes: 28536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		
      	if(s.charAt(s.length()-1) == 's') s += "es";
      	else s += "s";
      	
		System.out.println(s);
	}
}

Measured memory_bytes: 38472
import sys
import math
from collections import defaultdict,Counter

sys.setrecursionlimit(10**7)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    a,b,h,m=mis()
    if m==0:
        arg=min(h*30,360-h*30)
    else:
        H=h*30+m*0.5
        M=m*6
        l=min(abs(H-M),360-abs(H-M))
        arg=min(l,360-l)
    print((a**2+b**2-2*a*b*math.cos(math.radians(arg)))**0.5)
    


if __name__ == "__main__" :
    main()


Measured memory_bytes: 9808
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	cout << (A + B) % 24 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

const int N=5e5+5;
const int mod=998244353;
int n,k,fac[N],inv[N];

inline int mul(int x,int y) {return 1ll*x*y%mod;}
inline int C(int n,int m) {return mul(fac[n],mul(inv[m],inv[n-m]));}
inline int modpow(int x,int y,int res=1) {
	for(;y;y>>=1,x=mul(x,x)) if(y&1) res=mul(res,x);
	return res;
} 
int main() {
	scanf("%d %d",&n,&k),fac[0]=inv[0]=1;
	for(int i=1;i<N;++i) fac[i]=mul(i,fac[i-1]);
	for(int i=1;i<N;++i) inv[i]=modpow(fac[i],mod-2);
	int ans=0;
	for(int i=n;i<=k;++i) ans=(ans+C(k-1,i-1))%mod;
	printf("%d\n",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 4096
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int(), M = Reader.Int();
        var E = new bool[N, N];
        for (int i = 0; i < M; i++)
        {
            int a = Reader.Int() - 1, b = Reader.Int() - 1;
            E[a, b] = E[b, a] = true;
        }
        int ans = 0;
        var index = Enu.Range(1, N - 1).ToArray();

        do
        {
            int at = 0;
            foreach (int i in index)
                if (E[at, i]) at = i;
                else break;
            if (at == index[N - 2]) ans++;

        } while (NextPermutation(index));

        Console.WriteLine(ans);
    }

    static bool NextPermutation(int[] A)
    {
        for (int a = A.Length - 2; a >= 0; a--)
            if (A[a] < A[a + 1])
            {
                int b = A.Length - 1;
                while (A[a] >= A[b]) b--;
                var tmp = A[a]; A[a] = A[b]; A[b] = tmp;
                Array.Reverse(A, a + 1, A.Length - 1 - a);
                return true;
            }
        return false;
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 














int main()
{
     int k;
     cin>>k;
     ll res=0;
     for(int i=1;i<=k;i++)
     {
          for(int j=1;j<=k;j++)
          {
               for(int l=1;l<=k;l++)
               {
                    res+=__gcd(i,__gcd(j,l));
               }
          }
     }
     cout<<res;
}
























 
 
 
 
 

















Measured memory_bytes: 3588
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

using namespace std;
long long sum[200010],xo[200010];
int main()
{
    ios::sync_with_stdio(false);
    int N,a;
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>a;
        xo[i]=xo[i-1]^a;
        sum[i]=sum[i-1]+a;
    }
    int l=0;
    long long ans=0;
    for(int i=1;i<=N;i++){
        while(sum[i]-sum[l]!=(xo[i]^xo[l])){
            l++;
        }
        ans=ans+i-l;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
parseInt(x::Union{AbstractString,Char}) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::Union{AbstractString,Char}) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::Union{AbstractString,Char}) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::Union{AbstractString,Char}) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
parseMapBig(x::Array{SubString{String},1}) = map(parseBigInt, x)

function main()
    println((parseInt(readline())+parseInt(readline()))*parseInt(readline())÷2)
end
main()

Measured memory_bytes: 109436
import sys
n = int(sys.stdin.readline()[:-1])
S = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))
q = int(sys.stdin.readline()[:-1])
T = sorted(list(map(int, (sys.stdin.readline()[:-1]).split())))

count = 0
for i in T:
    x = 0
    while x < len(S):
        if i == S[x]:
            count += 1
            S = S[x:]
            break
        x += 1

print(count)

Measured memory_bytes: 8440
S = input()
 
INF = 10 ** 9 + 7
 
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1 # 後ろからi文字目までで、13で割った余りがjであるものの個数 0 → 3 → 43 → 543
# 実際にはjの部分に0 → 3 → 43 → 543が入るイメージだが、13で割って入れている
mul = 1 # 桁の部分を示す
 
for i in range(len(S)):
    x = S[-(i+1)] 
    if x == "?":
        for k in range(10): # ?の場合は、?の部分を0から9まで埋めた上で、余りが0から12のケースの個数を数える
            for j in range(13):
                dp[i+1][(mul * k + j) % 13] += dp[i][j] # 例えば43の時の個数は、3の時の個数に40の時の個数を加えたもの
                dp[i+1][(mul * k + j) % 13] %= INF
                
    else:
        k = int(x)
        for j in range(13):
            dp[i+1][(mul * k + j) % 13] += dp[i][j]
            dp[i+1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13
    
print(dp[len(S)][5])

Measured memory_bytes: 62300
#include<bits/stdc++.h>
    using namespace std;
    int main(){
    string a,b,c;
    double d=0;
    int h=0,e=1;
    cin>>a>>b;
    a=a+b;
    for(int i=a.size()-1;i>=0;i--){
    d=d+((int)a[i]-48)*e;
    e=e*10;
    }
    d=sqrt(d);
    h=(int )d;
    if(d==h) cout<<"Yes";
    else cout<<"No";
    cout<<"\n";
    }

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

using ll=long long;
struct X{
    int id;
    ll val;
    int sc;
    X* prev;
};
bool operator<(X lhs,X rhs){
    return lhs.val==rhs.val ? lhs.sc>rhs.sc : lhs.val<rhs.val;
}
using ll=long long;
const ll INF=1e15;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vector<ll> sum(n+1);
    partial_sum(a.begin(),a.end(),sum.begin()+1);

    vector<vector<X>> dp(n+1);
    dp[0].push_back(X{0,-INF,0,nullptr});

    for(int i=0;i<n;i++){
        vector<X> xs;
        for(int j=0;j<=i;j++){
            ll rangeSum=sum[i+1]-sum[j];
            X x=X{-1,rangeSum,n,nullptr};
            auto it=lower_bound(dp[j].begin(),dp[j].end(),x);
            if(it==dp[j].begin()) continue;
            it=prev(it);
            xs.push_back(X{i+1,rangeSum,(it->sc)+1,&(*it)});
        }
        sort(xs.begin(),xs.end());
        
        dp[i+1].push_back(xs[0]);
        int presc=xs[0].sc;
        for(int j=1;j<xs.size();j++){
            if(xs[j].sc<=presc) continue;
            presc=xs[j].sc;
            dp[i+1].push_back(xs[j]);
        }
    }
    // cerr<<"DP part finished"<<endl;
    X* x=&(dp[n].back());
    vector<int> res;
    
    while(x!=nullptr){
        res.push_back(x->id);
        x=x->prev;
    }
    res.pop_back();
    reverse(res.begin(),res.end());
    
    cout<<res.size()<<endl;
    for(int i=0;i+1<res.size();i++){
        cout<<res[i]<<(i+2==res.size() ? "" : " ");
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 9332
S=list(input())
count_0 = 0
count_1 = 0

#101010
for (i,item) in enumerate(S):
    if i%2 != 0 and item=="0":
        count_1 +=1


    elif i%2==0 and item=="1":
        count_1 +=1

#010101
for (i,item) in enumerate(S):
    if i%2 != 0 and item =="1" :
        count_0 +=1

    elif i%2==0 and item=="0":
        count_0 +=1

print(min(count_0,count_1))

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll n;
    cin >>n;
    vector<ll> ans(n+1,0);
    for(ll i=1;i<(ll)n;i++){
        ll temp;
        cin >>temp;
        ans[temp]++;
    }
    for(ll i=1;i<=(ll)n;i++){
        
        cout << ans[i] <<endl;
    }
}

Measured memory_bytes: 4768
n, m = gets.split.map(&:to_i)

if (n - m).abs > 1
  puts 0
else
  ans = 1
  for i in 1 .. n
    ans = ((ans * i) % (1E9 + 7)).to_i
  end
  for i in 1 .. m
    ans = ((ans * i) % (1E9 + 7)).to_i
  end
  if n == m
    ans = (ans * 2 % (1E9 + 7)).to_i
  end
  puts ans
end


Measured memory_bytes: 1916
n, k = map(int, input().split())
count = 0
ab = [list(map(int, input().split())) for _ in range(n)]
ab = sorted(ab)
i = 0
while count < k:
  a, b = ab[i]
  count += b
  i += 1
  if count >= k:
    print(a)
    break


Measured memory_bytes: 28640
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    vector<ll>prevDP(3,0);

    for(int i=0;i<n;i++){
        ll a[3];
        vector<ll>curDP(3,0);

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

        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k){
                    curDP[j]=max(curDP[j], a[j]+prevDP[k]);
                }
            }
        }
        prevDP = curDP;

    }

    cout<<max({prevDP[0],prevDP[1],prevDP[2]})<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,count=0;
    cin >> n;
    vector<int> p(n);
    for(int i=0;i<n;i++) cin>>p[i];

    for(int i=0;i<n;i++){
        if(p[i]!=i+1) count++;
    }
    if(count<=2){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define print(x) cout<<x<<"\n"
#define For(i,start,end) for(int i=start;i<end;i++)
#define cases() int tc;scanf("%d",&tc);For(sc,1,tc+1)
#define pb push_back
#define fastaf ios_base::sync_with_stdio(false); cin.tie(NULL);
#define sorta(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.begin(),v.end(),greater<int>())

int main(){
fastaf;
#ifndef ONLINE_JUDGE
freopen("C:/Users/vnagp/Documents/I_O/input.txt", "r", stdin);
freopen("C:/Users/vnagp/Documents/I_O/output.txt", "w", stdout);
#endif

int n;cin>>n;
map<string,int> m;
m["AC"]=0;
m["WA"]=0;
m["TLE"]=0;
m["RE"]=0;
For(i,0,n){
	string s;cin>>s;
	m[s]++;
}

cout<<"AC x "<<m["AC"]<<"\n";
cout<<"WA x "<<m["WA"]<<"\n";
cout<<"TLE x "<<m["TLE"]<<"\n";
cout<<"RE x "<<m["RE"];

return 0;
}

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

using namespace std;

typedef long long ll;

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

    ll a, b, c;
    cin >> a >> b >> c;

    if(a<=c){
        c = c-a;
        a = 0;
    }
    else {
        a-=c;
        c = 0;
    }
    if(b<=c){
        c-=b;
        b=0;
    }
    else {
        b-=c;
        c=0;
    }

    cout << a << " " << b;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

ll x[100010], v[100010], a[100010]/*時計*/, b[100010]/*反時計*/;

int main() {
	int n, i;
	ll c, ans = 0;

	cin >> n >> c;
	x[0] = 0;
	v[0] = 0;
	for (i = 1; i <= n; i++)cin >> x[i] >> v[i];

	x[n + 1] = c;
	v[n + 1] = 0;

	for (i = 1; i <= n; i++)a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
	for (i = 1; i <= n; i++)a[i] = max(a[i], a[i - 1]);

	for (i = n; i >= 1; i--)b[i] = b[i + 1] + v[i] - (x[i + 1] - x[i]);
	for (i = n; i >= 1; i--)b[i] = max(b[i], b[i + 1]);

	for (i = 1; i <= n; i++) {
		ans = max(ans, a[i]);
		ans = max(ans, a[i] - x[i] + b[i + 1]);

		ans = max(ans, b[i]);
		ans = max(ans, b[i] - (c - x[i]) + a[i - 1]);
	}

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

Measured memory_bytes: 3328
import java.io.*;
import java.util.*;

public class Main {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    public static void main(String[] args) {
        new Main().run();
        // Sworn to fight and die
    }

    void init() throws FileNotFoundException {
        if (1 > 0) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    public long check(int[] a, long start) {
        long current = start;
        for (int i = 0; i < a.length; i++) {
            if (current % a[i] != 0) {
                current = (current / a[i]) * a[i];
            }
        }
        return current;
    }

    public void solve() throws IOException {
        int k = readInt();
        int[] a = new int[k];
        long max = -1;
        for (int i = 0; i < k; i++) {
            a[i] = readInt();
            max = Math.max(max, a[i]);
        }

        if (a[k - 1] > 2) {
            out.print(-1);
            return;
        }

        long left = max;
        long right = Long.MAX_VALUE - 100;

        for (int zz = 0; zz < 150; zz++) {
            long mid = (left + right) / 2;
            long result = check(a, mid);
            if (result > 2) {
                right = mid - 1;
            } else {
                left = mid;
            }
        }

        long mmax = (right + left) / 2;


        left = max;
        right = Long.MAX_VALUE - 100;

        for (int zz = 0; zz < 150; zz++) {
            long mid = (left + right) / 2;
            long result = check(a, mid);
            if (result < 2) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }

        long mmin = (right + left) / 2;

        if (check(a, mmin - 1) == 2) {
            mmin--;
        }
        if (check(a, mmax + 1) == 2) {
            mmax++;
        }

        if (mmax < mmin) {
            out.print(-1);
            return;
        }
        out.print(mmin + " " + mmax);
    }
}

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

int d2;

struct Graph {
    struct Vertex { int n, d; };
    struct Edge { int i, n; };
    Graph(int n, int m) : v(n, { -1, -1 }), e(m), n(n), m(0) {}
    void add_edge(int i, int j) {
        e[m] = { j, v[i].n };
        v[i].n = m;
        m++;
    }
    void dfs(int i, int p) {
        if (i == 0) {
            v[i].d = d;
            f = 1;
            return;
        }
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            d++;
            dfs(o.i, i);
            d--;
            if (f) {
                v[i].d = d;
                return;
            }
        }
    }
    void dfs2(int i, int p) {
        if (v[i].d >= 0 && v[i].d < d2) return;
        k++;
        for (int j = v[i].n; j >= 0; j = e[j].n) {
            Edge& o = e[j];
            if (o.i == p) continue;
            dfs2(o.i, i);
        }
    }
    vector<Vertex> v;
    vector<Edge> e;
    int n, m;
    int d, f, k;
};

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

    int n;
    cin >> n;

    Graph g(n, (n - 1) * 2);

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        g.add_edge(a, b);
        g.add_edge(b, a);
    }

    g.d = 0;
    g.f = 0;
    g.dfs(n - 1, -1);

    d2 = (g.v[0].d + 1) / 2;
    int t = g.v[0].d % 2; // 1ならフェネックの手番

    g.k = 0;
    g.dfs2(0, -1);
    bool r = g.k - (g.v[0].d - d2 + 1) > (n - g.k) - d2 || (g.k - (g.v[0].d - d2 + 1) == (n - g.k) - d2 && t == 0);

    cout << (r ? "Fennec" : "Snuke") << endl;

    return 0;
}

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

using namespace std;

int main() {

    int n, q;
    cin >> n >> q;
    
    string s;
    cin >> s;
    
    int count = 0;
    vector<int> dp(n, 0);
    
    for(int i = 0; i < n-1; ++i) {
        if(s[i] == 'A' && s[i+1] == 'C') {
            count++;
        }
        dp[i] = count;
    }
    
    for(int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        int ans = dp[r-1] - (l-1 >= 0 ? dp[l-1] : 0);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int s1 = s / 100;
		int s2 = (s - s1 * 100) / 10;
		int s3 = s - s1 * 100 - s2 * 10;
		System.out.println(s1 + s2 + s3);
		scan.close();
	}

}


Measured memory_bytes: 23508
import Foundation

let nk = readLine()!
    .split(separator: " ")
    .map { Int($0)! }
let n = nk[0]
let k = nk[1]
let ax = readLine()!
    .split(separator: " ")
    .map { Int($0)! }

for i in 0..<n-k {
    print(ax[i] < ax[i + k] ? "Yes" : "No")
}


Measured memory_bytes: 27232
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int A = scanner.nextInt();
    int B = scanner.nextInt();
    long[] v = new long[N];
    long[] cv = new long[N];
    for (int i = 0; i < N; i++) v[i] = scanner.nextLong();

    Arrays.sort(v);
    reverse(v);
    for (int i = 0; i < N; i++) {
      cv[i] = v[i];
      if (i > 0) cv[i] += cv[i - 1];
    }
    HashMap<Long, Integer> freq = new HashMap<>();
    for (int i = 0; i < N; i++) freq.put(v[i], freq.getOrDefault(v[i], 0) + 1);
    int[] iv = new int[N];
    int inum = 1;
    iv[0] = 1;
    for (int i = 1; i < N; i++) {
      if (v[i] == v[i - 1]) inum++;
      else inum = 1;
      iv[i] = inum;
    }

    long[][] C = choose(N);
    int imax = 1;
    long smax = 0;
    long count = 0;
    for (int i = A; i <= B; i++) {
      long s = cv[i - 1];
      // if (s/i > smax/imax)
      if (s * imax > smax * i) {
        imax = i;
        smax = s;
        count = C[freq.get(v[i - 1])][iv[i - 1]];
      } else if (s * imax == smax * i) {
        count += C[freq.get(v[i - 1])][iv[i - 1]];
      }
    }
    System.out.println(smax * 1.d / imax);
    System.out.println(count);
  }

  private static void reverse(long[] a) {
    int i = 0;
    int j = a.length - 1;
    while (i < j) {
      swap(a, i, j);
      i++;
      j--;
    }
  }

  private static void swap(long[] a, int i, int j) {
    long tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }

  public static long[][] choose(int n) {
    long[][] C = new long[n + 1][n + 1];
    for (int i = 0; i <= n; i++) C[i][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= i; j++) {
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);
      }
    }
    return C;
  }
}


Measured memory_bytes: 23764
import math


def is_prime(x):
    for i in range(3, math.ceil((x ** 0.5) + 1), 2):
        if x % i == 0:
            return False
    return True

x = int(input())

if x == 2:
    print(2)
else:
    if x % 2 == 0:
        x += 1
    while (not is_prime(x)):
        x += 2
    print(x)

Measured memory_bytes: 3060
H,W = map(int, input().split())
C = [[int(i) for i in input().split()] for _ in range(10)]
A = [[int(i) for i in input().split()] for _ in range(H)]

from scipy.sparse.csgraph import floyd_warshall

C = floyd_warshall(C)

ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] < 0: continue
        ans += int(C[A[i][j]][1])

print(ans)

Measured memory_bytes: 17284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string str;
string target = "keyence";
int main(){
	cin>>str;
	if(str == target){
		puts("YES");
		return 0;
	}
	int n = str.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			//delete [i,j]
			string S = "";
			for(int k=0;k<n;k++){
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(str[k]);
			}
			if(S == target){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main{
  public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int second = Integer.parseInt(br.readLine());
		int h = second / (60 * 60);
                int m = second % (60 * 60) / 60;
                int s = second % (60 * 60) % 60;
                System.out.println(h + ":" + m + ":" + s);
	}
}

Measured memory_bytes: 17024
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}
bool f(string S) {
  string T(S.rbegin(), S.rend());
  if (S == T) return false;
  return true;
}

int main() {
  std::string S;
  cin >> S;
  if (f(S)) {
    cout << "No\n";
    return 0;
  }
  int N = S.size();
  string S_2(S.begin(), S.begin() + ((N-1)/2));
  if (f(S_2)) {
    cout << "No\n";
    return 0;
  }
  string S_3(S.begin() + ((N+3)/2) - 1, S.end());
  if (f(S_3)) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
}


Measured memory_bytes: 760
import sys
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
s = input()
readline = sys.stdin.readline
LR = [[int(i)-1 for i in readline().split()] for _ in range(q)] # 0-indexed

nums = [0]*(n-1)
for i in range(n-1):
    if s[i:i+2] == 'AC':
        nums[i] = 1

# 累積和を作る
tot = [0]*(len(nums)+1)
for i in range(len(nums)):
    tot[i+1] = tot[i]+nums[i]

for l,r in LR:
    print(tot[r]-tot[l])

Measured memory_bytes: 30476
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,w,h;
    cin>>h>>w>>a>>b;
    cout<<(h-a)*(w-b);
  
  
  
    return(0);
}

Measured memory_bytes: 256
"""
参考(神様)
https://atcoder.jp/contests/abc045/submissions/6046010
"""

###かぶるやつを考える.例えばあるマスのかぶり値が9だとしたら,
###周囲はすべて黒->j=9のが1つとカウントしてよい,他の値についても同様.

import sys
from collections import defaultdict,Counter

def input():
    return sys.stdin.readline().strip()

H,W,N = map(int,input().split())

covered = defaultdict(int)
vector = [(0,0),(0,1),(0,-1),(1,0),(-1,0),(1,1),(-1,-1),(1,-1),(-1,1)]

for _ in range(N):
    a,b = map(int,input().split())

    for i,j in vector:
        x = a+i-1
        y = b+j-1

        if 0 < x < H-1 and 0 < y < W-1:
            covered[(x,y)] += 1

num = Counter(covered.values())
##print(num)
num[0] = (H-2)*(W-2)-sum(num.values())

for i in range(10):
    print(num[i])

Measured memory_bytes: 166860
#include<stdio.h>
//using namespace std;
int main() {
 int H,W,j,i,k;
 i=1;
 j=1;
 k=1;
 while(1){
  scanf("%d %d",&H,&W);
  if(H==0 && W==0) break;  
    
    while(j<H+1){        //tate

      while(i<W+1){      //yoko
        i=i+1;
	
	if(j%2==1){
	  if(k==1){
            printf("#");
	    k=k-1;
	  }else{
	    printf(".");
	    k=k+1;
	  }
	}
	if(j%2==0){
          if(k==1){
            printf(".");
	    k=k-1;
	  }else{
	    printf("#");
	    k=k+1;
	  }
        }
        
      }//yoko
      
      printf("\n");
      j=j+1;
      i=1;
      k=1;
    }//tate
    
    i=1;
    j=1;
    printf("\n"); 
 }//1
}//main


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

int main() {
    string needle;
    cin >> needle;
    int n;
    cin >> n;
    string* str = new string [n];
    for (int i = 0; i < n; i++) {
        cin >> str[i];
        str[i] += str[i].substr(0, (int) needle.length() - 1);
    }
    int count = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= (int) (str[i].length() - needle.length()); j++) {
            string strj = str[i].substr(j, needle.length());
            if (needle == strj) {
                count++;
                break;
            }
        }
    }
    cout << count << endl;
    delete[] str;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;


class UnionFind{
    public:
        UnionFind(int N) : parent(N, -1) {}
        bool unite(int x, int y){
            x = find(x);
            y = find(y);
            if (x == y){return false;}
            if (parent[x] > parent[y]){swap(x, y);}
            parent[x] += parent[y];
            parent[y] = x;
        }
        int find(int x) {
            if (parent[x] < 0){return x;}
            return parent[x] = find(parent[x]);
        }
        int size(int x) {
            return -parent[find(x)];
        }
        private:
            vector<int> parent;
};


int main(void) {
    int n,m;cin>>n>>m;
    UnionFind uf(n+m);    
    rep(i,n){
        int k;
        cin>>k;
        rep(j,k){
            int tmp;cin>>tmp;
            uf.unite(i,tmp+n-1);
        }
    }
    int root = uf.find(0);
    rep(i,n){
       if(root != uf.find(i)){
           cout << "NO" << endl;
           return 0;
       }
    }
    cout << "YES" << endl;
    return 0;
}


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

int main() {
  int N;
  ll K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  ll d = pow(10, 9) + 7;
  ll ans = 0;
  ll sum1 = 0;
  ll sum2 = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (A[i] > A[j]) sum1++;
    }
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A[i] < A[j]) sum2++;
    }
  }
  
  ans += K * sum1 % d;
  ans += (K * (K - 1) / 2) % d * (sum2);
  ans %= d;
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
n,p = map(int, input().split())
s = input()
ans=0

rem=[0]*p
remls=[0]*n
remnow=0
for i in range(n-1,-1,-1):
    remnow = (remnow+int(s[i])*pow(10, n-1-i, p))%p
    rem[remnow]+=1
    remls[i]=remnow

ans=0
remnow2=0
remdiff=1
for i in range(n-1,-1,-1):
    remdiff2=(remdiff-remnow2)%p
    idx=-remnow2*pow(remdiff2,p-2,p)%p
    ans+=rem[idx]
    remnow2-=int(s[i])
    remnow2%=p
    remnow2*=pow(10,p-2,p)
    remnow2%=p
    remdiff-=int(s[i])
    remdiff%=p
    remdiff*=pow(10,p-2,p)
    remdiff%=p
    rem[remls[i]]-=1

if p==2:
    ans=n*(n+1)//2
    for i in range(n):
        if int(s[i])%2:
            ans-=(i+1)

if p==5:
    ans=n*(n+1)//2
    for i in range(n):
        if int(s[i])%5:
            ans-=(i+1)


print(ans)

Measured memory_bytes: 45260
n, a, b = map(int, input().split())
allr = abrr = 1

for i in input():
        if i=="a":
                if allr<=a+b:
                        print("Yes")
                        allr += 1
                else: print("No")
        elif i=="b":
                if allr<=a+b and abrr<=b:
                        print("Yes")
                        allr += 1
                else: print("No")
                abrr += 1
        else: print("No")


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

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


def main():
    # Failed to predict input format
    c = [input() for _ in range(2)]
    print(YES if c == [ci[::-1] for ci in c[::-1]] else NO)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = a.sort
b.reverse!
a_count = 0
aa = a.dup
aa.each do |a_i|
  a_count += a.count { |a_j| a_j < a_i }
  a.delete_at(0)
end
b_count = 0
b.each do |b_i|
  b_count += b.count { |b_j| b_j < b_i }
end
puts ( a_count * k + b_count * k * (k - 1) / 2 ) % ( 10**9 + 7 )

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

int main() {
  int n; ll k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  vector<int> path;
  vector<int> order(n + 1, -1);
  int v = 1;
  while (order.at(v) == -1) {
    order.at(v) = path.size();
    path.push_back(v);
    v = a.at(v - 1);
  }

  int period = path.size() - order.at(v);
  int before = order.at(v);
  if (k < before) {
    cout << path.at(k) << endl;
  } else {
    k -= before;
    k %= period;
    cout << path.at(before + k) << endl;
  }

  return 0;
}

Measured memory_bytes: 5860
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  vector<int> t(3);
  cin >> t[0] >> t[1] >> t[2];
  sorti(t);
  cout << t[0] + t[1] << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int binarySearch(int);
int N,A[100000];
int main(){
  int i,M,key,l=0,c;

  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  scanf("%d",&M);
  for(i=0;i<M;i++){
    scanf("%d",&key);
    c=binarySearch(key);
    if(c>=0 && c<=100000)
      l++;
  }
  printf("%d\n",l);
  return 0;
}

int binarySearch(int key){
  int left=0;
  int right=N;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(A[mid]==key) return mid;
    else if(key<A[mid])
      right=mid;
    else
      left=mid+1;
  }
  if(A[mid]!=key) return -1;
}
    

Measured memory_bytes: 984
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String[] c = str.split("");
    String[] op = new String[4];
    op[3] = "=";
    int[] num = new int[4];
    int result = 0;
    StringBuilder answer = new StringBuilder();
    for(int i = 0; i < 4; i++) {
      num[i] = Integer.parseInt(c[i]);
    }
    outside: for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 2; j++) {
        for(int k = 0 ; k < 2; k++) {
          if(i == 0) {
            op[0] = "+";
            result += (num[0] + num[1]);
          } else {
            op[0] = "-";
            result += (num[0] - num[1]);
          }
          if(j == 0) {
            op[1] = "+";
            result += num[2];
          } else {
            op[1] = "-";
            result -= num[2];
          }
          if(k == 0) {
            op[2] = "+";
            result += num[3];
          } else {
            op[2] = "-";
            result -= num[3];
          }
          if(result == 7) {
            for(int l = 0; l < 4; l++) {
              answer.append(Integer.toString(num[l]));
              answer.append(op[l]);
            }
            answer.append("7");
            System.out.println(answer);
            break outside;
          } else {
            result = 0;
          }
        }
      }
    }
  }
}


Measured memory_bytes: 21844
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);


const [a, b, k] = input[0].split(' ').map((x : string) : number => +x);

let kk = k;
if (k <= a){
    console.log(a-k,b);
}else{
    if (k-a <= b){
        console.log(0,b-(k-a));
    }else{
        console.log(0,0);
    }
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000
#define EPS 1e-10
#define MOD 1000000007
using namespace std;
typedef pair<int,int> P;

int w, h, s;
int u[32][32];
int dp[32][32][32][32];
int tab[32][32];

int func(int h1, int w1, int h2, int w2, int x){
	if(h1 >= 1 && w1 >= 1){
		if(tab[h2][w2]+tab[h1-1][w1-1]-tab[h2][w1-1]-tab[h1-1][w2] < x) return -INF;
	} else if(h1 >= 1 && w1 == 0){
		if(tab[h2][w2]-tab[h1-1][w2] < x) return -INF;
	} else if(h1 == 0 && w1 >= 1){
		if(tab[h2][w2]-tab[h2][w1-1] < x) return -INF;
	} else{
		if(tab[h2][w2] < x) return -INF;
	}
	if(h1==h2&&w1==w2&&u[h1][h2] >= x) return 1;
	if(dp[h1][w1][h2][w2] != INF) return dp[h1][w1][h2][w2];
	int ret = 1;
	for(int i = h1; i <= h2-1; i++) ret = max(ret,func(h1,w1,i,w2,x)+func(i+1,w1,h2,w2,x));
	for(int i = w1; i <= w2-1; i++) ret = max(ret,func(h1,w1,h2,i,x)+func(h1,i+1,h2,w2,x));
	dp[h1][w1][h2][w2] = ret;
	return ret;
}

void solve(){
	int sum = 0;
	rep(i,h) rep(j,w) cin >> u[i][j];
	rep(i,h) rep(j,w) sum += u[i][j];
	rep(i,h) rep(j,w) tab[i][j] = u[i][j];
	rep(i,h) for(int j = 1; j < w; j++) tab[i][j] += tab[i][j-1];
	for(int i = 1; i < h; i++) rep(j,w) tab[i][j] += tab[i-1][j];
	rep(j,32) rep(k,32) rep(l,32) rep(l1,32) dp[j][k][l][l1] = INF;
	int ans = func(0,0,h-1,w-1,sum-s);
	int st = 0, en = 200000, i;
	while(true){
		if(en-st==1) break;
		i = (st+en)/2;
		rep(j,32) rep(k,32) rep(l,32) rep(l1,32) dp[j][k][l][l1] = INF;
		int p = func(0,0,h-1,w-1,sum-s+i);
		if(p >= ans){
			st = i;
		} else{
			en = i;
		}
	}
	cout << ans << " " << st << endl;
}

int main(){
	while(cin >> h >> w >> s){
		if(w==0&&h==0&&s==0) break;
		solve();
	}
}

Measured memory_bytes: 5272
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;
 
int main(){
	int n,m;
	cin >> n >> m;
	int x,y;
	int left=-1,right=999999;
	for(int i=0;i<m;i++){
		cin >> x >> y;
		left=max(left,x);
		right=min(right,y);
	}
	int ans=right-left+1;
	if(left>right)ans=0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256