akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

h, w = map(int, input().split())
ch, cw = map(lambda x: int(x) - 1, input().split())
dh, dw = map(lambda x: int(x) - 1, input().split())
s = [input() for _ in range(h)]

INF = 10**10
cost = [[INF] * w for _ in range(h)]

dxy = [(0, +1, 0), (0, 0, +1), (0, -1, 0), (0, 0, -1)]
dxy += [(1, i, j) for i in [-2, 2] for j in range(-2, 3)]
dxy += [(1, i, j) for j in [-2, 2] for i in range(-1, 2)]
dxy += [(1, -1, -1), (1, -1, +1), (1, +1, -1), (1, +1, +1)]

q = [(0, ch, cw)]
cost[ch][cw] = 0
while q:
    c, x, y = heappop(q)
    if cost[x][y] < c:
        continue

    if x == dh and y == dw:
        break

    for c_, dx_, dy_ in dxy:
        nx = x + dx_
        ny = y + dy_
        nc = c + c_
        if nx < 0 or nx >= h or ny < 0 or ny >= w:
            continue
        if s[nx][ny] == '#':
            continue
        if cost[nx][ny] <= nc:
            continue
        cost[nx][ny] = nc
        heappush(q, (nc, nx, ny))

ans = -1 if cost[dh][dw] == INF else cost[dh][dw]
print(ans)
# print(*cost, sep='\n')


Measured memory_bytes: 117208
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iter = input.split_whitespace();

    let s = iter.next().unwrap();

    let mut result = String::new();
    for _ in 0..s.len() {
        result.push('x');
    }
    return result;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
using namespace std;


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

  string s; cin >> s;
  int left = 10*(s[0]-'0')+(s[1]-'0');
  int right = 10*(s[2]-'0')+(s[3]-'0');
  string ans="NA";
  if((left>12 or left==0) and right <=12 and right>0) ans="YYMM";
  else if(left>0 and left<=12 and (right>12 or right==0)) ans="MMYY";
  else if(left>0 and left<=12 and right>0 and right<=12) ans="AMBIGUOUS";
  cout << ans << endl;
}






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

int main(){
	int a, b, c, x;
	cin >> a >> b >> c >> x;

	int ans = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(500*i+100*j+50*k == x)
					ans++;
			}
		}
	}

	cout << ans << endl;
}

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

bool Plindrome(string S){
    string T = S;
    reverse(T.begin(), T.end());
    return (S == T);
}

