akhauriyash/Code-Regression huggingface dataset:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	li=[]
	for i in range(n):
		a,b=map(int,input().split())
		li.append((a,b))
	li.sort(key=lambda x:x[1])
	
	ans="Yes"
	now=0
	for a,b in li:
		now+=a
		if now>b:
			ans="No"
			break
	
	print(ans)



if __name__ == '__main__':
	main()


Measured memory_bytes: 63312
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    ans, i = 0, 1
    for a in A:
        if a != i:
            ans += 1
        else:
            i += 1

    if ans == N:
        print(-1)
    else:
        print(ans)


main()


Measured memory_bytes: 17976
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

bool flag=false;
bool used[705][705];
vector<int> path[705];
int color[705];
int t[2];
bool dp[705];
vector<P> v1;

bool check(int pos,int c){
	if(color[pos]!=-1){
		if(color[pos]==c)return true;
		return false;
	}
	color[pos]=c;
	t[c]++;
	for(auto to:path[pos]){
		if(!check(to,1-c))return false;
	}
	return true;
}

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	int su[2]={0};
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		a--,b--;
		used[a][b]=true;
		used[b][a]=true;
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i==j || used[i][j])continue;
			path[i].push_back(j);
		}
	}
	memset(color,-1,sizeof(color));
	for(i=0;i<n;i++){
		if(color[i]!=-1)continue;
		memset(t,0,sizeof(t));
		if(!check(i,0)){
			cout<<-1<<endl;
			return 0;
		}
		v1.push_back(make_pair(t[0],t[1]));
	}
	
	memset(dp,false,sizeof(dp));
	dp[0]=true;
	for(auto node:v1){
		a=node.first,b=node.second;
		for(i=n;i>=0;i--){
			if(!dp[i])continue;
			dp[i]=false;
			dp[i+a]=true,dp[i+b]=true;
		}
	}
	int s=1e9;
	for(i=0;i<=n;i++){
		if(!dp[i])continue;
		b=i,c=n-i;
		a=b*(b-1)/2+c*(c-1)/2;
		s=min(s,a);
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int x,a,b;
cin>>x>>a>>b;
if(b-a>x)cout<<"dangerous"<<endl;
else if(b-a>0)cout<<"safe"<<endl;
else cout<<"delicious"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
ll a[310];
bool ok[130];
int bit_choice[64];

void solve(){
    cin >> n;
    ll S=0,X=0;
    rep(i,n){
        cin >> a[i];
        X^=a[i];
    }
    X^=(a[0]^a[1]);
    S=a[0]+a[1];

    //cout << S << " " << X << endl;
    
    per(i,64){
        if(X&(1ll << i)) {
            S-=(1ll << i);
            bit_choice[i]=2;
        }
        else ok[i+1]=1;
    }
    ll Y=0;
    //cout << S << " " << X << endl;
    rep(i,64){
        if(S&(1ll << i)) if(ok[i]) {
            Y+=(1ll << i);
            bit_choice[i-1]=1;
        }
    }
    if(S!=Y){
        cout << -1 << endl;
        return;
    }
    ll ans=0;
    rep(i,64){
        if(bit_choice[i]==1) ans+=(1ll << i);
    }
    if(ans>a[0]){
        cout << -1 << endl;
        return;
    }
    per(i,64){
        if(bit_choice[i]==2) if(ans+(1ll << i)<a[0]) ans+=(1ll << i);
    }
    if(ans==0) cout << -1 << endl;
    else cout << a[0]-ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3628
K = int(input())
if (K%2==0)or(K%5==0):
  print(-1)
  
else:
  x = 7
  i = 1
  x %= K
  while (x!=0)or(i>=10**7):
    x += (7%K) * pow(10,i,K)
    x %= K
    i += 1
  if i<10**7:  
    print(i)
  else:
    print(-1)

Measured memory_bytes: 63472
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a= in.nextInt();
        int b= in.nextInt();
        int max=Integer.MIN_VALUE;
        max=Math.max(max, a+b);
        max=Math.max(max, a-b);
        max=Math.max(max, a*b);
        System.out.println(max);
    }
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

// 約数リスト
vector<ll> get_divisors(const ll n) {
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m;
  cin >> n >> m;

  auto divs = get_divisors(m);

  ll ans = 1;

  FORm(it, divs) {
    if (*it <= m / n) {
      chmax(ans, *it);
    }
  }

  cout << ans << endl;

  return 0;
}


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

int main()
{
	string x, y; cin >> x >> y;
	sort(x.begin(), x.end());
	sort(y.begin(), y.end() , greater<char>());
	if (x < y)
		cout << "Yes";
	else cout << "No";
}

// 

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
int n;
cin >> n;
vector<int>a(n);
int ans =0 ;
for(int i=0;i<n;i++)cin >> a.at(i);
int che =1;
for(int i=1;i<n;i++){
    if(a.at(i-1)==a.at(i))che++;
    else{
        ans+=che/2;
        che=1;
    }
    if(i==n-1)ans+=che/2;
}

cout<<ans<<endl;
}
 


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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

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

  int rnum = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == '(') rnum++;
    else if(s[i] == ')' && rnum > 0) rnum--;
  }

  int lnum = 0;
  for(int i = n-1; i >= 0; --i){
    if(s[i] == ')') lnum++;
    else if(s[i] == '(' && lnum > 0) lnum--;
  }

  string ans = "";
  for(int i = 0; i < lnum; ++i){
    ans += '(';
  }
  ans += s;
  for(int i = 0; i < rnum; ++i){
    ans += ')';
  }

  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import sys

