akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N)
{
    cout << (N * (N - 1)) / 2 << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  print(a[k-1]);
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [usize; n]
    }
    let mut ans = 0;
    let mut ac = 0;
    for i in 1..n {
        ac += v[i - 1];
        ans += ac * v[i];
    }
    println!("{}",  ans);
}


Measured memory_bytes: 4352
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N, M = map(int, input().split())
A = [0]*N
B = [0]*N
l = []
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
    l.append((a, b))
    
l.sort()
ans = 0
for (a, b) in l:
    if b >= M:
        ans += a * M
        break
    else:
        ans += a * b
        M -= b
print(ans)



Measured memory_bytes: 18572
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 110;
const ll mod = 1000000007;
char str[N], str1[N];
int main() {
	ll n, ans = 1;
	cin >> n >> str >> str1;
	bool flag = false;
	for(ll i = 0; i < n; i ++) {
		if(i == 0) {
			if(str[i] == str1[i]) {
				ans = 3;
			} else {
				ans = 6;flag = true;i++;
			}
		}else {
			if(str[i] == str1[i]) {
				if(flag) {
					flag = false;
				}else {
					ans *= 2;
					ans %= mod;
				}
				flag = false;
			} else {
				if(flag) {
					ans *= 3;
					ans %= mod;
				}else {
					ans *= 2;
					ans %= mod;
				}
				flag = true;
				i++;
			}
		}
	}
	printf("%lld\n",ans%mod);
	return 0;
}


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

	public static void main(String[] args) {

		 Scanner sc = new Scanner(System.in);
		 int n=sc.nextInt();
		 int[] A=new int[n];
		 for(int i=0; i<n; i++){
			 A[i]=sc.nextInt();
		 }
		 int q=sc.nextInt();
		 for(int i=0; i<q; i++){
			 int m=sc.nextInt();
			 if(check(m,A)){
				 System.out.println("yes");
			 }else{
				 System.out.println("no");
			 }

		 }
	}
	public static Boolean check(int m,int[] A){
		Boolean res=false;
		for(int j=0; j<A.length; j++){
			if(solve(j,m,A)){
				res=true;
				break;
			}
		}
		return res;
	}
	public static Boolean solve(int i,int m,int[] A){
		if(m==0){
			return true;
		}else if(i>=A.length){
			return false;
		}
		Boolean res=solve(i+1,m,A)||solve(i+1,m-A[i],A);
		return res;
	}



}


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

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

	int H, W;
	char a[500*500];
	char red[500*500];
	char blue[500*500];
	cin >> H >> W;
	for(int i=0; i<H*W; i++) cin >> a[i];

	for(int i=0; i<H*W; i++){
		red[i] = '.';
		blue[i] = '.';
	}

	for(int x=0; x<W; x++){
		red[x] = '#';
		blue[W*(H-1)+x] = '#';
	}
	for(int y=1; y<H-1; y++){
		for(int x=0; x<W; x++){
			if(x%2==0) red[W*y+x] = '#';
			else blue[W*y+x] = '#';
		}
	}

	for(int i=0; i<W*H; i++){
		if(a[i]=='#'){
			red[i] = '#';
			blue[i] = '#';
		}
	}

	// print
	for(int y=0; y<H; y++){
		for(int x=0; x<W; x++){
			cout << red[W*y+x];
		}	cout << endl;
	}
	cout << endl;

	for(int y=0; y<H; y++){
		for(int x=0; x<W; x++){
			cout << blue[W*y+x];
		}	cout << endl;
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1536
using System;
namespace kozaiyApp
{
    public class B
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            string ans = "Yes";

            string[] inputH = Console.ReadLine().Split(' ');
            int[] hyo = new int[N];
            double sohyo = 0;

            for (int i = 0; i < N; i++)
            {
                hyo[i] = int.Parse(inputH[i]);
                sohyo += int.Parse(inputH[i]);
            }

            // 降順ソート
            Array.Sort(hyo, (a, b) => b - a);


            // 人気商品M個を調べる
            for (int i = 0; i < M; i++)
            {
                double s = 1.0 / (4.0 * M);
                if ((sohyo * s) > hyo[i])
                {
                    ans = "No";
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main() {
    string x;
    cin >> x;
    string one = "", two = "";
    int start = 0;
    for (int i = 0; i < x.size(); i++) {
        one += char(start + '0');
        two += (char)((start ^ 1) + '0');
        start ^= 1;
    }
    int res1 = 0, res2 = 0;
    for (int i = 0; i < x.size(); i++) {
        res1 += x[i] != one[i];
        res2 += x[i] != two[i];
    }
    cout << min(res1, res2);
    return 0;
}

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

struct UnionFind{
	vector<int> par;
	vector<int> rank;
	vector<int> diff_weight;

	UnionFind(int n = 1){
		init(n);
	}

	void init(int n = 1){
		par.resize(n); rank.resize(n);diff_weight.resize(n);
			for(int i=0;i<n;i++){
				par[i] = i;
				rank[i] = 0;
				diff_weight[i] = 0;
			}
		}
		int root(int x){
			if(par[x] == x)return x;
			else{
				int r = root(par[x]);
				diff_weight[x] += diff_weight[par[x]];
				return par[x] = r;
			}
		}

		int weight(int x){
			root(x);
			return diff_weight[x];
		}

		bool issame(int x,int y){
			return root(x)==root(y);
		}

		bool merge(int x, int y, int w){
			w += weight(x);w -= weight(y);
			x = root(x);y = root(y);
			if(x == y)return false;
			if(rank[x] < rank[y]){
				int temp = x;
				x = y;
				y = temp;
				w = -w;
			}
			if(rank[x] == rank[y])rank[x]++;
			par[y] = x;
			diff_weight[y] = w;
			return true;
		}
		int diff(int x,int y){
			return weight(y)-weight(x);
		}
};

int main(void){
	int N,M;
	cin>>N>>M;
	UnionFind tree(N);
	for(int i=0;i<M;i++){
		int l,r,d;
		cin>>l>>r>>d;
		l--;r--;
		if(tree.issame(l,r)){
			int diff = tree.diff(l,r);
			if(diff != d){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else
			tree.merge(l,r,d);
	}
	cout<<"Yes"<<endl;
	return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int x; cin >> x;

    for (int i = 1; i < 100000; ++i) {
        if ((i * i + i) / 2 >= x) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int n, q;
vector<int> a(2000);
bool solve(int i, int num) {
	if (num == 0) return 1;
	if (i >= n)return 0;
	int res = solve(i + 1, num) || solve(i + 1, num - a[i]);
	return res;
}
int main(void) {
	cin >> n;
	for (int i = 0;i < n;i++)cin >> a[i];
	cin >> q;
	for (int i = 0;i < q;i++) {
		int in;
		cin >> in;
		if (solve(0,in)) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	return 0;
}




Measured memory_bytes: 3120
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int syc(long i,long Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
		//return 0;
	}
}

int main(){
	int n,t;
	cin >> n >> t;
	int ans=100100100;
	int cost[n],tim[n];
	
	for(int i=0;i<n;i++){
		cin >> cost[i] >> tim[i];
		if(tim[i]<=t && cost[i]<ans)ans=cost[i];
	}
	if(ans==100100100){
		cout << "TLE" << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
function main(arg) {
    var str = arg.split("\n")[0]
    if (str.length === 2) {
        console.log(str)
    } else if (str.length === 3) {
        console.log(str[2] + str[1] + str[0])
    }
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // input
    int a, b, c;
    cin >> a >> b >> c;
    // output
    cout << max(0, b + c - a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
#define MOD 1e9+7
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  int i,n;cin>>n;vint a(n);
  for(i=0;i<n;i++){cin>>a[i];}
  //caricurate
  vsort(a);
  int mi,ma;mi=a[0];ma=a[n-1];
  lint ans,nw;ans=INF;
  for(i=mi;i<=ma;i++){
    nw=0;
    for(int j=0;j<n;j++){
      nw+=(a[j]-i)*(a[j]-i);
    }
    if(ans>nw){ans=nw;}
  }
  //output
  cout<<ans<<endl;
}

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

bool helper(){

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    int ans2 = 0;
//    string t1, t2;
    for(int start = 0; start < s.size() - t.size()+1; ++start){
        for(int k = 0; k < t.size(); ++k){
//            t1 += t[k];

            if(t[k]==s[start+k]){
                ++ans;
            }
//            t2 += s[k+start];
        }
//        cout << "S is " << t2 << " and T is " << t1 << endl;
        ans2 = max(ans,ans2);
        ans = 0;
//        t1 = "";
//        t2 = "";

    }
    cout << t.size() - ans2 << endl;

    return 0;
}


Measured memory_bytes: 3608
s=list(input())
q=int(input())
c=0
left=[]
right=[]
for i in range(q):
    s1=input()
    if s1[0]=='1':
        c+=1
    else:
        if s1[2] == '1':
            if c % 2 == 0:
                left.append(s1[4])
            else:
                right.append(s1[4])
        else:
            if c % 2 == 0:
                right.append(s1[4])
            else:
                left.append(s1[4])
left=left[::-1]
left.extend(s)
left.extend(right)
if c%2==0:
    print(''.join(left))
else:
    left=left[::-1]
    print(''.join(left))


Measured memory_bytes: 9036
s = input()
maxacgt = 0
cnt = 0

for i in list(s):
    if i in ("A","C","G","T"):
        cnt += 1
    else:
        if cnt > maxacgt:
            maxacgt = cnt
        cnt = 0
else:
    if cnt > maxacgt:
            maxacgt = cnt
    ans = maxacgt

print(ans)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N = int(input())
s = '<'+input()[:-1]
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][N] = 1
MOD = 10**9+7

for i in range(N):
    for j in range(N+1):
        if s[i]=='<':
            dp[i+1][0] += dp[i][j]
            dp[i+1][j] -= dp[i][j]
        else:
            dp[i+1][j] += dp[i][j]
            dp[i+1][N-i] -= dp[i][j]
    
    dp[i+1][0] %= MOD
    
    for j in range(1, N+1):
        dp[i+1][j] += dp[i+1][j-1]
        dp[i+1][j] %= MOD

print(dp[N][0])

Measured memory_bytes: 112476
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int yen500 = sc.nextInt();
		int yen100 = sc.nextInt();
		int yen50 = sc.nextInt();
		int value = sc.nextInt();
		
		int max500 = value / 500 < yen500 ? value / 500 : yen500;
		int max100;
		int result = 0;
		int nokori500;
		int nokori100;

		
		for (int i = 0; i <= max500; i++) {
			nokori500  = value - 500 * i;
			max100  = nokori500 / 100 < yen100 ? nokori500 / 100 : yen100;
			for (int j = 0; j <= max100; j++) {
				nokori100 = nokori500 - 100 * j;
				if (nokori100 % 50 == 0) {
					if (nokori100 / 50 <= yen50) {
						result++;						
					}
				}
			}
		}
		
		System.out.println(result);
	}
}


Measured memory_bytes: 22228
#include <iostream>
using namespace std;
#include <math.h>
int a,i,b;
double tp;
int main(){
	cin>>a;
	i=0;
	for (a;a>i;i++){
		cin>>b;
		tp+=pow(b,-1);
	}
	tp=pow(tp,-1);
	cout<<tp;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) c.begin(), c.end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<P> a(n);
    REP(i,n){
        cin >> a[i].first >> a[i].second;
    }
    sort(ALL(a));
    ll s = 0;
    REP(i,n){
        s += a[i].second;
        if (s >= k){
            cout << a[i].first << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1024
//  RAKSHIT KADAM
 #include <bits/stdc++.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
 #warning !!!check the size of arrayss!!!
 
 #define ll long long
 #define int long long
 #define MOD  1000000007
 #define newMOD  998244353
 #define MAX 300006
            
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define endl "\n"
 #define x first
 #define y second
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define INF 1000000000000000005
 #define vi vector<ll>
#define pi 3.1415926535897932384626433832795
#define Endl endl
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
 
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}

void solve()
{
    ll a,b;cin>>a>>b;
    cout<<min(a,(b-a%b)%b)<<endl;
    
    
}
signed main()
{
    
   
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

  solve();
    return 0;
    
}
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define read1(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define read4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
  return 0;
}

#define ld long double

ld dp[55][55]{0};

ld max(ld a,ld b){
    if(a>b)return a;
    return b;
}

ld f(ll *a,ll i,ll j){
    if(i>j){
        return 0;
    }
    if(i==j){
        return a[i];
    }
    if(i+1==j){
        return (a[i]+a[j])/2.0;
    }
    if(dp[i][j]!=-1.0){
        return dp[i][j];
    }
    ld &res=dp[i][j];
    res=0;
    for(ll k=i;k<j;k++){
        res=max(res,(f(a,i,k)+f(a,k+1,j))/2.0);
    }
    return res;
}


int main() {

    IO; 

    ll n;
    cin>>n;
    ll a[n];
    loop(i,0,n){
        cin>>a[i];
        // cout<<a[i]<<" ";
    }
    // cout<<endl;
    sort(a,a+n);
    for(ll i=0;i<55;i++){
        for(ll j=0;j<55;j++){
            dp[i][j]=-1.0;
        }
    }
    cout<<fixed<<setprecision(8)<<f(a,0,n-1)<<endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		int [] list = {0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
		int n = sc.nextInt();
		for(int i=0; i < n; i++){
			int in = sc.nextInt();
			int out = sc.nextInt();
			int len = list.length;
			boolean skip;
			if(in > out && in <= 5)
				skip = true;
			else{
				skip = false;
			}
			for(int j=0; j < len; j++){
				if(list[j] == in){
					if(skip){
						skip = false;
					}
					else{
						int ind = j;
						while (list[ind % len] != out){
							System.out.print(list[ind % len]+ " ");
							ind++;
						}
						System.out.println(out);
						break;
					}
				}
			}
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

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

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    for (auto &x : A) {
        cin >> x;
    }
    sort(A.begin(), A.end());
    ll n1 = A.at(N - 1);
    auto itr = lower_bound(A.begin(), A.end(), n1 / 2);
    if (itr == A.end() - 1) {
        itr--;
    } else if (n1 / 2 - *(itr - 1) < *itr - n1 / 2) {
        itr--;
    }
    cout << n1 << ' ' << *itr << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,mod=998244353;
typedef long long ll;
int n,m,k,t;
struct node
{
    int l,r,c;
    bool operator<(const node&p)const
    {
        return l<p.l;
    }
}p[maxn];
ll mi[maxn<<2];
void build(int l,int r,int rt)
{
    mi[rt]=1e18;
    if(l==r)return;
    int mid=l+r>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
}
void pup(int rt)
{
    mi[rt]=min(mi[rt<<1],mi[rt<<1|1]);
}
void upd(int x,ll y,int l,int r,int rt)
{
    if(x==l&&x==r)
    {
        mi[rt]=y;
        return;
    }
    int mid=l+r>>1;
    if(x<=mid)upd(x,y,l,mid,rt<<1);
    else upd(x,y,mid+1,r,rt<<1|1);
    pup(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
    if(L<=l&&r<=R)return mi[rt];
    ll ret=1e18;
    int mid=l+r>>1;
    if(L<=mid)ret=min(ret,query(L,R,l,mid,rt<<1));
    if(mid+1<=R)ret=min(ret,query(L,R,mid+1,r,rt<<1|1));
    return ret;
}
ll dp[maxn];
int main(){
    int i,j;
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].c);
    }
    for(i=1;i<=n;i++)
        dp[i]=1e18;
    dp[1]=0;
    sort(p+1,p+m+1);
    build(1,n,1);
    upd(1,0,1,n,1);
    for(i=1;i<=m;i++)
    {
        ll temp = query(p[i].l,p[i].r,1,n,1) + p[i].c;
        if(temp<dp[p[i].r])
        {
            dp[p[i].r]=temp;
            upd(p[i].r,temp,1,n,1);
        }
    }
    if(dp[n]!=1e18)printf("%lld\n",dp[n]);
    else puts("-1");
    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	double x,y,sum=0;
	double x1,x2,y1,y2,x3,y3,s,a,b,c;
	scanf("%lf,%lf",&x1,&y1);
	scanf("%lf,%lf",&x2,&y2);
	while(scanf("%lf,%lf",&x3,&y3)!=EOF){
		a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		b=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
		c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
		s=(a+b+c)/2;
		sum+=sqrt(s*(s-a)*(s-b)*(s-c));
		x2=x3;y2=y3;
		
	}
	printf("%.6lf\n",sum);
	return 0;
}
	

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


signed main(){
	int n;
	double ans=0;
	cin>>n;
	vector<double>vec(n);
	vector<string>vek(n);
	for(int i=0;i<n;i++){
		cin>>vec[i]>>vek[i];
		if(vek[i]=="JPY"){
			ans+=vec[i];
		}
		else{
			ans+=vec[i]*380000;
		}
	}
	printf("%8lf",ans);
	cout<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
int i,j,t,data[10];
for (i=1;i<=10;i++) {
scanf("%d\n",&data[i]);
}
for (j=1;j<=10;j++){
for (i=1;i<=9;i++) {
if (data[i]<data[i+1]) {
t=data[i];
data[i]=data[i+1];
data[i+1]=t;
}
}
}
for (i=1;i<=3;i++) {
printf("%d\n",data[i]);
}
return 0;
}

Measured memory_bytes: 604
#include <stdio.h>

void f(int n);

int main()
{
	int n;

	scanf("%d", &n);

	if (n == 0) {
		puts("0");
		return 0;
	}

	f(n);
	putchar('\n');

	return 0;
}

void f(int n)
{
	if (n == 0) {
		return;
	}

	int r = n % -2;

	if (r < 0) {
		r = r + 2;
	}

	f((n - r) / -2);

	if (r == 1 || r == -1)  {
		putchar('1');
	} else {
		putchar('0');
	}

	return;
}


Measured memory_bytes: 128
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


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

l = [0]*(n+2) # l(i) = A1, A2, ..., A(i-1)のgcd
r = [0]*(n+2) # r(i) = Ai, A(i+1), ..., A(n)のgcd

for i in range(n):
	l[i+1] = gcd(l[i],a[i])
for i in reversed(range(n)):
	r[i] = gcd(r[i+1],a[i])

ext = [0] * n
for i in range(n):
	ext[i] = gcd(l[i],r[i+1])

print (max(ext))

Measured memory_bytes: 14052
#include <cstdio>
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>

const int64_t BEAUCOUP = std::numeric_limits<int64_t>::max();

template<typename T>
T abs(T value)
{
	if (value < 0)
		return -value;
	return value;
}

int main()
{
	int64_t nbStones, K;
	std::scanf("%d %d", &nbStones, &K);

	std::vector<int64_t> stones(nbStones);
	for (int64_t i=0; i<nbStones; i++)
		std::scanf("%d", &stones[i]);

	std::vector<int64_t> DP(nbStones+2, BEAUCOUP);
	DP[0] = 0;

	for (int64_t i=0; i<DP.size(); i++)
		for (int newIndex = i+1; newIndex < nbStones && newIndex <= i + K; newIndex++)
			DP[newIndex] = std::min(DP[newIndex], DP[i] + abs(stones[newIndex] - stones[i]));

	/*for (int i=0; i<nbStones; i++)
		std::cout << DP[i] << ' ';
	std::cout << '\n';*/

	std::printf("%d\n", DP[nbStones-1]);
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
typedef long long ll;
int main(){
   ll N;
   scanf("%lld",&N);
   ll A[100002];
   bool zero_f = false;
   for(int i=0;i<N;i++){
       scanf("%lld",A+i);
       if(A[i]==0)
           zero_f = true;
   }
   if(zero_f){
       printf("%d",0);
       return 0;
   }
   ll max =(ll)pow(10,18);
   ll ans=1;
   for(int i=0;i<N;i++){
        if(max/ans<A[i]){
            ans=-1;
            break;
        }
        ans*=A[i];
   }
   printf("%lld",ans);
   return 0;
}


Measured memory_bytes: 2512
/*input
8 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int n,k;
	cin>>n>>k;
	cout<<(n-1)*(k-1);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

struct edge{
	int f,t,c;
	edge(){}
	edge(int ff,int tt,int cc){
		f=ff;
		t=tt;
		c=cc;
	}
	bool operator<(const edge& e1)const{
		return c<e1.c;
	}
};
int n,m;
edge e[50001];
bool have[501];
int par[501];
int rank[501];
vector<int> vs;
void init(){
	for(int i=0;i<n;i++){
		par[i]=i;
		rank[i]=0;
	}
}

int find(int x){
	if(par[x]==x)return x;
	return par[x]=find(par[x]);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(rank[x]>rank[y]){
		par[y]=x;
	}else{
		par[x]=y;
		if(rank[x]==rank[y])rank[y]++;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&e[i].f,&e[i].t,&e[i].c);
		e[i].f--;
		e[i].t--;
	}
	sort(e,e+m);
	init();
	int cost=0;
	for(int i=0;i<m;i++){
		if(!same(e[i].f,e[i].t)){
			unite(e[i].f,e[i].t);
			cost+=e[i].c;
			vs.push_back(i);
		}
	}
	for(int i=0;i<vs.size();i++){
		init();
		int cc=0;
		int cnt=0;
		for(int j=0;j<m;j++){
			if(vs[i]==j)continue;
			if(!same(e[j].f,e[j].t)){
				unite(e[j].f,e[j].t);
				cc+=e[j].c;
				cnt++;
			}
		}
		if(cc!=cost || cnt!=n-1){
			have[i]=true;
		}
	}
	int resc=0,res=0;
	for(int i=0;i<vs.size();i++){
		if(have[i]){
			resc++;
			res+=e[vs[i]].c;
		}
	}
	printf("%d %d\n",resc,res);
	return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
#define bit(k) (1LL<<(k))

// [0,x)
ll f(ll x) {
    if (x == 0) return 0;
    ll res = (x%4 == 2 || x%4 == 3);
    rep(k,60){
        if ((x-1)&bit(k) && x&1) {
            res |= bit(k);
        }
    }
    return res;
}

int main(void){
    ll a,b;
    cin >> a >> b;
    cout << (f(a)^f(b+1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#ifndef _DEBUG
#define main_ main
#endif
#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;

template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
	return left.second > right.second;
}

bool P[8][8];
int N, M;

void init_global() {
	FOR(i, 0, 8) {
		FOR(j, 0, 8) {
			P[i][j] = false;
		}
	}
}

void dfs(int i, vb& v, ll& cnt) {
	v[i] = true;

	bool all_visited = true;
	FOR(j, 0, N) {
		if (!v[j]) all_visited = false;
	}

	if (all_visited) {
		cnt++;
		v[i] = false;
		return;
	}

	FOR(j, 0, N) {
		if (!P[i][j] || v[j]) continue;
		dfs(j, v, cnt);
	}
	v[i] = false;
}

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

	cin >> N >> M;
	int a, b;
	FOR(i, 0, M) {
		cin >> a >> b;
		a--; b--;
		P[a][b] = P[b][a] = true;
	}

	ll ans=0;
	vb v(N, false);
	dfs(0, v, ans);

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define rep( i, s, t ) for( register int i = s; i <= t; ++ i )
#define re register
#define D(i) ( 1 << (i) )
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e5 + 5 ;
const int M = 16 ;
int n, ans, w[N], cnt[M], dp[1 << M], R[1 << M] ;
signed main()
{
	n = gi() ; int x, y, z, Sta ; 
	rep( i, 2, n ) x = gi() + 1,  y = gi() + 1, 
	z = gi(), w[x] ^= z, w[y] ^= z ; 
	rep( i, 1, n ) ++ cnt[w[i]] ;
	rep( i, 1, 15 ) ans += cnt[i] / 2, Sta |= ( ( cnt[i] & 1 ) << ( i - 1 ) ) ;
	int maxm = ( 1 << 15 ) - 1 ;
	rep( i, 1, maxm ) {
		rep( j, 1, 15 ) if( D(j - 1) & i ) R[i] ^= j, ++ dp[i] ;
		-- dp[i] ;
	}
	rep( i, 1, maxm ) {
		if( R[i] != 0 ) continue ;
		for( re int j = i; j; j = ( j - 1 ) & i )
		if( R[j] == 0 ) dp[i] = min( dp[i], dp[j] + dp[i ^ j] ) ;
	}
	printf("%d\n", ans + dp[Sta] ) ;
	return 0 ;
}


Measured memory_bytes: 896
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int a,b,x;

  cin>>a>>b>>x;

  if(a<=x&&a+b>=x){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;

}




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

using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    
    vector<int> v;
    int x;
    
    int sum;
    
    bool flag;
    
    //初期化
    sum = 0;
    flag = false;
    
    //入力
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> x;
        v.push_back(x);
        
        sum += x;
    }
    sort(v.begin(), v.end());
    
    
    if (sum % 10 != 0) {
        cout << sum << endl;
    }else{
        for (int i = 0; i < n; i++) {
            if (v[i] % 10 != 0) {
                sum -= v[i];
                flag = true;
                break;
            }
        }
        if (flag != true) {
            sum = 0;
        }
        cout << sum << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
/**
 * Copyright (c) 2017, xehoth
 * All rights reserved.
 * 「ARC 070D」No Need 18-08-2017
 * 贪心
 * @author xehoth
 */
#include <bits/stdc++.h>

namespace Task {

const int MAXN = 5000;

int a[MAXN + 1];

inline void solve() {
    register int n, k, sum = 0, pos;
    std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL);
    std::cin >> n >> k, pos = n;
    for (register int i = 0; i < n; i++) std::cin >> a[i];
    std::sort(a, a + n);
    for (register int i = n - 1; i >= 0; i--) {
        if (sum + a[i] < k)
            sum += a[i];
        else
            pos = i;
    }
    std::cout << pos;
}
}

int main() {
    Task::solve();
    return 0;
}

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

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

	int N = s.size();
	vector<int> num( 26 );
	for( int i = 0; i < N; i++ ) {
		num[ s[i] - 'a' ]++;
	}
	int ans = N;
	for( int i = 0; i < 26; i++ ) {
		if( num[i] == 0 ) continue;
		string ss = s;
		int n = N;
		char c = (char)('a' + i);
		int cnt = 0;
		while( 1 ) {
			if( ss == string( n, c ) ) break;
			string t;
			for( int j = 0; j < n - 1; j++ ) {
				if( ss[j] == c || ss[j + 1] == c ) t += c;
				else t += ss[j];
			}
			n--;
			ss = t;
			cnt++;
		}
		ans = min( ans, cnt );
	}

	cout << ans << endl;
}


Measured memory_bytes: 3640
import collections
import copy

def solve():
    a = copy.copy(A)
#    print(a)
    a.sort(reverse=True)
#    print(a)
#    print(A)
    if a[0] == a[1]:
        for i in range(N):
            print(a[0])
    else:
        for i in range(N):
            if A[i] == a[0]:
                print(a[1])
            else:
                print(a[0])
    

if __name__ == "__main__":
    N = int(input())
    A = [int(input()) for _ in range(N)]
    solve()


Measured memory_bytes: 19424
sx,sy,tx,ty = map(int, input().split())
x=-sx
y=-sy
sx+=x
sy+=y
tx+=x
ty+=y
tx=abs(tx)
ty=abs(ty)
 
ans=[]
ans+=['U']*ty
ans+=['R']*tx
ans+=['D']*ty
ans+=['L']*tx
ans+=['L']
ans+=['U']*(ty+1)
ans+=['R']*(tx+1)
ans+=['D']
ans+=['R']
ans+=['D']*(ty+1)
ans+=['L']*(tx+1)
ans+=['U']
print(''.join(ans))

Measured memory_bytes: 3188
/*2019/08/25 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int llasc(const void *a,const void *b){return *(ll*)a-*(ll*)b;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
/*
int asc_t(const void *a,const void *b){return ((struct_t*)a)->member - ((struct_t*)b)->member;}
int desc_t(const void *a,const void *b){return ((struct_t*)b)->member - ((struct_t*)a)->member;}
*/

int main(){
    int a,b;

    scanf("%d %d",&a,&b);
    int cnt=1;
    
    int x=a;
    for(int x=a;x<b;x+=a-1,cnt++){
        //printf("x:%d\n",x);
    }

    if(b!=1)printf("%d\n",cnt);
    else printf("0\n");
    return 0;
}   

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define scch(x) scanf("%c", &x)
#define scld(x) scanf("%Lf", &x)
#define scll(x) scanf("%lld", &x)

int main() {
	ll n, k;
	cin >> n >> k;
	ll result = 0;
	for (ll i=1; i<=n; i++) {
		ll maxsisa = i-1;
		if (maxsisa >= k) {
			ll banyaklengkap = n/i;
			ll subres = 0;
			result+=banyaklengkap*(maxsisa-k+1);
			subres += banyaklengkap*(maxsisa-k+1);
			ll sisagalengkap = n%i;
			//cout << sisagalengkap << endl;
			if (sisagalengkap>=k && k!=0) {
				result+=sisagalengkap-k+1;
				subres+=sisagalengkap-k+1;
			}
			//cout << maxsisa-k+1 << endl;
			//cout << banyaklengkap*(maxsisa-k+1)+sisagalengkap-k+1 << endl;
		}
	}
	if (k!=0)
		cout << result << endl;
	else
		cout << n*n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

#define NUM 2147483647

int N;
int* table;

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int loc,int value){
	loc += N-1;

	table[loc] = value;

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] = min(table[2*parent+1],table[2*parent+2]);

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}


int query(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right)return NUM;

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	int left_min = query(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	int right_min = query(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return min(left_min,right_min);
}


int main(){

	int first_N,Q,command,left,right;
	table = new int[263000];
	N = 1;

	scanf("%d %d",&first_N,&Q);

	init(first_N);

	for(int i = 0; i <= 2*N-2; i++)table[i] = NUM;

	for(int i = 0; i < Q; i++){
		scanf("%d %d %d",&command,&left,&right);

		if(command == 0){
			update(left,right);
		}else{
			printf("%d\n",query(left,right,0,0,N-1));
		}
	}

	return 0;
}

Measured memory_bytes: 3720
/*
Code by b21
Time: 19:17 Sun 01/03/2020
*/

#include <bits/stdc++.h>

using namespace std;

const int mn = 1 * (int)(1e5) + 10;
const int mod = 1 * (int)(1e9) + 7;
const int mm = 1 * (int)(1e3) + 10;
const int base = 1 * (int)(1e9);
const bool aNs = 0;

int tt, ntest = 1;
void docfile()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    if (ifstream("test.inp"))
    {
       freopen("test.inp", "r", stdin);
       if (!aNs) freopen("test.out", "w", stdout);
       else freopen ("test.ans", "w", stdout);
    }
   else if (ifstream("abc157_d.inp"))
    {
        freopen("abc157_d.inp", "r", stdin);
        freopen("abc157_d.out", "w", stdout);
    }
}

template <typename T>
void read(T& x)
{
    x = 0; T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}

template <typename T>
void write (T a)
{
    if (a < 0)
    {
        putchar ('-');
        write (-a);
        return;
    }
    if (a < 10)
    {
        putchar ('0' + a);
        return;
    }
    write (a / 10);
    putchar ((char)('0' + (a % 10)));
}

set<int> e[mn];
int fa[mn];

int Fa (int u) {
    return (fa[u] < 0 ? u : fa[u] = Fa (fa[u]));
}

void Uni (int u, int v) {
    if (u == v) return;
    if (fa[v] > fa[u]) swap (u, v);
    fa[u] += fa[v];
    fa[v] = u;
}

void enter()
{
    int n, m, k;
    cin >> n >> m >> k;
    memset (fa, - 1, sizeof (fa));
    for (int i = 0; i < m; ++ i) {
        int u, v;
        cin >> u >> v;
        Uni (Fa (u), Fa (v));
        e[u].emplace(v);
        e[v].emplace(u);
    }
    for (int i = 0; i < k; ++ i) {
        int u, v;
        cin >> u >> v;
        e[u].emplace(v);
        e[v].emplace(u);
    }
    for (int i = 1; i <= n; ++ i)
    {
        int sol = - fa[Fa (i)];
        for (int j : e[i])
        if (Fa (i) == Fa (j)) -- sol;
        cout << sol - 1 << " ";
    }
}

void solve()
{

}

void print_result()
{

}

main()
{
    docfile();
    //cin>>ntest;
    for (tt = 1; tt <= ntest; ++ tt)
    {
        enter();
        solve();
        print_result();
    }
}

Measured memory_bytes: 26240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define make_pair mkp
int main()
{ 
	ll n,m;
	cin>>n>>m;
	ll sum = 0;
	while(m--)
	{
		ll a;
		cin>>a;
		sum+=a;
	}
	if(n>=sum)
	{
		cout<<n-sum<<endl;
		return 0;
	}
	cout<<-1<<endl;
	return 0;
} 

Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <locale>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

const long long int INF = 1e9;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Rep(i, n) for(int i = 1; i <= (int)(n); i++)
#define llrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define llRep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;

struct Point{
	int x,y;
};

bool vector_finder(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return true;
    }
  else { // 発見できなかったとき
    return false;
    }
}

ll factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
    }
    return ans;
}

ll extended_factorial(ll N){
    ll ans = 1;
    llRep(i,N){
        ans *= i;
        ans %= (ll)(1e9+7);
    }
    return ans;
}

vector<ll> Eratosthenes(ll N){
    bool arr[N+1];
    //initialization
    arr[0] = false;
    arr[1] = false;
	for(ll i = 2; i < N+1; i++){
		arr[i] = true;
	}
    //eratosthenes
	for(ll i = 2; i <= sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) <= N; j++){
				arr[i *(j + 2)] = false;//not prime number
			}
		}
	}
    vector<ll> prime;
    llRep(i,N){
        if (arr[i]==true){
            prime.push_back(i);
        }
    }
    return prime;
}

ll gcd(ll a, ll b){
  ll temp;
	while (a % b != 0){
		temp = b;
		b = a % b;
		a = temp;
	}
	return b;
}

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

char alphabet[] = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
};


int main(){
    ll N,M,a,add,sum=0;
    cin >> N >> M;
    std::priority_queue<ll> A;
    llrep(i,N){
        cin >> a;
        A.push(a);
        sum += a;
    }
    llrep(i,M){
        add = A.top() / 2;
        sum -= (A.top() - add);
        A.pop();
        A.push(add);
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n ;
  int a = (n / 1000), b = (n / 100) - (a * 10), c = (n / 10) - (a * 100 + b * 10), d = n - (a * 1000 + b * 100 + c * 10);
   if (a == b && b == c || b == c && c == d) {
     cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int s(int x){
    int y = 0;
    while(x!=0){
        y += x%10;
        x /= 10;
    }
    return y;
}


int main(){
    int res = 0;
    int n,a,b;cin >> n >> a >> b;
    for (int i=1;i<=n;i++){
        if(a<=s(i) && s(i)<=b){res+=i;}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256