int main(){
    string S;
    cin >> S;
    int N = S.length();
    string S_x = "";
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != 'x') {
            S_x += S[i];
        }
    }
    int n = S_x.length();
    int ans = -1;
    if (Plindrome(S_x)) {
        ans = 0;
        vector<int> cnt(n + 1, 0);
        int now = 0;
        for (int i = 0; i < N; i++) {
            if (S[i] == 'x') {
                cnt[now]++;
            } else {
                now++;
            }
        }
        
        for (int i = 0; i < (n + 1) / 2; i++) {
            ans += abs(cnt[i] - cnt[n - i]);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define N 22000000
#define LL long long

const LL mod=1000000007;
LL n,m,k,p,ans,fac[N],ifac[N];

LL inv(LL x){
	return x==1?1:(mod-mod/x)*inv(mod%x)%mod;
}

int main(){
	scanf("%lld%lld%lld",&n,&m,&k); p=n+m;
	fac[0]=1; for (LL i=1;i<=p;++i) fac[i]=fac[i-1]*i%mod;
	ifac[p]=inv(fac[p]); for (LL i=p-1;~i;--i) ifac[i]=ifac[i+1]*(i+1)%mod;
	ans=k*fac[p]%mod*ifac[p-k]%mod;
	for (LL i=1;i<=k;++i){
		ans=(ans+fac[p]*ifac[p-k]%mod*(k-i+1))%mod;
		ans=(ans+2*n*m%mod*(i-1)%mod*(k-i+1)%mod*fac[p-2]%mod*ifac[p-k])%mod;
	}
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 317696
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}
fn binary_search_left<T: Ord>(v: &Vec<T>, x: T) -> usize {
    let mut l: isize = -1;
    let mut r: isize = v.len() as isize;
    while r - l > 1 {
        let m = (r + l) / 2;
        if v[m as usize] < x {
            l = m;
        } else {
            r = m;
        }
    }
    r as usize
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let a: Vec<usize> = parse!(it, n);
    let b: Vec<usize> = parse!(it, n);
    let mut ret = std::usize::MAX;
    'outer: for i in 0..(1 << n) {
        let flags: Vec<bool> = (0..n).map(|j| (i >> j) & 1 == 1).collect();
        let c: Vec<usize> = (0..n).map(|j| if flags[j] { b[j] } else { a[j] }).collect();
        let mut d = c.clone();
        d.sort();
        let mut arg = vec![None; n];
        let mut used = vec![false; n];
        for i in 0..n {
            let l = binary_search_left(&d, c[i]);
            let r = binary_search_left(&d, c[i] + 1);
            for j in l..r {
                if !used[j] && if i < j { j - i } else { i - j } % 2 == flags[i] as usize {
                    arg[i] = Some(j);
                    used[j] = true;
                    break;
                }
            }
            if arg[i] == None {
                continue 'outer;
            }
        }
        let mut p = 0usize;
        for i in 0..n {
            for j in (i + 1)..n {
                p += (arg[i] > arg[j]) as usize;
            }
        }
        ret = std::cmp::min(ret, p)
    }
    println!(
        "{}",
        if ret == std::usize::MAX {
            -1
        } else {
            ret as i64
        }
    );
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
// Vicfred
// https://atcoder.jp/contests/dp/tasks/dp_d
// dynamic programming
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;

void main() {
    long N, W;
    readf("%d %d\n", &N, &W);

    long[] ws = new long[N];
    long[] vs = new long[N];

    long[][] dp = new long[][](N+1, W+1);

    foreach(i; 0..N)
        readf("%d %d\n", &ws[i], &vs[i]);

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= W; j++) {
            if(ws[i-1] <= j)
                dp[i][j] = max(dp[i-1][j],
                        dp[i-1][j-ws[i-1]] + vs[i-1]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }

    dp[N][W].writeln;
}



Measured memory_bytes: 82084
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class A {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N;
        int[] h;
        Input(out N);
        InputArray(out h);
        int[] min = new int[N];
        min[0] = 0;
        min[1] = Math.Abs(h[0] - h[1]);
        for(int i = 2; i < N; i++) {
            int cost1 = Math.Abs(h[i - 1] - h[i]) + min[i - 1];
            int cost2 = Math.Abs(h[i - 2] - h[i]) + min[i - 2];
            if(cost1 < cost2) {
                min[i] = cost1;
            } else {
                min[i] = cost2;
            }
        }
        Print(min[N - 1]);
        Out.Flush();
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 26716
#include <cstdio>
#include <vector>
#include <algorithm>

const int N = 100000 + 10;

int n;
std::vector<int> adj[N];

void init() {
  int m;
  for (scanf("%d%d", &n, &m); m--;) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
}

std::vector<int> ans;

bool flag[N];

void dfs(int a) {
  if (flag[a]) return;
  flag[a] = true;
  ans.push_back(a);
  for (auto b : adj[a]) {
    if (!flag[b]) {
      dfs(b);
      return;
    }
  }
}

int main() {
  init();
  dfs(1);
  std::reverse(ans.begin(), ans.end());
  for (auto a : adj[1]) {
    if (!flag[a]) {
      dfs(a);
      break;
    }
  }
  printf("%d\n", ans.size());
  for (auto i : ans) printf("%d ", i);
  return 0;
}


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

using namespace std;

int main(){
  set<int> s;
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int x;cin >> x;
    s.insert(x);
  }
  if(n == s.size())cout << "YES";
  else cout << "NO";
  return 0;
}

Measured memory_bytes: 9600
N,K=map(int,input().split())
A=list(map(int,input().split()))*2

mod=10**9+7

inside=0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            inside+=1

outside=0
for i in range(N):
    for j in range(N,2*N):
        if A[i]>A[j]:
            outside+=1
    
#print(inside,outside)
print((inside*K+outside*(K-1)*K//2)%mod)

Measured memory_bytes: 3316
s = input()
k = int(input())

if len(s) == 1:
    print(k // 2)
    exit()

if s[0] != s[-1]:
    count = 1
    box = []
    for i in range(len(s)-1):
        if s[i+1] == s[i]:
            count += 1
        else:
            box.append(count)
            count = 1
    box.append(count)

    ans = 0
    for b in box:
        ans += b // 2
    print(ans * k)
    exit()

flag = 0
word = s[0]
for si in s:
    if si != word:
        flag = 1

if flag == 0:
    print(len(s) * k // 2)
    exit()

if k == 1:
    count = 1
    box = []
    for i in range(len(s) - 1):
        if s[i + 1] == s[i]:
            count += 1
        else:
            box.append(count)
            count = 1
    box.append(count)

    ans = 0
    for b in box:
        ans += b // 2
    print(ans)
    exit()


count = 1
box = []
for i in range(len(s)-1):
    if s[i+1] == s[i]:
        count += 1
    else:
        box.append(count)
        count = 1
box.append(count)

front = box[0] // 2
back = box[-1] // 2

mid = 0
for i in range(len(box)-1):
    if i == 0:
        continue
    mid += box[i] // 2

joint = (box[0] + box[-1]) // 2

print(front + back + mid * k + joint * (k-1))


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

signed main() {
  int A, B, C, K; cin >> A >> B >> C >> K;

  int ans = 0;
  
  while(A>0&&K>0) {
    ans++;
    A--;
    K--;
  }
  while(B>0&&K>0) {
    B--;
    K--;
  }
  while(C>0&&K>0) {
    ans--;
    C--;
    K--;
  }

  cout << ans << endl;

}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

vector<int> v;

int main() {
    int n;
    cin >> n;
    rep(i, n){
        int a; cin >> a;
        v.pb(a);
    }

    vector<int> x = v, y = v;
    sort(all(x));
    sort(all(y));

    int af = x[size(x) - 1];
    int as = y[size(y) - 2];

    rep(i, n){
        if(v[i] == af){
            println(as);
        }else{
            println(af);
        }
    }

}


Measured memory_bytes: 4084
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
using namespace std;
int main() {
	long long u[10],v=1,uv[10];
	for (int i = 0; i < 10 ; i++) {
		u[i] = v;
		if (i == 0) uv[i] = u[i];
		else uv[i] = u[i - 1] + u[i];
		v *= 2;
	}
	int h, w;
	while (cin >> h >> w&&h != 0 && w != 0) {
		bool a[10][10000];
		int b[10000];
		fill(b, b + w, 0);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> v;
				if (v == 0) {
					a[i][j] = true;
					b[j]++;
				}
				else a[i][j] = false;
			}
		}
		long long c = 0;
		int sum2 = 0;
		for (c = 0; c <=uv[h-1] ; c++) {
			int c2 = c;
			int b2[10000];
			for (int i = 0; i < w; i++) {
				b2[i] = b[i];
			}
			for (int i = h-1; i >= 0; i--) {
				if (c2 >= u[i]) {
					c2 -= u[i];
					for (int j = 0; j < w; j++) {
						if (a[(h-1)-i][j]) {
							b2[j]--;
						}
						else b2[j]++;
					}
				}
			}
			int sum = 0;
			for (int i = 0; i < w; i++) {
				sum += max(b2[i], h - b2[i]);
			}
			sum2 = max(sum2, sum);
		}
		cout << sum2 << endl;
	}
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int x=a[0],y=a[1];
    vector<int> v;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            v.pb(i);
            v.pb(x/i);
        }
    }
    for(int i=1;i*i<=y;i++){
        if(y%i==0){
            v.pb(i);
            v.pb(y/i);
        }
    }
    sort(be(v));
    bool maki;
    for(int i=v.size()-1;i>=0;i--){
        maki=false;
        for(int j=0;j<n;j++){
            if(a[j]%v[i]){
                if(maki){
                    j=n;
                }
                else{
                    maki=true;
                }
            }
            if(j==n-1){
                cout << v[i]<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};
    
int32_t main(){
    int n, k;
    cin >> n >> k;
    vector<int> v(k, 0);
    FOR(i, 1, n+1){
        v[i%k]++;
    }

    int cnt=0;
    REP(i, k){
        int t = (k-i)%k;
        int u = (k-t)%k;

        if(!((i+u)%k) && t>=0 && u>=0){
            cnt+=v[i]*v[t]*v[u];
        }
    }

    cout << cnt << endl;
}

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

using namespace std;
typedef long long ll;

int main() {
    int N, W; cin >> N >> W;
    vector<int> v(N), w(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i] >> w[i];
    }

    vector<vector<int> > dp(N+1, vector<int>(W+1));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j - w[i] >= 0)
                dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
            else dp[i+1][j] = dp[i][j];
        }
    }

    cout << dp[N][W] << endl;
}



Measured memory_bytes: 6808
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

void Maximum_Profit(vector<int> vec,int n ){
int minv=vec[0];
    int maxv=-2147483648;
    for(int i=1; i < n ; i++){
          maxv= max(maxv, vec[i]-minv);
           minv=min(minv,vec[i]);
        }
  cout << maxv << endl;
    }
  int main(){
     int n;

    cin >> n;
    vector<int> vec(MAX);
    for(int i=0;i<n;i++){
     cin>> vec[i];
  }
   Maximum_Profit(vec, n);
    return 0;
  }



Measured memory_bytes: 4476
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Text.RegularExpressions;

namespace Yuzuki
{
    class Yukari
    {
        public static void Main(string[] args)
        {
            string[] buf = Console.ReadLine().Split();
            int n = int.Parse(buf[0]), m = int.Parse(buf[1]);
            buf = Console.ReadLine().Split();
            int[] vs = new int[m];
            for (int i = 0; i < m; i++)
            {
                vs[i] = int.Parse(buf[i]);
            }
    
            Console.WriteLine(Max(n - vs.Sum(), -1));
        }
    }
}

Measured memory_bytes: 28820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
    int n, m; cin >> n >> m;
    int ans=0, left=1, right=n;
    for(int i=0;i<m;i++){
        int l, r;
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    if(left<=right){
        ans = right-left+1;
    }
    
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int main()
{
string s,t;
cin >> s;

t = s;

reverse(all(s));

int counter = 0;
rep(i,s.size()){
    if(s[i]!=t[i]) counter++;
}

int ans = counter / 2;
cout << ans << endl;


return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
double x[510];
double y[510];
int bfs[510];
double ABS(double a){return max(a,-a);}
double z[510];
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<c;i++){
		scanf("%lf%lf",x+i,y+i);
		z[i]=x[i];
	}
	std::sort(z,z+c);
	double dis=0;
	for(int i=0;i<c-1;i++)dis=max(dis,ABS(z[i]-z[i+1]));
	//printf("%.12f\n",dis);
	double left=0;
	double right=1100000000;
	for(int i=0;i<100;i++){
		double M=(left+right)/2;
		for(int j=0;j<c;j++)bfs[j]=0;
		queue<int>Q;
		for(int j=0;j<c;j++){
			if(x[j]<M){
				bfs[j]=1;
				Q.push(j);
			}
		}
		while(Q.size()){
			int at=Q.front();Q.pop();
			for(int j=0;j<c;j++){
				if(bfs[j])continue;
				if((x[j]-x[at])*(x[j]-x[at])+(y[j]-y[at])*(y[j]-y[at])<4*M*M){
					bfs[j]=1;
					Q.push(j);
				}
			}
		}
		bool dame=false;
		for(int j=0;j<c;j++){
			if(bfs[j]&&x[j]>(double)a-M){
				dame=true;
			}
		}
		if(dame)right=M;
		else left=M;
	}
	printf("%.12f\n",left);
}

Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n,cnt=0,maks=0;
    cin >> n;
    int k[n+1];
    for(int i=0;i<n;i++) {
        cin >> k[i];
        if(k[i]>=maks) maks = k[i],cnt++;


    }

    cout << cnt;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int N=2e5+10;
int a[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<n;i++){
		int x;
		cin>>x;
		a[x]++;
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<"\n";
	return 0;
}


Measured memory_bytes: 4428
n,m = map(int,input().split())
xyz = []
for i in range(n):
    x,y,z = map(int,input().split())
    xyz.append((x,y,z))
k1 = [1,1,1,1,-1,-1,-1,-1]
k2 = [1,1,-1,-1,1,1,-1,-1]
k3 = [1,-1,1,-1,1,-1,1,-1]

sx,sy,sz = 0,0,0
ans_list = []
for i in range(8):
    xyz.sort(key=lambda x: x[0]*k1[i]+x[1]*k2[i]+x[2]*k3[i],reverse=True)
    for j in range(m):
        sx,sy,sz = sx+xyz[j][0],sy+xyz[j][1],sz+xyz[j][2]
    ans_list.append(abs(sx)+abs(sy)+abs(sz))
    sx,sy,sz = 0,0,0
print(max(ans_list))

Measured memory_bytes: 3344
<?php
// スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $n, $t);

$data = array();
for ($i = 0; $i < $n; $i++) {
  $data[] = fscanf(STDIN, "%d %d");
}

$min_cost = -1;

//tより小さい経路でコストが小さいものを更新していく
foreach ($data as $a) {
  if ($a[1] <= $t) {
    if ($min_cost === -1 || $min_cost > $a[0]) {
      $min_cost = $a[0];
    }
  }
}

//min_costが-1のままだったらTLE
if ($min_cost === -1) {
  echo "TLE";
} else {
  echo $min_cost;
}
?>


Measured memory_bytes: 3828
using System;
using System.Collections.Generic;
//重複のない要素のデータ構造はsetという
//C#ではHashSetとSortedHash(並び替えが行われる)

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var H = new HashSet<string>();
        for(int i=0; i < n; i++)
        {

            H.Add(Console.ReadLine());
        }
        Console.WriteLine(H.Count);
    }
}