num = input().split()
participant = int(num[0])
init_point = int(num[1])
correct = int(num[2])

tmp = [0]*participant

for i in range(correct):
  answer_person = int(input())-1
  tmp[answer_person] += 1

for i in tmp:
  if i<=correct-init_point:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 4680
#include <stdio.h>

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int H, i, A[10000];

  scanf("%d",&H);
  for(i=1; i<=H; i++){
    scanf("%d",&A[i]);
  }
  for(i=1; i<=H; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(parent(i)>=1){
      printf("parent key = %d, ", A[parent(i)]);
    }
    if(left(i)<=H){
      printf("left key = %d, ", A[left(i)]);
    }
    if(right(i)<=H){
      printf("right key = %d, ", A[right(i)]);
    }
    printf("\n");
  }
  
  return 0;
}
		      

Measured memory_bytes: 608
//  Mayank Agarwal
//  IIIT Hyderabad



#include<bits/stdc++.h>
using namespace std;
const long long int M = 1000000007; 
#define ll long long int
#define ld double
#define pb push_back
#define mp make_pair
ll power(ll x, ll y,  ll p) 
{ 
    ll res = 1;      
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1;x = (x*x) % p; 
    } return res%p; 
} 
ll modinver(ll a,ll b)
{
    return (power(a,1,M)*power(b,M-2,M))%M;
}
void SieveOfEratosthenes(int n) 
{   
    bool prime[10005]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
} 
ll n,a[102],k;
ll dp[100005][3];
ll kstonesans(ll stones,ll chance)
{
	if(dp[stones][chance]!=-1)
		return dp[stones][chance];
	if(chance==0)
	{
		if(stones<a[0])
		{
			dp[stones][chance]=0;
			return 0;
		}
		else
		{
			ll ans=0;
			for (int i = 0; i < n; ++i)
			{
				if(stones>=a[i])
				{
					ans=ans||kstonesans(stones-a[i],1-chance); 
				}
				else{
					break;
				}
			}
			dp[stones][chance]=ans;
			return ans;
		}
	}
	else
	{
		if(stones<a[0])
		{
			dp[stones][chance]=1;
			return 1;
		}
		else{
			ll ans=1;
			for (int i = 0; i < n; ++i)
			{
				if(stones>=a[i])
				{
					ans=ans&&kstonesans(stones-a[i],1-chance); 
				}
				else{
					break;
				}
			}
			dp[stones][chance]=ans;
			return ans;
		}
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for (int i = 0; i <=100002; ++i)
    {
    	dp[i][0]=-1;
    	dp[i][1]=-1;
    }
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    if(kstonesans(k,1)==0)
    {
    	cout<<"First\n";
    }
    else
    {
    	cout<<"Second\n";
    }

}


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

int main(){
	int n,m,l;
	cin >> n >> m >> l;
	int a[n][m],b[m][l];
	long long c[n][l];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			cin >> b[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<l;j++){
			c[i][j]=0;
			for(int k=0;k<m;k++){
				c[i][j]=c[i][j]+a[i][k]*b[k][j];
			}
			cout << c[i][j];
			if(j<l-1){
				cout << " ";
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, q, s, e;

typedef struct node{
    ll s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(ll ss, ll ee, ll v, ll p){
        s = ss, e = ee, val = v, pos = p;
    }
} node;
 
ll occs[500005], triee[500005], ans[500005];
 
void update(ll x, ll val){
    while(x <= n){
        triee[x] += val;
        x += x&(-x);
    }
}
 
ll query(ll x){
    ll res = 0;
    while(x > 0){
        res += triee[x];
        x -= x&(-x);
    }
    return res;
}

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

    vector<node> v;
    cin >> n >> q;
    REP(i, 0, n){
        cin >> s;
        v.push_back(node(i + 1, i + 1, s, -1));
    }
    REP(i, 0, q){
        cin >> s >> e;
        v.push_back(node(s, e, 0, i));
    }
 
    sort(v.begin(), v.end());
 
    REP(i, 0, (int)v.size()){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
 
    REP(i, 0, q){
        cout << ans[i] << endl;
    }

}

//cout.flush()

Measured memory_bytes: 46904
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

int _find(vector<string> &arr,int n){
    set<string> s;
    if(n==0){return 1;}
    s.insert(arr[0]);
    int lastCh=arr[0].back();
    for(int i=1;i<n;i++){
        if(s.count(arr[i])){
            return false;
        }
        if(arr[i][0]!=lastCh){
            return false;
        }
        s.insert(arr[i]);
        lastCh=arr[i].back();
    }
    return 1;
}

void solve(){
    
    int a,b,k;
    cin>>a>>b>>k;
    set<int> s;
    int cnt=0;
    for(int i=a;i<=b && cnt++<k;i++){
        s.insert(i);
    }
    cnt=0;
    for(int i=b;i>=a && cnt++<k;i--){
        s.insert(i);
    }
    for(auto i:s){
        cout<<i<<endl;
    }
}




int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const long long MOD = 1000000007;

void solve(long long N, long long K, std::vector<long long> a){
    vector<vll> dp(N+1, vll(K+1, 0));
    REP(i, N+1){
        dp[i][0]=1;
    }
    REP(i, N){
        for(ll k=1; k<= K; k++){
            if(k - a[i]-1>=0){
                dp[i+1][k] = (dp[i][k] + dp[i+1][k-1] - dp[i][k-a[i]-1] +MOD) % MOD;
            }
            else{
                dp[i+1][k] = (dp[i][k] + dp[i+1][k-1]) % MOD; 
            }
        }
    }
    cout << dp[N][K]<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b){
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}


// ll memo[2020][2020];
// int pascal_triangle(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int factrial(int n){
//   if(n == 0) return 1;
//   return n*factrial(n-1);
// }

// int divisor(int a){
//   int cnt = 0;
//   for(int i=1; i <= a; i++) if(a%i == 0) cnt++;
//   return cnt;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }





int main(){
  int N;
  cin >> N;
  vector<int> l(N);
  vector<P> v;
  rep(i,N){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      v.push_back(make_pair(i,j));
    }
  }
  int ans = 0;
  rep(i,v.size()){
    int left = v[i].second;
    int sum = l[v[i].first] + l[v[i].second];
    ans += int( lower_bound(min(l.begin()+left+1,l.end()),l.end(),sum)  - min(l.begin()+left+1,l.end()));
  }
  cout << ans << endl;
  
}
  





Measured memory_bytes: 18796
#include<stdio.h>
int main()
{
	int a;
	while(scanf("%d",&a)!=EOF)
	{
		char A[a];
		char B[a];
		char C[a];
		scanf("%s%s%s",A,B,C);
		int count=0;
		for(int i=0;i<a;i++)
		{
			if(A[i]==B[i]&&B[i]==C[i]) count+=0;
			else if(A[i]==B[i]&&B[i]!=C[i]) count++;
			else if(A[i]==C[i]&&A[i]!=B[i]) count++;
			else if(B[i]==C[i]&&A[i]!=C[i]) count++;
			else                            count+=2;
		}
		printf("%d\n",count);
	}
	return 0;
 } 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

void solve()
{
	int R, C;
	while(cin >> R >> C, R || C)
	{
		vector< bitset<10001> > senbei(R);
		for(int i = 0; i < R; ++i)
		{
			for(int j = 0; j < C; ++j)
			{
				int a;
				cin >> a;
				if(a == 1)
				{
					senbei[i].set(j);
				}
			}
		}
		int k = 1;
		for(int i = 0; i < R; ++i)
		{
			k <<= 1;
		}
		--k;
		int max_sum = 0;
		for(int i = 0; i <= k; ++i)
		{
			vector< bitset<10001> > senbei_copy = senbei;
			int b = i;
			int count = 0;
			while(b)
			{
				if(b & 1)
				{
					senbei_copy[count] = ~senbei_copy[count];
				}
				b >>= 1;
				++count;
			}
			int sum = 0;
			for(int i = 0; i < C; ++i)
			{
				int sum1 = 0;
				int sum2 = 0;
				for(int j = 0; j < R; ++j)
				{
					if(senbei_copy[j][i])
					{
						++sum1;
					}
					else
					{
						++sum2;
					}
				}
				sum += max(sum1, sum2);
			}
			max_sum = max(max_sum, sum);
		}
		cout << max_sum << endl;		
	}
}

int main()
{
	solve();
	return(0);
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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 */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) (x).erase(unique(all(x)), (x).end())
#define int long long

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    int k, s, cnt = 0;
    cin >> k >> s;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            if (0 <= s - i - j && s - i - j <= k)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	string N;
	cin >> N;
	int s=N.size();
	int K;
	cin >> K;
	int dp0[110][5]={0}, dp1[110][5]={0};
	dp0[0][0]=1;
	rep(i,s){
		int n=N[i]-'0';
		rep(j,4){
			if(n!=0){
				dp0[i+1][j+1]+=dp0[i][j];
				dp1[i+1][j]+=dp0[i][j]+dp1[i][j];
				dp1[i+1][j+1]+=dp0[i][j]*(n-1)+dp1[i][j]*9;
			}
			else{
				dp0[i+1][j]+=dp0[i][j];
				dp1[i+1][j]+=dp1[i][j];
				dp1[i+1][j+1]+=dp1[i][j]*9;
			}
		}
	}
	cout << dp0[s][K]+dp1[s][K] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <regex>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

template <class... T>
void output__(T ...a) {
  for(auto v: {a...}) {
    cout << v << " ";
  }
  cout << endl;
}

int main(){
  int in(a, b) out(2 * b - a);
}


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

if N < (A + B - 1) or N > (A * B):
	print(-1)
	exit(0)

if B == 1 and A == N:
	seq = [str(n) for n in range(1,N+1)]
	print(' '.join(seq))
	exit(0)

seq = [str(num)for num in range(N-A+1,N+1)]
dif = (A * B - N)
div = A - (dif // (B-1))
mer = (dif % (B-1))

n = N - A
for i in range((B-1) - mer):
	for j in range(n-(div)+1,n+1):
		seq.append(str(j))
	n -= (div)

for i in range(mer):
	for j in range(n-div+2,n+1):
		seq.append(str(j))
	n -= (div - 1)

print(' '.join(seq))


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

mii fats(int x) {
	mii fs;
	for (int i = 2;i * i <= x;i++) {
		while (x % i == 0) {
			fs[i]++;
			x /= i;
		}
	}
	if (x > 1) fs[x]++;
	return fs;
}

pair<ll, ll> eucl(ll a, ll b) {
	if (b == 0) return make_pair(1ll, 0ll);
	ll x, y;
	tie(x, y) = eucl(b, a % b);
	return make_pair(y, x - a / b * y);
}

ll inv(ll a) {
	ll x;
	tie(x, ignore) = eucl(a, mod);
	return (x % mod + mod) % mod;
}

ll choose(ll n, ll k) {
	k = min(k, n - k);
	ll a = 1, b = 1;
	loop(k) {
		a *= n - i;
		b *= i + 1;
		a %= mod;
		b %= mod;
	}
	return a * inv(b) % mod;
}

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

	int n, m;
	cin >> n >> m;
	mii fs = fats(m);
	ll ans = 1;
	each(p, fs) {
		ans *= choose(p.second + n - 1, n - 1);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}



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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long N, num = 26;
    vector<int> alphabetList;
    cin >> N;
    while(N/num){
        alphabetList.push_back(N%num);
        if(N%num==0){
            N = N / num - 1;
        }else{
            N /= num;
        }
    }
    if(N!=0){
        alphabetList.push_back(N%num);
    }
    for(int i=alphabetList.size()-1; i>=0; i--){
        cout << (char)(96+(alphabetList[i] == 0 ? 26 : alphabetList[i]));
    }
    return 0;
}

Measured memory_bytes: 3636
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 10000000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll x,y;
  cin>>x>>y;
  if((x+y)%3!=0 || 2*x<y || 2*y<x){
    cout<<0<<endl;
    return 0;
  }
  ll big,small;
  if(x>=y){
    big=x;
    small=y;
  }else{
    big=y;
    small=x;
  }
  ll n=0,k=0;
  ll bigg=big,smalll=small;
  rep(i,bigg){
    big-=1;
    small-=2;
    k+=1;
    if(big==2*small){
      n=small;
      break;
    }
  }
  n+=k;
  COMinit();
  cout<<COM(n,k)<<endl;
  
}



Measured memory_bytes: 234624
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  int r; cin>>r;
  if(r<1200)
  cout<<"ABC"<<endl;
  else if(r<2800)
  cout<<"ARC"<<endl;
  else
  cout<<"AGC"<<endl;

  return 0;
}


Measured memory_bytes: 256
A,B,C,D = map(int,list(input()))

for i in [-1,1]:
  for j in [-1,1]:
    for k in [-1,1]:
      if A + B*i+ C*j + D*k == 7:
        it = "-" if i == -1 else "+"
        jt = "-" if j == -1 else "+"
        kt = "-" if k == -1 else "+"
        print(str(A)+it+str(B)+jt+str(C)+kt+str(D)+"=7")
        exit(0)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N, M; cin >> N >> M;
    ll L = lcm(N,M);
    string S,T; cin >> S >> T;
    if (N < M) {
        swap(N,M);
        swap(S,T);
    }
    if (N % M == 0) {
        cout << -1 << endl;
        return 0;
    }
    ll C = lcm(L/N, L/M);
    for (int i = 0; i * C * M / L <= M; i++) {
        if (S[i*C*N/L] != T[i*C*M/L]) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << L << endl;
}


Measured memory_bytes: 3776
N = int(input())
sum_money = 0
for i in range(N):
    money = input().split()
   # money = int(money)
    if money[1] == 'JPY':
        sum_money = sum_money + float(money[0])
        #print(sum_money)
    else:
        sum_money = sum_money + (float(money[0])*380000)
        #print(sum_money)

print(sum_money)
        



Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    int[] p = new int[n];
    for(int i = 0;i<n;i++){
      p[i] = sc.nextInt();
    }

    int a = 0;
    while(true){
      int check = x - a;
      boolean ju = true;
      for(int i = 0;i<n;i++){
        if(check == p[i]){
          ju = false;
          break;
        }
      }
      if(ju == true){
        System.out.println(check);
        return;
      }
      check = x + a;
      for(int i = 0;i<n;i++){
        if(check == p[i]){
          ju = true;
          break;
        }
      }
      if(ju == false){
        System.out.println(check);
        return;
      }

      a++;
    }
  }
}


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

