akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#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
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,ans=0;
  cin>>n;
  rep(i,1,n+1)
    {
      if(i%2==0) continue;
      int cnt=0;
      rep(j,1,i+1)
	if(i%j==0) cnt++;
      if(cnt==8) ans++;
    }
  cout<<ans<<endl;
  return 0 ;
}


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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	cin >> n;

	if(n % 2 == 0) {
		cout << n << endl;
	}else{
		cout << 2 * n << endl;
	}
	
}

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


int main()
{
    int a,x[105],add1=0;
    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>x[i];
        add1+=x[i];
    }
    int b=add1/a;
    int d=b+1;
    int add2=0,add3=0;
    for(int i=0;i<a;i++)
    {
        add2+=pow((x[i]-b),2);
        add3+=pow((x[i]-d),2);
    }
    int add=min(add2,add3);
    cout<<add<<endl;
    return 0;
}


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

#define PI acos(-1)

int main() {
	double r;
	cin>>r;
	cout<<fixed << setprecision(6) << PI *r * r << " " <<  2 * M_PI * r;
	return 0;
}
//   https://www.youtube.com/watch?v=O-cawByg2aA


Measured memory_bytes: 3268
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int k,a,b;
  cin >>k;
    cin >>a>>b;
  int key=0;
  rep2(i,a,b+1){
    if(i%k==0) key=1;
  }
  if( key==1) cout <<"OK"<<endl;
  else cout <<"NG"<<endl;
}

Measured memory_bytes: 3640
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 - 1]
    }
    let mut ans = v[0] + v[n - 2];
    for i in 0..n - 2 {
        ans += min(v[i], v[i + 1]);
    }
    println!("{}", ans);
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if ( d > 0 && d * d > 4 * a * b){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
 }
}


Measured memory_bytes: 256
N = int(input())
XY = []
for _ in range(N):
    A = int(input())
    tmp = []
    for __ in range(A):
        tmp.append(list(map(int, input().split())))
    XY.append(tmp)
ans = 0


def judge(bit):
    for i in range(N):
        tmp = XY[i]
        if((bit >> i) & 1 == 1):
            for j in tmp:
                #i番目の人の証言
                x = j[0] - 1 #人X
                y = j[1]    #1:正直者である 2:不親切な人

                #証言では正直者だけど、bitでは不親切な人の場合は矛盾

                if(y == 1 and (~bit) & (1 << x)):
                    return False
                #証言では不親切な人だけど、bitでは正直者の場合は矛盾
                if((y == 0) and bit & (1 << x)):
                    return False
    return True


for bit in range(1 << N):
    if(judge(bit)):
        counter = 0
        for i in range(N):
            if(bit & (1 << i)):
                counter += 1
        ans = max(ans, counter)
print(ans)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
  int k;
  string s;

  cin >> k >> s;

  if(s.size() <= k){
    cout << s << endl;
  }
  else{
    for(int i = 0; i < k; i++){
      cout << s[i];
    }
    cout << "..." << endl;
  }

  return 0;
}

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

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

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

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