Measured memory_bytes: 47336
# Euler Tourとimos法で殴る。
from bisect import bisect


N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(M)]

if M % 2 == 1:
    print(-1)
    exit()

inv_ABs = [dict() for _ in range(N+1)]
for i, (A, B) in enumerate(ABs):
    inv_ABs[A][B] = i
    inv_ABs[B][A] = i

reverse_ABs = [False] * M

iseven = [True] * (N+1)
for A, B in ABs:
    if not iseven[B]: # B -> A
        iseven[B] = True
        reverse_ABs[inv_ABs[A][B]] = True
    else:
        iseven[A] = (not iseven[A])


# Euler Tour
start = 1
stack = [start]
parent = [0] * (N+1)
parent[start] = start
et = []
while stack:
    v = stack.pop()
    if v >= 0:
        et.append(v)
        for nv in inv_ABs[v]:
            if parent[nv] == 0:
                parent[nv] = v
                stack.append(~nv)
                stack.append(nv)
    else:
        et.append(parent[~v])

# print(et)

imos = [0] * (len(et) + 1)
odd_nodes = set((i for i, e in enumerate(iseven) if not e))
for i, v in enumerate(et):
    if v in odd_nodes:
        odd_nodes.remove(v)
        imos[i] += 1
    imos[i+1] += imos[i]