double avetemp(int T, int x){
  return T - x * 0.006;
}

int main(){
  int N, T, A;
  cin >> N >> T >> A;
  
  double diffabs;
  double diff;
  double mindiff = 300;
  int H;
  int index;
  for (int i = 1; i < N + 1; i++){
    cin >> H;
    diff = A - avetemp(T, H);
    if (diff < 0){
      diffabs = diff*(-1);
    }
    else{
    diffabs = diff;
    }
    if (diffabs < mindiff){
      mindiff = diffabs;
      index = i;
    }
  }
  
  cout << index << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	map<string,int> map;
	REP(i, n) {
		string meirei, str;
		cin >> meirei >> str;
		if (meirei[0] == 'i') map[str] = 1;
		else if (map[str] == 1) cout << "yes\n";
		else cout << "no\n";
	}

	return 0;
}


Measured memory_bytes: 47368
#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define td(v) v.begin(),v.end()
#define tdr(v) v.rbegin(),v.rend()
#define endl "\n"
#define Matrix vector<vector<int> >
using namespace std;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 9;
const int INF = 2e18;
 
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
 
inline long long mod(long long n, long long m){
    long long ret = n%m;
    if(ret < 0) ret += m;
    return ret;
}
 
int exp(int a, int b, int m){
    int result = 1;
    while (b > 0){
        if (b & 1)
            result = mod(result*a,m);
 
        b >>= 1;
        a = mod(a*a,m);
    }
    return result;
}
 
