akhauriyash/Code-Regression huggingface dataset:
#107c
import bisect
N,K = map(int, input().split()) #N<=10**5
A_list = [int(e) for e in input().split()]

#折り返しは1回が最大→どこで折り返すかをN全探索でOK

#わかりやすいように0がなければ0を入れて、位置を調べる。
if 0 in A_list:
    zero_index = bisect.bisect_left(A_list, 0)
    K -= 1
else:
    bisect.insort(A_list, 0)
    zero_index = bisect.bisect_left(A_list, 0)
    N += 1
    
#print(A_list)
#print(zero_index)

if K == 0:
    ans = 0
    turn_index = 0
else:
    ans = 10**100+7
    
    for i in range(N):
        if abs(zero_index - i) <= K and i != zero_index:
            if abs(zero_index - i) == K:
                time = abs(A_list[i])
                if ans > time:
                    ans = time
                    #turn_index = i
            elif abs(zero_index - i) < K:
                #K付けられていないので折り返しの必要がある
                time = abs(A_list[i])*2 #原点まで戻る
                remain = K - abs(zero_index - i)
                
                if zero_index > i and zero_index + remain < N:
                    #折り返し地点が0より左側
                    time += A_list[zero_index + remain]
                    if ans > time:
                        ans = time
                        #turn_index = i
                elif zero_index < i and zero_index - remain >= 0:
                    #折り返し地点が0より右側
                    time += abs(A_list[zero_index - remain])
                    if ans > time:
                        ans = time
                        #turn_index = i

#print("#########")
#print(turn_index)
print(ans)

Measured memory_bytes: 14548
#include<bits/stdc++.h>
using namespace std;
char s[107];int n,a;
int main() {
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<n/2;++i)
		if(s[i]!=s[n-i-1])++a;
	cout<<a;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m, R;
int r[10];
ll d[205][205];

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

  cin >> n >> m >> R;
  REP(i, n) REP(j, n) d[i][j] = INF;
  REP(i, R) cin >> r[i], r[i]--;

  REP(i, m) {
    ll a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    if(d[a][b] > c) d[a][b] = d[b][a] = c;
  }
  sort(r, r + R);
  REP(k, n) REP(i, n) REP(j, n) {
    if(d[i][j] > d[i][k] + d[k][j]) d[i][j] = d[i][k] + d[k][j];
  }

  ll ans = INF;

  do {
    ll sum = 0;
    FOR(i, 1, R) sum += d[r[i - 1]][r[i]];
    ans = min(ans, sum);
  } while(next_permutation(r, r + R));
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k ;
  vector<int> d(k+1);
  vector<vector<int>> a(1000,vector<int>(1000));
  for(int i=1;i<=k;i++){
    cin >> d[i];
    for(int j=1;j<=d[i];j++){
      cin >> a[i][j];
    }
  }
  vector<bool> aa(n+1,false);
  for(int i=1;i<=k;i++){
    for(int j=1;j<=d[i];j++){
      aa[a[i][j]] = true;
    }
  }
  int cnt = 0;
  for(int i=1;i<=n;i++){
    if(aa[i]==false) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 7544
import math
a, b, h, m = map(int, input().split(" "))
h_ = h*360/12 + m*360/12/60
m_ = m*360/60
# print(h_, m_)
sub = abs(h_ - m_)
c_2 = a**2 + b**2 - 2*a*b*math.cos(math.radians(sub))
print(math.sqrt(c_2))

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {
    
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n)    cin>>s[i];

    sort(all(s));

    vector<pair<string,int>> c;

    int count=1;
    rep(i,n) {
        if(i==n-1)  c.PB(MP(s[i],count));
        else if(s[i]==s[i+1]) {
            count++;
        }
        else {
            c.PB(MP(s[i],count));
            count=1;
        }
    }
    int ma=0;
    int m=c.size();
    rep(i,m) {
        ma=max(ma,c[i].second);
    }
    rep(i,m) {
        if(c[i].second==ma) {
            cout<<c[i].first<<'\n';
        }
    }


 return 0;
}