for i in range(len(et) - 1):
    if imos[i] % 2 == 1:
        reverse_ABs[inv_ABs[et[i]][et[i+1]]] = (not reverse_ABs[inv_ABs[et[i]][et[i+1]]] )

for rflg, (A, B) in zip(reverse_ABs, ABs):
    if rflg:
        print(B, A)
    else:
        print(A, B)

Measured memory_bytes: 141860
n = gets.to_i
until n == 0
    kaidan = []
    kaidan[1] = 1
    kaidan[2] = 2
    kaidan[3] = 4
    ans = 0
    if n > 3
    for i in 4..n do
        kaidan[i] = kaidan[i-1] + kaidan[i-2] + kaidan[i-3]
    end
    end
    if kaidan[n] % 3650 == 0
        puts kaidan[n] / 3650
    else
        a = (kaidan[n] / 3650)
        puts a + 1
    end
    n = gets.to_i
end


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

using namespace std;

class JOI
{
	public:
	int J,O,I;
	
	JOI()
	{
		J = 0;
		O = 0;
		I = 0;
	}
	JOI operator+ (JOI &b){
		JOI c;
		c.J = J + b.J;
		c.O = O + b.O;
		c.I = I + b.I;
		return c;
	}
	JOI operator- (JOI &b){
		JOI c;
		c.J = J - b.J;
		c.O = O - b.O;
		c.I = I - b.I;
		return c;
	}
	void print(){
		printf("%d %d %d\n",J,O,I);
	}
};