pair<int,int> adj[5000][5000];
void solve(){
    int n; cin>>n;
    vector<int>vet(n);
    for(int &i : vet) cin>>i;
    for(int i=0;i<n;i++){
        adj[i][i]={vet[i],0};
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<n-i;j++){
            int x = vet[j];
            int y = vet[j+i];
            int eu,ele;
            if(x+adj[j+1][j+i].second>y+adj[j][j+i-1].second){
                eu = x+adj[j+1][j+i].second;
                ele = adj[j+1][j+i].first;
            }
            else{
                eu = y+adj[j][j+i-1].second;
                ele = adj[j][j+i-1].first;
            }
            adj[j][j+i] = {eu,ele};
        }
    }
    cout<<adj[0][n-1].first-adj[0][n-1].second<<endl;
}
main(){
    fastio;
    solve();
}

Measured memory_bytes: 85852
#include<iostream>

int main(){

    int P,Q,R;
    std::cin>>P>>Q>>R;

    int outnum=0;
    if(P+Q < Q+R){
        if(P+Q < R+P){
            outnum = P+Q;
        }
        else{
            outnum = R+P;
        }
    }
    else{
        if(Q+R < R+P){
            outnum = Q+R;
        }
        else{
            outnum = R+P;
        }
    }
    std::cout<< outnum <<std::endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int K, A, B;
		cin >> K >> A >> B;

		for( int i = A; i <= B; ++i ) {
			if( i%K == 0 ) {
				cout << "OK" << endl;
				return;
			}
		}

		cout << "NG" << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();

	return 0;
}


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

