akhauriyash/Code-Regression huggingface dataset:
#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>
 
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
 
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>
 
#include <memory.h>
#include <cassert>
#include <time.h>
 
using namespace std;
 
#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
 
#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
 
typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;
 
const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
 
#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif
 
void prepare(string s)
{
#ifdef MY_DEBUG
    freopen ("input.txt", "r", stdin);
    // freopen ("output.txt", "w", stdout);
#else
    if (s.length() != 0)
    {
        freopen ((s + ".in").c_str(), "r", stdin);
        freopen ((s + ".out").c_str(), "w", stdout);
    }
#endif
}

int k;
string s;

void read() {
    cin >> k >> s;
  
}



void solve() {
    if (s.length() <= k) {
        printf("%s\n", s.c_str());
    } else {
        printf("%s...\n", s.substr(0, k).c_str());
    }
    
}

int main() {
	prepare("");
    read();
    solve();

    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long x, long long y)
{
	long long result = 1;
	while (y != 0) {
		if (y%2 != 0) {
			result *= x;
			y -= 1;
		}	
		x *= x;
		y /= 2;
	}
	return result;
}
int main(void)
{
	long long a, b;
	cin >> a >> b;
	uint64_t ans = 0;
	for (long long i = 0; i <= 40; i++) {
		long long acount, bcount;
		{
		long long n = (a)/mypow(2, i+1);
		long long m = (a)%mypow(2, i+1);
		acount = n*mypow(2, i) + max(0LL, m-mypow(2LL, (long long)i));
		}
		{
		long long n = (b+1)/mypow(2, i+1);
		long long m = (b+1)%mypow(2, i+1);
		bcount = n*mypow(2, i) + max(0LL, m-mypow(2LL, (long long)i));
		}
		ans += (bcount - acount)%2 * mypow(2, i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
    int D, L, a, b;

    cin >> D >> L;

    a = (D / L);

    if((D % L) != 0){

        b = (D - (L * a));

    }

    cout << (a + b) << endl;
}

/*
10 5
2

7 4
4
*/


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

using namespace std;

short N;

int main(){
    cin >>N;
    vector<int> x(N);

    float sum = 0;
    for(int i = 0; i < N; i++){
        cin >> x[i];
        sum += x[i];
    }

    sum /= N;

    int ave = round(sum);
    int ans = 0;
    for(int i = 0; i < N; i++){
        ans += pow((x[i] - ave),2);
    }
    cout << ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ref(i,n) for(int i=0;i<n;i++)
using namespace std;
vector<int> a[100001];
int sh[100001];
int paths[100001];
typedef pair<int,int> P;
queue<P> q;
int main()
{
    int n,m;
    cin>>n>>m;

    ref(i,m){
        int x,y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    q.push(P(1,1));
    sh[1]=1;
    while(!q.empty()){
        P p=q.front();
        q.pop();
        ref(i,a[p.first].size())
        if(sh[a[p.first][i]]==0) {
            sh[a[p.first][i]]=p.second+1;
            paths[a[p.first][i]]=p.first;
            q.push(P(a[p.first][i],p.second+1));
        }

    }
    ref(i,n-1) if(!sh[i+2]){cout<<"No"; return 0;}
    cout<<"Yes"<<endl;
    ref(i,n-1) cout<<paths[i+2]<<endl;

}


Measured memory_bytes: 11044
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
#define N 1000005
int a,b,c,d,e,f,g,h,i;
bool judge()
{
    int s=a+b+d;
    if(s!=e+c+f||s!=g+h+i||s!=a+e+g)
        return 0;
    if(s!=b+c+h||s!=d+f+i||s!=a+c+i||s!=g+c+d)
        return 0;
    return 1;
}
int main()
{
    LL x,a,b,c,len;

            cin>>x;
    a=1;
    len=2;
    for(i=1;i<=x;++i){
        b=len;
        c=b+1;
        len=a+b+c;
    }
    cout<<len<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//整数の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		//計算
		int a = A + B;
		int b = A - B;
		int c = A * B;
		
		if (a > b && a > c){
			System.out.println(a);
		}
		else if (b > c){
			System.out.println(b);
		}
		else {
			System.out.println(c);
		}
	}
}

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

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0);
#define smid ((i + j) >> 1)
#define lc (sidx * 2)
#define rc (lc + 1)

typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((ld)a) / b); }

int faltu;

const int mod = 1e9+7;
const ll inf = 4e18;
const ll ninf = -inf;
const int imax = 2e9 + 100;

