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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
	for(int i=0; i<v.size(); i++) is >> v[i];
	return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;

	int n; cin >> n;
	vector<string> s(n); cin >> s;

	map<string, int> cnt;
	for(string t: s) cnt[t]++;

	cout << "AC x " << cnt["AC"] << endl;
	cout << "WA x " << cnt["WA"] << endl;
	cout << "TLE x " << cnt["TLE"] << endl;
	cout << "RE x " << cnt["RE"] << endl;

	return 0;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s;
    cin >> s;
    int n = sz(s);
    vi cnt(3, 0);
    rep(i, n) cnt[s[i]-'a']++;
    int k = n/3;
    bool flag = true;
    rep(i, 3) {
        if (cnt[i] != k && cnt[i] != k+1) flag = false;
    }
    cout << (flag ? "YES" : "NO") << endl;
    
}

Measured memory_bytes: 512
#include<iostream>
#include<cstring>
using namespace std;
int map[105];
int main()
{
	int n,m;
	cin>>n>>m;
	memset(map,0,sizeof(map));
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		map[a]++;
		map[b]++;
	}
	for(int i=1;i<=n;i++)
		cout<<map[i]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//import jdk.internal.org.jline.utils.InputStreamReader;

//import java.io.*;

public class Main{
        public static void main(final String[] args){
            Scanner scanner = new Scanner(System.in);
        
            while(true){
                int H = scanner.nextInt();
                int W = scanner.nextInt();
                if(H + W == 0){
                    break;
                }
                
                for(int i = 0; i < H; i++){
                    for(int j = 0; j < W; j++){
                        double flag = Math.pow(-1, i + j);
                        if(flag == 1){
                            System.out.printf("#");
                        }else {
                            System.out.printf(".");
                        }
                        
                    }
                    System.out.printf("\n");
                }
                System.out.printf("\n");
            }
            scanner.close();
        }
         

}


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

#define watch(x) cout<<#x<<" -> "<<x<<endl
#define ALL(x) x.begin() , x.end()
#define INF 100000

typedef long long ll;

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N,X,T;
    cin>>N>>X>>T;
    if (N%X == 0){
        cout<<N/X * T<<endl;
    }
    else{
        cout<<((N/X)+1)*T<<endl;
    }
}



Measured memory_bytes: 3648
use proconio::{input, marker::Chars};
use num::BigUint;

fn main() {
    input! {
        s: Chars,
    }

    let len = s.len();

    if len < 4 {
        println!("0");
        return;
    }

    let mut mod_vec: Vec<Vec<usize>> = vec![Vec::new(); 2019];
    let mut rest: usize = 0;
    let modulus = BigUint::from(2019_usize);

    mod_vec[0].push(0);
    for i in 0..len {
        let digit = s[len - i - 1].to_digit(10).unwrap() as usize;
        let pow = BigUint::from(10_usize).modpow(&BigUint::from(i), &modulus);
        rest = (rest + digit * pow.to_u32_digits()[0] as usize) % 2019;
        mod_vec[rest].push(i);
    }

    let mut count = 0;

    for e in &mod_vec {
        if e.len() <= 1 {
            continue;
        }

        count += e.len() * (e.len() - 1) / 2;
    }

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


Measured memory_bytes: 6216
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n, d = map(int, input().split())
    cnt = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if math.sqrt(x**2+y**2) <= d: cnt+=1
    print(cnt)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 79532
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

ll fact[2001], ifact[2001];
ll dp[2001][2001];
ll sum[2001];

ll modulo_inverse(ll n) {
  ll t = MOD - 2, p = 1, q = n;
  while(t > 0) {
    if(t % 2) p = (p * q) % MOD;
    q = (q * q) % MOD;
    t /= 2;
  }
  return p % MOD;
}

int main(void) {
  fact[0] = 1;
  REP(i, 1, 2001) fact[i] = (fact[i - 1] * i) % MOD;
  REP(i, 0, 2001) ifact[i] = modulo_inverse(fact[i]);

  while(1) {
    ll N, D, X;
    cin >> N >> D >> X;

    if(N == 0 && D == 0 && X == 0) break;

    REP(i, 0, N + 1) REP(j, 0, N + 1) dp[i][j] = 0;
    dp[0][0] = 1;

    REP(i, 0, N) {
      sum[0] = 0;
      REP(j, 0, N) sum[j + 1] = (sum[j] + dp[i][j]) % MOD;
      REP(j, 0, N + 1) dp[i + 1][j] = (sum[j] - sum[max(j - X + 1, 0LL)] + MOD) % MOD;
    }

    ll ans = 0;
    REP(i, 1, min(N, D) + 1) {
      ll comb = 1;
      for(ll j = D; j > D - i; j--) comb = (comb * (j % MOD)) % MOD;
      comb = (comb * ifact[i]) % MOD;
      ll x = (comb * dp[i][N]) % MOD;
      ans = (ans + x) % MOD;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 34388
import sys
def main():
    input = sys.stdin.readline
    N = int(input())

    t, a = 1, 1
    for _ in range(N):
        T, A = map(int, input().split())
        nt = t + (T - (t % T) if t % T else 0)
        na = a + (A - (a % A) if a % A else 0)
        n = na // A if nt // T < na // A else nt // T
        t, a = T * n, A * n
    print(t + a)

if __name__ == '__main__':
    main()

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

#define ll long long 
#define pll pair<ll,ll> 
const ll mod=1e9+7;

char A[1005][1005];
ll M[1005][1005];

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<n;i++)
		for(ll j=0;j<m;j++)
			cin>>A[i][j];
	
	memset(M,0,sizeof M);
	//if(A[0][1]=='.')
		//M[0][1]++;
	//if(A[1][0]=='.')
		//M[1][0]++;
	M[0][0]=1;
	
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			if(A[i][j]=='.'){
				if(i-1>=0)
				M[i][j]=(M[i-1][j]);
				if(j-1>=0)
				M[i][j]=(M[i][j]+M[i][j-1])%mod;
			}
		}
	}

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

}


