akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long 
#define N 1000005
int n,a[N];
bool vis[N];
int s[N];
int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	std::cin>>n;
	int mx=0;
	rep(i,1,n){
		std::cin>>a[i];
		++s[a[i]];
		mx=std::max(mx,a[i]);
	}
	int g=a[1];
	rep(i,2,n) g=std::__gcd(g,a[i]);
	bool setwise=g==1;
	if(!setwise) return std::cout<<"not coprime\n",0;
	bool pairwise=1;
	rep(i,2,mx){
		if(vis[i]) continue;
		int cnt=0;
		for(int j=i;j<=mx;j+=i){
			vis[j]=1;
			cnt+=s[j];
		}
		if(cnt>1){pairwise=0; break;}
	}
	
	if(pairwise) std::cout<<"pairwise coprime\n";
	else std::cout<<"setwise coprime\n";
	return 0;
}

Measured memory_bytes: 12364
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()


int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int ans = 0;
  rep(i, n) {
    while (h[i] > 0) {
      h[i]--;
      ans++;
      int j = i+1;
      while (h[j] > 0 && j < n) {
        h[j]--;
        j++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]

n = dp[-1] % k

print(n)


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

#define MAX_N 100000

int a[MAX_N];

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i != n - 1 && a[i] == a[i + 1]) i++;
        else ans++;
    }
    printf("%d\n", ans);
    return 0;
}


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

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 1e5 + 10;
const int M = (int) 2018 * 2018;
const int K = (int) 500 + 10;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

string s;

string rv(string s) {
	reverse(all(s));
	return s;
}

bool palindrome(int i, int j) {
	//cout << i << ' ' << j << " " << rv(s.substr(i, j - i + 1)) << ' ' << s.substr(i, j - i + 1) << "\n";
	return rv(s.substr(i, j - i + 1)) == s.substr(i, j - i + 1);
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> s;
	map<char, int> cnt;
	for (auto it : s) {
		cnt[it]++;
	}
	ll ans = (sz(s) + 1) * 1ll * sz(s) / 2;
	for (auto it : cnt) {
		ans -= ((it.s + 1) * 1ll * it.s) / 2;
	}
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 640
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
//#include <chrono>
//#include <set>
//#include <map>
//#include <deque>
//#include <cmath>
//#include <queue>
//#include <cassert>
//#include <random>
//#include <bitset>
//#include <iomanip>
//#include <numeric>
//#include <time.h>
//#include <ctime>
//#include <string>
//#include <cstdio>
//#include <vector>
//#include <cstdlib>
//#include <iostream>
//#include <algorithm>
//#include <unordered_map>
//#include <unordered_set>
//#include <fstream>
//#include <stack>
//#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.14159265358979;
//----------------------------------------------------
#define endl '\n';
//----------------------------------------------------
int n;
int a[2*100*1000];
int res[2*100*1000];
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n;
    forn(i, n) cin >> a[i];
}

int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    int val = 0;
    forn(i, n) val ^= a[i];
    forn(i, n/2){
        res[i*2] = val ^ a[i*2];
        res[i*2+1] = val ^ a[i*2+1];
    }

    forn(i, n) cout << res[i] << " ";

}


Measured memory_bytes: 5140
def shuffle(str, h)
    return str[h..str.size-1]+str[0..h-1]
end
loop do
    s=gets.chomp
    if s=="-"
        break
    end
    m=gets.to_i
    hs=[]
    m.times do
        s = shuffle(s, gets.to_i)
    end
    puts s
end


Measured memory_bytes: 6888
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  string S;
  int w;
  cin >> S >> w;
  int l = S.length();
  for (int i = 0; i < l; i += w) {
	  cout << S[i];
	}
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

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


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(a*b,c);
}

	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;


map<pair<int,int>, int> mp;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        int n;
        cin >> n;
        vector<pair<int,int>>v;
        for(int i = 0; i < n; i++)
        {
            int x,y;
            cin >> x >> y;
            v.push_back({x,y});
        }

        int mx = 0;
        for(int i = 0; i < n; i++)
        {
            int x = v[i].first;
            int y = v[i].second;
            for(int j = 0; j < n; j++)
            {
                if(i == j) continue;
                int p = v[j].first;
                int q = v[j].second;
                int a = x - p;
                int b = y - q;
                // cerr << a << " "<<b<<endl;
                mp[{a,b}]++;
                mx = max(mp[ {a,b}], mx);
            }
        }
        //cerr << n << " "<<mx << endl;
        cout << n - mx << endl;

    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