void findSubset(int n, string &s, map <pair <string, string> , int> &mp) {
	for(int i = 0; i < (1 << n); i++) {
		string tmp = "", other = "";
		for(int j = 0; j < n; j++) {
			if(i & (1 << j)) {
				tmp += s[j];
			} else {
				other += s[j];
			}
		}
		mp[{tmp, other}] ++;
	}
}

int main()
{
	time_t t1, t2;
	t1 = clock();
	srand(time(0));

	int n;
	string s;
	cin >> n;
	cin >> s;
	reverse(s.begin() + n, s.end());
	string t = s.substr(n, n), s1 = s.substr(0, n);
	map <pair <string, string> , int> mp1, mp2;
	trace(s1, t);
	findSubset(n, s1, mp1);
	findSubset(n, t, mp2);
	ll ans = 0;
	for(auto &x: mp1) {
		if(mp2.find(x.F) != mp2.end()) {
			// trace(x.F.F, x.F.S);
			ans += 1ll * mp2[x.F] * x.S;
		}
	}
	cout << ans << endl;
	t2 = clock();
	cerr << "time taken: " << t2 - t1 << endl;
	return 0;
}

Measured memory_bytes: 91904
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := nextInt(), nextInt()

	ans := 0
	if N <= M/2 {
		ans = (N + M/2) / 2
	} else {
		ans = M / 2
	}

	fmt.Println(ans)

}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
B - 1 Dimensional World's Tale
https://atcoder.jp/contests/abc110/tasks/abc110_b

