akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n,i;
	cin>>n;
	int a[n],b[n],c[n];
	cin>>a[0]>>b[0]>>c[0];
	for(i=1;i<n;i++)
	{
	    int p,q,r;
	    cin>>p>>q>>r;
	    a[i]=p+max(c[i-1],b[i-1]);
	    b[i]=q+max(c[i-1],a[i-1]);
	    c[i]=r+max(a[i-1],b[i-1]);
	}
	int ans=max(a[n-1],max(b[n-1],c[n-1]));
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 4808
#include<cstdio>
int main(){
    char s[11];
    scanf("%s",s);
    int ans=0,cnt=0;
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
            cnt++;
            if(ans<cnt)ans=cnt;
        }else{
            cnt=0;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int N;
    int S=0;
    for(int n=0; n<3; n++) {
        cin >> N;
        S+=N;
    }
    if(S>=22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
/*************************************************************************
    > File Name: a.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2019年12月28日 星期六 22时04分58秒
 ************************************************************************/

#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    long long n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    register long long ans = (b-a)>>1;
    if((b-a)&1)
        ans += min(a, n+1-b);
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N;
vector<int> l;

int main() {
  cin >> N;
  l = vector<int>(N);
  for (int i=0; i<N; i++)
    cin >> l.at(i);
  sort(l.begin(), l.end());
  int count = 0;
  for (int i = 0; i < N - 2; i++) {
    int a = l[i];
    for (int j = i + 1; j < N - 1; j++) {
      int b = l[j];
      int add = 0;
      int c_lower = j + 1;
      auto c_upper = lower_bound(l.begin(), l.end(), a + b);
      if (c_upper - l.begin() == N - 1)
        // not found
        if (l[N - 1] < a + b)
          add = 1;
      if (c_upper - l.begin() < c_lower)
        continue;

      int diff = c_upper - l.begin() - c_lower;
      if (diff < 0)
        diff = 0;

      count += diff + add;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long d = Integer.parseInt(sc.next());
        d *= d;
        Long[] x = new Long[n];
        Long[] y = new Long[n];
        for (int i = 0; i < n; i++) {
            x[i] = Long.parseLong(sc.next());
            y[i] = Long.parseLong(sc.next());
        }
        sc.close();

        // 主処理
        int result = 0;
        for (int i = 0; i < n; i++) {
            long dist = x[i] * x[i] + y[i] * y[i];
            if (dist <= d) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 69980
//https://github.com/dush1729/cp/blob/master/library/query/mo.cpp
#include<bits/stdc++.h>
using namespace std;

const int N=5e5+20,Q=N,MAX=N,SIZE=sqrt(N)+1;

int n,q,a[N],l,r,cl=1,cr=1,f[MAX],ans[Q],cnt;
vector <pair<pair<int,int>,int>> p;

bool cmp(pair<pair<int,int>,int> &a, pair<pair<int,int>,int> &b)
{
    if(a.first.first/SIZE!=b.first.first/SIZE) return a.first.first<b.first.first;
    return a.first.second<b.first.second;
}

void add(int idx)
{
    if(!f[a[idx]]) cnt++;
    f[a[idx]]++;
}

void remove(int idx)
{
    if(f[a[idx]]==1) cnt--;
    f[a[idx]]--;
}

int main()
{
    //https://codeforces.com/contest/86/problem/D
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=0;i<q;i++)
    {
        scanf("%d%d",&l,&r);
        p.push_back({{l,r},i});
    }

    sort(p.begin(),p.end(),cmp);

    for(int i=0;i<q;i++)
    {
        l=p[i].first.first,r=p[i].first.second;

        while(cl<l) remove(cl++);
        while(cl>l) add(--cl);
        while(cr>r+1) remove(--cr);
        while(cr<r+1) add(cr++);

        ans[p[i].second]=cnt;
    }

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


Measured memory_bytes: 15584
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

int main(int argc, char const *argv[]) {
    int n,q;cin>>n>>q;
    long long inv2 = M/2 + 1;
    vector<int> a(n);
    for(int i=0;i<n;++i)cin>>a[i];
    vector<vector<long long>> dp(n,vector<long long>(n));
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(a[i]<a[j])dp[i][j]=1;
        }
    }
    for(int qq=0;qq<q;++qq){
        int s,t;cin>>s>>t;
        s--;
        t--;
        for(int i=0;i<n;++i){
            if(i!=s && i!=t){
                long long tmp = dp[i][t] + dp[i][s];
                tmp *= inv2;
                tmp %= M;
                dp[i][t] = tmp;
                dp[i][s] = tmp;
                tmp = dp[s][i] + dp[t][i];
                tmp *= inv2;
                tmp %= M;
                dp[s][i] = tmp;
                dp[t][i] = tmp;
            }
        }
        // for(int i=0;i<n;++i){
        //     for(int j=0;j<n;++j){
        //         if(i!=s&&i!=t&&j!=s&&j!=t)dp[i][j]*=2;
        //     }
        // }
        long long tmp = dp[s][t] + dp[t][s];
        tmp *= inv2;
        tmp %= M;
        // cout<<tmp<<endl;
        dp[s][t] = tmp;
        dp[t][s] = tmp;
    }
    long long res = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<i;++j)res=(res+dp[i][j])%M;
    }
    for(int i=0;i<q;++i)res = (res*2)%M;
    cout<<res<<endl;
    return 0;
}

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,d,a;
    cin>>n>>d>>a;
    vector<pair<ll,ll>> vec(n);
    for(ll i=0;i<n;++i)
    {
    	ll a,b;
    	cin>>a>>b;
    	vec[i]=make_pair(a,b);

    }

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

    long long ans=0;
    set<pair<ll,ll> >s;
    long long sum=0;
    for(ll i=0;i<n;++i)
    {
    	auto it1=s.lower_bound(make_pair(vec[i].first,-1));
    	auto it2=s.rbegin();
    	ll y=0;
    	if(it1!=s.end()&&s.size()>=1)
    	{
    	    if(it1!=s.begin())
    	    {
    	        it1--;
    	        ll start=it1->second;
    	        ll end=it2->second;
    	      
    	        
    	            y=end-start;
    	        
    	    }
    	    else
    	    {
    	        y=it2->second;
    	    }
    	}
    	
    	ll right=vec[i].first+2*d;
    	ll res=0;
    	if(vec[i].second>=y)
    	{
    	res=(vec[i].second-y+a-1)/a;
    	}
    	
    	ans+=res;

    	sum+=res*a;
    	s.insert(make_pair(right,sum));
    	

    }

    cout<<ans<<endl;



}


Measured memory_bytes: 15872
# 102b

def atc_102b(N: int, Ai_input: str) -> int:
    Ai = [int(i) for i in Ai_input.split(" ")]
    return max(Ai) - min(Ai)

N_input_value = int(input())
Ai_input_value = input()
print(atc_102b(N_input_value, Ai_input_value))


Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	int n;
	cin>>n;
	int i=2;
	while(i<=n){
		i = i*2;
	}
	cout<<i/2;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){


	int a[3] = {0};
	REP(i,3){ 
		int x,y;
		scanf("%d %d", &x, &y);
		a[x]++;
		a[y]++;

	}

	bool flag1 = false;
	bool flag2 = false;

	FOR(i,1,5){
		if(a[i] == 1) flag1 = true;
		else if(a[i] == 2) flag2 = true;
	}


	if(flag1 and flag2) printf("YES\n");
	else printf("NO\n");


	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int gcd(int a, int b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int main() {
	long long n, a, sum = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a;
		if (h == 0) {
			sum = a;
		}
		else if(sum != a){
			sum = gcd(sum, a);
		}
	}
	cout << sum << endl;
	cin >> n;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int n;
    cin >> n;
    vi a(n),b(n);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    vi v(2,INF);
    rep(i,n){
        v[a[i]] = min(v[a[i]],b[i]);
    }
    if(v[0] == INF || v[1] == INF){
        cout << 0 << endl;
    }else{
        cout << v[0] + v[1] << endl;
    }
}



Measured memory_bytes: 3104
n = int(input())
a_1 = list(map(int,input().split()))
a_2 = list(map(int,input().split()))
for i in range (1,n):
    a_1[i]+=a_1[i-1]        
    a_2[n-1-i]+=a_2[n-i]    
max = 0
for i in range(n):
    if a_1[i]+a_2[i] > max:
        max = a_1[i] + a_2[i]
print(max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> S;
    vi v(26);
    REP(i, S.size()) {
        v[S[i] - 'a']++;
    }
    REP(i, 26)
    if (v[i] & 1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N;
vector<pair<int,int> >B,At,A;
bool used[1<<17];
void dfs(int u)
{
	used[u]=true;
	int v=A[u].second;
	if(!used[v])dfs(v);
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;cin>>a;At.push_back(make_pair(a,i));
	}
	for(int i=0;i<N;i++)
	{
		int b;cin>>b;B.push_back(make_pair(b,i));
	}
	sort(B.begin(),B.end());
	A=At;
	for(int i=0;i<N;i++)
	{
		A[i]=make_pair(At[B[i].second].first,i);
	}
	sort(A.begin(),A.end());
	for(int i=0;i<N;i++)
	{
		if(A[i].first>B[i].first)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	int cnt=0;
	for(int i=0;i<N;i++)
	{
		if(!used[i])
		{
			dfs(i);
			cnt++;
		}
	}
	if(cnt>=2)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=0;i<N;i++)
	{
		int id=A[i].second;
		if(A[id].first<=B[i].first&&A[i].first<=B[id].first)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 2804
#include <bits/stdc++.h>
#define pll pair<long long,long long>
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int mod = 998244353;
 
 
int main() {
    	int n,p,t;
    	cin>>n>>p;
        cout<<n*(n-1)/2+p*(p-1)/2<<"\n";
        }
      //  cout<<su<<" "<<r<<"\n";
            
        
 

Measured memory_bytes: 256
#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() {
    string s; cin >> s;
    map<char, int> mp;
    bool ok = true;
    rep(i, s.size()) mp[s[i]]++;
    for(auto it=mp.begin();it!=mp.end();it++) {
        int ss = it->second;
        if(ss%2 != 0) ok = false;
    }
    if(ok) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t, n;
  int cnt;
  int s, f;

  cin >> t;
  while(t != 0){
    cin >> n;
    cnt = 0;
    for(int i = 0;i < n;i++){
      cin >> s >> f;
      cnt += (f - s);
    }
    
    if(cnt >= t){
      cout << "OK" << endl;
    }else{
      cout << t - cnt << endl;
    }
    cin >> t;
  }
  return 0;
}




Measured memory_bytes: 3128
# coding: utf-8
import fractions

def lcm(a, b):
    return a * b // fractions.gcd(a, b)


a, b, c, d = map(int, input().split())
ac = (a - 1) // c
ad = (a - 1) // d
acd = (a - 1) // lcm(c, d)
bc = b // c
bd = b // d
bcd = b // lcm(c, d)
print((b - a + 1) - ((bc + bd - bcd) - (ac + ad - acd)))


Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}
ll lcm(ll l,ll a){
    return a/__gcd(l,a)*l;
}


int main(){
    int n;cin >> n;
    vector<int> ans(n,0);
    rep2(i,2,n+1){
        int l;
        cin >> l;
        ans[l-1]++;
    }
    rep(i,n)cout << ans[i] << endl;
}


Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;

#define MOD 998244353


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

bool primeNumber(ll n){
    if(n < 2) return false;
    else{
        for(ll i = 2; i * i <= n; i++){
            if(n % i == 0) return false;
        }
        return true;
    }
}
  
  

int main(){
    string a,b;
    cin >> a>> b;
    
    if (a=="H")cout << b << endl;
    else if (a == "D" && b=="H")puts("D");
    else puts("H");
    
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*16
#define REP(i,n) for(long long i = 0;i < n;++i)
int main(){
	int n;
	cin >> n;
	long long a = 0, b = 0;
	REP(i, n) {
		long long c;
		cin >> c;
		a += c;
		b = max(b, c);
	}
	if (a > b * 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


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


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    r = INT()
    print(2 * pi * r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10520
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >> k;
  int n = k/2;
  if(k%2==0){
    cout << n*n << endl;
  }else{
    cout << n*(n+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

ll solve() {
    int N;
    cin >> N;
    int ans = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        if (a%2 == 0) {
            while (a%2 == 0) {
                a /= 2;
                ans++;
            }
        }
    }
    return ans;
}

int main() {
    cout << solve() << endl;
#ifdef DEBUG
    while (1) {
        cout << solve() << endl;
    }
#endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 100000000000000000
signed main(void){
    int n,m,q;cin>>n>>m>>q;
    vector<vector<int>>v(n,vector<int>(n,0));
    int f,t;
    rep(i,m){
        cin>>f>>t;f--;t--;
        v[f][t]++;
    }
    vector<vector<int>>G(n,vector<int>(n,0));
    rep(i,n){
        if(i==0){
            rep(j,n){
                G[i][j]+=v[i][j];
                if(j>0)G[i][j]+=G[i][j-1];
            }
        }
        else{
            rep(j,n){
                G[i][j]+=v[i][j];
                G[i][j]+=G[i-1][j];
                if(j>0)G[i][j]+=G[i][j-1]-G[i-1][j-1];
            }
        }
    }
    
    rep(i,q){
        cin>>f>>t;f--;t--;
        if(f==0)cout<<G[n-1][t]<<endl;
        else cout<<G[n-1][t]-G[f-1][t]<<endl;
    }
}


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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    constexpr int kMod = 1'000'000'000 + 7;
    vector<vector<int>> dp(n, vector<int>(n, 0));
    dp[0][0] = 1;
    for (int i = 0; i < m; ++i) {
        vector<vector<int>> nxt(n, vector<int>(n, 0));
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k < n; ++k) {
                if (dp[j][k] == 0) continue;
                nxt[j + k][0] += 1LL * dp[j][k] * (j + 1) % kMod;
                if (nxt[j + k][0] >= kMod) nxt[j + k][0] -= kMod;
                if (j + k + 1 < n) {
                    nxt[j][k + 1] += 1LL * (n - 1 - j - k) * dp[j][k] % kMod;
                    if (nxt[j][k + 1] >= kMod) nxt[j][k + 1] -= kMod;
                }
                nxt[j][k] += 1LL * k * dp[j][k] % kMod;
                if (nxt[j][k] >= kMod) nxt[j][k] -= kMod;
            }
        }
        dp = nxt;
    }
    printf("%d\n", dp[n - 1][0]);
    return 0;
}


Measured memory_bytes: 1028
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
ll dp[100001];
int main()
{
    fio;
    ll n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,n)
    {
        cin>>a[i];
    }
    memset(dp,(ll)1e9+5,sizeof(dp));
    dp[0]=0;
    //cout<<dp[0]<<" "<<dp[1];
    //dp[1]=abs(a[0]-a[1]);
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j+i<n)
            dp[i+j]=min(dp[i+j],dp[i]+abs(a[i+j]-a[i]));//,cout<<dp[i+j]<<" ";
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 5188
import sys
from collections import deque

input = sys.stdin.readline
output = sys.stdout.writelines


def bfs(G, v, p, counter):
    queue = deque([(v, p)])
    while queue:
        v, p = queue.popleft()
        for c in G[v]:
            if c == p:
                continue
            counter[c] += counter[v]
            queue.append((c, v))


def main():
    N, Q = map(int, input().split())

    G = [[] for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)

    counter = [0] * (N + 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        counter[p] += x

    bfs(G, 1, -1, counter)

    output([" ".join(map(str, counter[1:])), "\n"])


if __name__ == "__main__":
    main()


Measured memory_bytes: 65636
# coding: utf-8

import sys
n = input()

while(n != 0):
    convTable = {}
    
    for i in range(n):
        t = raw_input().split()
        convTable[t[0]] = t[1]
    
    n = input()
    for i in range(n):
        t = raw_input().split()
        if t[0] in convTable:
            sys.stdout.write(convTable[t[0]])
        else:
            sys.stdout.write(t[0])
    sys.stdout.write("\n")
    n = input()
    

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

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (A > 2 * B)
    {
        cout << A - 2 * B << endl;
    }
    else
    {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n; cin >> n;
  ll ans=n*(n-1)/2;
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections
n = int(input())
aa = list(map(int, input().split()))
ca = collections.Counter(aa)
la = sorted([a for a in ca.items()], key = lambda x:x[0], reverse=True)

list1 = []
list2 = []

for a in la:
  if a[1] > 1:
    list1.append(a)
  if a[1] >3:
    list2.append(a)
    
if len(list1) > 1:    
    xr = list1[0][0] * list1[1][0]
else:
  xr = 0
    
if len(list2) > 0:
  xs = list2[0][0] * list2[0][0]
else:
  xs = 0
  
ans = max(xr, xs)

print(ans)


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll S, W; cin >> S >> W;
  if (W >= S) {
    cout << "unsafe\n";
  }else {
    cout << "safe\n";
  }

  return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int N=55;
long long dp[N][N*N];      //dp值会爆int
int main()
{
    int n,a;
    cin>>n>>a;
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        for(int j=i-1;j>=0;j--)    //每一次个数向下减少
            for(int k=0;k<=N*j;k++)    //优化时间  由于k最大为N*j次
                dp[j+1][k+x]+=dp[j][k];       //个数加1 则找到前面个数的值相加
    }
    long long ans=0;       
    for(int i=1;i<=n;i++)
            ans+=dp[i][i*a];    //累计所有个数会出现平均值满足a的情况
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];

  int x0, y0, h0;
  for (int i = 0; i < n; i++) {
    if (h[i]) {
      x0 = x[i];
      y0 = y[i];
      h0 = h[i];
      break;
    }
  }
  for (int cx = 0; cx < 101; cx++) {
    for (int cy = 0; cy < 101; cy++) {
      int ch = h0 + abs(cx - x0) + abs(cy - y0);
      bool flag = true;
      for (int i = 0; i < n; i++) {
        if (max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        printf("%d %d %d\n", cx, cy, ch);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int a, b;

int main()
{
    scanf("%d%d", &a, &b);
    for(int i = 0; i < 2000; i++)
    {
        if(b <= i * (a - 1) + 1)
        {
            printf("%d", i);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

import java.util.StringTokenizer;


public class Main {

    private final static FastReader in = new FastReader();
    private static final PrintWriter out = new PrintWriter(System.out);


    public static int solve(int[] arr) {
        int ans=0;
        int min1=0,min2=0,max=0;
        for (int i = 0; i < arr.length; i++) {
            for (int ii = i + 1; ii < arr.length; ii++) {
                for (int iii = ii + 1; iii < arr.length; iii++) {
                  if(arr[i]!=arr[ii]&&arr[ii]!=arr[iii]&&arr[i]!=arr[iii]){
                      if(arr[i]>arr[ii]&&arr[i]>arr[iii]){
                          min1=arr[ii];
                          min2=arr[iii];
                          max=arr[i];
                      }else if(arr[ii]>arr[i]&&arr[ii]>arr[iii]){
                          min1=arr[i];
                          min2=arr[iii];
                          max=arr[ii];
                      }else if(arr[iii]>arr[ii]&&arr[iii]>arr[i]){
                          min1=arr[ii];
                          min2=arr[i];
                          max=arr[iii];
                      }
                      if(max<(min1+min2)){
                          ans++;
                      }
                  }
                }
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        int n = in.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        out.println(solve(arr));

        out.flush();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }


        public final String next() {
            while (ST == null || !ST.hasMoreTokens()) {
                try {
                    ST = new StringTokenizer(BF.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return ST.nextToken();

        }

        final int nextInt() {
            return Integer.parseInt(next());
        }

    }


}


Measured memory_bytes: 33924
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    a, b, x = MI()
    print(b // x - (a - 1) // x)


main()


Measured memory_bytes: 64920
X = input()

A, B, C, D = [int(X[i]) for i in range(4)]

for i in range(2**3, 2**4):
    s = format(i, 'b')[1:]
    E = A + (-1) ** int(s[0]) * B + (-1) ** int(s[1]) * C + (-1) ** int(s[2]) * D
    if E == 7:
        break

op = ['+', '-']

print(str(A) + op[int(s[0])] + str(B) + op[int(s[1])] + str(C) + op[int(s[2])] + str(D) + '=7')

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

const int limit=50;

int N,M;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){//全て通れるか確かめる関数
  visited[v]=true;
  for(int v2=0;v2<N;v2++){
    if(graph[v][v2]==false){
      continue;
    }
    if(visited[v2]==true){
      continue;
    }
dfs(v2);
    
  }
}

int main(){
  cin>>N>>M;
  
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    
  }
  
  int ans=0;
  
  for(int i=0;i<M;i++){
    
     graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;//グラフから一つの橋を消す
    for(int j=0;j<N;j++){
      visited[j]=false;//リセット
    }
     dfs(0);//試す
    
    bool bridge=false;
    
    for(int j=0;j<N;j++){
      if(visited[j]==false){//全部通れないパターンの場合trueを返す
        bridge=true;
      }
    }
    if(bridge){
      ans++;
    }
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;//元に戻す
  }
  
  cout<<ans<<endl;

}

 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
  int x,y,a,b,n[31];
  char s;

  cin >> y >> x;
  for(int i=1; i<=y; i++)n[i]=i;

  for(int i=0; i<x; i++){
    cin >> a >> s >> b;
    swap(n[a],n[b]);
  }
  for(int i=1; i<=y; i++)cout << n[i] << endl;

  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=LLONG_MAX,mod=1000000007,BS,k;

int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
		ll n,m,k;cin>>n>>m>>k;
		ll arr[2][k];
		ll freq[300005],idx=-1,ma=0;
		// cout<<"y";
		// for(ll i=0;i<)
		for(ll i=0;i<k;i++){
			cin>>arr[0][i]>>arr[1][i];
			freq[arr[0][i]]++;
			if(freq[arr[0][i]]>ma){
				ma=freq[arr[0][i]];
				idx=arr[0][i];
			}
		}
		ll sum=0;
		sum=ma;ll ma1=0,freq1[300005];for(ll i=0;i<300005;i++)freq1[i]=0;
		for(ll i=0;i<k;i++){
			if(arr[0][i]==idx)continue;
			else
			freq1[arr[1][i]]++;
			if(freq1[arr[1][i]]>ma1){
				ma1=freq1[arr[1][i]];
				// idx=arr[0][i];
			}
		}
		sum+=ma1;

		ll ans=0;
		ans=sum;
		
		sum=0;ma=0;ma1=0;
		for(ll i=0;i<300005;i++)freq[i]=0,freq1[i]=0;
		for(ll i=0;i<k;i++){
			// cin>>arr[0][i]>>arr[1][i];
			freq[arr[1][i]]++;
			if(freq[arr[1][i]]>ma){
				ma=freq[arr[1][i]];
				idx=arr[1][i];
			}
		}
		
		sum=ma;
		for(ll i=0;i<k;i++){
			if(arr[1][i]==idx)continue;
			else
			freq1[arr[0][i]]++;
			if(freq1[arr[0][i]]>ma1){
				ma1=freq1[arr[0][i]];
				// idx=arr[0][i];
			}
		}
		sum+=ma1;

		ans=max(ans,sum);
	cout<<ans;
}


Measured memory_bytes: 12976
import sys
n,u,v=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)

def bfs(v):
  distance=[-1]*n
  distance[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    ct+=1
    for i in range(len(next)):
      if visited[next[i]]==-1:
        distance[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return distance

x=bfs(u-1)
y=bfs(v-1)
ans=[]
for i in range(n):
  if x[i]<y[i]:
    ans.append(y[i]-1)
print(max(ans))

Measured memory_bytes: 86104
#include<queue>
#include<string>
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		vector<int> G[15];
		rep(i,m){
			int u,v; scanf("%d%d",&u,&v); u--; v--;
			G[u].push_back(v);
			G[v].push_back(u);
		}

		int S_ini=0;
		rep(u,n){
			int b; scanf("%d",&b);
			S_ini|=b<<u;
		}

		vector<int> sw[15];
		rep(u,n){
			int k; scanf("%d",&k);
			sw[u].resize(k);
			rep(i,k) scanf("%d",&sw[u][i]), sw[u][i]--;
			sort(sw[u].begin(),sw[u].end());
		}

		if((S_ini&1<<0)==0){
			puts("Help me!");
			continue;
		}

		static int d[15][1<<15];
		static char msg[15][1<<15][32];
		static pair<int,int> pre[15][1<<15];
		rep(u,n) rep(S,1<<n) d[u][S]=-1;
		d[0][S_ini]=0;

		queue< pair<int,int> > Q;
		Q.push(make_pair(0,S_ini));
		while(!Q.empty()){
			int u=Q.front().first,S=Q.front().second; Q.pop();

			// スイッチ切り替え
			rep(i,sw[u].size()){
				int v=sw[u][i];
				if(d[u][S^1<<v]==-1 && v!=u){
					d[u][S^1<<v]=d[u][S]+1;
					if(S&1<<v) sprintf(msg[u][S^1<<v],"Switch off room %d.",v+1);
					else       sprintf(msg[u][S^1<<v],"Switch on room %d.",v+1);
					pre[u][S^1<<v]=make_pair(u,S);
					Q.push(make_pair(u,S^1<<v));
				}
			}
			// 部屋移動
			rep(i,G[u].size()){
				int v=G[u][i];
				if(d[v][S]==-1 && S&1<<v){
					d[v][S]=d[u][S]+1;
					sprintf(msg[v][S],"Move to room %d.",v+1);
					pre[v][S]=make_pair(u,S);
					Q.push(make_pair(v,S));
				}
			}
		}

		if(d[n-1][1<<n-1]!=-1){
			printf("You can go home in %d steps.\n",d[n-1][1<<n-1]);
			vector<string> path;
			int u=n-1,S=1<<n-1;
			while(u!=0 || S!=S_ini){
				path.push_back(msg[u][S]);
				pair<int,int> tmp=pre[u][S];
				u=tmp.first;
				S=tmp.second;
			}
			reverse(path.begin(),path.end());
			rep(i,path.size()) puts(path[i].c_str());
		}
		else{
			bool b=false;
			rep(S,1<<n) if(d[n-1][S]!=-1) b=true;
			puts(b?"You can not switch off all lights.":"Help me!");
		}
	}

	return 0;
}

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

/*int main(){
    int a,i,ans=0;
    
    cin >> a;
    
    while(a){
        i = a % 10;
        ans += i;
        a /= 10;
    }

    cout << ans << endl;

}*/

/*int main()
{
    int s, ans;
    cin >> s;

    while (s)
    {
        ans += s % 10;
        s /= 10;
    }
    cout << ans << endl;

}*/

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    if (s[0] == '1') { ++ans; }
    if (s[1] == '1') { ++ans; }
    if (s[2] == '1') { ++ans; }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  ll N, A, B, dist = 0;
  cin >> N >> A >> B;
  vector<ll> X(N);
  REP(i, N) { cin >> X[i]; }
  sort(ALL(X));
  FOR(i, 0, N - 1 - 1) {
    if ((X[i + 1] - X[i]) * A < B) {
      dist += (X[i + 1] - X[i]) * A;
    } else {
      dist += B;
    }
  }
  cout << dist << endl;
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long x = in.nextLong();
        System.out.println(asd(x - 1));
    }

    public static String asd(long i) {
        if (i < 0) {
            return "-" + asd(-i - 1);
        }

        long quot = i / 26;
        long rem = i % 26;
        char letter = (char) ((int) 'a' + rem);
        if (quot == 0) {
            return "" + letter;
        } else {
            return asd(quot - 1) + letter;
        }
    }
}


Measured memory_bytes: 39828
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    double a, b, c, d, e, f;
    double x, y;
    while(cin >> a >> b >> c >> d >> e >> f){
        double g = b*d - a*e;
        printf("%.3lf %.3lf\n", ((long long)((1000*(b*f-c*e)/g)))/1000.0, ((long long)((1000*(d*c-a*f)/g)))/1000.0);
    }
    return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>

using namespace std;
typedef pair<int, pair<int, int> > PP;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vec;
int inf = -1;
ll mod = pow(10, 9) + 7;

int main() {
    int n;cin>>n;
    if(n%2==0){
        cout<<n/2-1<<endl;
    }
    else{
        cout<<(n-1)/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 764
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	
	ll i,n,m,t,x=0,y=0;
	cin>>n;
	vi a(n);
	for0(i,n) cin>>a[i];
	for0(i,n-1) x+=a[i];
	y = a[n-1];
	m = abs(x-y);
	for(i=n-2 ; i>=1 ; i--){
		x -= a[i];
		y += a[i];
		t = abs(x-y);
		m = min(m,t);
		}
	cout<<m<<nw;
	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  double ans = 0;
  for (int i = 0; i < N; i++)
  {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY")
      ans += x;
    else
    {
      ans += x * 380000.0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//不取完石子是没有意义的
//A在i，B把棋子推向j，如果a[i]<=a[j]，来回推则A必输 
#include<cstdio>
int a[3005],n,head[3005],num;
struct edge{int to,next;}e[6005];
void add(int u,int v){e[++num]=(edge){v,head[u]},head[u]=num;}
bool check(int u,int fa)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].to;if(v==fa||a[v]>=a[u])continue;
		if(!check(v,u))return 1;
	}return 0; 
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1,u,v;i<n;i++)
	{scanf("%d%d",&u,&v),add(u,v),add(v,u);}
	for(int i=1;i<=n;i++)if(check(i,0))printf("%d ",i);
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
#### 逆元リストいらない
fact = [1]
for i in range(10**5+5):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
N,M = map(int,input().split())
if abs(N-M) > 1:
    ans = 0
elif abs(N-M) == 1:
    ans = fact[N] * fact[M] % mod
elif abs(N-M) == 0:
    ans = fact[N] * fact[M] * 2 % mod
print(ans)

Measured memory_bytes: 7060
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define     int                 ll
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max({b*d,a*c,b*c,a*d}) << '\n';
}

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

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    L, R, D = MI()

    ans = 0
    for i in range(L, R+1):
        if i % D == 0:
            ans += 1
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9228
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

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

ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    int n;
    cin>>n;
    if(n>999) cout<<"ABD"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define eb emplace_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
#define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
#define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
#define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ", ";}cout<<endl // for map
#define deb(x) cerr << #x << '\t' << x << endl
const int imax = numeric_limits<int>::max(), imin = numeric_limits<int>::min();
const long long	lmax = numeric_limits<long long>::max(), lmin = numeric_limits<long long>::min();
/*========================================================================*/
/* strategi/note:

/*========================================================================*/

bool Svd=0;
void solve(){Svd=1;
	int n,m;
	cin >> n >> m;
	list<int> adj[n];
	bool visited[n] = {0};
	int a,b;
	while(m--){
		cin >> a >> b;
		adj[a -1].push_back(b -1);
		adj[b -1].push_back(a -1);
	}
	int groups = 0;
	stack<int> dfs;
	rep(i,n){
		if(!visited[i]){
			// simulate dfs
			dfs.push(i);
			while(!dfs.empty()){
				int id = dfs.top();
				dfs.pop();
				if(!visited[id]){
					// mark and traverse neighbor
					visited[id] = 1;
					for(int& ng : adj[id]){
						dfs.push(ng);
					}
				}
			}
			// dfs done
			groups ++;
		}
	}
	cout << groups-1 << endl; // 'greedy' aja, perlu 1 jalan antara 2 group
}

/*========================================================================*/
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
//cout<<fixed<<setprecision( ); // iomanip **
 solve();
 //int t;cin>>t;while(t--){solve();}
if(!Svd)cout<<"solve() function blm dipanggil!"<<endl;
//cout.flush(); cin.get();
return 0;
}


Measured memory_bytes: 12512
S = input()
if(S[0]=='A' and S[2:-1].count('C') == 1):
  cnt = 0
  for i in S:
    if(not (97<=ord(i) and ord(i)<=122)):
      cnt+=1
  if(cnt==2):
    print('AC')
  else:
    print('WA')
else:
  print('WA')

Measured memory_bytes: 3060
n,m=list(map(int,input().split()))
N=[list(input()) for _ in range(n)]
M=[list(input()) for _ in range(m)]

for i in range(n-m+1):
  for j in range(n-m+1):
    count = 0
    for k in range(m):
      if N[i+k][j:j+m] == M[k][:]:
        count += 1
    if count == m:
      print("Yes")
      exit()
    
print("No")

Measured memory_bytes: 9208