Measured memory_bytes: 384
import sys
 
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
 
n, y = inm()
not_discov = (-1, -1 , -1)
def solve():
    if y % 1000 != 0:
        print("-1 -1 -1")
    y_n = y // 1000
    for c in range(n + 1):
        b_tmp = y_n - 9 * c - n
        if b_tmp < 0 or b_tmp > 4 * n or b_tmp % 4 != 0:
            continue
        b = b_tmp // 4
        a = n - b - c
        if a < 0 or a > n:
            continue
        return c, b, a
    return not_discov

print(*solve())

Measured memory_bytes: 9104
N = int(input())
n = N % 10
if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
    print("pon")
elif n == 3:
    print("bon")


Measured memory_bytes: 9164
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))

s = input()
ans = "Yes"
for i in range(len(s)):
    if ((i+1) % 2 == 1):
        if (s[i] != "R" and s[i] != "U" and s[i] != "D"):
            ans = "No"
            break
    else:
        if (s[i] != "L" and s[i] != "U" and s[i] != "D"):
            ans = "No"
            break
print(ans)




Measured memory_bytes: 8940
#include<cstdio>

using namespace std;

int abs(int x){
    if (x > 0) {
        return x;
    }else{
        return -x;
    }
    
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int x[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &x[i]);
    }
    int idx0;
    for(int i = 0; i < n; i++){
        if (x[i] >= 0) {
            idx0 = i;
            break;
        }
    }
    
    int mn = 500000000;
    for(int i = 0; i < k; i++){
        if (idx0 + i >= n ) {
            break;
        }else if(idx0 + i + 1 < k){
            continue;
        }
        int sm = 0;
        sm = 2 * x[idx0 + i] + abs(x[idx0 + i + 1 - k]);
        if (mn > sm) {
            mn = sm;
        }
    }
    // printf("%d\n", mn);
    if (n - idx0 >= k) {
        int sm = x[idx0 + k - 1];
        if (mn > sm) {
            mn = sm;
        }   
    }

    if (x[idx0] != 0) {
        idx0--;
    }
    
    // printf("%d\n", mn);
    // printf("idx0 = %d\n", idx0);
    for(int i = 0; i < k; i++){
        if (idx0 - i < 0) {
            break;
        }else if(n - (idx0 + 1) + i + 1 < k){
            continue;
        }
        int sm = 0;
        sm = 2 * abs(x[idx0 - i]) + x[idx0 + k - i - 1];
        if (mn > sm) {
            mn = sm;
        }
        // printf("%d\n", n - idx0 + i + 1);
        // printf("i = %d, sm = %d\n", i,  sm);
    }
    // printf("%d\n", mn);
    // printf("%d\n", idx0);
    if (idx0 >= k - 1) {
        int sm = abs(x[idx0 - k + 1]);
        if (mn > sm) {
            mn = sm;
        }   
    }
    printf("%d\n", mn);
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<vector>

using namespace std;

const int MX = 100005;

typedef pair<int,int> pii;

//int N = 1057, K = 33;
int K = 38, N = K*(K-1) + 1;
int vst[2005][2005];
int cnt[2005];
vector<int> ans[2005];
vector<int> rns[2005];

int main()
{
	for(int i = 1; i <= K; i++){
		ans[1].push_back(i);
		for(int j = (N-1)/K*(i-1)+2, t = 0; t < K-1; j++, t++){
			ans[j].push_back(i);
		}
	}
	for(int i = K+1, t = 0; i <= N; i += K-1, t++){
		for(int j = i, p = 0; j < i+K-1; j++, p++){
			ans[t+2].push_back(j);
			for(int k = 1; k < K; k++){
				int off = (k*t+p) % (K-1);
				ans[2 + (K-1) * k + off].push_back(j);
			}
		}
	}
	printf("%d %d\n", N, K);
	for(int i = 1; i <= N; i++){
		for(int c : ans[i]) printf("%d ", c);
		printf("\n");
	
		for(int c : ans[i]) rns[c].push_back(i);
	}

	for(int i = 1; i <= N; i++){
		for(int c : rns[i]){
			for(int d : rns[i]){
				if( c < d ) vst[c][d]++;
			}
		}
	}
}


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

int main() {
  char C;
  cin >> C;
  string str = "abcdefghijklmnopqrstuvwxyz";
  for (int i = 0; i < str.size(); i++) {
    if (C == str[i]) {
      cout << str[i + 1];
      break;
    }
  }
}