"""
import sys


def solve(X, Y, x_cities, y_cities):
    for z in range(x_cities[-1]+1, y_cities[0]+1):
        if X < z <= Y:
            return 'No War'
    return 'War'


def main(args):
    N, M, X, Y = map(int, input().split())
    x_cities = sorted(map(int, input().split()))
    y_cities = sorted(map(int, input().split()))
    ans = solve(X, Y, x_cities, y_cities)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main() {
  std::string str;
  std::cin >> str;
  int A = 0;
  long long ans = 0;
  int i = 0;
  while (i < str.size())
  {
    if (str[i] == 'A')
    {
      ++A;
      ++i;
    }
    else
    {
      if (0 < A && i + 1 < str.size() &&
          str[i] == 'B' && str[i + 1] == 'C')
      {
        ans += A;
        i += 2;
      }
      else
      {
        A = 0;
         ++i;
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 640
def yymm(s):
    a = s[:2]
    b = s[2:]
    if (int(a)<=12 and int(a)>=1) and (int(b)<=12 and int(b)>=1):
        return 'AMBIGUOUS'
    if (int(a)<=12 and int(a)>=1) and (int(b)>12 or int(b)<1):
        return 'MMYY'
    if (int(b)<=12 and int(b)>=1) and (int(a)>12 or int(a)<1):
        return 'YYMM'
    else:
        return 'NA'
s = input()
print(yymm(s))

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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;
    // t = 10^100
    // a * t
    constexpr long MOD = 1e9 + 7;
    ll res = 0;
    for(ll a=k; a<=n+1; a++) {
        ll mi = a*(0+a-1)/2;
        ll ma = a*(n-a+1 + n)/2;
        (res += (ma - mi + 1) % MOD) %= MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 3660
#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
char T[3], U[10] = "ABCDEFGHI"; int n, c[3][2], x[5][5]; double p[100][5][5];

void A(int E, int B, int C, double D, int F, int G) { 
	if (x[B][C] == 0) { 
		p[E][B][C] += D; 
	} 
	else {
		p[E][F][G] += D;
	}
}

int main() {
	while (true) {
		memset(p, 0.0, sizeof(p));
		cin >> n;
		if (!n) { break; }
		cin >> T[0] >> T[1] >> T[2];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 9; j++) {
				if (U[j] == (char)T[i]) {
					c[i][0] = j / 3 + 1;
					c[i][1] = j % 3 + 1;
				}
			}
		}
		p[n][c[0][0]][c[0][1]] = 1;
		for (int i = 0; i < 25; i++) {
			x[i / 5][i % 5] = 1;
		}
		for (int i = 1; i <= 3; i++) {
			for (int j = 1; j <= 3; j++) {
				if (i != c[2][0] || j != c[2][1]) {
					x[i][j] = 0;
				}
			}
		}
		for (int i = n - 1; i >= 0; i--) {
			for (int j = 1; j <= 3; j++) {
				for (int k = 1; k <= 3; k++) {
					if (p[i + 1][j][k]>0) {
						A(i, j - 1, k, p[i + 1][j][k] / 4.0, j, k);
						A(i, j + 1, k, p[i + 1][j][k] / 4.0, j, k);
						A(i, j, k + 1, p[i + 1][j][k] / 4.0, j, k);
						A(i, j, k - 1, p[i + 1][j][k] / 4.0, j, k);
					}
				}
			}
		}
		cout << fixed << setprecision(15) << p[0][c[1][0]][c[1][1]] << endl;
	}
}

Measured memory_bytes: 1260
import math

n = int(input())
p = [int(i) for i in input().split()]

ans = 0
tmp = 0

for i in range(n):
    if i+1 == p[i]:
        if tmp != 1:
            ans += 1
            tmp = 1
        else:
            tmp = 0
    else:
        tmp = 0
        
print(ans)

Measured memory_bytes: 13812
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

int main()
{

   string s;

   cin >> s;


   int N = s.size();


   if(s[N-1]=='s'){


       s = s+"es";
   }
   else{


       s=s+'s';
   }


   cout << s << endl;




    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int A[N+1];
    int s=0;
 
    for(int i=1;i<=N;i++)
    {
        cin>>A[i];
 }
 
    for(int i=1;i<=N;i++)
    {
        for(int j=i+1;j<=N;j++)
        {
            s+=A[i]*A[j];
        }
    }
 
    cout<<s;
 return 0;
}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
const int N=2*1e5+10;
vector<int> mp[N];
int n,Q,cnt[N],u,v,deep[N];
void dfs(int root,int deg){
	deep[root]=deg;
	for(int i=0;i<mp[root].size();i++)
	    if(!deep[mp[root][i]]) dfs(mp[root][i],deg+1);
}
void dfs2(int root,int ans){
	cnt[root]+=ans;
	for(int i=0;i<mp[root].size();i++)
	    if(deep[mp[root][i]]>deep[root]) dfs2(mp[root][i],cnt[root]);
}
int main(){
	cin>>n>>Q;
	for(int i=1;i<n;i++) cin>>u>>v,mp[u].push_back(v),mp[v].push_back(u);
	dfs(1,1);
	for(int i=1;i<=Q;i++){
	    cin>>u>>v;
	    cnt[u]+=v;
	}
	dfs2(1,0);
	for(int i=1;i<=n;i++){
		if(i!=1) printf(" ");
		printf("%d",cnt[i]);
	}
	return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if ((e - a) <= k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
}


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

struct SegmentTree {
	vector < ll > st;
	SegmentTree (int n) {
		st.resize (4 * n);
	}
	
	void update (int index, ll value, int low, int high, int pos) {
		if (low > index || high < index) {
			return;
		}
		if (low == high) {
			st[pos] = value;
			return;
		}
		int mid = low + (high - low) / 2;
		update (index, value, low, mid, pos + pos + 1);
		update (index, value, mid + 1, high, pos + pos + 2);
		st[pos] = max (st[pos + pos + 1], st[pos + pos + 2]);
	}
	
	ll query (int left, int right, int low, int high, int pos) {
		if (left > high || low > right) return 0;
		if (left <= low && right >= high) return st[pos];
		int mid = low + (high - low) / 2;
		return max (
			query (left, right, low, mid, (pos << 1) + 1),
			query (left, right, mid + 1, high, (pos << 1) + 2)
		);
	}
};

int main() {
	int n;
	scanf ("%d", &n);
	vector < int > h (n), a (n);
	for (int & x : h) scanf ("%d", &x);
	for (int & x : a) scanf ("%d", &x);
	// O (N ^ 2) solution
	vector < ll > dp (n);
	SegmentTree tree (n + 1);
	ll answer = 0ll;
	for (int i = 0; i < n; i++) {
		ll max_value = tree.query (1, h[i] - 1, 0, n, 0);
		dp[i] = max_value + a[i];
		tree.update (h[i], dp[i], 0, n, 0);
		answer = max (answer, dp[i]);
	}
	printf ("%lld\n", answer);
	return 0;
}



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

using namespace std;
typedef long long ll;

int mat[10][1 << 8];

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

  for (int i = 0; i < n; i++) {
    mat[0][i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    mat[0][a] = 0;
  }

  int ans = 0;
  for (int i = 0; 1 << i < n; i++) {
    for (int j = 0; j < n >> i; j += 2) {
      ans += (mat[i][j] && mat[i][j + 1]);
      mat[i + 1][j / 2] = mat[i][j] || mat[i][j + 1];
    }
  }
  cout << ans << endl;

  return 0;
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i32 s = input();
    set<i32> st;

    range(i, 1, 1000001) {
        if (st.count(s)) {
            cout << i << endl;
            return;
        }

        st.insert(s);

        if (s & 1)
            s = 3 * s + 1;
        else
            s /= 2;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}

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

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
S = input().rstrip()
T = input().rstrip()

ok = True

now_r = sc
for i in range(N):
    if S[i] == 'R':
        if now_r == W:
            ok = False
            break
        now_r += 1
    if T[i] == 'L':
        now_r = max(now_r-1, 1)

now_l = sc
for i in range(N):
    if S[i] == 'L':
        if now_l == 1:
            ok = False
            break
        now_l -= 1
    if T[i] == 'R':
        now_l = min(now_l+1, W)

now_u = sr
for i in range(N):
    if S[i] == 'U':
        if now_u == 1:
            ok = False
            break
        now_u -= 1
    if T[i] == 'D':
        now_u = min(now_u+1, H)

now_d = sr
for i in range(N):
    if S[i] == 'D':
        if now_d == H:
            ok = False
            break
        now_d += 1
    if T[i] == 'U':
        now_d = max(now_d-1, 1)

if ok:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3888
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define VIN(n,v) for(int64_t i=0;i<(n);i++){cin >> (v).at(i);}

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I x,y;
  cin >> x >> y;
  I t=1;
  I c = x;
  while (true){
    x *= 2;
    if (x > y){
      break;
    }else{
      t++;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define mod 1000000007

int main() {
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int l, r, mn = 2e9; cin >> l>> r;
        if (r / 2019 - (l - 1) / 2019 >= 1) {
                cout << "0\n";
        } else {
                l %= 2019;
                r %= 2019;
                for (int i = l; i <= r; i++) {
                        for (int j = i + 1; j <= r; j++) {
                                mn = min(mn, (i * j) % 2019);
                        }
                }
                cout << mn;
        }
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
template<class T>inline bool chmax(T& a, T b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T& a, T b){if(a > b){a = b; return 1;}return 0;}
const ll INF = 1LL<<60;
//const int dy[4] = {0, 1, 0, -1};
//const int dx[4] = {1, 0, -1, 0};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

void solve(){
    ll n; cin >> n;
    vector<ll> ac(n+1, 0);
    ll sum = 0;
    REP(i, n){
        ll a; cin >> a;
        ac[i+1] = ac[i] + a;
        sum += a;
    }
    ll res = 10000000000;
    for(int i=1; i<n; i++){
        res = min(res, abs(2*ac[i] - sum));
    }
    cout << res << endl;
}

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

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

using namespace std;

int main()
{
  typedef pair<int, int> P;
  int n; cin >> n;
  vector<P> av(n);
  for(P &p : av) cin >> p.second >> p.first, p.first *= -1;
  sort(av.begin(), av.end());
  cout << av[0].second << " " << -av[0].first << endl;
  return 0;
}

Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<complex>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	int n;
	cin>>n;
	int a[n],b[n];
	vector<int>c;
	map<int,int>mp;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		mp[b[i]]++;
	}
	for(int i=0;i<n;i++){
		auto id=mp.upper_bound(a[i]);
		if(id==mp.end())id=mp.upper_bound(0);
		int v=(*id).first;
		c.pb(v);
		mp[v]--;
		if(mp[v]==0)mp.erase(id);
	}
	int f=0;
	for(int i=0;i<n;i++)if(c[i]==a[i]){f=1;break;}
	if(f){
		c.clear();
		for(int i=0;i<n;i++)mp[b[i]]++;
		for(int i=n-1;i>=0;i--){
			auto id=mp.upper_bound(a[i]);
			if(id==mp.end())id=mp.upper_bound(0);
			int v=(*id).first;
			c.pb(v);
			mp[v]--;
			if(mp[v]==0)mp.erase(id);
		}
		reverse(c.begin(), c.end());
		for(int i=0;i<n;i++)if(c[i]==a[i]){cout<<"No";return;}
	}
	cout<<"Yes\n";
	for(int i=0;i<n;i++)cout<<c[i]<<" ";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 14528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
  long key;
  struct node *left;
  struct node *right;
  struct node *p;
}Node;

void print_tree(Node *x,int order) {
  if (order == 0) {
    printf(" %ld", x->key);    
  }
  if(x->left != NULL) print_tree(x->left,order);
  if (order == 1) {
    printf(" %ld", x->key);    
  }
  if(x->right != NULL) print_tree(x->right,order);
  if (order == 2) {
    printf(" %ld", x->key);    
  }
}

Node *insert(Node *root, long key) {
  Node *z = (Node*)malloc(sizeof(Node));
  z->key = key;
  z->p = NULL;
  z->left = NULL;
  z->right = NULL;
  Node *x,*y;
  y = NULL;
  x = root;
  while(x != NULL) {
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y  == NULL) return z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  return root;
}

int main()
{
  long i,N,key;
  char command[7];
  Node *root = NULL;
  scanf("%ld",&N);
  for (i = 0; i < N; i++) {
    scanf("%s",command);
    if(strcmp(command,"insert") == 0) {
      scanf("%ld",&key);
      root = insert(root,key);
    }
    if(strcmp(command,"print") == 0) {
      print_tree(root,1);
      printf("\n");
      print_tree(root,0);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 25136
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll dp[200005][4];

vector < ll > vec;

const ll mn = -1e18;

ll solve(ll pos, ll skip)
{
	ll &ret = dp[pos][skip];

	if(ret != mn) return ret;

	if(pos >= vec.size())
	{
		if(vec.size() & 1)
			if(skip == 2) return ret = mn / 1000;

		return ret = 0;
	}

	ret = solve(pos + 2, skip) + vec[pos];

	if(skip) ret = max(ret, solve(pos + 1, skip - 1));

	return ret;
}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		vec.clear();
		vec.resize(n);

		for(ll i = 0; i < n; i++) cin >> vec[i];

		for(ll i = 0; i <= n + 3; i++) for(ll j = 0; j < 4; j++) dp[i][j] = mn;

		ans = solve(0,(n % 2) + 1);

		cout << ans << "\n";

    }


}





Measured memory_bytes: 15660
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;
	ll sum = 0;
	cin >> N;
	vector<int> A(N), B(N), C, D;
	FOR(i, 0, N)
	{
		ll H;
		cin >> H;
		--H;
		A.at(i) = H;
		if(i!=0){
			if(A.at(i)-A.at(i-1)==1)
				D.push_back(A.at(i - 1));
		}
	}
	sort(range(D));
	FOR(i, 0, N)
	{
		ll K;
		cin >> K;
		sum += K;
	}
	int k = 0;
	FOR(i, 0, N - 1)
	{
		ll p;
		cin >> p;
		C.push_back(p);
	}

	FOR(i,0,D.size()){
		sum += C.at((D.at(i)));
	}

		cout << sum << endl;

		return 0;
}



Measured memory_bytes: 3632
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    H1, M1, H2, M2, K = map(int, input().split())
    HM1 = H1*60+M1
    HM2 = H2*60+M2
    print(HM2-HM1-K)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9140
import java.util.Arrays;
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in .nextInt();
        int [][] tasks = new int[n][2];
        for(int i=0;i<n;i++){
            tasks[i][0]=in.nextInt();
            tasks[i][1]=in.nextInt();
        }

        Arrays.sort(tasks, (a, b)->a[1]-b[1]);
//        for(int i=0;i<n;i++){
//            System.out.println(""+ tasks[i][0] + " " + tasks[i][1]);
//        }
        boolean flag=true;
        int timer=0;
        for(int i=0;i<n;i++){

            timer+=tasks[i][0];
            if(timer>tasks[i][1]) {
                flag = false;
                break;
            }
        }
        if(flag==true)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


Measured memory_bytes: 109168
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long int ll;
 ll  p=1e9+7; 

 int  main() {
        ff;
       
       ll x;
       cin>>x;
       ll z=100;
       ll cnt=0;
       while(1){
           z=z+z/100;
           cnt++;
           if(z>=x){
               cout<<cnt<<endl;
               break;
           }
       }
       
      
    return 0;
}


Measured memory_bytes: 3668
def dfs(f, r):
    if r==1:
        return 1
    if len(f) == 0:
        return 0

#    print(f, r)
    out = dfs(f[1:], r)
    for i in range(1, min(r, f[0][1])+1):
        if r%(i+1) == 0:
            out += dfs(f[1:], r//(i+1))
    return out

N = int(input())
s = 0

fact = {}
for j in range(2, N+1):
    s = 0
    k = j
    while s==0:
        for i in range(2,k+1):
            if k%i==0:
                k=int(k/i)
                if k==1:
                    s=1
                fact[i] = fact.get(i, 0)+1
                break

fact = list(fact.items())
res = dfs(fact, 75)
print(res)        


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    int N;
    cin >> N;

    int d = N%10;
    if(d==2 || d==4 || d==5 || d==7 || d==9) 
      cout << "hon" << endl;  
    else if(d==0 || d==1 || d==6 || d==8) 
      cout << "pon" << endl;
    else if(d==3)
      cout << "bon" << endl;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
int main(void){
    double a,b,c,d,e,f,det,x,y;
 
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
 
 
    det=a*e-b*d;
    /*x=(e*c-b*f)/det;*/
    y=(-d*c+a*f)/det;
    x=(c-b*y)/a;
 
   printf("%.3lf %.3lf\n",x,y);
    }
 
    return 0;
}

Measured memory_bytes: 652
import bisect

def binary_search(items, a, b, i, j):
    def c_is_x(c):
        is1 = c > max(a - b, b - a)
        is2 = c < a + b

        if is1 and is2:
            return 0
        elif is1:
            return 1
        else:
            return 2

    low = j+1
    high = len(items) - 1

    while low <= high:
        mid = (low + high) // 2
        ans = items[mid]
        c_type = c_is_x(ans)
        if c_type == 0 and mid != i and mid != j:
            return mid
        elif c_type == 1:
            low = mid + 1
        else:
            high = mid - 1

    return None


N = int(input())
L = list(map(int, input().split()))

L.sort()
# print(L)
count = 0
for i in range(N):
    for j in range(i+1, N):
        # i = N - i - 1
        # j = N - j - 1
        a = L[i]
        b = L[j]
        k = bisect.bisect_left(L, a+b, lo=j) - 1

        if k < N:
            c = L[k]
            # print(a, b, c, a+b)
            # print(i, j, k)
            count += max(k - j, 0)


print(count)




Measured memory_bytes: 9312
#include <bits/stdc++.h>
using namespace std;
//typedef int64_t int;
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise cout.precision(10); cout << fixed;
#define pb push_back
#define mk make_pair
#define endl "\n"
#define int int64_t
#define ll long long
#define in(num,n) std::vector<int> num(n); for (int i = 0; i < n; i++)cin >> num[i]
const ll Inf = 1e9 + 7;
void solve() {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int sum = 0;
    if (n > k) {
        cout << k*x + (n - k)*y << endl;
    } else {
        cout << n*x << endl;
    }



}


int32_t main()
{
    fastio;
    precise;
    solve();
    return 0;
}

Measured memory_bytes: 3668
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, D := sc.nextInt(), sc.nextInt()
	count := 1
	for {
		if (D*2+1)*count >= N {
			break
		}
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n)
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define ill(_x)  ll _x;scanf("%lld",&_x);
#define idb(_x)  double _x;scanf("%lf",&_x);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vs vector<string>
#define in0(x,a,b)((x)>=a && (x)<=b	)
#define in1(x,a,b)((x)>a && (x)<b)
#define  rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const double pi = 3.14159265358979323846;
const int INF = 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;

ll subArraySum(ll arr[], ll n)
{
    unordered_map<ll, pll> map;
    ll curr_sum = 0;
    ll t=0;
    for (int i = 0; i < n; i++)
    {
        curr_sum = curr_sum + arr[i];
        if (curr_sum == 0)
        {
            t++;
        }

        if (map.count(curr_sum))
        {
            t+=map[curr_sum].second;
        }

        map[curr_sum].first = i;
        map[curr_sum].second++;
    }
    return t;
}

ll arr[200005];
void _(){
    ill(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld",&arr[i]);
    }
    cout << subArraySum(arr,n);


}





int main() {
#if __MINGW32__
	freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Input.txt", "r", stdin); freopen("E:\\Workspace\\Desktop\\cpp\\IO\\Output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);    cin.tie(NULL);
	_();
	return 0;

}








Measured memory_bytes: 13256
import collections

_=input()
a=list(map(int,input().split()))
c=collections.Counter(a)
l=sorted(c.items(), key=lambda x: x[0])
x=0
for i in l[::-1]:
    if i[1]>3:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            print(i[0]*i[0])
            exit(0)
    elif i[1]>1:
        if x:
            print(i[0]*x)
            exit(0)
        else:
            x=i[0]
print(0)

Measured memory_bytes: 27208
package main

import (
    "fmt"
)

var n, m int 
var ps [][]int
var dp []int

func main() {
    fmt.Scan(&n, &m) 

    ps = make([][]int, n)
    for i := 0; i < m; i++ {
        var x, y int 
        fmt.Scan(&x, &y) 
        x-- 
        y-- 
        ps[x] = append(ps[x], y)
    }   

    // dp[i] iスタートの最長パス
    dp = make([]int, n)
    for i := range dp {
        dp[i] = -1
    }   

    for i := range dp {
        if dp[i] == -1 {
            search(i)
        }   
    }   

    var max int 
    for _, v := range dp {
        if v > max {
            max = v 
        }   
    }   

    fmt.Println(max)
}

func search(p int) int {
    if dp[p] != -1 {
        return dp[p]
    }   
    if len(ps[p]) == 0 { 
        dp[p] = 0 
        return dp[p]
    }   
    var max int 
    for _, v := range ps[p] {
        c := search(v)
        if c > max {
            max = c 
        }   
    }   
    dp[p] = max + 1 
    return dp[p]
}


Measured memory_bytes: 15104
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int solve(int N, vector<int>& v, int sum)
{
    int ans = 0;

    for (int i = 0; i < N; ++i)
        ans += (sum - v[i]) * v[i];

    return ans / 2;
}

int main() {
    fast_io();

    int N = fetch<int>();

    vector<int> v(N);
    int sum = 0;
    for (int i = 0; i < N; ++i)
    {
        v[i] = fetch<int>();
        sum += v[i];
    }
    
    std::cout << solve(N, v, sum) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int main(){
  int N;
  int a[50];
  int flag=0;
  string ans="NO";

  cin >> N;
  for(int i=0; i<N; i++) {
    cin >> a[i];
    if (i>0 && a[i] < a[i-1]) flag = 1;
  }
  if (flag ==0) {
    cout << "YES" << endl;
    return 0;
  }


  for (int i=0; i<N-1; i++) {
    for (int j=i+1; j<N; j++) {
      int tmp;
      flag=0;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      for (int k=1; k<N; k++) {
        if (a[k] < a[k-1]){
          flag=1;
          break;
        }
      }
      if (flag) {
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      } else {
        ans = "YES";
        break;
      }

    }
    if (ans == "YES") break;
  }

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

Measured memory_bytes: 256
#include<stdio.h>

int main (void) {
    int x, y;

    scanf("%d %d", &x, &y);
    while(x != 0 || y != 0) {
        if(x < y) {
            printf("%d %d\n", x, y);
        }
        else {
            printf("%d %d\n", y, x);
        }
        scanf("%d %d", &x, &y);
    }
    return 0;
}

Measured memory_bytes: 600
require 'set'

N, M = gets.chomp.split(" ").map(&:to_i)
E = Hash.new{|h, k| h[k] = []}
M.times{
  u, v = gets.chomp.split(" ").map(&:to_i)
  E[u] << v
}
S, T = gets.chomp.split(" ").map(&:to_i)

def next_step(s)
  ret = []
  s.each{|x|
    ret.concat(E[x])
  }
  ret.uniq
end

past = Set.new
past.add(S)
now_pos = [S]
cnt = 1
ans = -1
while(!now_pos.empty? && ans == -1) do
  step3 = next_step(next_step(next_step(now_pos)))
  now_pos = []
  step3.each{|s|
    (ans = cnt; break) if s == T
    if !past.include?(s) then
      now_pos << s
      past.add(s)
    end
  }
  cnt += 1
end

puts ans


Measured memory_bytes: 28248
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        int N = scanner.nextInt();
        
        int[] a = new int[N];
        long y = 0;
        
        a[0] = scanner.nextInt();
        for(int i = 1; i < N; i++) {
            a[i] = scanner.nextInt();
            y += a[i];
        }
        
        long x = a[0];
        long min = Math.abs(x - y);
        long calc;
        for(int i = 1; i < N - 1; i++) {
            x += a[i];
            y -= a[i];
            calc = Math.abs(x - y);
            if(min > calc) {
                min = calc;
            }
        }
        System.out.println(min);
        
    }
}

Measured memory_bytes: 85524
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  if(A <= 5)
    cout << 0 << endl;
  else if(A <=12)
    cout << B/2 << endl;
  else
    cout << B << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


int main(){
cout<<fixed<<setprecision(10);
//cin.tie(0); ios::sync_with_stdio(false);

  int X,Y;
  cin>>X>>Y;
int N=100;
  int M=100;
  
  bool OK=false;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=M;j++){
      if(i*2+j*4==Y&&i+j==X){
        OK=true;break;
      }
    }
  }
  if(OK){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
        
      
}



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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int ans = 0;
    if (d[N / 2] == d[N / 2 - 1]) {
        cout << ans << endl;
        return 0;
    } else {
        ans = d[N / 2] - d[N / 2 - 1];
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
AtCoder C
"""
 
# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = int(input()) for _ in range(N) # 1 row N column
 
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
 
def main():
    A, B = list(map(int,input().split()))
    S =str(input())
    out=""
    i=1
    for s in S:
        if i==B:
            if s=="A":
                out+="a"
            elif s=="B":
                out+="b"
            elif s=="C":
                out+="c"
        else:
            out+=s
        i+=1
    print(out)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
#define lli long ling int;

int gcd(int a, int b)
{
    int r;
    r = a % b;
    while(r!=0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main()
{
    long long int K, sum = 0;
    scanf("%lld", &K);

    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                // i,j,k gcd
                int a, b, c, d, tmp;
                a = i;
                b = j;
                c = k;
                if (a < b) {
                    tmp = a;
                    a = b;
                    b = tmp;
                }
                d = gcd(a, b);

                if (c < d) {
                    tmp = c;
                    c = d;
                    d = tmp;
                }
                int res = gcd(c, d);
                //printf("%d %d %d %d\n", i, j, k, res);
                sum += res;
            }
        }
    }

    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 3784
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,x,y,k,ans,curr,temp,m,s;
    cin >> n >> k >> s;
    if(s == 1) curr = s+1;
    else curr = s-1;
    for(i=1;i<=n;i++)
    {
        if(i <= k) printf("%d ", s);
        else printf("%d ", curr);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
	int N;
	cin >> N;
 
	vector<string> s(N);
	for (int i = 0; i < N; i++)
	{
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
 
	sort(s.begin(), s.end());
 
	long long ans = 0;
	int count = 0;
	for (int i = 1; i < N; i++)
	{
		if (s[i] == s[i-1]) {
			count++;
			ans += count;
		}
		else {
			count = 0;
		}
	}
	
	cout << ans << endl;
 
	return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))