int main(){
  
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    v[i] = x;
  }
  
  sort(v.begin(),v.end());
  
  double ans = v[0];
  
  for(int i=1;i<N;i++){
    ans = (ans + v[i])/2;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var N, K, Q int
	fmt.Scanf("%d %d %d", &N, &K, &Q)

	point := make(map[int]int, N)
	//for i := 0; i < N; i++ {
	//	point[i+1] = K
	//}

	var A int
	for i := 0; i < Q; i++ {
		fmt.Scanf("%d", &A)
		point[A]++
	}

	for i := 0; i < N; i++ {
		if (K + point[i+1] - Q) > 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}


Measured memory_bytes: 7248
n, l = map(int, input().split())
totalTaste = 0
tastes = []
minAbs = 9999
minIdx = 9999

for i in range(1, n+1):
    totalTaste += l + i - 1
    tastes.append(l + i - 1)

for i in range(n):
    temp = abs(tastes[i])
    if temp < minAbs:
        minAbs = temp
        minIdx = i

#print(totalTaste)
#print(tastes)
#print(totalTaste - minAbs)
print(totalTaste - tastes[minIdx])


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,i;
    cin >> N;
    vector < pair <pair <string , ll >,ll> > v;
    string S;
    ll P;
    for(i=0;i<N;i++){
        cin >> S >> P;
        v.push_back(make_pair(make_pair(S,-P),i+1));
    }
    sort(v.begin(),v.end());
    for(auto itr=v.begin();itr!=v.end();++itr){
        cout << itr->second<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from math import sqrt
def solve(cx, cy, r, x1, y1, x2, y2):
    xd = x2 - x1; yd = y2 - y1
    X = x1 - cx; Y = y1 - cy
    a = xd**2 + yd**2
    b = xd * X + yd * Y
    c = X**2 + Y**2 - r**2
    D = b**2 - a*c
    s1 = (-b + sqrt(D)) / a
    s2 = (-b - sqrt(D)) / a
    return (x1 + xd*s1, y1 + yd*s1), (x1 + xd*s2, y1 + yd*s2)
cx, cy, r = map(int, raw_input().split())
q = input()
for i in xrange(q):
    x1, y1, x2, y2 = map(int, raw_input().split())

    p0, p1 = sorted(solve(cx, cy, r, x1, y1, x2, y2))
    print "%.08f %.08f %.08f %.08f" % (p0 + p1)

Measured memory_bytes: 6532
//
// Created by kuroneko on 2019-09-07.
//
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;

#define INF 1000000000000009LL
#define MOD 1000000007LL

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    Edge(int src, int dst, Weight weight):src(src), dst(dst), weight(weight) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int main() {
    int N; cin >> N;
    cout << pow(N, 3) << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	int a;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1) {
			sum++;
		}
	}

	if (sum % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
import bisect as bs
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

a = np.array([iarr() for i in range(3)])
n = iinput()
for i in range(n):
    b = iinput()
    for i in range(3):
        for j in range(3):
            if a[i][j] == b: a[i][j] = 0

vertical = np.all(a == 0, axis=0)
horizontal = np.all(a == 0, axis=1)
diagonal = a[0][0]==a[1][1]==a[2][2]==0 or a[0][2]==a[1][1]==a[2][0]
flag = np.any(vertical==1) or np.any(horizontal==1) or diagonal
ans = "Yes" if flag else "No"
print(ans)


Measured memory_bytes: 37808
read
sort -nk3,3 -nk1,1|awk 'lc==$3{if($1-lt<0.5){lt=$2}else{print ls-0.5,lt,lc;ls=$1;lt=$2}}lc!=$3{print ls-0.5,lt,lc;ls=$1;lt=$2}{lc=$3}END{print ls-0.5,lt,lc}'|sed 1d|awk '{print $1,"s";print $2,"t"}'|sort -nk1,1|awk '$2=="s"{c++;m=(c>m)?c:m}$2=="t"{c--}END{print m}'

Measured memory_bytes: 20124
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<cctype>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;
typedef pair<int,int> pa;
inline ll read()
{
	long long f=1,sum=0;
	char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}
const int MAXN=100010;
const int MAXM=200010;
const int COLSET=1000010;
struct edge{
	int next,to;
}e[5000010];
int head[MAXN*10],cnt;
void addedge(int u,int v)
{
	e[++cnt].next=head[u];
	e[cnt].to=v;
	head[u]=cnt;
}
int fa[MAXN],rk[MAXN];
int find(int x)
{
	if (fa[x]!=x) fa[x]=find(fa[x]);
	return fa[x];
}
void uni(int x,int y)
{
	int f1=find(x),f2=find(y);
	if (f1==f2) return ;
	if (rk[x]<rk[y]) fa[f1]=f2;
	else if (rk[x]==rk[y]) fa[f1]=f2,rk[f2]++;
	else fa[f2]=f1;
}
vector <pa> col[COLSET];
bool visit[MAXN];
int id[MAXN];
bool vis[MAXN*10];
queue <int> q;
int dis[MAXN*10];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v,opt;
		scanf("%d%d%d",&u,&v,&opt);
		col[opt].push_back(mp(u,v));
	}
	int tot=n+1;
	for (int i=1;i<COLSET;i++)
	{
		if (col[i].empty()) continue;
		for (int j=0;j<(int)col[i].size();j++)
		{
			pa now=col[i][j];
			fa[now.first]=now.first,fa[now.second]=now.second;
			rk[now.first]=rk[now.second]=0;
			id[now.first]=id[now.second]=0;
			visit[now.first]=visit[now.second]=0;
		}
		for (int j=0;j<(int)col[i].size();j++)
		{
			pa now=col[i][j];
			uni(now.first,now.second);
		}
		for (int j=0;j<(int)col[i].size();j++)
		{
			pa now=col[i][j];
			if (!visit[now.first])
			{
				visit[now.first]=1;
				int f=find(now.first);
				if (!id[f]) id[f]=tot++;
				addedge(now.first,id[f]),addedge(id[f],now.first);
			}
			if (!visit[now.second])
			{
				visit[now.second]=1;
				int f=find(now.second);
				if (!id[f]) id[f]=tot++;
				addedge(now.second,id[f]),addedge(id[f],now.second);
			}
		}
	}
	q.push(1);
	vis[1]=1;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=head[x];i;i=e[i].next)
		{
			int v=e[i].to;
			if (vis[v]) continue;
			vis[v]=1;
			q.push(v);
			dis[v]=dis[x]+1;
		}
	}
	if (!dis[n]) cout<<-1;
	else cout<<dis[n]/2;
	return 0;
}