Measured memory_bytes: 256
import sys
from collections import deque
sys.setrecursionlimit(10**7)
inf=float("inf")

def BFS(x,y):
    color=[["white" for _ in range(w+2)] for _ in range(h+2)]
    D=[[inf for _ in range(w+2)] for _ in range(h+2)]

    color[x][y]="gray"
    D[x][y]=0
    queue=deque([[x,y]])
    while len(queue)!=0:
        a,b=queue.popleft()
        for c,d in ((1,0),(0,1),(-1,0),(0,-1)):
            X,Y=a+c,b+d
            if S[X][Y]=="." and color[X][Y]=="white":
                color[X][Y]="gray"
                D[X][Y]=D[a][b]+1
                queue.append([X,Y])
        color[a][b]="black"

    return D


h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for _ in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))
D=BFS(1,1)

black=0
for i in range(1,h+1):
    black +=S[i][1:w+1].count("#")
print(h*w-black-D[h][w]-1 if D[h][w]!=inf else -1)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  int c;

  if (a <= 5) {
    c = 0;
  } else if (a <= 12) {
    c = b / 2;
  } else {
    c = b;
  }

  cout << c << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){


	while(1){
	    int a=0,b=0,c=0;
        int d=0,e=0,f=0;
        cin>>a>>b>>c;
        if(a==-1)break;
        c+=a*3600;
        c+=b*60;
        c=7200-c;
        //cout<<"-"<<c<<endl;
        a=0,b=0;
        f=3*c;
        int flg=1;
        for(;flg==1;){
            flg=0;
            if(c>=3600)a++,c-=3600,flg=1;
            else if(c>=60)b++,c-=60,flg=1;
        }
        printf("%02d:%02d:%02d\n",a,b,c);
        flg=1;
        for(;flg==1;){
            flg=0;
            if(f>=3600)d++,f-=3600,flg=1;
            else if(f>=60)e++,f-=60,flg=1;
        }
        printf("%02d:%02d:%02d\n",d,e,f);



	}


	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<ctime>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<tuple>
#include<cassert>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<iomanip>
#include<climits>
#include<typeinfo>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
double pi = 3.141592653589793238;
using ll = long long;
using namespace std;

ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpcombination[10000][10000];

ll modi = 1000000007;
ll combination(ll n, ll r) {
	if (n == r) { return dpcombination[n][n] = 1; }
	else if (r == 0) { return dpcombination[n][0] = 1; }
	else if (r == 1) { return dpcombination[n][1] = n; }
	else if (dpcombination[n][r]) { return dpcombination[n][r]; }
	else { return dpcombination[n][r] = combination(n - 1, r - 1) % modi + combination(n - 1, r) % modi; }
}

void clockman(int time1) {

	cout << 1.0*(clock() - time1) / CLOCKS_PER_SEC << endl;
	return;
}
//cout << fixed << setprecision(10)



int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	int m, M;
	sort(a.begin(), a.end());
	m = a[0];

	M = a[n - 1];
	cout << M - m << endl;
	


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
struct edge{ll to,cost;};
typedef pair<ll,ll> P;
ll V,d[200001],INF=1e18;
vector<edge> G[200001];
int dijkstra(ll s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d+1,d+V+1,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        ll v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost) d[e.to]=d[v]+e.cost,que.push(P(d[e.to],e.to));
        }
    }
}
int main(){
    ll n,m,l,r,c;
    cin>>n>>m;
    rep(i,m) cin>>l>>r>>c,G[l].push_back({r,c});
    rep(i,n-1) G[i+2].push_back({i+1,0});
    V=n;
    dijkstra(1);
    if(d[n]==INF) {cout<<-1;return 0;}
    cout<<d[n];
}

Measured memory_bytes: 12412
N = int(input())
ans = 'No'
cnt = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
    else:
        cnt = 0
    if cnt == 3:
        ans = 'Yes'
print(ans)
        

Measured memory_bytes: 62352
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long i=sc.nextLong();
		long j=sc.nextLong();
		System.out.println(npmodm_solve(i,j,1000000007));
	}
	public static long npmodm_solve(long n,long p,long m) {		//n^p mod m

		long[] amari=new long[64];

		amari[0]=n%m;
		for(int i=0; i<62; i++) {
			amari[i+1]=amari[i]*amari[i]%m;
		}
		long tmp=p;
		int counter=0;
		long ans=1;
		while(tmp>0) {
			if(tmp%2==1) {
				ans=ans*amari[counter]%m;
				tmp/=2;
				counter++;
			}
			else {
				tmp/=2;
				counter++;
			}
		}
		 return ans;
	}
}