JOI world[1002][1002];

int main()
{
	JOI ans;
	int m,n,k,x1,x2,y1,y2;
	char feeld[1000][1001];

	cin >> m >> n >> k;

	for(int i =0 ;i < m; i++){
		cin >> feeld[i];
	}

	for(int i = 1; i <= m; i++){
		for(int j = 1; j <= n; j++){
			world[i][j] = world[i][j-1] + world[i-1][j] -world[i-1][j-1];
			switch(feeld[i-1][j-1]){
				case 'J':
					world[i][j].J++;
					break;
				case 'O':
					world[i][j].O++;
					break;
				default:
					world[i][j].I++;
			}
		}
	}
	
	for(int i = 0; i < k; i++){
		cin >> y1 >> x1 >> y2 >> x2;
		ans = world[y2][x2] - world[y2][x1-1] - world[y1-1][x2] + world[y1-1][x1-1];
		ans.print();
	}

	return 0;
}

Measured memory_bytes: 13888
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N; ll K; cin >> N >> K;
  vector <ll> A(N), S(N + 1);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    S[i + 1] = S[i] + A[i];
  }

  vector < pair<int, int> > res(N + 1);
  for (int i = 0; i < N + 1; i++){
    ll now = S[i] - i;
    now %= K;
    res[i] = make_pair((now + K) % K, i);
  }
  sort(res.begin(), res.end());
  
  ll ans = 0;
  queue <int> que; que.push(res[0].second);

  for (int i = 1; i < N + 1; i++){
    if (res[i].first != res[i - 1].first){
      while (!que.empty()) que.pop();
      que.push(res[i].second);
    }else{
      while (!que.empty()){
        int Q = que.front();
        if (res[i].second - Q < K) break;
        else que.pop();
      }
      ll now = que.size(); ans += now;
      que.push(res[i].second);
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 998244353;

template <ll mod>
struct ModCombination{
    ll N;
    vector<ll> fact,inv,finv;

    ModCombination(ll n):N(n){
        fact.assign(n+1, 1);
        inv.assign(n+1, 1);
        finv.assign(n+1,1);
        for(int i=1;i<n;i++){
            fact[i+1] = fact[i]*(i+1)%mod;
            inv[i+1] = inv[mod%(i+1)]*(mod-mod/(i+1))%mod;
            finv[i+1] = finv[i]*inv[i+1]%mod;
        }
    }

    ll Comb(ll n,ll k){
        if(k<0||n<k)return 0;
        return (fact[n]*finv[k]%mod)*finv[n-k]%mod;
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,X;cin>>N>>X;
  ModCombination<MOD> C(2*N);
  ll ans=0;
  repeat(K,N+1){
    //debug(K);
    ll tmp=0;
    for(int S=K;S<min(X,2*K+1);S++){
      tmp = (tmp+C.Comb(K,S-K))%MOD;
    }
    //debug(tmp);
    for(int S=X+1;S<=2*K;S+=2){
      if(S<2*(X-1)&&K+X-1-S>0&&K+X-1-S!=X-1-K)tmp = (tmp+C.Comb(K+X-1-S,X-1-K))%MOD;
    }
    if(2*K>=X)tmp = (tmp+(X&1))%MOD;
    //debug(tmp);
    //cerr<<C.Comb(N,K)<<endl;
    ans = (ans+tmp*C.Comb(N,K)%MOD)%MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
const int nmax=40,abmax=10,inf = 1000000;

int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];

int main(void){
  int n,ma,mb;
  cin >> n >> ma >> mb;

  for(int i=0; i<nmax+1; i++){
    for(int j=0; j<nmax*abmax+1; j++){
      for(int k=0; k<nmax*abmax+1; k++){
        dp[i][j][k] = inf;
      }
    }
  }
  dp[0][0][0] = 0;

  int a,b,c;
  for(int i=0; i<n; i++){
    cin >> a >> b >> c;
    for(int j=0; j<nmax*abmax+1; j++){
      for(int k=0; k<nmax*abmax+1; k++){
        dp[i+1][j][k] = min(dp[i][j][k],dp[i+1][j][k]);
        if( (j - a >= 0) && (k - b >= 0) ){
          dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j-a][k-b]+c);
        }
      }
    }
  }

  int ia,ib;
  ia = ma;
  ib = mb;
  int ret = inf;
  while( (ia <= nmax*abmax) && (ib <= nmax*abmax) ){
    ret = min(ret, dp[n][ia][ib]);
    ia += ma;
    ib += mb;
  }
  if(ret == inf){
    ret = -1;
  }
  cout << ret << "\r\n";
  return 0;
}

Measured memory_bytes: 25984
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    REP(i, n){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double ans = v[0];
    FOR(i, 1, n){
        ans = (ans + v[i]) / 2.0;
    }
    printf("%.14f\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

const long long mod = 1000000007;

struct UnionFind{
	vector<int> par;
	void init(int N){
		par.clear();
		for(int i = 0; i < N; ++i){
			par.push_back(i);
		}
	}
	int find(int x){
		if(x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y){
		x = find(x), y = find(y);
		if(x == y) return;
		par[x] = y;
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
};

long long pw[220];

vector<long long> valid_cycles;
vector<long long> num_t;

int N, M, A;

void dfs(int c, UnionFind uf, long long st){
	if(c == M){
		for(int c2 = 1; c2 < M; ++c2){
			if(((st >> c2) & 1) == 0){
				bool flg = false;
				for(int i = 0; i + c2 < M; ++i){
					bool tmp = uf.same(i, i + c2);
					if(!tmp){
						flg = true;
						break;
					}
				}
				if(!flg) return;
			}
		}
		valid_cycles.push_back(st);
		int cnt = 0;
		for(int i = 0; i < M; ++i){
			if(uf.find(i) == i) cnt++;
		}
		num_t.push_back(pw[cnt]);
		return;
	}
	//c is not a period
	bool flg = false;
	for(int i = 0; i + c < M; ++i){
		bool tmp = uf.same(i, i + c);
		if(!tmp){
			flg = true;
			break;
		}
	}
	if(flg){
		dfs(c + 1, uf, st);
	}
	//c is a period
	for(int i = 0; i + c < M; ++i){
		uf.unite(i, i + c);
	}
	dfs(c + 1, uf, st | (1ll << c));
}

long long dp[220];

long long count_s(long long cycles){
	for(int i = 0; i < 220; ++i) dp[i] = 0;
	for(int i = M; i <= N; ++i){
		dp[i] = pw[i - M];
		for(int j = M; j <= i - M; ++j){
			long long coe1 = dp[j];
			long long coe2 = pw[i - M - j];
			dp[i] = (dp[i] - coe1 * coe2) % mod;
		}
		for(int j = i - M + 1; j < i; ++j){
			int d = i - j;
			if((cycles >> d) & 1){
				dp[i] = (dp[i] - dp[j]) % mod;
			}
		}
	}
	long long res = 0;
	for(int i = M; i <= N; ++i){
		long long coe1 = dp[i];
		long long coe2 = pw[N - i];
		res = (res + coe1 * coe2) % mod;
	}
	res += mod;
	res %= mod;
	return res;
}

void count_t(){
	for(int i = (int)valid_cycles.size() - 1; i >= 0; --i){
		for(int j = i + 1; j < valid_cycles.size(); ++j){
			if((valid_cycles[i] & valid_cycles[j]) == valid_cycles[i]){
				num_t[i] = (num_t[i] - num_t[j]) % mod;
			}
		}
	}
}

long long solve(){
	pw[0] = 1;
	for(int i = 1; i < 220; ++i) pw[i] = (pw[i - 1] * A) % mod;
	UnionFind uf;
	uf.init(M);
	dfs(1, uf, 0);
	count_t();
	long long ans = 0;
	for(int i = 0; i < valid_cycles.size(); ++i){
		long long num1 = num_t[i];
		long long num2 = count_s(valid_cycles[i]);
		ans = (ans + num1 * num2) % mod;
	}
	ans += mod;
	ans %= mod;
	return ans;
}

int main(){
	scanf("%d%d%d", &N, &M, &A);
	long long ans = solve();
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1156
import heapq

INF = float('inf')
n, k = map(int, input().split())
sushi = {}

for _ in range(n):
    t, d = map(int, input().split())
    if t not in sushi:
        sushi[t] = []
    sushi[t].append(d)

for s in sushi.values():
    s.sort(reverse=True)

eat_counts = {s: 0 for s in sushi.keys()}

# まだ食べてないやつ
news = []
# リピート
repeats = []
# 食べた履歴
eats = []

# 各寿司の一番おいしいやつを heap へ
for name, deli_li in sushi.items():
    # (-おいしさ, name)
    heapq.heappush(news, (-deli_li[0], name))

sum_deli = 0
variety = 0

for _ in range(k):
    # おいしいやつから食べる
    if news and (not repeats or news[0] <= repeats[0]):
        deli, name = heapq.heappop(news)
        variety += 1
    else:
        deli, name = heapq.heappop(repeats)

    sum_deli += -deli
    eat_counts[name] += 1
    heapq.heappush(eats, (-deli, name))
    if eat_counts[name] < len(sushi[name]):
        heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name))

# 美味しいやつから順に食べた
# 種類増やしたらもっと得点上がるか確かめる
ans = sum_deli + variety ** 2
while True:
    if not news or not eats:
        break

    # 食べたやつポイント小さいやつから置き換えたい
    ate_min_deli, ate_min_name = heapq.heappop(eats)
    eat_counts[ate_min_name] -= 1
    if eat_counts[ate_min_name] <= 0:
        # これは種類減っちゃうからだめ
        continue

    sum_deli -= ate_min_deli

    deli, name = heapq.heappop(news)
    variety += 1
    sum_deli += -deli
    eat_counts[name] += 1

    ans = max(ans, sum_deli + variety ** 2)

print(ans)


Measured memory_bytes: 43652
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// https://atcoder.jp/contests/agc005/tasks/agc005_b
//もしも一番大きいやつならば
// Ci 最大値がiになる区間の個数
// sum of Ci * i

//二番目に大きいのは自分より大きいものをちょうど１個含む区間
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> idx(n);
    REP(i, n) { idx[a[i]] = i; }
    set<int> s;
    ll ans = 0;
    for(int x = n - 1; x >= 0; x--) {
        int i = idx[x];
        ll c = 0;
        { // calc c
            s.insert(i);
            vector<int> l(2, -1);
            vector<int> r(2, n);
            {                        // calc l
                auto it = s.find(i); //いまxがいる場所のiterator
                REP(j, 2) {
                    if(it == s.begin())
                        break;
                    it--;
                    l[j] = *it; // iteratorの値をとる
                }
            }
            {                        // calc r
                auto it = s.find(i); //いまxがいる場所のiterator
                REP(j, 2) {
                    it++;
                    if(it == s.end())
                        break;
                    r[j] = *it; // iteratorの値をとる
                }
            }
            vector<int> ls(2);
            ls[0] = i - l[0];
            ls[1] = l[0] - l[1];
            vector<int> rs(2);
            rs[0] = r[0] - i;
            rs[1] = r[1] - r[0];
            c = (ll)ls[0] * rs[1] + (ll)ls[1] * rs[0];
        }
        ans += c * (x + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>
int main(){
    int a,b,c;
    char op;
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+'){
            c=a+b;
            printf("%d\n",c);
        }
        else if(op=='-'){
            c=a-b;
            printf("%d\n",c);
        }
        else if(op=='*'){
            c=a*b;
            printf("%d\n",c);
        }
        else if(op=='/'){
            c=a/b;
            printf("%d\n",c);
        }
        else if(op=='?'){
            break;
        }
        else{
        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#include <string.h>
#include <map>
#include <bitset>
#include <queue>


#define Z class
#define ln cout<<'\n'
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (n); ++i)
//ASCII a=97, A=65
// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
// sort(vec.begin(), vec.end()); std::greater<>()
// reverse(vec.begin(), vec.end());
// scanf("%s",s);
// printf("%d\n",end-start+1);
// ceil (a + (b - 1)) / b

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
using pll = pair<long long, long long>;

template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;

int main() {
    int N; cin >> N;
    int p = 0; int y = 0; int w = 0; int g = 0;
    rep (i, N) {
        char A; cin >> A;
        if(A=='P') p++;
        else if(A=='Y') y++;
        else if(A=='W') w++;
        else g++;
    }
    if(min({p,y,w,g}) == 0) cout << "Three" << endl;
    else cout << "Four" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define st first
#define nd second
#define PQ priority_queue

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int N = 5;
const int mod = 1e9 + 7;
int mul(int a, int b) {return 1LL * a * b % mod;}
int add(int a, int b){
	a += b;
	if(a > mod) a -= mod;
	return a;
}

int main(){
	int n, sum = 0, ans = 0;
	scanf("%d", &n);	
	for(int i = 1; i <= n; i++){
		int x;
		scanf("%d", &x);
		ans = add(ans, mul(sum, x));
		sum = add(sum, x);
	}
	printf("%d", ans);

}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110

int N;
int b[MAX];
int used[MAX];
vector<int> ans;


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	cin>>N;
	
	for(int i = 1; i <= N; i++){
		cin>>b[i];
	}
	
	for(int i = 1; i <= N; i++){
		int temp = -1, temp2;
		for(int j = 1, con = 1; j <= N; j++){
			if(used[j])continue;
			// cout<<i<<" "<<j<<" "<<con<<" "<<b[j]<<endl;
			if(b[j] == con){
				temp = con;
				temp2 = j;
			}
			con++;
		}
		if(temp == -1){
			cout<<-1<<endl;
			return 0;
		} else {
			ans.push_back(temp);
			used[temp2] = true;
		}
	}
	
	for(int i = N-1; i >= 0; i--){
		cout<<ans[i]<<endl;
	}
	
	return 0;
}

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

int main (){
    int a, b, c, t;
    cin >> a >> b >> c;
    if (a > b){ t = a; a = b; b = t;}
    if (b > c){t = b; b = c; c = t;}
    if (a > b){t = a; a = b; b = t;}
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3088
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a)]
d=[0 for i in range(a)]
for i in range(a):
  d[i]=(c[i][0]*(i+1)*100+c[i][1])
e=[0 for i in range(a)]
f=100000000
def s(e,d,c,i):
  g=0
  h=0
  e[i]=c[i][0]
  for j in range(a):
    if e[j]!=0:
      g+=d[j]
    if e[j]==0:
      h=j
  gh=c[h][0]
  global b
  global f
  if b<=g:
    f=min(f,sum(e))
  elif b<=g+(h+1)*100*(gh-1):
    hh=math.ceil((b-g)/((h+1)*100))
    f=min(f,sum(e)+hh)
  if i!=a-1:
    s(e,d,c,i+1)
  g=0
  h=0
  e[i]=0
  for j in range(a):
    if e[j]!=0:
      g+=d[j]
    if e[j]==0:
      h=j
  gh=c[h][0]
  global b
  global f
  if b<=g:
    f=min(f,sum(e))
  elif b<=g+(h+1)*100*(gh-1):
    hh=math.ceil((b-g)/((h+1)*100))
    f=min(f,sum(e)+hh)
  if i==a-1:
    return
  else:
    s(e,d,c,i+1)

s(e,d,c,0)
print(f)

Measured memory_bytes: 3308
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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
















int main(){
    ll a, b;
    cin >> a >> b;
    cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<62;

struct edge {int to;LL cost;};

const int M_N=100001;


struct Dijkstra{
    vector<edge> G[M_N+1];
    LL d[M_N+1];
    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                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(){
    Dijkstra Da,Db;
    fill(Da.d,Da.d+M_N+1,LINF);
    fill(Db.d,Db.d+M_N+1,LINF);
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--,t--;
    for(int i=0;i<m;i++){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--,v--;
        Da.G[u].pb({v,a});
        Da.G[v].pb({u,a});
        Db.G[u].pb({v,b});
        Db.G[v].pb({u,b});
    }
    Da.d[s]=0;
    Db.d[t]=0;
    Da.dijkstra(s);
    Db.dijkstra(t);
    vector<LL> ans;
    LL sum=LINF;
    for(int i=0;i<n;i++){
        sum=min(sum,Da.d[n-1-i]+Db.d[n-1-i]);
        ans.pb(sum);
    }
    for(int i=0;i<n;i++){
        cout << 1000000000000000LL-ans[n-1-i] << endl;
    }
    return 0;
}

Measured memory_bytes: 19964
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  vector<int> score(n);
  int sum = 0;
  int minScore = 101;
  REP(i, n)
  {
    cin >> score[i];
    sum += score[i];

    if (score[i] % 10 != 0)
    {
      minScore = min(minScore, score[i]);
    }
  }
  if (sum % 10 != 0)
  {
    cout << sum << endl;
  }
  else
  {
    if (minScore != 101)
    {
      sum -= minScore;
      cout << sum << endl;
    }
    else
    {
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	string s;
	cin >> s;
	int hori = 0, ver = 0;
	string H = "an";
	string V = "AN";

	for (int i = 0; i < s.size(); i++)
	{
		if ('A' <= s[i] && s[i] <= 'M') {
			ver += 1;
		}else if ('N' <= s[i] && s[i] <= 'Z') {
			ver -= 1;
		}
		else if ('a' <= s[i] && s[i] <= 'm') {
			hori += 1;
		}
		else {
			hori -= 1;
		}
	}

	string ans = "";
	for (int i = 0; i < abs(hori); i++)
	{
		ans += (hori > 0 ? H[0] : H[1]);
	}

	for (int i = 0; i < abs(ver); i++)
	{
		ans += (ver > 0 ? V[0] : V[1]);
	}
	cout << ans.size() << endl;
	cout << ans << endl;


	return 0;
}



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

int main(){
	char str[1001];

	while(1){
		scanf("%s",str);
		if(str[0] == '0')break;
		int sum = 0;
		for(int i = 0; i < strlen(str);i++){
			sum += (str[i]-'0');
		}

		printf("%d\n",sum);
	}

	return 0;
}

Measured memory_bytes: 3192