Measured memory_bytes: 46464
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int n,m,p,a,b,t[8],d[30][30],x,y,z;
double dp[1<<8][30];

int main(){
	while(cin>>n>>m>>p>>a>>b&&n){
		rep(i,m)fill(d[i],d[i]+m,-1);
		rep(i,n)cin>>t[i];
		rep(i,p){cin>>x>>y>>z;d[x-1][y-1]=z;d[y-1][x-1]=z;}
		rep(i,1<<n)fill(dp[i],dp[i]+m,INF);
		dp[(1<<n)-1][a-1]=0;
		double res=INF;
		for(int S=(1<<n)-1;S>=0;S--){
			rep(v,m)rep(i,n)if(S>>i&1)rep(u,m)if(d[v][u]>=0)
			dp[S&~(1<<i)][u]=min(dp[S&~(1<<i)][u],dp[S][v]+(double)d[v][u]/t[i]);
			res=min(res,dp[S][b-1]);
		}
		if(res==INF)cout<<"Impossible\n";
		else cout<<res<<endl;
	}
}

Measured memory_bytes: 992
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int H = 21;
const int W = 21;

bool check(bool v[H][W]){
  REP(i, H) REP(j, W) if(v[i][j]) return false;
  return true;
}

int main() {
  int N;
  map<char, int> my, mx;
  my['N'] = 1; my['E'] = 0; my['S'] = -1; my['W'] = 0; mx['N'] = 0; mx['E'] = 1; mx['S'] = 0; mx['W'] = -1;
  while(cin >>N && N){
    bool v[H][W];
    REP(i, H) REP(j, W) v[i][j] = false;
    REP(i, N){
      int x, y; cin >>x >>y;
      v[y][x] = true;
    }
    int y = 10, x = 10;
    int M; cin >>M;
    REP(i, M){
      char c;
      int d;
      cin >>c >>d;
      REP(j, d){
        y += my[c]; x += mx[c];
        v[y][x] = false;
      }
    }
    cout <<(check(v) ? "Yes" : "No") <<endl;
  }
  return 0;
}

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

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

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