Measured memory_bytes: 26300
#include <iostream>
#include <cstdio>
#define maxn 100000


char dream[6] = {'d', 'r', 'e', 'a', 'm'};
char erase[6] = {'e', 'r', 'a', 's', 'e'};
char dreamer[8] = {'d', 'r', 'e', 'a', 'm', 'e', 'r'};
char eraser[8] = {'e', 'r', 'a', 's', 'e', 'r'};

inline int check (char s[], int a) {
    if (s[a] == 'r') {
        if (s[a-2] ==  's') {
            for (int i = 0; i <= 5; i++) {
                if (eraser[i] != s[a - 5 + i])
                    return -10;
            }
            return a - 6;
        } else if (s[a-2] == 'm') {
            for (int i = 0; i <= 6; i++) {
                if (dreamer[i] != s[a - 6 + i])
                    return -10;
            }
            return a - 7;
        } else
            return -10;
    } else if (s[a] == 'm') {
        for (int i = 0; i <= 4; i++) {
            if (dream[i] != s[a - 4 + i])
                return -10;
        }
        return a - 5;
    } else if (s[a] == 'e') {
        for (int i = 0; i <= 4; i++) {
            if (erase[i] != s[a - 4 + i])
                return -10;
        }
        return a - 5;
    }
    else
        return -10;
}

int main() {
    char s[maxn + 2], rez = 1;
    char ch = fgetc(stdin);
    int i = 0;
    while(ch != '\n') {
        i++;
        s[i] = ch;
        ch = fgetc(stdin);
    }
    int a = i;
    while (a > 0 && rez == 1) {
        a = check(s, a);
        if (a == -10)
            rez = 0;
    }
    if (rez == 1)
        printf("YES");
    else
        printf("NO");
    return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
//static const long double pi = 3.1415926535897932;

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

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

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

ll combination(ll n, ll r) { // nCr の計算
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> WA(n+1);
	vector<bool> AC(n+1);
	for (int i = 1; i <= n; i++) {
		WA[i] = 0;
		AC[i] = false;
	}
	int clearCount = 0, outCount = 0;
	for (int i = 0; i < m; i++) {
		int p;
		string s;
		cin >> p >> s;
		if (AC[p]) continue;
		if (s == "AC") {
			AC[p] = true;
			clearCount++;
			outCount += WA[p];
		} else if (s == "WA"){
			WA[p]++;
		}
	}
	cout << clearCount << " " << outCount << endl;
	return 0;
}

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

int main(){
    string INPUT_STRING;
    int is_ACGT[10]={};
    cin>>INPUT_STRING;
    for(int i;i<INPUT_STRING.size();i++){
        if(INPUT_STRING[i]=='A'||INPUT_STRING[i]=='T'||INPUT_STRING[i]=='G'||INPUT_STRING[i]=='C'){
            is_ACGT[i]=1;
        }
    }
    
    int number_continuous_one=0;
    int number_max_counituous_one=0;
    for(int i;i<INPUT_STRING.size();i++){
        if(is_ACGT[i]==1){
            number_continuous_one+=1;
        }else{
            if(number_max_counituous_one<number_continuous_one){
                number_max_counituous_one=number_continuous_one;    
            }
            number_continuous_one=0;
        }
    }
   if(number_max_counituous_one<number_continuous_one){
        number_max_counituous_one=number_continuous_one;    
    }
    cout<<number_max_counituous_one<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	V<ll> a(n), b(n),c(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n)c[i] = b[i] - a[i];

	ll k = 0;
	rep(i, n) {
		if (c[i] > 0)k += c[i] / 2;
		else k += c[i];
	}

	if (k >= 0)cout << "Yes" << endl;
	else cout << "No" << endl;

}

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

p = a[n-1]
r = []

for i in range(n-1,-1,-1):
    if a[i] >= p:
        p = a[i]
    else:
        r.append(p-a[i])

res = r.count(max(r))

print(res)

Measured memory_bytes: 15020
#include<iostream>
#include<string>
using namespace std;
#define ll long int
int main()
{
ll k,n;
cin>>k>>n;
ll a[n];
for(ll i=0;i<n;i++)
    cin>>a[i];
ll max=(k-a[n-1])+a[0];
for(ll i=0;i<n-1;i++)
{
if(max<(a[i+1]-a[i]))
    max=(a[i+1]-a[i]);
}
cout<<k-max;



return 0;
}


Measured memory_bytes: 1792
# /user/bin/python
# -*- coding: utf-8 -*-
import sys 

n,m = map(int, sys.stdin.readline().rstrip().split())
xyz = []
for _ in range(n):
  xyz.append(list(map(int, sys.stdin.readline().rstrip().split()))+[0])

ans = -sys.maxsize
for i in range(8):
  s = str('{0:03b}'.format(i))
  xyz_s = [(-1)**int(s[0]), (-1)**int(s[1]), (-1)**int(s[2])]

  for j in range(n):
    xyz[j][3] = xyz[j][0]*xyz_s[0] + xyz[j][1]*xyz_s[1] + xyz[j][2]*xyz_s[2] 

  xyz = sorted(xyz, key = lambda x: x[3])

  sum = [0,0,0]
  for i in range(1,m+1):
    sum = [sum[0]+xyz[-i][0], sum[1]+xyz[-i][1], sum[2]+xyz[-i][2]]
  ans = max(ans, abs(sum[0])+abs(sum[1])+abs(sum[2]))

print(ans)

Measured memory_bytes: 3332
#include<cstdio>

int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int l = a+b;
    int r = c+d;
    if(l > r){
        printf("Left");
    }else if(l < r){
        printf("Right");
    }else if(l == r){
        printf("Balanced");
    }
}