ll par[100000];
ll r_ank[100000];
ll siz[100000];
ll comb=0;
ll totsiz=0;

void init(ll n){
    for(int i=0;i<n;i++){
        par[i]=i;
        r_ank[i]=0;
        siz[i]=1;
    }
    totsiz=0;
}

ll root(ll x){
    if(par[x]==x){
        return x;
    }else{
        ll a=par[x];
        ll rt=root(par[x]);
        totsiz-=siz[rt]*(siz[rt]-1)/2;
        totsiz-=siz[x]*(siz[x]-1)/2;
        totsiz+=(siz[rt]+siz[x])*(-1+siz[rt]+siz[x])/2;
        siz[rt]+=siz[x];
        siz[x]=0;
        par[x]=rt;
        return par[x];
    }
}
bool same(ll x,ll y){
    return root(x)==root(y);
}
void unite(ll xx,ll yy){
    ll x=root(xx);
    ll y=root(yy);
    if (x==y) return;
        totsiz-=siz[y]*(siz[y]-1)/2;
        totsiz-=siz[x]*(siz[x]-1)/2;
        totsiz+=(siz[y]+siz[x])*(-1+siz[y]+siz[x])/2;
    siz[y]+=siz[x];
    siz[x]=0;
    par[x]=y;
/*    if(r_ank[x]<r_ank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if (r_ank[x]==r_ank[y])r_ank[x]++;
    }*/
}

