akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
using namespace std;


int main(){
	int n,b,f,r,v ;
	cin >>n;
	int t1[10][3]={{0}};
	int t2[10][3]={{0}};
	int t3[10][3]={{0}};
	int t4[10][3]={{0}};	
	for(int i=0; i<n;i++){
		cin >> b >> f >> r>>v;
		if(b ==1){
			t1[r-1][f-1] += v;
		}
		else if(b ==2){
			t2[r-1][f-1] += v;
		}
		else if(b ==3){
			t3[r-1][f-1] += v;
		}
		else if(b ==4){
			t4[r-1][f-1] += v;
		}
	}
	for(int x=0;x<3;x++){
		for(int y =0;y<10;y++){
			cout <<" "<<t1[y][x];
		}
		cout <<"\n";
	}
	for(int w=0;w<20;w++){
		cout<<'#';
	}
	cout <<"\n";
	for(int x=0;x<3;x++){
		for(int y =0;y<10;y++){
			cout <<" "<<t2[y][x];
		}
		cout <<"\n";
	}
	for(int w=0;w<20;w++){
		cout<<'#';}
		cout <<"\n";
	for(int x=0;x<3;x++){
		for(int y =0;y<10;y++){
			cout <<" "<<t3[y][x];
		}
		cout <<"\n";
	}
	for(int w=0;w<20;w++){
			cout<<'#';}
	cout <<"\n";
	for(int x=0;x<3;x++){
		for(int y =0;y<10;y++){
			cout <<" "<<t4[y][x];
		}
		cout <<"\n";
	}
return 0;
}



Measured memory_bytes: 3092
n = int(input())
x = list(map(int,input().split()))
pmin = min(x)
pmax = max(x)
unchi = []
for t in range(pmax-pmin+1):
	p = t+pmin
	count = 0
	for i in range(n):
		count = count + (x[i]-p)**2
	unchi.append(count)
print(min(unchi))

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9+7;

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

int main() {
  string s, t;
  cin >> s >> t;

  int m = s.size(), n = t.size();
  vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (s[i] == t[j]) {
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }

  string ans(dp[m][n], ' ');
  int i = m - 1, j = n - 1;
  int tail = ans.size() - 1;
  while (i >= 0 && j >= 0) {
    if (s[i] == t[j]) {
      ans[tail--] = s[i];
      i--; j--;
    } else if (dp[i][j+1] >= dp[i+1][j]) {
      i--;
    } else {
      j--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, D, x; cin >> r >> D >> x;
  rep(i, 10) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (int y = 0; y < H; y++) cin >> s.at(y);
  bool ans = true;
  vector<int> dy = { 0, 0, 1, -1 };
  vector<int> dx = { 1, -1, 0, 0 };
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++) {
      if (s.at(y).at(x) == '.') continue;
      bool flag = false;
      for (int i = 0; i < 4; i++) {
        int ny = y + dy.at(i);
        int nx = x + dx.at(i);
        if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
        if (s.at(ny).at(nx) == '#') flag = true;
      }
      if (!flag) ans = false;
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main() {

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  int sum = 0;
  for (int i = 0; i < M; i++) {
     cin >> A.at(i);
     sum += A.at(i);
  }
    
    if(N>=sum) {
        cout << N-sum << endl;
    }
    else {
        cout << "-1" << endl;
    }
    
}

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

using namespace std;
using ll = int64_t;

int reverse_game(ll i, const vector<ll>& as, ll& n_min, ll& n_max) {
  i--;
  if (n_max < as[i])
    return -1;
  if (i == 0) {
    n_max += as[0] - 1;
    return 0;
  } else {
    auto d_min = (n_min-1) / as[i-1];
    n_max += as[i] - 1;
    auto d_max = n_max / as[i-1];
    if (d_min == d_max)
      return -1;
    else {
      n_min = (d_min + 1) * as[i-1];
      n_max = d_max * as[i-1];
      return reverse_game(i, as,n_min, n_max);
    }
  }
}

int main() {
  ll k;
  cin >> k;
  if (k < 1 || pow(10, 5) < k) {
    cout << "-1";
    return 0;
  }
  vector<ll> a(k);
  for (auto & z : a) {
    cin >> z;
  }
  for (auto & z : a) {
    if (z < 2 || pow(10, 9) < z ) {
      cout << "-1";
      return 0;
    }
  }

  ll n_min=2, n_max=2;
  if(reverse_game(k, a, n_min, n_max) == 0) {
    cout << n_min << " " << n_max;
  } else {
    cout << "-1";
  }
  return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  if(b%a == 0){
    cout << a + b << endl;
  }
  else{
    cout << b - a << endl;
  }
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[100010],n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a,a+n+1);
	cout<<a[n/2+1]-a[n/2];
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				bad = 1;
			}
		}
		
		if(bad){
			cout << "NO" << endl;
			bad = 0;
		}else{
			cout << "YES" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var str string
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%s", &str)
	chars := strings.Split(str, "")

	var K int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &K)

	ns := make([]int, len(chars))
	for i, c := range chars {
		ns[i], _ = strconv.Atoi(c)
	}

	countFirstOne := 0
	notOne := -1
	for _, n := range ns {
		if n == 1 {
			countFirstOne++
		} else {
			notOne = n
			break
		}
	}

	if K <= countFirstOne {
		fmt.Println(1)
	} else {
		fmt.Println(notOne)
	}
}