Measured memory_bytes: 128
#include <stdio.h>

int A[100][100],n,d[101],f[101];

void bfs(){
  int i,v;
  int a=0,z=0;
  
  for(i=1;i<=n;i++)d[i]=-1;

  f[z++]=1;
  d[1]=0;

  while(a!=z){
    v=f[a++];
      for(i=1;i<=n;i++){
	if(d[i]==-1&&A[v-1][i-1]==1){
	  d[i]=d[v]+1;
	  f[z++]=i;
	}
      }
  }
}


int main(){
  int i,j;
  int x,y,z;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&x,&y);
    x--;
    for(j=0;j<y;j++){
      scanf("%d",&z);
      z--;
      A[x][z]=1;
    }
  }

 
  bfs();

  for(i=1;i<=n;i++) printf("%d %d\n",i ,d[i]);

  return 0;
}



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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> A;
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    cout << *A.rbegin() - *A.begin() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
using ll=long long;
using namespace std;
int main(){
 int a,b;
 cin>>a>>b;
 if(a==1 ) a+=13;
 if (b==1) b+=13;
 if(a<b) cout<<"Bob"<<endl;
 else if(a>b) cout<<"Alice"<<endl;
 else cout<<"Draw"<<endl;
 }



Measured memory_bytes: 3600
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = sc.nextInt()
  val b = sc.nextInt()

  var count = 0
  for (i in 1..n) {
    val sum = i.toString().toCharArray().map { it.toInt() - '0'.toInt() }.sum()
    if (a <= sum && sum <= b) count += i
  }

  println(count)
}


Measured memory_bytes: 33468
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <climits>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

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

//二部グラフの頂点数がそれぞれn,m
//BM bm(n,m);
//適宜add_edge(２つの集合間のedgeのみaddする)
//BM.solve()で最大マッチングの数を計算
class BM {
private:
    struct edge {
        int to,cap,rev;
    };
    vector<vector<edge> > G;
    vector<int> level;
    vector<int> iter;
    int U,V;

public:
    BM(int u,int v) {
        U = u,V = v;
        G.resize(U+V+2);
        rep(i,u){
            init_edge(0,i+1);
        }
        rep(i,v){
            init_edge(U+i+1,U+V+1);
        }
    }

    void init_edge(int from,int to) {
        G[from].push_back((edge){to,1,(int)G[to].size()});
    	G[to].push_back((edge){from,0,(int)G[from].size()-1});
    }

    void add_edge(int from,int to) {
        from += 1,to += U+1;
    	G[from].push_back((edge){to,1,(int)G[to].size()});
    	G[to].push_back((edge){from,0,(int)G[from].size()-1});
    }

    void bfs(int s) {
        fill(level.begin(),level.end(),-1);
    	queue<int> que;
    	level[s] = 0;
    	que.push(s);
    	while(!que.empty()){
    		int v = que.front();
    		que.pop();
    		rep(i,(int)G[v].size()){
    			edge &e = G[v][i];
    			if(e.cap > 0 && level[e.to] < 0){
    				level[e.to] = level[v] + 1;
    				que.push(e.to);
    			}
    		}
    	}
    }