ll getsize(ll N){
    return totsiz;
/*    ll ans=0;
    for(int i=0;i<N;i++){
        if (siz[i]==0)continue;
        dbg cout <<"siz-"<<i<<":"<<siz[i]<<endl;
        ans+=siz[i]*(siz[i]-1)/2;
    }
    return ans;*/
}

int main(){
    ll N,M;
    cin >>N>>M;
    ll maxans=N*(N-1)/2;
    ll ans[M];
    vector<ll> g[N];
    ll input[M][2];
    for(int i=0;i<M;i++){
        cin >>input[i][0]>>input[i][1];
        input[i][0]--;
        input[i][1]--;
    }
    init(N);
    ans[M-1]=maxans;
    for(int i=M-1;i>0;i--){
        unite(input[i][0],input[i][1]);
        ans[i-1]=max((ll)0,maxans-getsize(N));
        dbg cout <<"siz "<<getsize(N)<<endl;
    }



    for(int i=0;i<M;i++){
        cout <<ans[i]<<endl;
    }

    return 0;

}

Measured memory_bytes: 8320
for v in range(1000):
  s,t,u = input().split()
  s = int(s)
  t = int(t)
  u = int(u)
  if s == 0:
    break
  else:
    l = []
    m = []
    for i in range(s):
      l.append(int(input()))

    for o in range(s-1):
      w = l[o]-l[o+1]
      w = abs(w)
      m.append(w)

    m = m[t-1:u]
    mx = max(m)
    lll = len(m)
    hhh=-1
    for i in range(lll): 
      if mx==m[i]:
        hhh=i+t
    print(hhh)
      


Measured memory_bytes: 5620