Measured memory_bytes: 12464
/// 13-03-2018
/// MD:NUR ALAM
/// Eastern University of Bangladesh

#include "bits/stdc++.h"

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define repp(i, a, b) for (int i = (a); i < (b); ++i)
#define fo(i, a, b) for (int i = (a); i <(b); ++i)
#define fors(i, s) for (int i = 0; s[i]; ++i)
#define rs(x) scanf("%s", (x))
#define mp make_pair
#define pb push_back
#define mso(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)

using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double lu;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<pii> vpll;
typedef pair<ll,ll> Pll;
typedef map<string,int>msi;
typedef set<ll>se;

template<class t> void _r(t &x) { cin >> x; }
void _r(int &x) { scanf("%d", &x); }
void _r(int64_t &x) { scanf("%lld", &x); }
void _r(double &x) { scanf("%lf", &x); }
void _r(char &x) { scanf(" %c", &x); }
void _r(char *x) { scanf("%s", x); }
void r() {}
template<class t, class... u> void r(t &head, u &... tail) { _r(head); r(tail...); }
template<class t> void _w(const t &x) { cout << x; }
void _w(const int &x) { printf("%d", x); }
void _w(const int64_t &x) { printf("%lld", x); }
void _w(const double &x) { printf("%.16f", x); }
void _w(const char &x) { putchar(x); }
void _w(const char *x) { printf("%s", x); }
template<class t,class u> void _w(const pair<t,u> &x) {_w(x.f); putchar(' '); _w(x.s);}
void w() {}
template<class t, class... u> void w(const t &head, const u &... tail) { _w(head); putchar(sizeof...(tail) ? ' ' : '\n'); w(tail...); }
template<class t, class... u> void debug(const t &head, const u &... tail) {
#ifdef HOME
#endif
}


int main(){

   char c[110];
   int n,a=0,b=0,cc=0,d=0;
   r(n);
   rep(i,n){
       r(c[i]);

       if(c[i]=='P') a=1;
       else if(c[i]=='W') b=1;
       else if(c[i]=='Y') cc=1;
       else if(c[i]=='G') d=1;
   }
     ll z=a+b+cc+d;

     if(z==1) cout<<"One";
     else if(z==2) cout<<"Two";
     else if(z==3) cout<<"Three";
     else if(z==4) cout<<"Four";
}


Measured memory_bytes: 256
a,b,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = min(A) + min(B) 
for i in range(m) :
    X = list(map(int,input().split()))
    y = A[X[0]-1] + B[X[1]-1] - X[2]
    if y <= ans :
        ans = y