    int dfs(int v,int t,int f) {
    	if(v==t){
    		return f;
    	}
    	for(int &i = iter[v];i<(int)G[v].size();i++){
    		edge &e = G[v][i];
    		if(e.cap > 0 && level[v] < level[e.to]){
    			int d = dfs(e.to,t,min(f,e.cap));
    			if(d>0){
    				e.cap -= d;
    				G[e.to][e.rev].cap += d;
    				return d;
    			}
    		}
    	}
    	return 0;
    }

    int solve() {
        level.resize(U+V+2);
        iter.resize(U+V+2);
    	int flow = 0;
        int s=0,t=U+V+1;
    	for(;;){
    		bfs(s);
    		if(level[t]<0){
    			return flow;
    		}
            fill(iter.begin(),iter.end(),0);
    		int f;
    		while((f=dfs(s,t,numeric_limits<int>::max())) > 0){
    			flow += f;
    		}
    	}
    }
};

int main(){
    int n;
    cin >> n;
    BM bm(n,n);
    vector<int> a(n),b(n),c(n),d(n);
    rep(i,n)cin >> a[i] >> b[i];
    rep(i,n)cin >> c[i] >> d[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[i]<c[j]&&b[i]<d[j]){
                bm.add_edge(i,j);
            }
        }
    }
    cout << bm.solve() << endl;
    return 0;
}

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

vector<int> A, B;

int root_A(int x){
    if(x == A[x]) return x;
    else return A[x] = root_A(A[x]);
}

int root_B(int x){
    if(x == B[x]) return x;
    else return B[x] = root_B(B[x]);
}