Measured memory_bytes: 18164
import fractions
A, B, C, D = map(int, input().split())
my_lcm = C * D // fractions.gcd(C, D)
print(
        (B - A + 1 
        - (B // C - (A - 1) // C) 
        - ((B // D - (A - 1) // D)) 
        + (B // my_lcm - (A - 1) // my_lcm)
        )
      )


Measured memory_bytes: 5304
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}


ll cum[100010];
ll Mcum[100010];
int a[100010];
int main() {
	int A,B,C;
	cin>>A>>B>>C;
	if(A+B>=C-1){
		cout<<B+C<<endl;
		return 0;
	}
	else{
		cout<<C-(C-(A+B))+1+B<<endl;
		return 0;
	}
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#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 <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int n, k;
	cin >> n >> k;
	if (n % k != 0) {
		cout << 1<< endl;
	}
	else cout << 0 << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	double V[60];
	cin >> N;
	rep(i, 0, N)
	{
		cin >> V[i];
	}

	sort(V, V + N,greater<double>());

	rrep(i, 1, N)
	{
		V[i - 1] = (V[i] + V[i - 1]) / 2.0;
	}

	cout << fixed << setprecision(10) << V[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<P, ll>;
using PP = pair<P ,P>;
constexpr ll MOD = 998244353;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main(){
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if(x < 4) ans += (4-x)*100000;
    if(y < 4) ans += (4-y)*100000;
    if(x == 1 && y == 1) ans += 400000;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import functools
# from math import gcd
from fractions import gcd

# def gcd(x,y):
#     if x<y:
#         x,y=y,x
#     #x>y
#     if y==0:
#         return x
#     if x%y==0:
#         return y
#     else:
#         return gcd(y,x%y)
 
def solve(N: int, A: "List[int]"):
    L = [0] * (N)
    R = [0] * (N)
 
    for i in range(1, N):
        L[i] = gcd(L[i-1], A[i-1])
    for i in reversed(range(0,N-1)):
        R[i] = gcd(R[i+1], A[i+1])
 
    # print(L)
    # print(R)
 
    ans = 0
    for i in range(N):
        ans = max(ans, gcd(L[i], R[i]))
 
    print(ans)
 
    return
 
 
# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 19028
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    dd = [(-1,0),(1,0),(0,-1),(0,1)]

    while True:
        w,h = LI()
        if w == 0:
            break
        a = [S() for _ in range(h)]
        q = []
        f = collections.defaultdict(bool)
        for i in range(h):
            for j in range(w):
                if a[i][j] == '@':
                    q.append((i,j))
        qi = 0
        while len(q) > qi:
            i,j = q[qi]
            qi += 1
            for di,dj in dd:
                ni = i + di
                nj = j + dj
                if 0 <= ni < h and 0 <= nj < w and a[ni][nj] == '.' and not f[(ni,nj)]:
                    f[(ni,nj)] = True
                    q.append((ni,nj))
        rr.append(len(q))

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9132
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define pqb             	priority_queue<int>
#define pqs             	priority_queue<int,vi,greater<int> >
#define prec(x)             fixed<<setprecision(20)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)  	type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define pi 3.14159265358979323846
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

int power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
}

void JH(){
    int e=0,f=0,g=0,p=0,w=0,flag=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int a,b,c,d;cin>>a>>b>>c>>d;

    e=c*60+d;
    // cout<<e<<endl;
    f1=e*0.5;
    f2=e*6;
    f1=remainder(f1,360.0);
    f2=remainder(f2,360.0);
    f3=(f1-f2);
    // cout<<f1<<" "<<f2<<" "<<f3<<endl;
   	double ans=power(a,2)+power(b,2)-2*a*b*cos(f3*pi/180);
   	cout<<prec(sqrt(ans));
}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<"Execution time: "<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 4276
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int h1, h2, h3, m1, m2, m3, s1, s2, s3, t1, t2, t3;

int main(void) {
  REP(i, 0, 3) {
    cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;

    t1 = h1 * 3600 + m1 * 60 + s1;
    t2 = h2 * 3600 + m2 * 60 + s2;

    t3 = t2 - t1;
    h3 = t3 / 3600;
    m3 = t3 % 3600 / 60;
    s3 = t3 % 3600 % 60;

    cout << h3 << " " << m3 << " " << s3 << endl;
  }

  return 0;
}

Measured memory_bytes: 3000
import sys
from collections import deque
n, q = map(int, input().split())

queues = {str(i): deque() for i in range(n)}

lines = sys.stdin.readlines()
for i in range(q):
    query, *arg = lines[i].split()
    if query == '0':    # enqueue t x
        queues[arg[0]].append(arg[1])
    elif query == '1':  # front
        if len(queues[arg[0]]):
            print(queues[arg[0]][0])
    elif query == '2':  # dequeue
        if len(queues[arg[0]]):
            queues[arg[0]].popleft()
    else:
        raise AssertionError


Measured memory_bytes: 36468
#20:20
a,b = map(int,input().split())
a -= 1
c = [a,b]
ans = 0
for x in c:
  if x % 4 == 0:
    ans ^= x
  elif x % 4 == 1:
    ans ^= 1
  elif x % 4 == 2:
    ans ^= x + 1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, alice = 0, bob = 0;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    
    for (int i = 0; i < n; i++)
    {
        if(i % 2)
            bob += a[i];
        else
            alice += a[i];
    }
    cout << alice - bob << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll INF = 1e9;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++)
    {
        v[i] = i;
        cin >> x[i] >> y[i];
    }

    double ans = 0;
    do
    {
        for(int i = 1; i < n; i++)
        {
            int l = v[i-1];
            int r = v[i];
            double sum = (x[l] - x[r]) * (x[l]-x[r]) + (y[l]-y[r]) * (y[l]-y[r]);
            ans += sqrt(sum);
        }
    }
    while(next_permutation(v.begin(), v.end()));
    int cnt = 1;
    for(int i = 1; i <= n; i++)
    {
      cnt  = cnt *  i;
    }
      
      
    printf("%.10f\n", ans/cnt);
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
res = 0
for i in range(n):
    a = list(map(int,input().split()))
    calc = 0
    for j in range(m):
        calc += a[j]*b[j]
    else:
        calc += c
    if calc > 0:
        res += 1
else:
    print(res)


Measured memory_bytes: 3060
def knapsack(N, C, weights, values):
    dp = [[0 for _ in range(N + 1)] for _ in range(C + 1)]
    for i in range(1, C + 1):
        for j in range(1, N + 1):
            if weights[j - 1] <= i:
                dp[i][j] = max(dp[i][j - 1], values[j - 1] + dp[i - weights[j - 1]][j - 1])
            else:
                dp[i][j] = dp[i][j - 1]
    return dp[C][N]
 
 
if __name__ == '__main__':
    n, c = list(map(int, input().split()))
    weights = [0] * n
    values = [0] * n
    for i in range(n):
        weights[i], values[i] = map(int, input().split())
    print(knapsack(n, c, weights, values))

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<int> l(n);rep(i,n)cin >> l[i];
    rep(i,n)
    {
        int sum = 0;
        rep(j,n)
        {
            if(j==i)continue;
            sum += l[j];
        }
        if(l[i]>=sum)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3592
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
int main(){
	int N;
	cin>>N;
	vector<pair<double, double>> X;
	for(int i=0;i<N;i++){
		double x, y;
		cin>>x>>y;
		X.eb(x, y);
	}
	sort(X.begin(), X.end());
	double ans=0.;
	int cnt=0;
	do{
		cnt++;
		double temp=0.;
		for(int i=1;i<N;i++){
			temp+=sqrt(abs((X[i-1].first-X[i].first)*(X[i-1].first-X[i].first))+abs((X[i-1].second-X[i].second)*(X[i-1].second-X[i].second)));
		}
		ans+=temp;
	}while(next_permutation(X.begin(), X.end()));
	
	for(int i=1;i<=N;i++)
		ans/=double(i);
	//cout<<cnt<<endl;
	cout<<setprecision(20)<<fixed<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	N := ScanInt(scanner)
	
	odd := 0
	for i := 0; i < N; i++ {
	    A := ScanInt(scanner)
	    if A % 2 == 1 {
	        odd++
	    }
	}
	
	if odd % 2 == 0 {
	    fmt.Println("YES")
	} else {
	    fmt.Println("NO")
	}
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func Max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Abs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=1005;

int main()
{
    int n;
    while(~scanf("%d", &n)){
        int l, r, ans=0;
        for(int i=0;i<n;i++){
            scanf("%d%d", &l, &r);
            ans+=abs(r-l)+1;
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdlib>
using namespace std;

#define Rep(i,l,r) for (int i = (l); i <= (r); ++ i)
#define RepD(i,r,l) for (int i = (r); i >= (l); -- i)
#define RepG(i,x) for (int i = hd[x]; i; i = e[i].nxt)

const int N = 1005;

int n, st[N];
struct pt {int x, y;} a[N];

int jd (bool x) {return x? 1: -1;}

int main () {
	bool fl = 0;
	scanf ("%d%d%d", &n, &a[1].x, &a[1].y);
	if (!((a[1].x^a[1].y)&1)) fl = 1, ++ a[1].x;
	Rep(i,2,n) {
		scanf ("%d%d", &a[i].x, &a[i].y);
		if (fl) ++ a[i].x;
		if (!((a[i].x^a[i].y)&1)) {puts ("-1"); return 0;}
	}
	printf ("%d\n", 31+fl);
	if (fl) printf ("1 ");
	Rep(i,0,30) printf ("%d ", 1<<i);
	puts ("");
	Rep(k,1,n) {
		if (fl) putchar ('L');
		int x = a[k].x, y = a[k].y;
		RepD(i,30,0) {
			if (1ll*abs (x+(1<<i))+abs (y)<(1<<i)) x += (1<<i), st[i] = 1;
			else if (1ll*abs (x-(1<<i))+abs (y)<(1<<i)) x -= (1<<i), st[i] = 2;
			else if (1ll*abs (x)+abs (y+(1<<i))<(1<<i)) y += (1<<i), st[i] = 3;
			else y -= (1<<i), st[i] = 4;
		}
		Rep(i,0,30) {
			if (st[i]==1) putchar ('L');
			if (st[i]==2) putchar ('R');
			if (st[i]==3) putchar ('D');
			if (st[i]==4) putchar ('U');
		}
		puts ("");
	}
	return 0;
}


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

// mannhattan distance => 45 degree rotation
// max( abs(x1-x2) + abs(y1-y2) )
// abs(x1-x2) = max( x1-x2, x2-x1)
// =>  max( abs(x1-x2) + abs(y1-y2) ) = max( x1-x2+y1-y2, x1-x2+y2-y1, x2-x1+y1-y2, x2-x1+y2-y1 )
// X = x+y, Y = x-y
// max( abs(x1-x2) + abs(y1-y2) ) = max( X1-X2, Y1-Y2, Y2-Y1, X2-X1 )
// = max( abs(X1-X2), abs(Y1-Y2) ) //

int main(){
    int N;
    cin >> N;
    vector<int> x45(N), y45(N);
    rep(i,N){
        int x,y;
        cin >> x >> y;
        x45[i] = x+y;
        y45[i] = x-y;
    }
    sort(x45.begin(),x45.end());
    sort(y45.begin(),y45.end());
    cout << max( abs(x45[N-1]-x45[0]), abs(y45[N-1]-y45[0]) );
    return 0;
}

Measured memory_bytes: 4820
#include <iostream>
#include <cstdint>
#include <string>
#include <array>
#include <vector>
#include <iterator>
#include <cstdlib>
#include <algorithm>

int main() {
  std::array<std::vector<std::int_fast32_t>, 3> s;
  for (std::int_fast32_t i = 0; i < 3; ++i) {
    std::string s_i;
    std::cin >> s_i;
    std::transform(s_i.begin(), s_i.end(), std::back_inserter(s[i]), [](const char c) {
      switch (c) {
      case 'a':
        return 0;
      case 'b':
        return 1;
      case 'c':
        return 2;
      default:
        exit(EXIT_FAILURE);
      }
    });
  }

  std::int_fast32_t player = 0;
  std::array<std::int_fast32_t, 3> discarded_counts = {0, 0, 0};
  while (true) {
    if (static_cast<std::size_t>(discarded_counts[player]) >= s[player].size()) {
      switch (player) {
      case 0:
        std::cout << "A" << std::endl;
        return 0;
      case 1:
        std::cout << "B" << std::endl;
        return 0;
      case 2:
        std::cout << "C" << std::endl;
        return 0;
      default:
        return EXIT_FAILURE;
      }
    }
    player = s[player][discarded_counts[player]++];
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;


int main()
{
    int w,h;
    cin >> h >> w;

    vector<string> word(h);
    rep(i, h) cin >> word[i];
    
    for(int i = 0; i < h+2; i++)
    {
        if (i == 0 || i == h+1)
        {
            rep(j, w+2)
            {
                cout << "#";
            }
            cout << endl;
        }
        else
        {
                cout << "#" << word[i-1] << "#" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(N)]

constraint = []
for x,y,z in xyz:
    ci = []
    for b in range(8):
        v = 0
        if (b>>0)&1==1: v += x 
        else: v -= x
        if (b>>1)&1==1: v += y
        else: v -= y
        if (b>>2)&1==1: v += z 
        else: v -= z
        ci.append(v)
    #print(ci)
    constraint.append(ci)

ans = 0
for c in zip(*constraint):
    cond = sorted(c, reverse=True)[:M]
    ans = max(ans, sum(cond))
print(ans)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var titleList = new List<string>(N);
            var lengthList = new List<int>(N);

            for (int i = 0; i < N; i++)
            {
                var array = Console.ReadLine().Split();

                titleList.Add(array[0]);
                lengthList.Add(int.Parse(array[1]));
            }

            var X = Console.ReadLine();

            var index = titleList.IndexOf(X);
            var sum = lengthList.Skip(index + 1).Sum();

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13152
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N,K = map(int,input().split())
A = list(map(int,input().split()))
D = sum(A)
D = make_divisors(D)[::-1]

for d in D:
    a = []
    for i in range(N):
        if A[i]%d != 0:
            a.append(A[i]%d)
    a.sort()
    b = [d-x for x in a]
    b.sort()

    c1 = [0]*(len(a)+1)
    for i in range(len(a)):
        c1[i] = a[i]+c1[i-1]
    c2 = [0]*(len(b)+1)
    for i in range(len(b)):
        c2[i] = b[i]+c2[i-1]

    k = float('inf')
    for i in range(len(a)):
        if c1[i] == c2[len(a)-2-i]:
            k = c1[i]
            break
    if k <= K:
        break
print(d)

Measured memory_bytes: 3188
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define ll long long



void solve(){
    
}

int main(){
    
    int n,m,a,b,pass[50]={};
    
    cin>>n>>m;
    rep(i,0,m){
        cin>>a>>b;
        pass[a-1]++;
        pass[b-1]++;
    }
    rep(i,0,n){
        cout<<pass[i]<<endl;
    }
    
    return 0;
}
 

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

x1 = a * c
x2 = a * d
x3 = b * c
x4 = b * d

win = x1
if win < x2:
  win = x2
if win < x3:
  win = x3
if win < x4:
  win = x4

print(win)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
long long n,a[300001],p,ans;
int main()
{
	cin>>n;
	p=n*3;
	for(int i=1;i<=p;i++) cin>>a[i];
	sort(a+1,a+p+1);
	for(int i=p-1;i>=n+1;i-=2) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	long n,p,p1=2,p2=1;
	cin>>n;
	if(n==1){
		cout<<1<<endl;
	}
	else{
		
	
	for(int i=0;i<n-1;i++){
		p=p1+p2;
		p1=p2;
		p2=p;
		
	}
	cout<<p<<endl;
	}

	
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  int i, j, k, l;
  for(i = 0; i < n; i++)
  {
    cin >> x.at(i) >> y.at(i);
  }
  int p, q;
  int min = n;
  for(i = 0; i < n-1; i++)
  {
    for(j = i+1; j < n; j++)
    {
      p = x.at(i) - x.at(j);
      q = y.at(i) - y.at(j);
      int dec = 0;
      for(k = 0; k < n-1; k++)
      {
        for(l = k+1; l < n; l++)
        {
          if((x.at(k) - x.at(l) == p && y.at(k) - y.at(l) == q)||(x.at(k) - x.at(l) == -p && y.at(k) - y.at(l) == -q))
          {
            dec++;
          }
        }
      }
      int count = n - dec;
      if(count < min)min = count;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
void printArray(const vector<T>& a) {
  int n = a.size();
  for (int i = 0; i < n; i++) {
    cout << a[i] << " \n"[i == n - 1];
  }
}

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) { cin >> a[i]; }

  ll i = 1;
  ll mini = a[0];
  vector<ll> m, M;
  while (i <= n) {
    if (i < n && a[i] >= a[i - 1]) {
    } else {
      m.push_back(mini);
      M.push_back(a[i - 1]);
      mini = a[i];
    }
    i++;
  }
  ll ans = 1000;

  REP(i, SZ(m)) {
    ll c = ans / m[i];
    ans += c * (M[i] - m[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
int main(){
    string s; cin >> s;
    bool acount=false;
    int ccount=0;
    bool charcount=true;
    if(s[0]=='A') acount=true;
    for(int i=1; i<s.size(); i++){
        if('a'-s[i]<=0){
            continue;
        }else if(i>1 && i<s.size()-1 && s[i]=='C'){
            ccount++;
        }else{
            charcount=false;
        }
    }

    if(acount && ccount==1 && charcount){
        cout << "AC";
    }else{
        cout << "WA";
    }
    cout << endl;
    return 0;

}

Measured memory_bytes: 256
(let* ((n (read))
       (a (make-array `(,(1+ n)) :initial-element 0))
       (max1 0)
       (max2 0))
  (loop :for i :from 1 :to n
        :for x := (read)
        :do (setf (aref a i) x)
        :do (cond ((<= max1 x)
                   (setf max2 max1)
                   (setf max1 x))
                  ((<= max2 x max1)
                   (setf max2 x))))
  (loop :for i :from 1 :to n
        :do (format t "~A~%" (if (= max1 (aref a i)) max2 max1))))


Measured memory_bytes: 78660
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;
ll arr[200005];

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,c,d,t,r,sm=0;
	string s;
	
	cin >> n;
	for(i=1;i<n;i++)
	{
		cin >> x;
		arr[x]++;
	}
	for(i=1;i<=n;i++)
		cout << arr[i] << endl;

	return 0;
}


Measured memory_bytes: 5072
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               (a).begin(),(a).end()
#define rall(a)              (a).rbegin(),(a).rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=s;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define MAX                  LLONG_MAX
#define MIN                  LLONG_MIN
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,x;cin>>n;
    si s;
    rep(i,0,n) cin>>x,s.insert(x);
    cout<<(s.size()==n?"YES":"NO");
}


Measured memory_bytes: 12904
A,B,C=(input().split())
K = int(input())
A = int(A)
B = int(B)
C = int(C)
for i in range(K):
    if B > C or C == B:
        C = C*2
    elif A > B or B == A:
        B = B*2
if A < B and B < C:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int p[n],q[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
        q[i]=p[i];
    }
    int cnt=0;
    sort(q,q+n);
    for(int i=0;i<n;i++){
        if(p[i]!=q[i])cnt++;
    }
    if(cnt<=2)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heapify, heappush 
def main():
    N, M = map(int, readline().split())
    tasks = [[] for _ in range(M)]
    for _ in range(N):
        a, b = map(int, readline().split())
        if M-a<0:
            continue
        tasks[M-a].append(b)
    s = 0
    h = []
    for i in [i for i in range(M)][::-1]:
        for b in tasks[i]:
            heappush(h, -b)
        if len(h)>0:
            s+=-heappop(h)
    print(s)
if __name__ == '__main__':
    main()


Measured memory_bytes: 22324
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<set>
#include<list>
#include<stack>
#include<vector>
#include<cstdlib>
#include<iterator>
#include<deque>
#include<ctime>
#include<iomanip>
#include<map>
#include<bitset>
#include<utility>
#include<sstream>
using namespace std;
int a[1000001],b[1000001];
int main()
{
	int n,m,i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++)
	{
		int st,ed;
		scanf("%d%d",&st,&ed);
		if(st==1)a[ed]=1;
		if(ed==n)b[st]=1;
	}
	for(i=1;i<=m;i++)
		if(a[i]&&b[i])
		{
			printf("POSSIBLE\n");return 0;
		}
	printf("IMPOSSIBLE\n");
	return 0;
}



Measured memory_bytes: 5120
def gcd(x,y):
    while 1:
        tmp = x%y
        if tmp==0:
            return y
        x = y
        y = tmp

a = list(map(int, input().split()))

if a[0]<=a[1]:
    s = gcd(a[1],a[0])
else:
    s = gcd(a[0],a[1])

print(s)


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

int main() {
    int n, r = 0;
    char c[200010];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        if (c[i] == 'R') r++;
    }

    int ans = 0;
    for (int i = 0; i < r; i++) {
        if(c[i] == 'W') ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3836
require 'pp'

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

s_list = gets_nsp_list
N = s_list.size
children = Array.new(N,0)

count_r, count_l = 0, 0
s_list.each_with_index do |s,i|
  if s == "R"
    count_r += 1
  else
    children[i] += count_r / 2
    children[i-1] += (count_r + 1) / 2
    count_r = 0
  end
end

children.reverse!
s_list.reverse.each_with_index do |s,i|
  if s == "L"
    count_l += 1
  else
    children[i] += count_l / 2
    children[i-1] += (count_l + 1) / 2
    count_l = 0
  end
end

puts children.reverse.join(" ")


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

int main(){
    bool ans =false;
    vector<vector<int>>vec(3,vector<int>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin >> vec[i][j];
        }
    }
    int N;
    cin >>N;
    for(int i=0;i<N;i++){
        int B;
        cin >> B;
        for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            if(vec[i][j] == B){
                vec[i][j] =-1;
                break;
            }
        }
        }
    }
    for(int i=0;i<3;i++){
        if(vec[i][0]==-1 && vec[i][1] == -1 &&vec[i][2] == -1){
            ans =true;
        }
    }
    for(int i=0;i<3;i++){
        if(vec[0][i]==-1 &&vec[1][i] == -1 &&vec[2][i] == -1){
            ans =true;
        }
    }
    if(vec[0][0] == -1 && vec[1][1] == -1 && vec[2][2] == -1){
        ans = true;
    }
    if(vec[2][0] == -1 && vec[1][1] == -1 && vec[0][2] == -1){
        ans = true;
    }
    if(ans == true){
        cout<<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i,a,min,max;
    int b[10000];
    long long sum;
     
    sum = 0;
    min = 1000000;
    max = -1000000;
 
    scanf("%d",&a);
 
    for(i=0;i<a;i++)
    {
        scanf("%d", &b[i]);
 
        if(b[i] < min)
        {
            min = b[i];
        }
        if(b[i] > max)
        {
            max = b[i];
        }
 
        sum = sum + b[i];
    }
 
    printf("%d %d %lld\n",min,max,sum);
 
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int n,m;
  cin >> n >> m;
  vector<pair<int,bool> > prob(n+1,make_pair(1,false));
  prob[1].second=true;
  REP(i,m){
    int x,y;
    cin >> x >> y;
    --prob[x].first;
    ++prob[y].first;
    if(prob[x].second) prob[y].second=true;
    if(prob[x].first==0) prob[x].second=0;
  }
  int answer=0;
  REP(i,n+1) if(prob[i].second) ++answer;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)

def don(dk, rate, amin):
    if not rate:
        return dk
    if len(rate)==1:
        a,b=rate[0]
        p,m=divmod(dk,a)
        return p*b+m
    if len(rate)==2:
        a0,b0=rate[0]
        a1,b1=rate[1]
        if b0/a0<b1/a1:
            a0,b0,a1,b1=a1,b1,a0,b0
        p0,m=divmod(dk,a0)
        re=b0*p0
        p1,m=divmod(m,a1)
        re+=b1*p1+m
        while p0>0 and m>0:
            p0-=1
            m+=a0
            p2,m=divmod(m,a1)
            p1+=p2
            tmp=p0*b0+p1*b1+m
            if tmp>re:
                re=tmp
        return re
    if dk < amin:
        return dk
    if dp[dk] != -1:
        return dp[dk]
    mx = 0
    for a, b in rate:
        if a > dk: continue
        tmp = don(dk - a, rate, amin) + b
        if tmp > mx:
            mx = tmp
    dp[dk] = mx
    return mx

n = int(input())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
atob = []
btoa = []
amin = 10 ** 7
bmin = 10 ** 7
for a, b in zip(aa, bb):
    if a < b:
        atob.append([a, b])
        if a < amin:
            amin = a
    elif a > b:
        btoa.append([b, a])
        if b < bmin:
            bmin = b
dp = [-1] * (n + 1)
n = don(n, atob, amin)
dp = [-1] * (n + 1)
print(don(n, btoa, bmin))


Measured memory_bytes: 198516
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0 ,1, 1, 1, 0, -1, -1, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int v[N];
int dp[N];
int n, k = 2;
int f(int i){
    if(i == n - 1)return 0;
    int &ans = dp[i];
    if(ans == -1){
        ans = 1e9;
        for(int j = 1; j <= k; j++)
            if(i + j < n)
                ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));
            else
                break;
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n;
    fore(i, 0, n)cin >> v[i];
    for(int i = 0; i < n; i++)
        dp[i] = 1e9;
    for(int i = n - 1; i >= 0; i--){
        int &ans = dp[i];
        if(i == n - 1){
            ans = 0;
            continue;
        }
        ans = 1e9;
        for(int j = 1; j <= k; j++){
            if(i + j < n)
                ans = min(ans, dp[i + j] + abs(v[i] - v[i + j]));
            else
                break;
        }
    }
    
    cout << dp[0] << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 4580
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  ll a=0,b=0,c=0,d=0;
  rep(i,N)
  {
    string S; cin>>S;
    if(S=="AC") {a++; continue;}
    if(S=="WA") {b++; continue;}
    if(S=="TLE") {c++; continue;}
    d++;
  }
  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<b<<endl;
  cout<<"TLE x "<<c<<endl;
  cout<<"RE x "<<d<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ers erase
#define ins insert
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << #x << "= " << x << '\n';
#define kill(x) return cout << x, 0;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll MOD = 1000 * 1000 * 1000 + 7;
const ll N = 3e2 + 10;
const ll INF = 1e18;
const ll LOG = 25;

ll dp[N][N][N], n, m, ans = 0;

vector<pll> SEG[N];

bool isval(ll R, ll G, ll B){
	ll Cnt = 0;
	if ((R == G && R != 0)|| (R == B && R != 0) || (G == B && G != 0)) return 0;
	for (auto u:SEG[max({R, G, B})]){
		Cnt = 0;
		if (R >= u.F) Cnt ++;
		if (G >= u.F) Cnt ++;
		if (B >= u.F) Cnt ++;
		if (Cnt != u.S) return 0;
	}
	return 1;
}


int main(){
	cin >> n >> m;
	for (int i = 1; i <= m; i++){
		ll l, r, x;
		cin >> l >> r >> x;
		SEG[r].pb({l, x});
	}
	dp[0][0][0] = 1;
	for (int R = 0; R <= n; R++){
		for (int G = 0; G <= n; G++){
			for (int B = 0; B <= n; B++){
				ll Max = max({R, G, B});
				if (!isval(R, G, B)) dp[R][G][B] = 0;
				else{
					dp[Max + 1][G][B] += dp[R][G][B];
					dp[R][Max + 1][B] += dp[R][G][B];
					dp[R][G][Max + 1] += dp[R][G][B];
					dp[Max + 1][G][B] %= MOD;
					dp[R][Max + 1][B] %= MOD;
					dp[R][G][Max + 1] %= MOD;
				}
				//cout << R << ' ' << G << ' ' << B << ' ' << dp[R][G][B] << '\n';
			}
		}
	}
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= n; j++){
			for (int k = 0; k <= n; k++){
				if (max({i, j, k}) == n){
					ans += dp[i][j][k];
					ans %= MOD;
				}
			}
		}
	}
	cout << ans;

	return 0;

}


Measured memory_bytes: 227584
#include<stdio.h>
#include<string.h>
int main(){
	char s[999];
	char*t="CF ";
	scanf("%s",s);
	int n=strlen(s);
	
	int pos=0;
	for(int i=0;i<n;i++)if(s[i]==t[pos])pos++;
	puts(pos==2?"Yes":"No");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"YES"<<endl
#define cN cout<<"NO"<<endl
#define ll long long


int main(void){
    bool ans1 = false;
    bool ans9 = false;
    bool ans7 = false;
    bool ans4 = false;
    rep(i,4){
        int num;
        cin >> num;
        if(num == 1)ans1 =true;
        else if(num == 9)ans9 =true;
        else if(num == 7)ans7 =true;
        else if(num == 4)ans4 =true;
    }
    if(ans1&&ans9&&ans7&&ans4)cY;
    else cN;
    return 0;
}

Measured memory_bytes: 256