using namespace std;

void find_string( string s){
    int cc = 0;
    if((int)s.size() < 3) cout<<0<<"\n";
   else{
       for (int i = 0; i < (int) s.size() - 2; i++){
           if(s.substr(i,3) == "ABC") cc++;

        }
        cout<< cc<<"\n";
    }

   
    
    
}
int main(){
    
    int a;

    string s;

    cin>>a>>s;

    find_string(s);


    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define eb emplace_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool ff=0;for(auto outi:v){cout<<(ff?" ":"")<<outi;ff=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

vector<int> Zalgorithm(string s){
  int i=1,j=0,k=0,N=s.size();
  vector<int> res(N);
  res[0]=N;
  while(i<N){
    while(i+j<N&&s[i+j]==s[j])++j;
    res[i]=j;
    if(!j){
      ++i;
      continue;
    }
    k=1;
    while(res[k]+k<j){
      res[i+k]=res[k];
      ++k;
    }
    i+=k;
    j-=k;
  }
  return res;
}
int quef[1000001],ques[1000001],size;
int main(){
  startupcpp();
  int i,N,K,ans=0;
  string first,s="",t;
  cin>>first>>t;
  while(s.size()<t.size())s+=first;
  N=s.size();K=t.size();
  vector<int> v=Zalgorithm(t+s+s);
  rep(i,N){
    if(v[i+K]<K)ques[size++]=i+K-(i+K>=N)*N;
  }
  rep(i,N){
    if(i==size){
      puts("-1");
      return 0;
    }
    chmax(ans,quef[i]);
    if(v[ques[i]+=K]>=K){
      ques[size]=ques[i]-N*(ques[i]>=N);
      quef[size++]=quef[i]+1;
    }
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 16852
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
const int N = 10000010;
 
 
int n,a[N],dp[N];

vector<int> g[N];
 
void dfs(int u){
	vector<int> v;
	for (int i = 0; i < g[u].size(); ++i){
		dfs(g[u][i]);
		v.push_back(dp[g[u][i]]);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	for (int i = 0; i < v.size(); ++i){
		dp[u] = max(dp[u],i + 1 + v[i]);
	}
}
int main() {
	//freopen("input.txt","r",stdin);
	scanf("%d",&n);
	for (int i = 2; i <= n; ++i){
		scanf("%d",&a[i]);
		g[a[i]].push_back(i);
	}
	dfs(1);
	printf("%d\n", dp[1]);
	return 0;
} 

Measured memory_bytes: 246400