int main(){
    int n, k, l;
    cin >> n >> k >> l;
    A.resize(n); B.resize(n);
    for(int i = 0; i < n; i++){
        A[i] = i; B[i] = i;
    }

    for(int i = 0; i < k; i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        int tmp1 = root_A(p);
        int tmp2 = root_A(q);
        if(tmp1 < tmp2) A[tmp1] = tmp2;
        else A[tmp2] = tmp1;
    }
    for(int i = 0; i < l; i++){
        int r, s;
        cin >> r >> s;
        r--; s--;
        int tmp1 = root_B(r);
        int tmp2 = root_B(s);
        if(tmp1 < tmp2) B[tmp1] = tmp2;
        else B[tmp2] = tmp1;
    }

    map<pair<int, int>, int> mp;
    for(int i = 0; i < n; i++){
        mp[make_pair(root_A(i), root_B(i))]++;
    }
    for(int i = 0; i < n; i++){
        if(i) cout << " " << mp[make_pair(root_A(i), root_B(i))];
        else cout << mp[make_pair(root_A(i), root_B(i))];
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 13568
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
short n; vector<short>a; queue<pair<vector<short>,short>>Q;
vector<pair<vector<short>, short>>a1, a2;
set<vector<short>>E;
void init(vector<short>R, short Lim, short D) {
	Q.push(make_pair(R, 0)); E.clear(); E.insert(R);
	while (!Q.empty()) {
		vector<short>H = Q.front().first; short L = Q.front().second; Q.pop();
		if (D == 0)a1.push_back(make_pair(H, L));
		if (D == 1)a2.push_back(make_pair(H, L));
		if (L == Lim)continue;
		for (short i = 0; i < n; i++) {
			for (short j = i + 1; j < n; j++) {
				vector<short>I = H; short Y = j;
				for (short k = i; k <= (i + j) / 2; k++) {
					swap(I[k], I[Y]); Y--;
				}
				if (E.find(I) == E.end()) {
					Q.push(make_pair(I, L + 1));
					E.insert(I);
				}
			}
		}
	}
}
int main() {
	cin >> n; for (short i = 0; i < n; i++) { short p; cin >> p; a.push_back(p); }
	short pos = min(4, n / 2); short pos2 = (n - 1) / 2; init(a, pos, 0); vector<short>Zero;
	for (int i = 0; i < n; i++)Zero.push_back(i + 1); init(Zero, pos2, 1);
	sort(a2.begin(), a2.end());
	short ret = n - 1;
	for (short i = 0; i < a1.size(); i++) {
		int S1 = lower_bound(a2.begin(), a2.end(), make_pair(a1[i].first, (short)0)) - a2.begin();
		int S2 = upper_bound(a2.begin(), a2.end(), make_pair(a1[i].first, pos)) - a2.begin();
		if (S1 != S2)ret = min(ret, (short)(a1[i].second + a2[S1].second));
	}
	cout << ret << endl;
	return 0;
}

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

int dp[2][1001][1001];
//dp[0]:white, dp[1]:black

int main(void){
	int n,k;
	cin>>n>>k;
	rep(i,n){
		int x,y;
		string c;
		cin>>x>>y>>c;
		bool isB = (c=="B")^((x/k + y/k)&1);
		dp[isB][y%k + 1][x%k + 1]++;
	}

	rep1(y,k)rep1(x,k)rep(i,2){
		dp[i][y][x] += dp[i][y-1][x] + dp[i][y][x-1] - dp[i][y-1][x-1];
	}

	int res = 0;
	rep1(y,k)rep1(x,k)rep(i,2){
		int cnt1 = dp[i][k][k] - dp[i][y][k] - dp[i][k][x] + 2*dp[i][y][x];
		int cnt2 = dp[!i][y][k] + dp[!i][k][x] - 2*dp[!i][y][x];
		res = max(res, cnt1+cnt2);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (d - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0;j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0]-lost+c[0]*(i+1-last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j]-lost+c[j]*(i+1-last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 10000)
    {
        vector<ll> tmpD(10);
        rep(j, 10)
        {
            tmpD[j] = (ll)rand() % d;
        }
        vector<ll> tmpN(10);
        rep(j, 10)
        {
            tmpN[j] = ans[tmpD[j]];
            ans[tmpD[j]] = (ll)rand() % 26 + 1;
        }

        if (score >= scorecalc(s, c, d, ans))
            rep(j, 10)
            ans[tmpD[j]] = tmpN[j];
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

Measured memory_bytes: 3796
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int H, W, N;
  get(H, W, N);
  vector<unordered_set<int>> list(H);
  vector<int> mns(H, 1 << 28);
  FOR(i, N) {
    int X, Y;
    get(X, Y);
    X--;
    Y--;
    list[X].insert(Y);
    mns[X] = min(mns[X], Y);
  }
  int mx = 0;
  FORIN(i, 1, H) {
    if (mns[i] <= mx) {
      print(i);
      return 0;
    }
    if (list[i].count(mx + 1)) {
    } else {
      mx++;
    }
  }
  print(H);
  return 0;
}

Measured memory_bytes: 24448
#include<iostream>
        using namespace std;
         
        int main(){
          int a, b, c, d;
          
          cin >> a >> b >> c >> d;
          
          if(abs(a - b) <= d && abs(b - c) <= d){
            cout << "Yes" << endl;
          } else if(abs(a - c) <= d){
            cout << "Yes" << endl;
          } else {
            cout << "No" << endl;
          }
          return 0;
        }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct edge{
  int cost, to;
}edge;

int main(int argc, char *argv[]){
  int a, n, m;
  while(std::cin >> a >> n >> m, a){
    vector<int> d(n, 0), k(m);
    for (int i = 0; i < n - 1; i++) {
      std::cin >> d[i];
    }
    for (int i = 0; i < m; i++) {
      std::cin >> k[i];
    }
    sort(d.begin(), d.end());
    sort(k.begin(), k.end());
    d.push_back(a);
    int ans = 0;
    for (int i = 0; i < k.size(); i++) {
      int x = lower_bound(d.begin(), d.end(), k[i]) -
        d.begin();
      ans += min(abs(k[i] - d[x]),
                 abs(k[i] - d[(x - 1 + d.size())%d.size()]));
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 2056
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
 
P calc(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/(imag((a-b)/c));
}
 
int main(){
  int n;
  double ax,ay,bx,by,cx,cy,dx,dy;
  scanf("%d",&n);
  while(n--){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
    P ans=calc(P(ax,ay),P(bx,by),P(cx,cy),P(dx,dy));
    printf("%.8f %.8f\n",ans.real(),ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
using namespace std;
void lomuto(char s[],long &l,long &r,int &flag){
	while(s[l]!='W')
		l++;
	while(s[r]!='R')
		r--;
	if(l>=r){flag=1;return;}
	swap(s[l],s[r]);l++;r--;
}
bool isSafe(char s[],long n){
	for(long i=0;i<n-1;i++)
		if(s[i]=='W'&& s[i+1]=='R')
			return false;
	return true;
}
long solve(char s[],long n){
	if(isSafe(s,n))
		return 0;
	long l=0,r=n-1;
	long c=0;int flag=0;
	while(r>l){
		lomuto(s,l,r,flag);
		if(flag==0)
		c++;
	}
	return c;

}

int main(){
	long n;char s[200000]="";
	cin>>n;
	cin>>s;
	cout<<solve(s,n);
	return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
int n,k;
map<pair<int,int>,long long int> mp;
vector<int> v[100005];
long long int d[100005];
void solve(int now,int before,long long int dis){
    if(now==before){
        for(auto u:v[now]){
            d[u]=mp[make_pair(min(now,u),max(now,u))];
            solve(u,now,mp[make_pair(min(now,u),max(now,u))]);
        }
    }
    else{
        for(auto u:v[now]){
            if(u!=before){
                if(d[u]>dis+mp[make_pair(min(now,u),max(now,u))]){
                    d[u]=dis+mp[make_pair(min(now,u),max(now,u))];
                    solve(u,now,dis+mp[make_pair(min(now,u),max(now,u))]);
            }}
        }
    }
}

int main(){
    cin >> n;
    int a,b,c;
    for(int i=0;i<n-1;i++){
        cin >> a >> b >> c;
        v[a].push_back(b);
        v[b].push_back(a);
        mp[make_pair(min(a,b),max(a,b))]=c;
    }
    int q;
    cin >> q >> k;
    for(int i=1;i<=n;i++)d[i]=1e18;
    solve(k,k,0);
    for(int i=0;i<q;i++){
        int x,y;
        cin >> x >> y;
        cout << d[x]+d[y] << endl;
    }
}

Measured memory_bytes: 30092
#include<stdio.h>
#include<math.h>

int main(int argc, char* argv[])
{
  double x1, x2, y1, y2;
  double a, b;

  scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  a = (x1 < x2)?(x2 - x1):(x1 - x2);
  b = (y1 < y2)?(y2 - y1):(y1 - y2);
  printf("%.08lf\n", sqrt(a*a+b*b));

  return(0);
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	FOR(i, 1, n) {
		cin >> a[i - 1];
	}
	sort(ALL(a));
	int rem = n-2;
	ll res = a[n-1];
	RFOR(i, n - 2, 0) {
		if (rem == 0)break;
		res += a[i];
		rem--;
		if (rem == 0)break;
		res += a[i];
		rem--;
	}
	pv(res)
}

Measured memory_bytes: 4048
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long LL;
LL i,j,k,n,m;
LL mod=1000000007;
string s;

int main() {
  cin >> n;
  map<LL, int> mp;
  for (i=0;i<n;++i) {
    int t; cin >> t;
    if (mp.find(t) != mp.end()) {
      mp[t] +=1;
    } else {
      mp[t] =1;
    }
  }
  vector<pair<LL, int>> v;
  for (auto const& ele: mp) {
    v.push_back(make_pair(ele.first,ele.second));
  }
  sort(v.begin(), v.end(), [](const pair<LL, int>& a,const pair<LL, int>& b){return a.first > b.first;});
  int edge_cnt =4;
  std::vector<LL> ve;
  while(edge_cnt>0) {
    bool found = false;
    for (i=0; i< v.size();++i){
      if(v[i].second >= 2) {
        ve.push_back(v[i].first);
        v[i].second -= 2;
        edge_cnt -= 2;
        found = true;
        break;
      }
    }
    if(!found) break;
  }
  if (ve.size() == 2){
    cout << ve[0] * ve[1] << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 8696
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <iterator>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<40;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main()
{
    ll n, W, ans, sum = 0, maxi = 1000000000000000LL;
    cin >> n >> W;
    vector<ll> v(n), w(n);
    for (int i = 0; i < n; i++)
    cin >> w[i] >> v[i], sum += v[i];
    vector<ll> dp(sum + 1, maxi);
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = sum - v[i]; j >= 0; --j)
        {
            dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    ans = 0;
    for (ll i = 0; i <= sum; i++)
    {
        if (dp[i] <= W)
        ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,r;
  while(1){
    cin >> n >> r;
    if(n==0) return 0;
    vector<int> card(n);
    vector<int> tmp(n);
    for(int i=0;i<n;i++){
      card[i]=n-i;
    }
    int p,c;
    for(int i=0;i<r;i++){
      cin >> p >> c;
      p--;
      for(int i=0;i<p;i++){
        tmp[i]=card[i];
      }
      for(int i=0;i<c;i++){
        card[i]=card[p+i];
      }
      for(int i=0;i<p;i++){
        card[c+i]=tmp[i];
      }
    }
    cout << card[0] << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	ll N;
	cin >> N;
	ll ans=0;
	ll min=INF;
	REP(i, N){
		ll p;
		cin >> p;
		if(min>p){
			min=p;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256