signed main() {
  INIT;
	VAR(int,n,m);
	int ans = min(n,m/2);
	n -= ans;
	m -= ans*2;

	ans += max(0L,m/4);
  OUT(ans)BR;
  return 0;
}


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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            if (a == 1)
            {
                a = 14;
            }
            if (b == 1)
            {
                b = 14;
            }

            if (a > b)
            {
                Console.WriteLine("Alice");
            }
            else if (a < b)
            {
                Console.WriteLine("Bob");
            }
            else
            {
                Console.WriteLine("Draw");
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
const ll MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
ll fast_power(ll x, ll p){
    ll res = 1;
    while(p > 0){
        if(p & 1){
            res = (res * x);
        }
        p = p >> 1;
        x = (x*x);
    }
    return res;
}
int n;
int a[100005];
ll dp[100005];

ll solve(int index) {
    if (index >= n - 1)
        return 0;
    if (index == n - 2)
        return abs(a[index] - a[n - 1]);
    if (dp[index] != -1) {
        return dp[index];
    }
    return dp[index] = min(solve(index + 1) + abs(a[index] - a[index + 1]), solve(index + 2) + abs(a[index] - a[index + 2]));
}

int main() {
    IO;
    cin >> n;
    memset(dp,-1,sizeof(dp));
    for (int i = 0; i < n; i++)
        cin >> a[i];
    cout << solve(0);
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool compare(pair<ll, ll> a, pair<ll, ll> b)
{
	if (a.first == b.first)
		return a.second > b.second;
	return a.first < b.first;
}
int main()
{

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

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt" , "r" , stdin);
// 	freopen("output.txt" , "w" , stdout);
// #endif

	ll n, m;
	cin >> n >> m;
	vector<pair<ll, ll>>v;
	for (ll i = 1; i <= m; i++)
	{
		ll a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end(), compare);
	ll ans = 1, pa = v[0].first, pb = v[0].second;
	for (ll i = 1; i < m; i++)
	{
		if (v[i].first >= pb)
		{
			ans += 1;
			pb = v[i].second;
		}
		else
		{
			pb = min(v[i].second, pb);
		}
	}
	cout << ans << endl;



}


Measured memory_bytes: 3444
n = int(input())
s = input()
ans = []
for i in range(n):
    if i == 0:
        counter = 0
        for k in range(1,n):
            if s[k] == 'E':
                counter += 1
        ans.append(counter)
    else:
        counter = ans[i-1]
        if s[i-1] == 'W' and s[i] == 'W':
            counter += 1
            ans.append(counter)
        elif s[i-1] == 'E' and s[i] == "E":
            counter += -1
            ans.append(counter)
        else:
            ans.append(counter)
print(min(ans))

Measured memory_bytes: 15520
A, B, C, D, E, F = map(int, input().split())
items = []

for w in range(16):
    for x in range(16):
        if w == x == 0:
            continue
        for y in range(1501):
            a = 100*A*w
            b = 100*B*x
            c = C*y
            i = (F-(a+b+c))//D
            for z in reversed(range(i+1)):
                d = D*z
                if a+b+c+d <= F and (a+b)*E >= (c+d)*100:
                    items.append((100*(c+d)/(a+b+c+d), a+b, c+d))
                    break

items.sort(reverse=True)

print(items[0][1]+items[0][2], items[0][2])


Measured memory_bytes: 4212
n, k = gets.split(' ').map(&:to_i)

x = gets.split(' ').map(&:to_i)

ans = []

for i in 0...(n - k + 1)
	ans.push(x[i].abs + (x[i + k - 1]-x[i]).abs)
	ans.push(x[i + k - 1].abs + (x[i]-x[i + k - 1]).abs)
end

p ans.min

Measured memory_bytes: 9348
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		sc.close();
		int ans = 0;

		for(int x=0; x<=k; x++) {
			for(int y=0; y<=k; y++) {
				if((s-x-y>=0)&&(s-x-y<=k)) ans++;
			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 23764
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main()
{
	int k, x;
	int i;

	scanf("%d %d", &k, &x);

	for (i = x - k + 1; i <= x + k - 1; i++)
	{
		printf("%d ", i);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 128
n=int(input())
lst_to=[[] for i in range(n**2)]
lst_from=[[] for i in range(n**2)]
for i in range(n):
    a=list(map(int,input().split()))
    for j in range(n-2):
        i1=i
        i2=i
        b=a[j]-1
        c=a[j+1]-1
        if i1>b:
            i1,b=b,i1
        if i2>c:
            i2,c=c,i2
        lst_to[n*i1+b].append(n*i2+c)
        lst_from[n*i2+c].append(n*i1+b)

que=[]
for i in range(n):
    for j in range(i+1,n):
        if not lst_from[n*i+j]:
            que.append(n*i+j)

count=0
while que:
    count+=1
    h=[]
    for u in que:
        for v in lst_to[u]:
            lst_from[v].remove(u)
            if not lst_from[v]:
                h.append(v)
    que=h

for i in range(n):
    for j in range(i+1,n):
        if lst_from[n*i+j]:
            print(-1)
            break
    else:
        continue
    break
else:
    print(count)

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

int main() {
  int N;
  cin >> N;
  
  long long l0=2, l1=1, ans;
  for(int i=2; i <=N ;i++){
    ans =l0 + l1;
    //更新処理
    l0 = l1;
    l1 = ans;
  }
  if(N==0){
    cout << l0 << endl;
  }else if(N==1){
    cout << l1 << endl;
  }else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const long long BIGINT = 1e9 + 7;
int N, M;

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> M;

    vector<bool> invalid(N + 1);
    rep(i, M)
    {
        int tmp;
        cin >> tmp;
        invalid[tmp] = true;
    }

    vector<ll> dp(N + 3);
    dp[0] = 1LL;
    for (int i = 1; i <= N; ++i)
    {
        if (invalid[i])
            dp[i] = 0LL;
        else
        {
            if (i == 1)
                dp[i] = dp[i - 1];
            else
                dp[i] = (dp[i - 1] + dp[i - 2]) % BIGINT;
        }
    }
    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    if(y%2)
      printf("No\n");
    else if(y>=x*2&&y<=4*x)
      printf("Yes\n");
    else
      printf("No\n");
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define mod 1000000007
using ll = long long;
using namespace std; 
const double pi = acos(-1);

int main(){
    int a,s,d,f,g;cin >> a >> s >> d >> f >> g;
    if (a==0){
        cout << 1 << "\n";
    }
    if (s==0){
        cout << 2 << "\n";
    }
    if (d==0){
        cout << 3 << "\n";
    }
    if (f==0){
        cout << 4 << "\n";
    }
    if (g==0){
        cout << 5 << "\n";
    }
}



Measured memory_bytes: 3588
from collections import deque

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

result = deque([])
while b:
    for i in range(len(b) - 1, -1, -1):
        if b[i] == i + 1:
            result.appendleft(b.pop(i))
            break
    else:
        break

if not b:
    print('\n'.join(str(i) for i in result))
    #print(*result, sep='\n')
else:
    print(-1)


Measured memory_bytes: 9464
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0]*(max(D)+1)
for i in range(N):
  A[D[i]] += 1
if D[0] != 0 or not all(D[1:]) or not all(A):
  print(0)
  exit()
if D[0] != 0:
  print(0)
  exit()
for i in range(1, max(D)+1):
#  if A[i] == 0:
#    print(0)
#    exit()
  ans = ans * pow(A[i-1], A[i], mod) % mod
print(ans % mod)

Measured memory_bytes: 13892
#include <iostream>
#include <bits/stdc++.h>
#define inf 1000000007
using namespace std;


int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    long long temp = 1LL * b * d;
    long long temp2 = 1LL * a * c;
    temp = max(temp,temp2);
    temp2 = 1LL * a * d;
    temp = max(temp,temp2);
    temp2 = 1LL * b * c;
    temp = max(temp,temp2);
    cout << temp;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
const int N=1e5+5;
int n,m,a[N],b[N],i,id[N],od[N],g[N*3],s1[N*3],s2[N*3];
bool bb[N*3];
int gfa(int x){
	return g[x]==x?x:g[x]=gfa(g[x]);
}
inline void uni(int x,int y){
	g[gfa(x)]=gfa(y);
}
int main(){
	scanf("%d%d",&n,&m);for(i=1;i<=n*3;++i)g[i]=i;
	for(i=1;i<=m;++i)scanf("%d%d",a+i,b+i),++od[a[i]],++id[b[i]],
		uni(a[i],b[i]+n),uni(a[i]+n,b[i]+n*2),uni(a[i]+n*2,b[i]);
	for(i=1;i<=n;++i){
		++s1[gfa(i)],++s2[gfa(i+n)];
		if(id[i] && od[i])bb[gfa(i)]=bb[gfa(i+n)]=bb[gfa(i+n*2)]=1;
	}
	long long ans=0;
	for(i=1;i<=n*3;++i)if(gfa(i)==i && bb[i])ans+=1ll*s1[i]*s2[i];
	for(i=1;i<=m;++i)ans+=!bb[gfa(a[i])];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 5632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WalkOnMultiplicationTable
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            long tmp = 0;
            long ans = n;
            
            for (long i = 1; i <= Math.Sqrt(n); i++)
            {

                if (n % i == 0)
                {
                    long j = n / i;
                    tmp = (i - 1) + (j - 1);
                    if (ans > tmp)
                    {
                        ans = tmp;
                    }
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey(true);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    long long A,B;
    int K;
    int v=0;
    while(scanf("%lld%lld%d",&A,&B,&K)!=EOF)
    {
        if(K<=B-A)
        {
            for(int i=A,k=1;k<=K;i++,k++)
            {
                 printf("%d\n",i);
                  v=i;
            }
            for(int j=B-K+1,k=1;k<=K;j++,k++)
            {
                if(j>v)
                printf("%d\n",j);
            }
        }
       else
            for(int i=A;i<=B;i++)
              printf("%d\n",i);
    }
    return 0;
}

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

namespace Contest20191031
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] t = Console.ReadLine().Split();
            int n = int.Parse(t[0]);
            int k = int.Parse(t[1]);
            string s = Console.ReadLine();

                for(int i = 1; i <= s.Length; i++)
                {
                if(k == i)
                {
                    if (s[k - 1] == 'A')
                        Console.Write('a');

                    else if (s[k - 1] == 'B')
                        Console.Write('b');

                    else if (s[k - 1] == 'C')
                        Console.Write('c');


                }

                else
                Console.Write(s[i-1]);
                }

            Console.Write("\n");

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 (ll)1 << 60
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, m;
vector<ll> list[110000];
int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		list[a].push_back(b);
	}
	//トポロジカルソート
	vector<ll> in(n), ans; // 答え
	queue<ll> que;
	//入次数
	REP(i, n) { //隣接リストの長さ
		REP(j, list[i].size()) { //隣接リストの変数名
			in[list[i][j]]++;
		}
	}
	REP(i, n) if (in[i] == 0)que.push(i);
	while (!que.empty()) {
		ll now = que.front();
		ans.push_back(now);
		que.pop();
		REP(i, list[now].size()) {
			in[list[now][i]]--;
			if (in[list[now][i]] == 0) {
				que.push(list[now][i]);
			}
		}
	}
	REP(i, ans.size())cout << ans[i] << endl;
}


Measured memory_bytes: 6460
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
typedef long long ll;
using namespace std;

int tra(int z,int m){
    int mod=z%m;
    if(mod==0)mod=m;
    return z+m-mod;
}

int main(){
    int n;cin>>n;
    int c[n],s[n],f[n];
    for(int i=1;i<=n-1;i++)cin>>c[i]>>s[i]>>f[i];
    
    for(int i=1;i<=n-1;i++){
        int ans=s[i];
        
        for(int j=i;j<=n-1;j++){
            if(ans<s[j])ans=s[j];
            ans=tra(ans,f[j]);
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
    printf("0");
    
    
    
    return 0;
}



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

int main() {
	int N, count=0;
	scanf("%d", &N);
	int a[N];
	for (int i = 0; i < N; ++i) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < N; i++){
        while(a[i] % 2 == 0){
            a[i] /= 2;
            count++;
        }
    }
    printf("%d", count);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,i,j;
    int sum=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        cin>>b[i];
        sum=sum+b[i];
    }
    for(i=0;i<n-1;i++){
        cin>>c[i];
    }
    for(i=0;i<n-1;i++){
        if(a[i]+1==a[i+1]){
            for(j=0;j<n;j++){
                if(a[i]==j){
                    sum=sum+c[j-1];
                }
            }
        }
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, m, x, a, res1, res2;
int main(void){
    // Your code here!
    cin >> n >> m >> x;
    for (int i = 0; i < m; i++) {
        cin >> a;
        if (a < x) res1++;
        else res2++;
    }
    cout << min(res1, res2) << endl;
}


Measured memory_bytes: 256
# edges[src][dst] = cost
def dijkstra(start, n, edges)
    dist = Array.new(n, Float::INFINITY)
    used = Array.new(n)
    dist[start] = 0
    loop do
        v = -1
        n.times do |u|
            if !used[u] && (v == -1 || dist[u] < dist[v])
                v = u
            end
        end
        break if v == -1
        used[v] = true
        edges[v].each do |u, c|
            dist[u] = dist[v] + c if dist[u] > dist[v] + c
        end
    end
    return dist
end



x_s, y_s, x_t, y_t = gets.split.map(&:to_i)
N = gets.to_i
#N = 1000
#x_s, y_s, x_t, y_t = 0, 0, 10**9, 10**9

xs, ys, rs = [x_s], [y_s], [0]
N.times do |i|
    xs[i+1], ys[i+1], rs[i+1] = gets.split.map(&:to_i)
    #xs[i+1], ys[i+1], rs[i+1] = 3.times.map{rand(10**9)}
end
xs[N+1], ys[N+1], rs[N+1] = x_t, y_t, 0

edges = Array.new(N+2){{}}
(N+2).times do |i|
    ((i+1)...(N+2)).each do |j|
        d = Math.sqrt((xs[i]-xs[j])**2 + (ys[i]-ys[j])**2) - rs[i] - rs[j]
        d = 0.0 if d < 0.0
        edges[i][j] = d
        edges[j][i] = d
    end
end

dist = dijkstra(0, N+2, edges)
puts dist[N+1]

Measured memory_bytes: 68732
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n , k;
  	cin >> n >> k;
  	string s;
  	cin >> s;
  	int p = 0, cnt = 0;
  	for(int i = 0 ; i < s.size() - 1 ; i++){
		if(s[i] != s[i + 1]) cnt++;
      	else p++;
    }
  	int ans = min(n - 1 , p + 2 * k);
  	cout << ans << endl;
 	return 0; 
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
	char a, b;
	scanf("%c %c",&a, &b); getchar();
	if(a == 'H' && b == 'H'){
		printf("H\n");
	}
	else if(a == 'H' && b == 'D'){
		printf("D\n");
	}
	else if(a == 'D' && b == 'H'){
		printf("D\n");
	}
	else if(a == 'D' && b == 'D'){
		printf("H\n");
	}
	return 0;
}

Measured memory_bytes: 128
#Sequence Growing Easy

import sys
input = sys.stdin.readline

N = int(input())
A = [int(input()) for i in range(N)]

judge = 1
for i in range(N):
    if i != N-1:
        if A[i+1] <= A[i]+1 and A[i] <= i:
            pass
        else:
            judge = 0
    else:
        if A[i] <= i:
            pass
        else:
            judge = 0

if judge == 0:
    print(-1)
else:
    n = 1
    if A[N-1] == 0:
        n = 0
    for i in range(N-1):
        if A[(N-2)-i] == 0:
            n = n
        elif A[(N-2)-i] < A[(N-1)-i] and A[(N-2)-i] != 0:
            n = n + 1
        elif A[(N-2)-i] == A[(N-1)-i] and A[(N-2)-i] != 0:
            n = n + A[(N-2)-i]
        elif A[(N-2)-i] > A[(N-1)-i] and A[(N-1)-i] != 0:
            n = n + A[(N-1)-i]
        else:
            n = n + 1
    print(int(n))

Measured memory_bytes: 11068
#include<bits/stdc++.h>
const long long INF = INT_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define ll long long int
using namespace std;
ll ans = 0, sum = 0, n, k, cnt = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
set<ll> st;
map<char, ll> mp;

/*--------------------template--------------------*/


int main()
{
	cin >> n >> k;
	cout << n*k << ' ' << 2 * (n + k) << endl;
}

Measured memory_bytes: 3192
import sys
import collections
import heapq

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()


INF = 1 << 62


def solve():
    N, A, B, C, D = nm()
    ans = D * N  # worst case
    mem = collections.defaultdict(lambda: INF)
    q = []
    heapq.heappush(q, (0, N))
    while q:
        coins, num = heapq.heappop(q)
        if mem[num] <= coins:
            continue
        mem[num] = coins
        if ans > num * D + coins:
            ans = num * D + coins
        if num == 0:
            continue
        tnum = num - (num % 2)
        heapq.heappush(q, (coins + (num - tnum) * D + A, tnum // 2))
        tnum = num + 2 - (num % 2)
        heapq.heappush(q, (coins + (tnum - num) * D + A, tnum // 2))

        tnum = num - (num % 3)
        heapq.heappush(q, (coins + (num - tnum) * D + B, tnum // 3))
        tnum = num + 3 - (num % 3)
        heapq.heappush(q, (coins + (tnum - num) * D + B, tnum // 3))

        tnum = num - (num % 5)
        heapq.heappush(q, (coins + (num - tnum) * D + C, tnum // 5))
        tnum = num + 5 - (num % 5)
        heapq.heappush(q, (coins + (tnum - num) * D + C, tnum // 5))

    return ans


def main():
    T = ni()
    for _ in range(T):
        print(solve())


main()


Measured memory_bytes: 137912
#include<stdio.h>
#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x=p0[0],x0=p1[0]-x,x1=p2[0]-x,x2=p3[0]-x,x3=x2-x1,x4=x1-x0,x5=x2-x0;
  long long y=p0[1],y0=p1[1]-y,y1=p2[1]-y,y2=p3[1]-y,y3=y2-y1,y4=y1-y0,y5=y2-y0;
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y1-y3*x1);
  long long d1=x1*x4+y1*y4,d2=x4*x5+y4*y5,d3=x2*x5+y2*y5,d4=x1*x2+y1*y2;
  return c1||c2?(c1<=0&&c2<=0?1:0):(d1>0&&d2>0&&d3>0&&d4>0?0:1);
}
double dMIN(double a,double b){return a<b?a:b;}
double dspl(int p0[2],int p1[2],int p2[2]){
  int a=p0[1]-p1[1],b=p0[0]-p1[0],c=p0[0]*p1[1]-p1[0]*p0[1];
  int d=p2[1]-p1[1],e=p2[0]-p1[0],f=p2[1]-p0[1],g=p2[0]-p0[0];
  if(a*d+b*e<0||a*f+b*g>0)return dMIN(hypot(d,e),hypot(f,g));
  return abs(p2[0]*a-p2[1]*b+c)/hypot(a,b);
}
double dsll(int *p0,int *p1,int *p2,int *p3){
  return ifcl(p0,p1,p2,p3)?0:dMIN(dMIN(dspl(p2,p3,p0),dspl(p2,p3,p1)),
				  dMIN(dspl(p0,p1,p2),dspl(p0,p1,p3)));
}
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%.9f\n",dsll(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

Measured memory_bytes: 652
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    a = dict([[int(input().rstrip('\n')), 0] for i in range(m)])
    dp = [0] * (n + 1)
    dp[0] = 1 if 0 not in a else 0
    dp[1] = 1 if 1 not in a else 0
    for i in range(2, n + 1):
        if i not in a:
            dp[i] = (dp[i-1] + dp[i-2]) % (10 ** 9 + 7)
        else:
            dp[i] = 0
    print(dp[-1])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63324
//greedy is not applicable here as even if select min "diff" at each step then
//also final ans will not be optimal min possible of all answers
//eg: 30 20 50 10 50 70
//greedy: 60
//bruteforce (mainly dp): 40
import java.io.*;
import java.util.*;
public class Main{
  	/*public int minRec(int a[],int dp[],int i,int j)
    {
      if(i==n && j==n)
        	return dp[n][n];
      if(
        return Math.min( Math.abs(a[]
    }*/
	public static void main(String args[]) throws IOException{
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      String st[]=br.readLine().trim().split("\\s+");
      int n=Integer.parseInt(st[0]);
      int k=Integer.parseInt(st[1]);
      String s[]=br.readLine().trim().split("\\s+");
      int size=s.length;
      int arr[]=new int[size];
      for(int i=0;i<size;i++)
        arr[i]=Integer.parseInt(s[i]);
      int ans=0;
      //int dp[][]=new int[][];
      //ans=minRec(a,dp,0,0);

      //if define dp[i] as "the minimum total cost to reach nth (i.e. last) stone from ith stone"
      // long dp[]=new long[size];
      // dp[n-1]=0;
      // dp[n-2]=(long)Math.abs((long)arr[n-1]-(long)arr[n-2]);
      // for(int i=n-3;i>=0;i--)
      //   dp[i]=(long)Math.min( dp[i+1]+Math.abs((long)arr[i]-(long)arr[i+1]), dp[i+2]+Math.abs((long)arr[i]-(long)arr[i+2]) );
      // System.out.println(dp[0]);
      //correct


      //if define dp[i] as "the minimum total cost to reach ith stone"
      long dp[]=new long[size];
      dp[0]=0;
      dp[1]=(long)Math.abs((long)arr[1]-(long)arr[0]);
      for(int i=2;i<size;i++)
        dp[i]=Integer.MAX_VALUE;
      for(int i=2;i<n;i++)
        for(int j=i-1;j>=i-k && j>=0;j--)
          dp[i]=(long)Math.min( dp[j]+Math.abs((long)arr[i]-(long)arr[j]), dp[i] );
      System.out.println(dp[n-1]);
      //correct
    }
}

Measured memory_bytes: 41728
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007
#define int long long

typedef pair<int, int> pint;
typedef long long ll;

signed main()
{
    int N;
    cin >> N;
    priority_queue<int> q;
    rep(i, N)
    {
        int tmp;
        cin >> tmp;
        q.push(tmp);
    }

    int max_edge[2] = {};
    int index = 0;
    while (!q.empty())
    {
        int tmp = q.top();
        q.pop();
        if ((!q.empty()) && q.top() == tmp)
        {
            q.pop();
            max_edge[index] = tmp;
            index++;
            if (index == 2)
                break;
        }
    }
    cout << max_edge[0] * max_edge[1] << endl;
}

Measured memory_bytes: 1400
import sys
readline = sys.stdin.readline

class UnionFind(object):
    def __init__(self, n):
        self._par = list(range(n))
        self.size = [1]*n

    def root(self, v):
        if self._par[v] == v:
            return v
        self._par[v] = self.root(self._par[v])
        return self._par[v]
    
    def unite(self, u, v):
        u, v = self.root(u), self.root(v)
        if u==v:
            return False
        if self.size[u] > self.size[v]:
            u, v = v, u
        self.size[v] += self.size[u]
        self._par[u] = v

    def is_connected(self, u, v):
        return self.root(u)==self.root(v)

n, m = map(int, readline().split())
P = list(map(lambda x:int(x)-1, readline().split()))
uf = UnionFind(n)
for _ in range(m):
    x, y = map(lambda x:int(x)-1, readline().split())
    uf.unite(x,y)

ans = 0
for i in range(n):
    if uf.is_connected(i, P[i]):
        ans += 1
print(ans)

Measured memory_bytes: 20468
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL

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

int main()
{
	int n;
  cin>>n;
  vector<P> p;
  for(int i=0; i<n; i++){
    int a;
    cin>>a;
    p.push_back(P(a, 1));
  }
  for(int i=0; i<n; i++){
    int b;
    cin>>b;
    p.push_back(P(b, -1));
  }
  sort(p.begin(), p.end());
  ll ans=1;
  int s=0;
  int x;
  for(auto p0:p){
    int t=p0.second;
    if(s==0) x=t;
    s+=t;
    if(x==t){
      ans*=((ll)(abs(s)));
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

k,q = map(int,input().split())
D =list(map(int,input().split()))
for _ in range(q):
  n,x,m = map(int,input().split())
  DD = [(d-1+m)%m+1 for d in D]
  tmp = x; s = (n-1) // k
  for i, di in enumerate(DD):
    tmp += di*(s + int((n-1)%k > i))
  print(n-1-(tmp//m-x//m))

Measured memory_bytes: 66140
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n,@x,@t = gets.split.map(&:to_i)
  end

  def solve
    ((n + x - 1) / x) * t
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14332
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	for q := 0; q < n; q++ {
		var s1, s2 string
		fmt.Scan(&s1, &s2)
		s1, s2 = " " + s1, " " + s2

		dp := make([][]int, len(s1))
		for i := range dp {
			dp[i] = make([]int, len(s2))
		}

		max := 0

		for i := 1; i < len(s1); i++ {
			for j := 1; j < len(s2); j++ {
				if s1[i] == s2[j] {
					dp[i][j] = dp[i-1][j-1] + 1
				} else {
					dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
				}
				max = Max(max, dp[i][j])
			}
		}

		fmt.Println(max)
	}
}

func Max(n ...int) int {
	max := n[0]
	for _, v := range n[1:] {
		if v > max {
			max = v
		}
	}
	return max
}

Measured memory_bytes: 19028
#include <iostream>

using namespace std;
 
int H;
int A[250 + 5];
 
int parent(int i) {
  return i / 2;
}
 
int left(int i) {
  return i * 2;
}
 
int right(int i) {
  return i * 2 + 1;
}
 
bool check(int i) {
  return 1 <= i && i <= H;
}
 
int main() {
  cin >> H;
  for (int i = 1; i <= H; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= H; i++) {
    cout << "node " << i << ": ";
    cout << "key = " << A[i] << ", ";
    if (check(parent(i))) {
      cout << "parent key = " << A[parent(i)] << ", ";
    }
    if (check(left(i))) {
      cout << "left key = " << A[left(i)] << ", ";
    }
    if (check(right(i))) {
      cout << "right key = " << A[right(i)] << ", ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;


// ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// ll pow(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2 == 1) { ans *= a; ans %= MOD; }b /= 2; a *= a; a %= MOD; }return ans; }
ll comb(ll a, ll b) { static constexpr ll size = 1e6; static VL fac(size); static VL finv(size); static VL inv(size); static ll n = 0; if (n > a) { return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD; }fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, a + 1) { inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; fac[i] = fac[i - 1] * (ll)i%MOD; finv[i] = finv[i - 1] * inv[i] % MOD; }n = a + 1; return comb(a, b); }
// multiset<ll> prime_decomposition(ll n) { ll i = 2; multiset<ll> table{}; while (i * i <= n) { while (n % i == 0) { n /= i;	table.emplace(i); }++i; }if (n > 1) { table.emplace(n); return table; }return table; }
//-- bit -- REP(i, (1 << n)) {REP(j, n) {cout << (1 & (i >> j));}cout << endl;}

//==============================================================================================

int main() {

	ll n;
	cin >> n;
	++n;
	VL v(n);
	REP(i, n) { cin >> v[i]; }

	ll pos1, pos2;
	{
		unordered_map<ll, ll> m;
		REP(i, n) {
			auto itr = m.find(v[i]);
			if (itr == m.end()) {
				m.emplace(v[i], i);
			} else {
				pos1 = itr->second;
				pos2 = i;
				break;
			}
		}
	}
	FOR(i, 1, n + 1) {
		ll ans = comb(n, i);
		if (pos1 + n - pos2 >= i) {
			ans -= comb(pos1 + n - pos2 - 1, i - 1);
		}
		if (ans < 0)ans += MOD;
		cout << ans % MOD << endl;
	}
}


Measured memory_bytes: 28616
#include<bits/stdc++.h>
using namespace std;
#define l long long 
int main()
{
  l n;
  cin>>n;
  l min=n-1;
  l ans;
  for(l i=2;i*i<=n;i++)
  {
    if(n%i==0)
    {
      ans=(i-1)+((n/i)-1);
      if(ans<min)
        min=ans;
    }
  }
  cout<<min<<endl;
  return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <bits/stdc++.h>
using namespace std;

long long remindersReps[2019];

int main()
{
    int L, R;
    cin >> L >> R;
    
    for(int i = 0; i < 2019; ++i)
    {
        remindersReps[i] = -1;
    }
    
    int el_lim = L +2020;
    if(R < el_lim)
        el_lim = R;
    for(int i = L; i <= el_lim ; ++i )
    {
        remindersReps[i%2019] = i;
    }
    
    long long reminders[2019];
    
    for(int i = 0; i< 2019;++i)
    {
        if(remindersReps[i]!=1)
            reminders[i] = remindersReps[i]%2019;
    }
    
    long long min = 3000;
    
    long long respL, respR;
    
    for(int i = 0; i < 2019; ++i)
    {
        for(int j = 0; j < 2019; ++j)
        {
            if(remindersReps[i] >= remindersReps[j] ||  remindersReps[i] == -1 || remindersReps[j] == -1)
                continue;
            
            long long temp = (reminders[i]*reminders[j])%2019;
            if( temp < min )
            {
                min = temp;
                respL = remindersReps[i];
                respR = remindersReps[j];
            }
        }
    }
    
    cout << min; 
}




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

using namespace std;

typedef long long ll;

int main(){
  int n; cin >> n;
  int a[n];
  int cnt=0; // count even numbers
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i] % 2==0) cnt++;
  }
  cout << pow(3, n) - pow(2, cnt) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int A, B, C, T, max;
    scanf("%d %d %d", &A, &B, &C);

    if (A >= B)
    {
        if (A >= C) {
            max = 1;
        }

        else if (A < C) {
            max = 3;
        }
    }

    else if (A < B)
    {
        if (B >= C) {
            max = 2;
        } 

        else if (B < C) {
            max = 3;
        }
    }

    switch (max) {
    case 1:
    T = A*10 + B + C;
    break;

    case 2:
    T = B*10 + C + A;
    break;

    case 3:
    T = C*10 + A + B;
    break;
    }

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

    return 0;
}

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

using namespace std;

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

const ll mod = 1e9 + 7;

vector<int> g[200005];
ll dp[200005];
ll s[200005];
ll rfac[200005];
ll fac[200005];
ll n;
ll ans[200005];

int dfs1(int v, int prev) {
  int res = 1;

  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(u == prev) continue;
   res +=  dfs1(u,v);
 
  }


  return s[v] = res;
}

  
  
ll dfs2(int v, int prev) {

  ll res = 1;
  ll tmp = 0;
  for(int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if(u == prev) continue;
    res = res * dfs2(u,v) % mod * rfac[s[u]] % mod;
    tmp += s[u];
  }

  res = res * fac[tmp] % mod;

  return dp[v] = res;
}		       
    
  

ll p(ll a, ll x) {
  ll res = 1;
  while(x > 0) {
    if(x & 1) res = res * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return res;
}

int main() {

  cin >> n;

  for(int i = 0; i < n - 1; i++) {
    int a,b;
    cin >> a >> b;
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  fac[0] = rfac[0] = 1;

  for(int i = 1; i <= n; i++) {
    fac[i] = fac[i-1] * i % mod;
    rfac[i] = p(fac[i],mod-2);
  }

  dfs1(0,-1);

  //  for(int i = 0; i < n; i++) cout << s[i] << endl;

  dp[0] = dfs2(0,-1);

  ans[0] = dp[0];

  queue<P> q;

  for(int i = 0; i < g[0].size(); i++) q.push(P(g[0][i],0));

  while(!q.empty()) {
    int v = q.front().first;
    int prev = q.front().second;
    q.pop();
    ans[v] = ans[prev]*rfac[n-1]%mod*fac[s[v]]%mod*fac[n-s[v]-1]%mod*fac[n-1]%mod*rfac[n-s[v]]%mod*rfac[s[v]-1]%mod;
    for(int i = 0; i < g[v].size(); i++) {
      int u = g[v][i];
      if(u == prev) continue;
      q.push(P(u,v));
    }
  }

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

								  



  


Measured memory_bytes: 23412
#include <stdio.h>

int main(void)
{
	int a[3];
	int min =10000000;
	scanf("%d %d %d",&a[0],&a[1],&a[2]);
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(i!=j){
				if(a[i]+a[j]<min){
					min = a[i]+a[j];
				}
			}	
		}
	}
	printf("%d\n",min);
}

Measured memory_bytes: 128
($N,$A,$B)=glob<>;
@o=1..$N;
$a=$N;
for($i=0;$i+$B-1<=$N-1&&$a-($B-1)>=$A;$i+=$B){
	++$f;
	@o[$i..$i+$B-1]=reverse@o[$i..$i+$B-1];
	$a-=$B-1;
}
if($a==$A||$i+$a-$A<=$N-1&&$a-$A>0&&$a-$A<$B){
	@o[$i..$i+$a-$A]=reverse@o[$i..$i+$a-$A];
	print$f?"@o":-1
}else{
	print-1
}


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

int main(void) {
  long long i, k;
  char s[110];
  scanf("%s%lld", s, &k);
  for(i = 0; i < k; ++i)  if(s[i] != '1') {
    printf("%c", s[i]);
    return 0;
  }
  printf("1");
  return 0;
}

Measured memory_bytes: 128
while True:
    R0, W0, C, R = map(int, input().split(' '))
    if R0 == 0 and W0 == 0 and C == 0 and R == 0:
        break
    cnt = 0
    while R0/W0 < C:
        R0 += R
        cnt += 1
    print(cnt)



Measured memory_bytes: 5592
#include <stdio.h>
int main(void){
  int i,j=0,n;
  scanf("%d",&n);
  char t[3][n];
  for(i=0;i<3;scanf("%s",t[i++]));
  for(i=0;i<n;i++){
   int a=(t[0][i]==t[1][i]),
       b=(t[2][i]==t[1][i]),
       c=(t[0][i]==t[2][i]);
   if(!a||!b){
     if(a||b||c)j++;
     else j+=2;
   }
  }
  printf("%d",j);
}

Measured memory_bytes: 128
while True:
    try:
        a = raw_input().split()
        b = raw_input().split()
        hit = reduce(lambda x,y:x+y,map(lambda x,y:x==y,a,b))
        blow = reduce(lambda x,y:x+y,map(lambda x:x in b,a)) - hit
        print hit, blow
    except EOFError:
        break

Measured memory_bytes: 23000
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
long long int MOD=1e9+7;
long long int fact(long long int val) {
	long long int te = 1;
	for (long long int i = 0; i < val; i++) {
		te = (te*(i+1));
		te = te%MOD;
	}
	return te;
}
int main() {
	int  n,m;
	scanf("%d%d",&n,&m);
	int N,M;
	N=max(n,m);
	M=min(n,m);
	if (N-M>1) {
		printf("0");
		return 0;
	} else if (N-M==0) {
		printf("%lld",2*fact(N)*fact(M)%MOD);
		return 0;
	}
	printf("%lld",fact(N)*fact(M)%MOD);
	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string S){
    if(S == "Sunny") cout << "Cloudy" << endl;
    if(S == "Cloudy") cout << "Rainy" << endl;
    if(S == "Rainy") cout << "Sunny" << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

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());
  cout<<d[n/2]-d[n/2-1]<<endl;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>

using namespace std;

int solve();

#define TASK ""

int main()
{
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif // DEBUG
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}

set<int> s;

int solve()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;   
        s.insert(x);
    }
    cout << (int)s.size() << endl;
}




Measured memory_bytes: 256