print(ans)


Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
bool check(string str)
{
	if(str.size() == 0) 
		return false;
	if(atoi(str.c_str()) >= 256) 
		return false;
	if(str.size() > 1 && str[0] == '0') 
		return false;
	return true;
}
int main()
{
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 1; i < s.size(); i++)
	{
		for(int j = i + 1; j < s.size(); j++)
		{
			for(int k = j + 1; k < s.size(); k++)
			{
				string a, b, c, d;
				a = b = c = d = "";

				a += s.substr(0, i);
				b += s.substr(i, j - i);
				c += s.substr(j, k - j);
				d += s.substr(k, s.size());
				//cout << a << "." << b << "." << c << "." << d << endl;
				if(check(a) == true && check(b) && check(c) && check(d))
				{
					cnt++;
					//cout << a << "." << b << "." << c << "." << d << endl;
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3176
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
	if (a < b)
	{
		int temp = a;
		a = b;
		b = temp;
	}
	int gcd = 0;
	int t = 0;
	while (b != 0)
	{
		t = a % b;
		a = b;
		b = t;
	}
	gcd = a;
	return gcd;
}
int main()
{
	int k,sum=0;
	cin >> k;
	for (int i = 1;i <= k;i++)
	{
		for (int j = 1;j <= k;j++)
		{
			for (int l = 1;l <= k;l++)
			{
				sum+=gcd(gcd(i, j), l);
			}
		}
	}
	cout << sum << "\n";
	return 0;
}

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


bool check(int num){
    for(int i=2;i<=sqrt(num);i++){
        if(num %i==0) return false;
    }
    return true;
}

int main() {
int n; cin>>n;
if(n==2){
    cout<<2; return 0;
}
for(int i=n;i<=1e5+3;i++){
    if(i%2==0){
        continue;
    }
    else{
        if(check(i)==true){
            cout<<i; return 0;
        }
    }
}


return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> x(M);
  vector<int> y(M-1);
  for ( int &X : x)
    cin >> X;
  
  sort(x.begin(), x.end());
  
  int length = x.at(M-1) - x.at(0);

  int count = 0;
  if(N < M){
    for (int i = 0; i < M-1; i++){
      y.at(i) = x.at(i+1) - x.at(i);
    }
    
    sort(y.rbegin(), y.rend());
    for (int i = 0; i < N-1; i++){
      length -= y.at(i);
    }
    count = length;
  }
  
  cout << count << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  char a[10];
  char b[10];
  char c[10];
  scanf("%s%s%s", a, b, c);
  printf("%c%c%c\n", a[0] -0x20,  b[0] -0x20,  c[0] -0x20);
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// up right down left
int mx[4] = {0, 1, 0, -1};
int my[4] = {-1, 0, 1, 0};
int H, W;

int bfs(vector<string> maze, int sx, int sy){
  vector<vector<int>> dist(H, vector<int>(W, -1));
  queue<pair<int, int>> que;
  que.push(make_pair(sx, sy));
  int dx, dy;
  int x, y;
  int ans = -1;
  dist[sy][sx] = 0;
  while(!que.empty()){
    x = que.front().first;
    y = que.front().second;
    que.pop();
    for(int k = 0; k < 4; ++k){
      dx = x + mx[k];
      dy = y + my[k];
      if(dx < 0 || dx >= W || dy < 0 || dy >= H) continue;
      if(maze[dy][dx] == '#') continue;
      if(dist[dy][dx] == -1){
        dist[dy][dx] = dist[y][x] + 1;
        que.push(make_pair(dx,dy));
        ans = max(dist[dy][dx], ans);
      }
    }
  }
  return ans;
}
int main(){
  cin >> H >> W;
  vector<string> maze(H);
  for(int i = 0; i < H; ++i){
    cin >> maze[i];
  }
  int ans = 0;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if(maze[i][j] == '#') continue;
      ans = max(ans, bfs(maze, j, i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>

using namespace std;

#define l first
#define r second

int n, a, b;
vector<int> q;

vector<int> gen()
{
    q.resize(0);
    for (int i = 1; i <= a; i++)
    {
        q.push_back(i);
    }
    vector<int> ans(n + 1);
    for (int k = 0; k <= n - a; k++)
    {
        int cnt = k + 1 + (n - k - 1) / a;
        if (cnt == b)
        {
            //cout << k << endl;
            for (int j = n - a + 1, keklol = 1; j + a >= 1; j -= a)
            {
                for (int i = 0; i < a; i++)
                {
                    if (j + i > k)
                        ans[j + i] = keklol++;
                }
            }
            for (int i = 1; i <= k; i++) ans[i] = n - i + 1;
            return ans;
        }
    }
    return {};
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> a >> b;
    if (a + b > n + 1 || 1LL * a * b < n)
    {
        cout << -1;
        return 0;
    }
    vector<int> t = gen();
    swap(a, b);
    vector<int> g = gen();
    if (t.size() != 0)
    {
        for (int i = 0; i < n; i++) cout << t[i + 1] << " ";
    }
    else if (g.size() != 0)
    {
        for (int i = 0; i < n; i++) cout << n + 1 - g[i + 1] << " ";
    }
}

Measured memory_bytes: 5364
open System 

let R() = Console.ReadLine()

let f : int array -> int =
    Array.windowed 3
    >> Array.where (fun xs -> 
        xs.[0] < xs.[1] && xs.[1] < xs.[2] 
       || xs.[2] < xs.[1] && xs.[1] < xs.[0])
    >> Array.length

let n = int <| R()
let p = R().Split() |> Array.map (string>>int)

f p 
|> printfn "%i"

Measured memory_bytes: 30004
l=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
l2=[0]*100001

N=int(input())

for i in range(1,N+1):
  mn=100000000000000000
  for x in l:
    if i-x>=0 and l2[i-x]<mn:
      mn=l2[i-x]+1
  l2[i]=mn

print(l2[N])

Measured memory_bytes: 3828
from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

A = [list(map(int, input().split())) for _ in range(N)]
flg = [[True for _ in range(N)]for _ in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                print(-1)
                exit()
            if A[i][j] == A[i][k] + A[k][j] and i != k and k != j:
                flg[i][j] = False
                flg[j][i] = False

ans = 0
for i in range(N):
    for j in range(N):
        if flg[i][j]:
            ans += A[i][j]
print(ans//2)

Measured memory_bytes: 46684
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const long long MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

// Nの桁数
int calc_digit(long long N) {
    int res = 0;
    while (N) {
        ++res;
        N /= 10;
    }
    return res;
}

long long GCD(long long x, long long y) {
    return y ? GCD(y, x%y) : x;
}

long long LCM(long long a, long long b) {
    return a / GCD(a, b) * b;
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    // 再帰的に解く (x, y を入れ替えておく)
    long long d = extGCD(b, a % b, y, x); 
    y -= a / b * x;
    return d;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int func(int n,int m) {
    int l=1,r=100000000;
    while (r-l>1) {
        int mid = (l+r)/2;
        int sum=0;
        int t = mid;
        while (t) {
            sum+=t/n;
            t/=n;
        }
        if (sum>=m) {
            r=mid;
        } else {
            l=mid;
        }
    }
    return r;
}

bool isprime(ll n) {
    if(n == 1) return false;
    for(int i=2; i*i<=n; i++) {
        if(!(n%i)) return false;
    }
    return true;
}

vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}

int main() {
    ll n,m;cin>>n>>m;

    const auto &pf = enum_divisors(m);

    ll ans=0;

    for (auto p:pf) {
        if (m/p>=n) {
            ans=p;
        } else {
            break;
        }
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
def zyunretu(s,y):
    l=[]
    for i in range(y,n):
        l.append(s[i])
    l.sort()
    for i in range(len(l)):
        if l[i]==s[y]:
            return i+1
    
def kaizyou(a):
    if a==1:
        return 1
    else:
        return a*kaizyou(a-1)
    
def num(x):
    a=0
    for i in range(n-1):
        a+=(zyunretu(x,i)-1)*kaizyou(n-i-1)
    return a
print(abs(num(p)-num(q)))

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

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, a, b;
    cin >> n >> a >> b;
    if (a % 2 == b % 2) {
        cout << (b - a) / 2 << endl;
        return 0;
    }
    if (a > b) {
        swap(a, b);
    }
    // so a < b
    long long case_1, case_2;
    // Two cases
    // Case (1): Both win until they A is in 1 and then win one more. (a rounds) Then they move together:
    case_1 = a + ((b-a)-1)/2;
    // Case (1): Both lose win until B is in n, then the lose one more. (n-b+1 rounds). Then they move together:
    case_2 = (n-b+1) + (n - (a+(n-b+1)))/2;
    cout << min(case_1, case_2) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = {}
for i in range(n):
  t = input()
  if t in s:
    s[t] += 1
  else:
    s[t] = 1
s = sorted(s.items(), key=lambda x:x[1], reverse=True)
vmax = s[0][1]
ans = []
for si in s:
  if si[1] == vmax:
    ans.append(si[0])
  else:
    break
ans.sort()
for a in ans:
  print(a)


      

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


int main(){
  int n,i,j,k;
  int a[3][3];
  bool ha[3][3];
  for(i=0;i<3;++i){
    for(j=0;j<3;++j){
      cin >> a[i][j];
      ha[i][j]=false;
    }
  }
  cin >> n;
  if(n<=2){
    cout << "No" << endl;
    return 0;
  }
  vector<int> b(n);
  for(i=0;i<n;++i){
    cin >> b[i];
  }
  for(i=0;i<n;++i){
    for(j=0;j<3;++j){
      for(k=0;k<3;++k){
        if(a[j][k]==b[i]){
          ha[j][k]=true;
        }
      }
    }
  }
  bool ans=false;
  int co=0;
  for(i=0;i<3;++i){
    co=0;
    for(j=0;j<3;++j){
      if(ha[i][j]==true){
        co++;
      }
    }
    if(co==3){
      ans=true;
    }
  }
  for(i=0;i<3;++i){
    co=0;
    for(j=0;j<3;++j){
      if(ha[j][i]==true){
        co++;
      }
    }
    if(co==3){
      ans=true;
    }
  }
  if(ha[0][0]==true && ha[1][1]==true && ha[2][2]==true){
    ans=true;
  }
  if(ha[0][2]==true && ha[1][1]==true && ha[2][0]==true){
    ans=true;
  }
  if(ans==true){
    cout <<"Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> c(n + 2);
    for(int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        c[l]++;
        c[r + 1]--;
    }
    for(int i = 1; i <= n; i++){
        c[i] = c[i] + c[i - 1];
        if(c[i] == m){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int W = sc.nextInt();
		long[] dp=new long[W+1];
		int[] w=new int[n];
		long[] v=new long[n];
		for(int i = 0; i<n; i++){
			w[i] =sc.nextInt();
			v[i] = sc.nextLong();
		}
		for(int i = 0; i<n; i++){
			for(int j=W; j>=w[i]; j--){
				dp[j]=Math.max(dp[j],dp[j-w[i]]+v[i]);
			}
		}
		System.out.println(dp[W]);
	}
}


Measured memory_bytes: 21972
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c;
	while(cin>>a>>b>>c) {
		cout<<(a==b ? c : (b==c ? a : b))<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int ang1,ang2;
    while(true){
        scanf("%d %d",&ang1,&ang2);
        if(ang1 == 0 && ang2 == 0) break;
        if(ang1 > ang2) printf("%d %d\n",ang2,ang1);
        else{
            printf("%d %d\n",ang1,ang2);
        }
    }
}


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

using namespace std;
int numfac(int x){
    int count = 0;
    for (int i = 1; i <= x; i++){
        if (x % i == 0)
            count ++;
    }
    return count;
}

int main(){
    int n;
    int count = 0;
    cin >> n;
    for (int x = 1; x <= n; x += 2){
        if (numfac(x) == 8)
            count++;
    }
    cout << count << endl;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define fout(x) cout << fixed << setprecision(20) << x << endl
const int MOD = 1e9 + 7;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 1e-8;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

auto print = [](auto &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
};

template <typename T>
struct edge {
  int from, to;
  T cost;

  edge(const int from, const int to)
      : from(from), to(to), cost(static_cast<T>(1)) {}

  edge(const int from, const int to, const T cost)
      : from(from), to(to), cost(cost) {}

  friend std::ostream& operator<<(std::ostream& os, const edge& e) {
    os << e.from << "->" << e.to << "cost: " << e.cost;
    return os;
  }
  friend std::istream& operator>>(std::istream& is, edge& e) {
    is >> e.from >> e.to >> e.cost;
    return is;
  }
};

template <typename T>
using Edges = std::vector<edge<T>>;


template <typename T>
std::vector<std::vector<T>> warshall_floyd(const Edges<T> &edges, const int n) {
  const T DINF = std::numeric_limits<T>::max();
  std::vector<std::vector<T>> dist(n, std::vector<T>(n, DINF));
  for (auto &e : edges) {
    dist[e.from][e.to] = e.cost;
  }
  for (int i = 0; i < n; ++i) dist[i][i] = 0;
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        if (dist[i][k] == DINF || dist[k][j] == DINF)
          continue;
        else
          dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  return dist;
}

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

  int n;
  cin >> n;
  Edges<ll> edges;
  VVL a(n, VL(n));
  ll ans = 0;
  rep(i, n) rep(j, n) {
    ll d;
    cin >> d;
    edges.emplace_back(i, j, d);
    a[i][j] = d;
    ans += d;
  }
  VVL dist = warshall_floyd(edges, n);
  bool is_ok = true;
  rep(i, n) rep(j, n) {
    if(a[i][j] > dist[i][j]) {
      is_ok = false;
      continue;
    }
    rep(k, n) {
      if(k != i && k != j && a[i][j] == dist[i][k] + dist[k][j]) {
        ans -= a[i][j];
        break;
      }
    }
  }
  is_ok ? out(ans / 2) : out(-1);

  return 0;
}


Measured memory_bytes: 6044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
const ll INF=1e15;
vector<ll> dijkstra(vector<vector<ii>>&adj, ll& n, ll& src) {
	vector<ll> dist(n, INF);
	//map<ll,ll> path;
	dist[src]=0;
	priority_queue<ii> pq;
	pq.push(make_pair(0,src));
	while(!pq.empty()) {
		ll cost=-pq.top().first, cur_node=pq.top().second;
		pq.pop();
		if(dist[cur_node]<cost) continue;
		for (ll i=0; i<adj[cur_node].size(); i++) {
			ll nxt_node=adj[cur_node][i].first, nextDist=cost+adj[cur_node][i].second;
			if(dist[nxt_node]>nextDist) {
				dist[nxt_node]=nextDist;
				pq.push(make_pair(-nextDist, nxt_node));
				//path[nxt_node]=cur_node;
			}
		}
	}
	return dist;
}
int main(){
	ll n; cin>>n;
	vector<vector<ii>>adj(n);
	for(int i=0;i<n-1;i++){
		ll a,b,c; cin>>a>>b>>c;
		a--,b--;
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	ll q,k; cin>>q>>k;
	k--;
	vector<ll>dist=dijkstra(adj,n,k);
	for(int i=0;i<q;i++){
		ll x,y; cin>>x>>y;
		x--,y--;
		cout<<dist[x]+dist[y]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 11120
res = [0] * 4
for i in range(3):
  a, b = map(int, input().split())
  res[a-1] += 1
  res[b-1] += 1

cnt = 0
for i in range(4):
  if res[i] % 2 == 1:
    cnt += 1
if cnt <= 2:
  print("YES")
else:
  print("NO")

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

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

Measured memory_bytes: 256
from collections import deque
INFTY = 10**14+100
N = int(input())
T = {i:[] for i in range(1,N+1)}
for _ in range(N-1):
    a,b,c = map(int,input().split())
    T[a].append((b,c))
    T[b].append((a,c))
Q,K = map(int,input().split())
dist = [INFTY for _ in range(N+1)]
hist = [0 for _ in range(N+1)]
dist[K] = 0
hist[K] = 1
heap = deque([(K,0)])
while heap:
    x,d = heap.popleft()
    for y,d1 in T[x]:
        if hist[y]==0:
            heap.append((y,d+d1))
            dist[y] = d+d1
            hist[y]=1
for _ in range(Q):
    x,y = map(int,input().split())
    print(dist[x]+dist[y])

Measured memory_bytes: 89772
n = int(input())

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

amount = 0
sub = 0
for i in lst1:
    if i%4 == 0:
        amount += 1
    elif i%2 == 0:
        sub += 1

if amount + sub//2 >= len(lst1)//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62576
#include<stdio.h>
#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)

int max(int,int);

int main(void){
  int i,n,k,a[100001],sum,ans;
  
  while(scanf("%d %d",&n,&k),n,k){
    ans=sum=0;
    rep(i,n)scanf("%d",&a[i]);
    rep(i,k)sum+=a[i];
    for(i=0;k<n;i++,k++){
      sum+=a[k]-a[i];
      ans=(ans>sum)?ans:sum;
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;

int		main(void){
	int n;
	string s;
	cin >> n;
	cin >> s;
	int i;
	int j;

	int r = 0;
	int g = 0;
	int b = 0;

	int ii = 0;
	while (ii < n)
	{
		if (s[ii] == 'R')
			r++;
		if (s[ii] == 'G')
			g++;
		if (s[ii] == 'B')
			b++;
		ii++;
	}

	int fix = 0;
	i = 0;
	while (i < n)
	{
		j = i + 1;
		while (j < n)
		{
			if (j + j - i < n)
			{
				if (s[i] != s[j] && s[i] != s[j + j - i] && s[j] != s[j + j - i])
					fix++;
			}
			j++;
		}
		i++;
	}
		cout << (ll)r * (ll)g * (ll)b - fix << endl;
}


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

int main() {
  char siki;
  cin >> siki;
  string boin = "consonant";
   if  (siki=='a' || siki=='u' ||siki=='i' ||siki=='o' ||siki=='e' ){ boin= "vowel";}

 
  cout<< boin ;
}


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

int main() {
	int N,M;

	cin >> N >> M;

	for(int L = M/N; 1<= L; L--){
		if(M % L == 0){
			cout << L << endl;
			return 0;
		}
	}

	return 0;
}

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

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
int main() {
	// 入力
	ll N,K;cin>>N>>K;
	ll A[N];REP(i,N)cin>>A[i];

	// 解法 
    ll ans1 = 0;
	REP(i,N){
        REP(j,N){
            if (i>=j) continue;
            if (A[i]>A[j]) ans1++;
            ans1 %= mod;
        }
    }
    

    ll count[2005] = {0};
    REP(i,N){
        count[A[i]-1]++;
    }
	// REP(i,3) printf("%lld, ", count[i]);
	// printf("\n");
    ll ans2 = 0;
    ll remain = N;
    REP(i,2005){
        remain -= count[i];
        ans2 += count[i]*remain;
    }
	// cout << ans1 << endl;
	// cout << ans2 << endl;
    // K %= mod;
    ll ans = 0;
    ll tmp = K*(K-1);
    tmp /= 2;
    tmp %= mod;
    tmp *= ans2;
    tmp %= mod;
    ans += ans1 * K;
    ans %= mod;
    ans += tmp;
    ans %= mod;
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

class Debugger {
public:
	template<typename T>
	void printVector(vector<T> const &vec, bool printSize=true){
		if(printSize){
			cout << vec.size() << endl;
		}
		for(auto &elem : vec){
			cout << elem << " ";
		}
		cout << endl;
	}

	template<typename T>
	void printMatrix(vector<vector<T>> const &matrix){
		cout << matrix.size()<< " ";
		if(!matrix.empty()){
			cout << matrix[0].size();
		}
		cout << endl; 
		for(auto &vec : matrix){
			printVector(vec, false);
		}
		cout << endl;
	}
};

const int maxN = 200000 + 5;
const double PI = acos(-1);
const int MOD = (int)1e9 + 7;
#define ll long long

class TaskC {
private:
	Debugger debugger;

public:
	void solveOne(int it){
		int k;
		cin >> k;
		unordered_set<int> s;
		int curr = 0;
		for(int i = 0; ; i++) {
			curr = (curr*10 + 7) % k;
			if(curr == 0) {
				cout << i+1 << endl;
				return;
			}
			if(s.count(curr)) {
				break;
			}
			s.insert(curr);
		}
		cout << -1 << endl;
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskC solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 42520
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    int n ;
    cin >> n ;
    set <int> x ;
    int temp ;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> temp ;
        x.insert(temp) ;
    }
    if(x.size() == n) cout <<"YES\n" ;
    else cout <<"NO\n" ;

}


Measured memory_bytes: 13008
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
const long long INF = 1LL << 40;
 
int main()
{
	int N, M, L;
	cin >> N >> M >> L;
 
	vector<vector<long long>> g(N, vector<long long>(N, INF));
	for (int i = 0; i < M; ++i) {
		int A, B, C;
		cin >> A >> B >> C;
		--A;
		--B;
		g[A][B] = C;
		g[B][A] = C;
	}
 
	vector<vector<long long>> d = g;
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
 
	vector<vector<long long>> g2(N, vector<long long>(N, INF));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (d[i][j] <= L) {
				g2[i][j] = 1;
			}
		}
	}
 
	vector<vector<long long>> d2 = g2;
	for (int k = 0; k < N; ++k) {
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
			}
		}
	}
 
	int Q;
	cin >> Q;
	vector<long long> ans(Q);
	for (int i = 0; i < Q; ++i) {
		int s, t;
		cin >> s >> t;
		--s;
		--t;
		if (d2[s][t] == INF) {
			ans[i] = -1;
		}
		else {
			ans[i] = d2[s][t] - 1;
		}
	}
 
	for (auto x : ans) {
		cout << x << endl;
	}
}


Measured memory_bytes: 4096
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for x in range(n)]

dateCnt = 0
for ai in a:
  dt = 0
  cnt = 0
  while dt < d:
    dt = 1 + ai * cnt
    if dt <= d:
      dateCnt = dateCnt + 1
    else:
      break
    cnt  = cnt + 1

print(dateCnt + x)

Measured memory_bytes: 3064
//I AM THE CREED
/* //I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException 
    { 
  
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
          int n=input.nextInt();
          String s=input.next();
          
          int min=Integer.MAX_VALUE;
          int right=0;
          int left=0;
          for(int i=0;i<s.length();i++){
              if(s.charAt(i)=='R'){
                  left++;
              }
          }
          min=left;
          for(int i=s.length()-1;i>=0;i--){
              if(s.charAt(i)=='R'){
                 left--;
                 int moves=Math.max(right, i-left);
                 
                 min=Math.min(min, moves); 
                 right++;
              }
          }
          System.out.println(min);
        }
        
    }
    


}

Measured memory_bytes: 40332
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=105;
int a[N],n,x;
int main()
{
cin >>n>>x;
for(int i=1;i<=n;i++)cin >>a[i];
sort(a+1,a+1+n);
int ans=0;
for(int i=1;i<=n;i++)
	if(x>=a[i])
		ans++,x-=a[i];
if(x&&ans==n)ans--;
cout <<ans;
return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			String line = reader.readLine();
			int n = Integer.parseInt(line);
			if(n == 0){
				break;
			}
			int A = 0;
			int B = 0;
			for(int i = 0; i < n; i++){
				String lines = reader.readLine();
				String[] str = lines.split(" ", -1);
				int a = Integer.parseInt(str[0]);
				int b = Integer.parseInt(str[1]);
				if(a > b){
					A += a + b;
				}
				if(a < b){
					B += a + b;
				}
				if(a == b){
					A += a;
					B += b;
				}
			}
			System.out.println(A + " " + B);
		}
	}
}

Measured memory_bytes: 34696
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    while(cin>>x)
    {
        if(x<1200)
        {
           cout<<"ABC"<<endl;
        }
        else
        {
            cout<<"ARC"<<endl;
        }
    }
    return 0;
}


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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = 0;
			while((n=int.Parse(Console.ReadLine()))!=0)
			{
				int r=0;
				while ((n /= 5)>0)
					r += n;
				Console.WriteLine(r);
			}
		}
	}
}

Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
        ios::sync_with_stdio(0);
        cin.tie(0), cout.tie(0);

        ll A,B,C,D,K,sum=0;;
        cin>>A>>B>>C>>K;

       if(A<=K){sum+=A;K-=A;}
       else {sum+=K;K=0;}

        if(B<=K){sum+=0;K-=B;}
       else {sum+=0;K=0;}

        if(C<=K){sum-=C;K-=C;}
       else {sum-=K;K=0;}

       cout<<sum<<endl;
       return 0;

}


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int fore;
    for (fore = 0; fore < N && S[fore] == '<'; ++fore) {}

    int back;
    for (back = 0; back < N && S[N - back - 1] == '>'; ++back) {}

    cout << N - min(fore, back) << endl;
    return 0;
}



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

void fnInput(string& rsColor)
{
  int nColorSiz;
  cin >> nColorSiz >> rsColor;
}

int fnColorCount(string sColor)
{
  int nColorCnt = 0;
  int nBgn = 0;
  while (nBgn < sColor.size())
  {
    nColorCnt++;
    int nFoward = nBgn + 1;

    while (nFoward < sColor.size() &&
           sColor[nBgn] == sColor[nFoward])
      nFoward++;

    nBgn = nFoward;
  }
  return nColorCnt;
}

int main()
{
  string sColor;

  fnInput(sColor);
  cout << fnColorCount(sColor) << endl;

  return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int cm[][] = new int[h + 2][w + 2];
        Deque<Integer> que = new ArrayDeque<>();
        for (int i = 1; i <= h; i++) {
            String s = sc.next();
            for (int j = 1; j <= w; j++) {
                if (".".equals(s.substring(j - 1, j))) {
                    cm[i][j] = -1;
                } else {
                    que.add(i);
                    que.add(j);
                }
            }
        }
        sc.close();
        int ans = 0;
        while (que.size() > 0) {
            int y = que.poll();
            int x = que.poll();
            ans = cm[y][x] + 1;
            if (cm[y + 1][x] == -1) {
                cm[y + 1][x] = ans;
                que.add(y + 1);
                que.add(x);
            }
            if (cm[y - 1][x] == -1) {
                cm[y - 1][x] = ans;
                que.add(y - 1);
                que.add(x);
            }
            if (cm[y][x + 1] == -1) {
                cm[y][x + 1] = ans;
                que.add(y);
                que.add(x + 1);
            }
            if (cm[y][x - 1] == -1) {
                cm[y][x - 1] = ans;
                que.add(y);
                que.add(x - 1);
            }
        }
        System.out.println(ans - 1);
    }
}

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

template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

const long long INF = 1LL << 60;
const int MAX_N = 1e5 + 10;

int n;
long long h[MAX_N], dp[MAX_N];

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
	}

	for (int i = 0; i < MAX_N; ++i)
	{
		dp[i] = INF;
	}

	dp[0] = 0;
	for (int i = 0; i < n; ++i)
	{
		chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}

	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll N,ans=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    ans+=(i+(N/i)*i)*(N/i)/2;
  }
  cout<<ans;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define GC getchar
#define fi first
typedef int INT;
#define int long long
#define se second
#define SZ(x) ((int)(x).size())
#define FOR(i,a,b) for(int i=(a),__l=(b);i<=__l;++i)
#define DEP(i,a,b) for(int i=(a),__l=(b);i>=__l;--i)
using namespace std;
typedef double db;
typedef long long LL;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int inf=1000000005;
const int _L=1<<21;char _Buf[_L],*__S,*__T;
inline char Fast_getchar(){
if(__S==__T){__T=(__S=_Buf)+fread(_Buf,1,_L,stdin);if(__S==__T)return EOF;}return *__S++;}
template <class __T> inline void read_string(__T s[]){
	char c;for(c=GC();c<33||c>126;c=GC());
	for(;33<=c&&c<=126;*s++=c,c=GC());*s=0;}
template <class __T> inline void read(__T& x){
	x=0;char c=GC();int f=1;
	for(;!isdigit(c);c=GC())c=='-'?f=-1:0;
	for(;isdigit(c);c=GC())x=(x<<1)+(x<<3)+(c^'0');f<0?x=-x:0;}

/*----------------------------------------------------------------------------*/

const int N=1200005;
int n,a[N],sum[N];
int qsum(int l,int r){return sum[r]-sum[l-1];}
int D(int s,int m,int r) {
	return abs(qsum(s,m)-qsum(m+1,r));
}
int getp(int s,int t) {
	int l=s,r=t-1,m1,m2,res;
	while(l<=r) {
		m1=l+(r-l)/3;
		m2=r-(r-l)/3;
		if(D(s,m1,t) <= D(s,m2,t)) res=m1,r=m2-1;
		else res=m2,l=m1+1;
	}return res;
}

int check() {
	int mn=2e9;
	FOR(i,2,n-2) {
		int lp=getp(1,i),rp=getp(i+1,n);
		int mi=min ( min(qsum(1,lp),qsum(lp+1,i)),min(qsum(i+1,rp),qsum(rp+1,n)) );
		int mx=max ( max(qsum(1,lp),qsum(lp+1,i)),max(qsum(i+1,rp),qsum(rp+1,n)) );
		mn=min(mn,mx-mi);
	}return mn;
}


INT main() {
//	freopen("in.in","r",stdin);
	read(n);
	FOR(i,1,n) read(a[i]),sum[i]=sum[i-1]+a[i];
	cout << check() << '\n';
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define ITR(v, i) for(auto ite = v.begin(); ite != v.end(); ite++)
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vl A, B;
    rep(i, n) {
        cin >> x;
        A.push_back(x + (i + 1));
        B.push_back(-x + (i + 1));
    }

    sort(all(A));
    sort(all(B));

    // rep(i, n) { cout << A[i] << " " << B[i] << endl; }

    rep(i, n) { ans += upper_bound(all(B), A[i]) - lower_bound(all(B), A[i]); }

    cout << ans << endl;
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string line;
    cin >> line;
    int cn = 0;
    for(int i = 0; i < 3; i++){
        char x = line[i];
        if(x == '1'){
            cn++;
        }
    }
    cout << cn << "\n";
    return 0;
}


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

#define int long long
#define REP(i,n) for(int i=0;i<n;i++)
#define ARR(i,j) for(int i=-1;i<=1;i++)for(int j=-1;j<=1;j++)if(i!=0||j!=0)
typedef pair<int,int> P;

int h,w;
char a[1002][1002];
int kd[1002][1002];
int sr[1002][1002];
queue<P> now;
queue<P> nxt;

signed main(){
  cin>>h>>w;
  REP(i,h)REP(j,w)cin>>a[i][j];
  REP(i,h)REP(j,w){
    if(i==0||i==h-1||j==0||j==w-1)continue;
    if(a[i][j]!='.'){
      kd[i][j]=a[i][j]-'0';
      ARR(dx,dy)if(a[i+dx][j+dy]=='.')sr[i][j]++;
      if(sr[i][j]>=kd[i][j])nxt.push(P(i,j));
    }
  }
  int res=0;
  while(!nxt.empty()){
    res++;
    swap(now,nxt);
    while(!now.empty()){
      P p=now.front();now.pop();
      if(a[p.first][p.second]=='.')continue;
      a[p.first][p.second]='.';
      nxt.push(p);
    }
    swap(now,nxt);
    while(!now.empty()){
      P p=now.front();now.pop();
      ARR(dx,dy){
        int qx=p.first+dx;
        int qy=p.second+dy;
        sr[qx][qy]++;
        if(a[qx][qy]!='.'&&sr[qx][qy]>=kd[qx][qy])nxt.push(P(qx,qy));
      }
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 19788
#include <bits/stdc++.h>
using namespace std;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define present(container, element) (container.find(element) != container.end())
#define vpresent(container, element) (find(all(container),element) != container.end()) //for vectors

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b;cin>>a>>b;
  int d=0,s=0,m=1;
  d=a+b;s=a-b;m=a*b;
  if(d>=s && d>=m)
  cout<<d;
  else if(s>=d && s>=m)
  cout<<s;
  else
  cout<<m;
    return 0;
}

Measured memory_bytes: 256
for(;scanf("%d%d",&n,&k),n;){
    for(i=0;i<k;i++)scanf("%d",a+i);
    for(;n--;)
      for(i=0;i<k;i++)
        scanf("%d",&x),a[i]-=x;
    for(i=0;i<k&&a[i]>=0;i++);
    puts(k-i?"No":"Yes");
  }
  return 0;
}

Measured memory_bytes: 384