Measured memory_bytes: 640
import collections
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt
if __name__ == "__main__":
    N,K = map(int,input().split())
    Len = N
    A = list(map(int,input().split()))
    num = 10 ** 9 + 7
    ti = (K * (K -1) // 2)%num
    count = 0
    cnt = bubble_sort(A)
    count = (count +cnt*K) % num
    C = collections.Counter(A)
    c = sorted(C.items(),key=lambda x:x[1],reverse = True)
    for a in c:
        b = a[1]
        Len -= b
        for i in range(b):
            count = (count + Len * ti) % num
    print(int(count))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int A = 0;
  cin >> N;
  int B = N;
  for (int i = 0; i < 8; i++) {
    A += N % 10;
    N /= 10;
    if (N / 10 == 0) {
      A = A + N % 10;
      if (B % A == 0) {
        cout << "Yes" << endl;
        break;
      }
      else {
        cout << "No" << endl;
        break;
      }
    }
  }
}
    

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b, c, k) = readLine()!!.split(' ').map(String::toInt)
    val list = mutableListOf<Int>()
    if(k<=a){
        println(k)
    }else if(k<=a+b){
        println(a)
    }else{
        println(a-(k-a-b))
    }
}


Measured memory_bytes: 36188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{	
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		a[i] = abs(tmp - x);
	}

	int ans = a[0];
	for (int i = 0; i < n; i++) {
		ans = gcd(a[i], ans);
	}
	cout << ans << endl;
}

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

int main() {
	string str;
	char ch;
	cin >> str;
	for(int i=0;i<(int)str.size();i++){
		ch=str[i];
		ch-=3;
		if(ch<'A'){
			ch+=26;
		}
	cout << ch;
	}
	cout << endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3084
#define _GLIBCXX_DEBUG
#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 Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> S(N, vector<int>(26));
    rep(i, N){
        string a;
        cin >> a;
        rep(j, a.size()){
            S[i][a[j] - 'a']++;
        }
    }

    rep(i, 26){
        int num = INF;
        rep(j, N){
            num = min(num, S[j][i]);
        }
        rep(j, num) cout << char('a' + i);
    }
}

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

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

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++) cin >> a[i][j];
    }

    int ans = 1e7;// INF
    for(int bit=0; bit<(1<<n); bit++){
        int money = 0;
        vector<int> understand(m);
        for(int i=0; i<n; i++){
            if((bit >> i) & 1){
                money += c[i];
                for(int j=0; j<m; j++){
                    understand[j] += a[i][j];
                }
            }
        }
        bool flag = true;
        for(int j=0; j<m; j++){
            if(understand[j] < x) flag = false;
        }
        if(flag == true) ans = min(ans, money);
    }
    if(ans == 1e7) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int d[n],sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>d[i];
    }
    int i,j;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            sum=sum+(d[i]*d[j]);
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int a = cin.nextInt();
        int b = cin.nextInt();
        int c = cin.nextInt();
        int d = cin.nextInt();
        System.out.println(Math.ceil(1.0*a/d)>=Math.ceil(1.0*c/b) ? "Yes" : "No");
    }
}


Measured memory_bytes: 35764
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
struct Sched
{
public:
    bool operator<(const Sched& sched) const
    {
        if (s != sched.s) return s < sched.s;
        else if (c != sched.c) return c < sched.c;
        else return t < sched.t;
    }

    int s, t, c;
};

struct Recorder
{
public:
    int time = 0;
    int prev = -1;
};
//------------------------------------------------------------------------------
void _main()
{
    int N, C;
    cin >> N >> C;
    vector<Sched> scheds(N);
    {
        int s, t, c;
        rep(i, 0, N)
        {
            cin >> s >> t >> c;
            scheds[i] = {s, t, c};
        }
    }
    sort(scheds.begin(), scheds.end());

    array<Recorder, 30> recorders;

    for (const auto& sched : scheds)
    {
        for (auto& recorder : recorders)
        {
            if ((recorder.prev == -1) ||
                (recorder.time == sched.s && recorder.prev == sched.c) ||
                (recorder.time < sched.s))
            {
                recorder.time = sched.t;
                recorder.prev = sched.c;
                break;
            }
        }
    }

    int ans = 0;
    for (const auto& recorder : recorders)
    {
        if (recorder.prev != -1) ++ans;
    }

/*
    while (!scheds.empty())
    {
        ++ans;
        int time = 0;
        int prev = -1;

        while (true)
        {
            Sched sched = {time, 0, prev};
            auto it = lower_bound(scheds.begin(), scheds.end(), sched);

            if (it == scheds.end())
            {
                break;
            }

            if ((prev != -1) && !(it->s == time && it->c == prev))
            {
                Sched sched = {time + 1, 0, 0};
                it = lower_bound(scheds.begin(), scheds.end(), sched);
            }

            if (it == scheds.end())
            {
                break;
            }

            time = it->t;
            prev = it->c;
            scheds.erase(it);
        }
    }
    */
    cout << ans << endl;
}


Measured memory_bytes: 1408
/*
* @author:  codancer
* @createTime:  2020-05-02, 20:19:15
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	ll n,a,b;
	cin>>a>>b>>n;
	ll x=min(b-1,n);
	cout<<(x*a)/b+a*(x/b)<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    string s;
    cin >> s;
    deque<char> q;
    for(char c : s) q.push_back(c);
    bool flip = false;
    int Q;
    cin >> Q;
    rep(i, Q) {
        int ti;
        cin >> ti;
        if(ti == 1) {
            flip = !flip;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if(flip) f = 3 - f;
            if(f == 1) {
                q.push_front(c);
            } else {
                q.push_back(c);
            }
        }
    }

    if(flip) reverse(all(q));
    string ans;
    for(char c : q) ans += c;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N, K;
 cin >> N >> K;
 
 if ( N % 3 == 0 || K % 3 == 0 || (N + K) % 3 == 0 ){
   cout << "Possible" << endl;
 }
  else{
    cout << "Impossible" << endl;
  }
 }

Measured memory_bytes: 256
import itertools

N = int(input())
P = "".join(list(map(str, input().split())))
Q = "".join(list(map(str, input().split())))

a = 0
b = 0
deck = list(map(str, range(1,N+1)))
cnt = 0
for s in itertools.permutations(deck):
	ss = "".join(s)
	if ss == P:
		a = cnt
	if ss == Q:
		b = cnt

	cnt += 1

print(abs(a-b))


Measured memory_bytes: 3064
import java.util.Scanner;



public class Main {

	public static void main(String[] args) {
		
	Scanner scanner = new Scanner(System.in);
	
	int a = scanner.nextInt();
	int b = scanner.nextInt();
	
	if(a>b){
		System.out.println("a > b");
	}
	if(a<b){
		System.out.println("a < b");
	}
	if(a==b){
		System.out.println("a == b");
			}
		}
	}

Measured memory_bytes: 26172
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
//var input = 1463616;
var n = parseInt(input);
var on = n;

var primes = [];
while (n % 2 == 0) {
    primes.push(2);
    n = n / 2;
}
for (var i = 3; i <= Math.sqrt(n); i += 2) {
    while (n % i == 0) {
        primes.push(i);
        n /= i;
    }
}
if (n > 1) primes.push(n);

console.log(on + ': ' + primes.join(' '));


Measured memory_bytes: 16004
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{
	    ll s=0;
	    int n,k;
	    cin>>n>>k;
	    int a[n];
	    f(i,n)cin>>a[i];
	    sort(a,a+n);
	    f(i,k)
	    {
	        s+=a[i];
	    }
	   
	   p1(s);
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 3644
a,b = map(int, input().split())
s = input()
number = ['0','1','2','3','4','5','6','7','8','9']
cnt = 0

for i in range(a):
  if s[i] in number :
    cnt = cnt +1
    
if s[a] == '-':
  cnt = cnt +1
      
for j in range(a+1,a+b+1):
  if s[j] in number :
    cnt = cnt + 1

if cnt == a+b+1 :
  print('Yes')
else:
  print('No')

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

typedef long long ll;

#define rep(i,n) for(int i = 0; i < n; i++)
#define debug(x) cerr << #x << ": " << x << "\n";

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  string n;
  cin >> n;
  if(n.find("7") != string::npos) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3104
S=input()
lst=[]
i=0
while i<len(S):
    if S[i]=='A':lst+=[1]
    elif S[i]=='B' and i<len(S)-1 and S[i+1]=='C':lst+=[2];i+=1
    else:lst+=[0]
    i+=1
lll=[]
i=0
while i<len(lst):
    c=i
    while i<len(lst) and lst[c]==lst[i]:
        i+=1
    lll+=[[lst[c],i-c]]
r=0
i=0
while i<len(lll)-1:
    if lll[i][0]==1 and lll[i+1][0]==2:
        r+=lll[i][1]*lll[i+1][1]
        lll[i],lll[i+1]=lll[i+1],lll[i]
        if i<len(lll)-2 and lll[i+2][0]==1:
            lll[i+2][1]+=lll[i+1][1]
    i+=1
print(r)

Measured memory_bytes: 16228
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
char s[1000001];
main() {
	int n=read();
	cin>>s;
	int ans=0;
	for(int i=0; i<strlen(s); i++)
		if(s[i]!=s[i-1]) ans++;
	cout<<ans;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>

using namespace std;
int main()
{
    // 整数の入力
    long a,b,k;
    cin >> a >> b;
    k = (a + b)/2 ;
    if(abs(a-k) == abs(b-k))
    {
        cout << k << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1<<26
using namespace std;
int n,l;
int ans=INF;
int a[1111111];
int dfs(int now);//今みているつらら
int main(){
  cin >> n >> l;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ans=-1;
  for(int i=0;i<n;i++){
    ans=max(ans,dfs(i));// << endl;
  }
  cout << ans << endl;
}

int dfs(int now){
  int ret=0;
  if(now>0 && a[now-1]>a[now]){//右側をみてあげる
    ret=max(0,dfs(now-1));
  }
  if(now<n-1 && a[now+1]>a[now]){//左側をみてあげる
    ret=max(ret,dfs(now+1));
  }
  return ret+l-a[now];
}

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

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		while(true) {

		int H=sc.nextInt();
		int W=sc.nextInt();
		if(H==0 && W==0) {
			break;
		}

		for(int i=1;i<=H;i++) {
			if(i==1 || i==H) {
				for(int k=1;k<=W;k++) {
				System.out.print("#");
				}

			}else {
			for(int j=1;j<=W;j++) {
				if(j==1 || j==W) {
					System.out.print("#");
				}else {
					System.out.print(".");

				}
			}
			}
			System.out.print("\n");
		}

		System.out.print("\n");
		}
	}

}



Measured memory_bytes: 36812
#include <stdio.h>
#include <string.h>

int main(){
	int n,i,sum,tmp;
	int dice[3];
	char str[6];

	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}

		for(i = 0;i < 3;i++){
			dice[i] = i+1;
		}

		sum = dice[0];

		for(i = 0;i < n;i++){
			scanf("%s",str);
			if(!strcmp(str,"North")){
				tmp = dice[0];
				dice[0] = dice[1];
				dice[1] = 7-tmp;
			}else if(!strcmp(str,"East")){
				tmp = dice[2];
				dice[2] = dice[0];
				dice[0] = 7-tmp;
			}else if(!strcmp(str,"West")){
				tmp = dice[0];
				dice[0] = dice[2];
				dice[2] = 7-tmp;
			}else if(!strcmp(str,"South")){
				tmp = dice[1];
				dice[1] = dice[0];
				dice[0] = 7-tmp;
			}else if(!strcmp(str,"Right")){
				tmp = dice[1];
				dice[1] = dice[2];
				dice[2] = 7-tmp;
			}else{
				tmp = dice[2];
				dice[2] = dice[1];
				dice[1] = 7-tmp;
			}

			sum += dice[0];
		}

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

	return 0;
}

Measured memory_bytes: 604
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int n;

	while (n = readln.chomp.to!int, n) {
		int cnt;
		long[string] sell;
		string[] keys;
		bool[string] f;

		foreach (i; 0..n) {
			auto x = readln.split;
			auto w = x[1..$].map!(to!long);
			sell[x[0]] += w[0] * w[1];
			keys ~= x[0];
		}
		foreach (k; keys) {
			if (sell[k] >= 1_000_000 && f.get(k, 1)) {
				k.writeln;
				f[k] = 0;
				cnt++;
			}
		}
		if (!cnt) writeln("NA");
	}
}

Measured memory_bytes: 1284
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


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


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    H, N = MI()
    A = [0] * N
    B = [0] * N
    dp = [[10**12 for i in range(H+1)]
          for i in range(N+1)]
    # dp = [0 for _ in range(H + 2)]

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

    for i in range(N):
        A[i], B[i] = MI()
        # AB[i] = (A / B, A, B)

    for i in range(N):
        # dp_tmp = [0] * (H + 2)
        for h in range(H+1):
            if h - A[i] >= 0:
                dp[i+1][h] = min(dp[i+1][h-A[i]] + B[i], dp[i][h])
            else:
                dp[i+1][h] = min(dp[i][h], B[i])

    print(dp[N][-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 125884
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(string, s);
	vector< int > d(4);
	REP(i, 4) {
		d[i] = (s[i] - '0');
	}

	REP(bit, (1 << 3)) {
		int tmp = d[0];
		REP(i, 3) {
			tmp += ((bit >> i) & 1) ? d[i + 1] : - d[i + 1];
		}
		if (tmp == 7) {
			OUT(d[0]);
			REP(i, 3) {
				OUT(((bit >> i) & 1) ? '+' : '-');
				OUT(d[i + 1]);
			}
			break;
		}
	}
	OUT("=7")BR;
	
  
  return 0;
}


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


namespace std
{
    class Test {
        static void Main(string[] args) {
        
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var q = int.Parse(input[1]);
            Queue<int> quue = new Queue<int>();
            Queue<string> qname = new Queue<string>();
       
            int time = 0;
            for (int i = 0; i < n; i++) {
                var inp = Console.ReadLine().Split(' ');
           
                qname.Enqueue(inp[0]);
                quue.Enqueue(int.Parse(inp[1])); 

            }   

     
        
            while(quue.Count != 0) {//queeのプロセスが０になるまあで

                if (q < quue.Peek()) {//クオンタイムを過ぎたら残り分をキューの末尾に追加
                    quue.Enqueue((quue.Dequeue() - q));
                    qname.Enqueue(qname.Dequeue());
                    time += q;

                } else {
                    time += quue.Dequeue(); 
                    Console.WriteLine("{0} {1}",  qname.Dequeue() , time);
                }
            }
        }
    }
}




Measured memory_bytes: 25376
import os
import sys

import numpy as np


def solve(inp):
    def scc_dfs1(links, s, stack, checked, postorder, pi):
        stack[0] = 0
        stack[1] = s
        si = 2
        while si > 0:
            i = stack[si - 2]
            v = stack[si - 1]
            if i == 0 and checked[v]:
                si -= 2
                continue
            checked[v] = 1
            l = len(links[v])
            while i < l and checked[links[v][i]] == 1:
                i += 1
            if i == l:
                postorder[pi] = v
                pi += 1
                si -= 2
                continue
            stack[si - 2] = i + 1
            stack[si] = 0
            stack[si + 1] = links[v][i]
            si += 2
        return pi

    def scc_dfs2(rev_links, s, stack, checked):
        stack[0] = s
        si = 1
        checked[s] = 1
        scc = [s]
        while si > 0:
            si -= 1
            v = stack[si]
            for u in rev_links[v]:
                if checked[u] == 0:
                    checked[u] = 1
                    stack[si] = u
                    si += 1
                    scc.append(u)
        return scc

    def scc(n, links, rev_links):
        stack = np.zeros(n * 5, np.int64)
        checked = np.zeros(n, np.int8)
        postorder = np.zeros(n, np.int64)
        pi = 0

        for v in range(n):
            if checked[v]:
                continue
            pi = scc_dfs1(links, v, stack, checked, postorder, pi)

        postorder = postorder[::-1]
        checked = np.zeros(n, np.int8)
        sccs = []

        for v in postorder:
            if checked[v]:
                continue
            sccs.append(scc_dfs2(rev_links, v, stack, checked))

        return sccs

    n = inp[0]
    m = inp[1]
    aaa = inp[2::2]
    bbb = inp[3::2]

    int_list = [0]
    int_list.clear()
    links = [int_list.copy() for _ in range(n)]
    rev_links = [int_list.copy() for _ in range(n)]

    for i in range(m):
        a = aaa[i]
        b = bbb[i]
        if a != b:
            links[a].append(b)
            rev_links[b].append(a)

    return scc(n, links, rev_links)


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(len(ans))
for scc in ans:
    print(len(scc), *scc)


Measured memory_bytes: 241996
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <map>
#include <set>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
#define pb push_back
#define mp make_pair

const int maxn = 1e5+1;
int n;
vector<l4> g[maxn];
int sz[maxn];
ll ans;

void dfs(int cur, int pa)
{
  int maxi = 0;
  sz[cur] = 1;
  ll mini = 1e18;
  for (int i = 0; i < g[cur].size(); ++i)
    {
      int nxt = g[cur][i].first;
      ll len = g[cur][i].second;
      mini = min(len, mini);
      if (nxt == pa)
	continue;
      dfs(nxt, cur);
      sz[cur] += sz[nxt];
      if (sz[nxt]*2 == n)
	{
	  ans -= len;
	}
      maxi = max(sz[nxt], maxi);
      ans += len*2*min(sz[nxt], n-sz[nxt]);
      //cerr << len << " " << sz[nxt] << endl;
    }
  maxi = max(maxi, n-sz[cur]);
  if (maxi*2 < n)
    ans -= mini;
}
int main()
{
  scanf("%d", &n);
  for (int i = 0; i < n-1; ++i)
    {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      g[a].pb(mp(b, c));
      g[b].pb(mp(a, c));
    }
  ans = 0;
  dfs(1, 0);
  printf("%lld\n", ans);
}



Measured memory_bytes: 16256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int a, b, c, k, ans1=0;
    
    cin >> a >> b >> c >> k;

    if(k>=a){
        ans1 += a;
        k = k - a;
    }
    else{
        ans1 += k;
        k = 0;
    }

    if(k!=0 && k>=b){
        k = k - b;
    }
    else{
        k = 0;
    }

    if(k!=0 && k>=c){
        ans1 -= c;
        k = k - c;
    }
    else{
        ans1 -= k;
        k = 0;
    }

    cout << ans1;

}

Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

vector<int> G[100000];
int in[100000];
int dp[100000];

int main() {
  int n, m;
  cin >> n >> m;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    in[y]++;
  }
  queue<int> que;
  REP(i, n) {
    if (in[i] == 0) que.push(i);
  }
  vector<int> ts;
  while (que.size()) {
    int p = que.front();
    que.pop();
    ts.push_back(p);
    REP(i, G[p].size()) {
      int q = G[p][i];
      in[q]--;
      if (in[q] == 0) que.push(q);
    }
  }
  REP(i, ts.size()) {
    int cur = ts[i];
    REP(j, G[cur].size()) {
      int to = G[cur][j];
      dp[to] = max(dp[to], dp[cur] + 1);
    }
  }
  int ans = 0;
  REP(i, n) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7032
import math
import string
import itertools
import fractions
import heapq
import collections
import re
import array
import bisect
import sys
import random
import time
inf = 10**9


def main():
    w, h, x, y = map(int, input().split())

    print(w*h/2, 1 if w/2 == x and h/2 == y else 0)


if __name__ == '__main__':
    main()


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


int main()
{
	int a,b;
	cin>>a>>b;
	if(b==1)cout<<0<<endl;
	else cout<<(a-b+1)-1<<endl;
	return 0;
}

Measured memory_bytes: 256
//Volume0-0093
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//declare
		ArrayList<String> result = new ArrayList<String>();
		String[] s;
		int a,b,i;
		boolean flg,exst;

        //input
        Scanner sc = new Scanner(System.in);
        while(true){
        	s = sc.nextLine().split("\\s");
        	a = Integer.parseInt(s[0]);
        	b = Integer.parseInt(s[1]);
        	if(a+b == 0){break;}

        	//calculate
        	exst = false;
        	for(i=a;i<=b;i++){
        		flg = false;
        		if(i%400==0){
        			flg = true;
       			} else if(i%4==0 && i%100!=0){
					flg = true;
				}
        		if(flg){
        			result.add(String.valueOf(i));
        			exst = true;
       			}
        	}
        	if(!exst){result.add("NA");}
        	result.add("");
        }

        //output
        for(i=0;i<result.size()-1;i++){
        	System.out.println(result.get(i));
       	}
	}
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll a, b, x;
    cin >> a >> b >> x;
    if (a > x)
    {
        cout << "NO" << endl;
    }
    else
    {
        if (a + b >= x)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}


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


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

vector<string> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
bool seen[510][510];

void dfs(int h, int w)
{
    seen[h][w] = true;
    for (int dir = 0; dir < 4;dir++)
    {
            int nh = h + dx[dir];
            int nw = w + dy[dir];
        
        if(nh < 0|| nh >= H || nw < 0 || nw >= W){
            continue;
        }
        if(field[nh][nw] == '#'){
            continue;
        }
        if(seen[nh][nw]){
            continue;
        }
        dfs(nh, nw);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    int N;
    cin >> N;
    vector<ll> A(N);
        bool flag = true;
    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
        if(A[i] % 2 == 1){
            flag = false;
        }
    }
    ll ans = 0;
        while (flag)
        {
            for (int i = 0; i < N;i++)
            {
                A[i] /= 2;
                if(A[i] % 2 == 1){
                    flag = false;
                    break;
                }
            }
            ans++;
        }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = input()
H_list = list(map(int, input().split()))
H_edit_list = [10**10]

for h in list(reversed(H_list)):
    if h - H_edit_list[-1] > 0:
        H_edit_list.append(h - 1)
    else:
        H_edit_list.append(h)
    if H_edit_list[-2] < H_edit_list[-1]:
        print('No')
        exit()

print('Yes')       

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

int J(int n, int k) {
  if(n == 1) return 1;
  return (J(n-1, k) + k-1) % n + 1;
}

int main() {
  int n, k, m;
  
  while(cin >> n >> k >> m && n) {
    cout << (J(n-1, k) + m-1) % n + 1 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1468
n=int(input())
s=input()
rw=s.count("W")
re=s.count("E")
lw=0
le=0
now=""
m=10000000000000000000
for i in range(n):
    if now=="W":lw+=1
    if now=="E":le+=1
    if s[i]=="W":rw-=1
    if s[i]=="E":re-=1
    m=min(m,lw+re)
    now=s[i]
print(m)

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

int main(){
	int a[4];
	int b[4];
	int i=0;
	int s=0;
	int t=0;
	
	for(i=0;i<4;i++){
		cin>>a[i];
		s=s+a[i];
	}
	
	for(i=0;i<4;i++){  
		cin>>b[i];
		t=t+b[i];
	}
	
	if(s<t){
		cout<<t<<endl;
	}else{
		cout<<s<<endl;
	}
}	
	
	
	
	
	
	
	 

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

int main() {
  int N;
  int64_t A = 1LL;
  cin >> N;
  vector<int64_t> vec(N);
  
  for(int j=0; j<N; j++){
    cin >> vec.at(j);
    if(vec.at(j) == 0LL){
      cout << 0 << endl;
      return 0;
    }
  }

  for(int i=0; i<N; i++){
    A *= vec.at(i); 
 //  cout << i << ":" << A << endl;

    if (A > 1000000000000000000LL){
      cout << -1 << endl; 
      break;
    }else if (A <= 0LL){
      cout << -1 << endl; 
      break;
    }
    
    if(i == (N-1)){
        cout << A << endl;
    }
  }
}


Measured memory_bytes: 4048
#include "stdio.h"

int H,W;
char campus[30][30];

#define abs(a) ((a)>0?(a):-(a))

int main(){

  scanf("%d%d\n",&H,&W);

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      campus[i][j]=getchar();
    }
    getchar();
  }

  

  int max=0;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(campus[i][j]=='B'){
	for (int k=0;k<H;k++){
	  for (int h=0;h<W;h++){
	    if(campus[k][h]=='B'){
	      int dist=abs(i-k)+abs(j-h);
	      //printf("%d\n",dist);
	      max=max<dist?dist:max;
	    }
	  }
	}
      }
    }
  }

  printf("%d\n",max);

  return 0;
}



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

ll prime_factrization(const ll n)
{
    ll ans = 1;
    ll p = n;
    for (ll i = 2; i <= sqrt(n); ++i)
    {
        ll c = 0;
        while (p % i == 0)
        {
            p /= i;
            ++c;
        }
        if (c != 0)
        {
            ans *= c + 1;
        }
    }

    if (p > sqrt(n))
        ans *= 2;

    return ans - 1;
}

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

    ll ans = prime_factrization(n - 1);
    for (ll i = 2; i <= sqrt(n); ++i)
    {
        if (n % i == 0)
        {
            ll t = n;
            while (t % i == 0)
                t /= i;
            if ((t % i) == 1)
                ++ans;
        }
    }

    cout << ans + 1 << endl;
}

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

stack<int> st; 
int main() {
	int t;
	int ans = 0;
	while(scanf("%1d", &t) != EOF){
		if(st.empty()){
			st.push(t);
			continue;
		}
		int u = st.top();
		if(u != t){
			st.pop();
			ans += 2;
		}
		else
			st.push(t);
	}
	cout<<ans;
	return 0;
}

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

int main()
{
    string s;
    cin >> s;

    int currentCount = 0;
    int max = 0;

    for(int i = 0; i < s.length(); i++){
        if (s[i] == 'A' || 
            s[i] == 'C' ||
            s[i] == 'G' ||
            s[i] == 'T'){
                currentCount ++;
        }else{
            if (currentCount > max) max = currentCount;
            currentCount = 0;
        }
    }
    if (currentCount > max) max = currentCount;

    // 出力
    printf("%d\n", max);
    return 0;
}

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

using namespace std;
pair<pair<string,int>,int> pii[105];
int main()
{
  int n,p;
  string s;
  cin>>n;
  
  for(int i=1; i<=n; i++){
    cin>>s>>p;
    
    pii[i]=make_pair(make_pair(s,-p),i);
  }
  
  sort(pii+1,pii+n+1);
  
  for(int i=1; i<=n; i++){
    cout<<pii[i].second<<'\n';
  }      
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mm=1000000007;
int i,j,k,n,m,f[2][4101][2],now,pre,ans,t1,t2;
void upd(int x,int y,int v){
	f[now][x][y]=(f[now][x][y]+v)%mm;
}
int main(){
	scanf("%d%d",&n,&m);memset(f,0,sizeof(f));now=0;pre=1;
	for (i=0;i<=n;i++) f[now][i][0]=1;
	for (i=0;i<m;i++){
		now^=1;pre^=1;memset(f[now],0,sizeof(f[now]));
		for (j=0;j<=n;j++)
		 for (k=0;k<=1;k++){
		 	if (j){
		 		upd(j-1,(j==1)?1:k,f[pre][j][k]);
				upd(j,(j==1)?1:k,f[pre][j][k]);
			}
			if (j<n){
				upd(j+1,(j==0)?1:k,f[pre][j][k]);
				upd(j,(j==0)?1:k,f[pre][j][k]);
			}
		 }
	}
	for (i=ans=0;i<=n;i++) ans=(ans+f[now][i][1])%mm;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
class program
{
    static void Main()
    {
        var abck = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var a = abck[0];
        var b = abck[1];
        var k = abck[3];
        if (a > k)
        {
            Console.Write(k);
        }
        else if(a+b > k)
        {
            Console.Write(a);
        }
        else
        {
            Console.Write(2*a+b-k);
        }
    }
}

Measured memory_bytes: 28288
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>

using namespace std;

int main() {
  string s1 = "CODEFESTIVAL2016";
  string s2;
  cin >> s2;
  //int dp[17][17];
  int r = 0;
  for (int i = 0; i < 16; i++) {
    if (s1[i] != s2[i])r++;
  }
  cout << r;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

void
add(priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> & q, map<ll, ll> & best, ll value, ll cost) {
  if (value < 0) return;

  if (best.find(value) == best.end() || best[value] > cost) {
    //cout<<value<<":"<<cost<<endl;
    best[value] = cost;
    q.push({cost, value});
  }
}

void
check( priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> & q, map<ll, ll> & best, 
    ll value, ll cost, ll mul, ll mul_cost, ll one_cost) {

  if (value % mul == 0) {
    add(q, best, value / mul, cost + mul_cost);

    ll change = value / mul * (mul-1);
    if (change <= mul_cost/one_cost + 1)
      add(q, best, value / mul, cost + change * one_cost);
  }
  else {
    ll mod = value % mul;
    check(q, best, value - mod, cost + mod * one_cost, mul, mul_cost, one_cost);

    ll left = mul - mod;
    check(q, best, value + left, cost + left * one_cost, mul, mul_cost, one_cost);
  }
}

void
solve() {
  ll n, a, b, c, d;
  cin>>n>>a>>b>>c>>d;

  map<ll, ll> best;
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
  best[n] = 0;
  q.push({0, n});
  //cout<<n<<":"<<0<<endl;
  while (1) {
    auto p = q.top();
    q.pop();
    if (best.find(0) != best.end() && best[0] < p.first) break;

    //cout<<"current "<<p.second<<":"<<p.first<<endl;
    
    check(q, best, p.second, p.first, 2, a, d);
    check(q, best, p.second, p.first, 3, b, d);
    check(q, best, p.second, p.first, 5, c, d);
  }

  cout<<best[0]<<endl;
}

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

  ll t = 1;
  cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



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

using namespace std;
using ll = long long;

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

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


int main(void){

	
	ll A, B, K; cin >> A >> B >> K;

	ll ans_A, ans_B;
	if(A > K){
		ans_A = A-K;
		ans_B = B;
	}else{
		ans_A = 0;
		K = K - A;
		ans_B = max((ll)0, B-K);

	}

	cout << ans_A << " " << ans_B << endl;


	return 0;

}


Measured memory_bytes: 256