akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int s(int n){
return n<10?n:n%10+s(n/10);
}

int main(){
int n=read();
puts(n%s(n)?"No":"Yes");
}


Measured memory_bytes: 256
let a, b = Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (a, b)

let rec primes acc i = function
  | 0 | 1 -> acc
  | n ->
    let rec f i j = if i mod j = 0 then f (i / j) j else i in
    if i * i > n then
      if n = 1 then acc else n :: acc
    else if n mod i = 0 then primes (i :: acc) (i + 1) (f n i)
    else primes acc (i + 1) n

let () = primes [] 2 a 
  |> List.filter (fun i -> a mod i = 0 && b mod i = 0)
  |> List.length |> ((+) 1)
  |> Printf.printf "%d\n"

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define MAXN 200200
#define ll long long
using namespace std;
 
 
bool is_palindrome(string s, int b, int e){
    while(b <= e){
        if(s[b] != s[e]) return false;
        b++;e--;
    }

    return true;
}


int main(){
    string s;

    cin >> s;

    int len = s.length();

    if(is_palindrome(s, 0, len-1) && is_palindrome(s,0,(len-1)/2-1) && is_palindrome(s,(len+3)/2-1,len-1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int pasta[3];
  int soup[2];
  int i,j;
  int sum;
  int min=0;

  while(1){
    for(i=0; i<3; i++){
      cin >> pasta[i];
    }
    for(i=0; i<2; i++){
      cin >> soup[i];
    }

    for(i=0; i<3; i++){
      for(j=0; j<2; j++){
	sum=pasta[i]+soup[j];

	if(sum<min || min==0)
	  min=sum;
      }
    }
    break;
  }
  min=min-50;
  cout << min << endl;
}


Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD 998244353
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
i64 A[101010];

i64 gcd(i64 a, i64 b)
{
	while (b > 0) {
		i64 tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

i64 solve_fast()
{
	i64 ret = A[0];
	for (int i = 1; i < N; ++i) {
		i64 g = gcd(i, A[i]);
		i64 a = i / g, b = A[i] / g;
		ret = ret * g % MOD;
	}
	return ret;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld", A + i);
	sort(A, A + N);
	/*

	vector<int> perm;
	for (int i = 0; i < N; ++i) perm.push_back(i);

	i64 B[12];
	for (int i = 1; i <= N; ++i) B[i] = 0;
	do {
		vector<bool> marked(N, false);
		i64 prod = 1;
		int cyc = 0;
		for (int i = 0; i < N; ++i) if (!marked[i]) {
			i64 mn = A[i];
			int p = i;
			while (!marked[p]) {
				marked[p] = true;
				mn = min(mn, A[p]);
				p = perm[p];
			}
			prod *= mn;
			++cyc;
		}
		B[cyc] += prod;
	} while (next_permutation(perm.begin(), perm.end()));

	for (int i = 1; i <= N; ++i) printf("%d: %lld\n", i, B[i]);
	i64 sol = B[1];
	for (int i = 2; i <= N; ++i) sol = gcd(sol, B[i]);
	printf("%lld\n", sol);
	*/
	printf("%lld\n", solve_fast());
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<tuple<string,int,int>> score(N);
  for (int i = 0;i < N;i++){
    cin>>get<0>(score.at(i))>>get<1>(score.at(i));
    get<2>(score.at(i))=i+1;
  }
  sort(score.begin(),score.end());
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(get<0>(score.at(i))==get<0>(score.at(j)) && get<1>(score.at(i))<get<1>(score.at(j)))
        swap(score.at(i),score.at(j));
    }
  }
  for(int i=0;i<N;i++)
  cout<<get<2>(score.at(i))<<endl;
}

Measured memory_bytes: 256
#include<stdio.h> 
#include <ctype.h>

int main(){
 
  int i;
  char str[1024] ;

  scanf("%[a-zA-Z .]", &str);

  for(i=0;str[i] != '\0';i++){
    str[i] = toupper(str[i]);
  }
  printf( "%s\n", str );

    return 0;
}

Measured memory_bytes: 524
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
using namespace std;
const int N=200005;
map<int,int> mp;
map<int,int>::iterator ddq;
int n,i,j,k,l,x,y,ans,a[N],b[N],c[N],d[N],cnt,p[N];
bool brg[N];
int Abs(int a)
{
	return a>0?a:-a;
}
int find(int x)
{
	return !p[x]?x:p[x]=find(p[x]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d",a+i);
		a[n+1]^=a[i];
	}
	for(i=1;i<=n;++i)
	{
		scanf("%d",b+i);
		b[n+1]^=b[i];
	}
	for(i=1;i<=n+1;++i)
		c[i]=a[i],d[i]=b[i];
	sort(c+1,c+1+n+1);
	sort(d+1,d+1+n+1);
	for(i=1;i<=n+1;++i)
		if(c[i]!=d[i])
		{
			printf("-1");
			return 0;
		}
	for(i=1;i<=n;++i)
	if(a[i]!=b[i])
	{
		if(!mp.count(a[i]))
			mp[a[i]]=++cnt;
		if(!mp.count(b[i]))
			mp[b[i]]=++cnt;
		ans++;
		if(find(mp[a[i]])!=find(mp[b[i]]))
			p[find(mp[a[i]])]=find(mp[b[i]]);
	}
	if(ans==0)
	{
		printf("0");
		return 0;
	}
	for(i=1;i<=cnt;++i)
		if(find(i)==i)
			++ans;
	--ans;
	for(i=1;i<=n;++i)
		if(a[n+1]==b[i])
			break;
	if(i>n)
		++ans;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 9600
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var n = +input;
 
process.stdout.write(n + ': ');
 
var primes = [];
 
while (n % 2 == 0) {
    primes.push(2);
    n /= 2;
}
while (n % 3 == 0) {
    primes.push(3);
    n /= 3;
}
for (var i = 1; n > 1; i++) {
    var low = i * 6 - 1;
    var high = i * 6 + 1;
    while (n % low == 0) {
        primes.push(low);
        n /= low;
    }
    while (n % high == 0) {
        primes.push(high);
        n /= high;
    }
}
 
console.log(primes.join(' '));


Measured memory_bytes: 17176
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n: usize = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.parse().unwrap()
    };

    println!("{}", n * n * n);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
char S[500100],S1[500100];
int nxt[500100],nxt1[500100],n;
void KMP(char *t,int *nxt){
    nxt[0]=nxt[1]=0;
    for(int i=2,j=0;i<=n;i++){
        while(j&&t[j+1]!=t[i])j=nxt[j];
        if(t[j+1]==t[i])++j;
        nxt[i]=j;
    }
}
bool check(int x){
    int f1,f2;
    int l1=x-nxt[x],l2=n-x-(nxt1[n-x]);
    if(x==1||l1==x||x%l1!=0)f1=1;
    else f1=0;
    if(n-x==1||l2==n-x||(n-x)%l2!=0)f2=1;
    else f2=0;
    return (f1&&f2);
}
int main(){
	scanf("%s",S+1);
	n=strlen(S+1);
	for(int i=1;i<=n;i++)
		S1[i]=S[n-i+1];
	KMP(S,nxt),KMP(S1,nxt1);
    int temp=n-nxt[n];
    if(temp==1)
    	return printf("%d\n1\n",n),0;
    if(temp!=n&&n%temp==0){
        int ans=0;
        for(int i=1;i<n;i++){
            if(check(i))ans++;
        }
        printf("2\n%d\n",ans);
    }
    else puts("1\n1");
}

Measured memory_bytes: 5248
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int n = sc.nextInt();
			sc.nextLine();
			List<Integer> tList = new ArrayList<Integer>();
			int total = 0;
			for (int i = 0; i < n; i++) {
				int ti = sc.nextInt();
				tList.add(ti);
				total += ti;
			}
			sc.nextLine();

			int m = sc.nextInt();
			sc.nextLine();

			for (int i = 0; i < m; i++) {
				int pi = sc.nextInt();
				int xi = sc.nextInt();

				int t = tList.get(pi - 1);

				System.out.println(total - (t - xi));
				sc.nextLine();
			}

		} finally {
			sc.close();
		}
	}
}

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

int main(){
  int N;
  int x = 0;
  string S;
  cin >> N;
  cin >> S;
  for (int i = 0; i < N-2; i++){
    if (S.at(i) == 'A' && S.at(i+1) == 'B' && S.at(i+2) == 'C'){
      x++;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで



using namespace std;
lint n,k;
vector <pair <lint,lint> > v;

int main(){
  cin >> n >> k;
  REP(i,n){
    lint a,b;
    cin >> a >> b;
    v.pb(pair<lint,lint> (a,b));
  }
  sort(v.begin(),v.end());
  lint now = 0;
  REP(i,n){
    now += v[i].second;
    if(now>=k){
      cout << v[i].first << endl;
      return 0;
    }
  }
}


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

using i64 = long long;

const i64 INF = 1e18;

void rec(i64 head, int append, vector<i64> &lunlun) {
    if (append == 0) {
        lunlun.push_back(head);
    } else {
        int last = head % 10;
        for (int d : {-1, 0, 1}) {
          int t = last + d;
          if (0 <= t && t <= 9)
            rec(head * 10 + t, append - 1, lunlun);
        }
    }
}

int main() {
    vector<i64> lunlun;
    const int size = 12;
    for (int s = 1; s <= size; ++s) {
      for (int h = 1; h <= 9; ++h) {
        rec(h, s - 1, lunlun);
      }
    }
    int k;
    cin >> k;
    cout << lunlun[k - 1] << endl;
}


Measured memory_bytes: 18792
def cmb(n,r,mod):
  if r<0 or r>n:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n,a,b,k=map(int,input().split())
m=998244353
count=0

g1=[1,1]
g2=[1,1]
inverse=[0,1]

for i in range(2,n+1):
  g1.append((g1[-1]*i)%m)
  inverse.append((-inverse[m%i]*(m//i))%m)
  g2.append((g2[-1]*inverse[-1])%m)

for j1 in range(n+1):
  if (k-a*j1)%b==0:
    j2=(k-a*j1)//b
    count+=cmb(n,j1,m)*cmb(n,j2,m)
  count%=m
print(count)

Measured memory_bytes: 38988
#include<stdio.h>
 int main(void)
 {
     int N,K,L[55];
     int i,j,tmp,S=0;

     scanf("%d%d",&N,&K);

     for(i=0;i<N;i++)
       scanf("%d",&L[i]);

     for(i=0;i<N;++i){
       for(j=i+1;j<N;++j){
         if(L[i]>L[j]){
           tmp=L[i];
           L[i]=L[j];
           L[j]=tmp;
         }
       }
     }

     for(i=1;i<=K;i++)
       S+=L[N-i];

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

     return 0;
 }


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

using namespace std;

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

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

  int count = 0;
  
  for(int i = 0; i < n; i++)
    for(int j = n - 1; j > i; j--){
      if(a[j] < a[j - 1]){
	int tmp = a[j];
	a[j] = a[j - 1];
	a[j - 1] = tmp;
	count++;
      }	
    }

  for(int i = 0; i < n-1; i++) cout << a[i] << " ";
  cout << a[n-1] << endl;
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 3088
import sys
readline = sys.stdin.readline
def main():
	limit = 10 ** 4
	n = int(input())
	a = []
	for _ in range(n):
		a.append(tuple(map(int,input().split())))
	a = tuple(a)

	play = [0 for _ in range(n)]
	flag = [True for _ in range(n)]
	count = 0
	ans = 0
	while True:
		break_flag = True
		for i in range(n):
			if flag[i]:
				num = a[i][play[i]]-1
				if flag[num] and a[num][play[num]]-1 == i:
					play[num] += 1
					play[i] += 1
					flag[num] = False
					flag[i] = False
					break_flag = False
					count += 1
		if break_flag:
			print(-1)
			sys.exit()
		ans += 1

		if count == n*(n-1)//2:
			break
		if ans > limit:
			print(n*(n-1)//2)
			sys.exit()
		for i in range(n):
			if play[i] < n-1:
				flag[i] = True
			else:
				flag[i] = False

	if ans == 0:
		print(-1)
	else:
		print(ans)
if __name__ == '__main__':
	main()

Measured memory_bytes: 68572
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

string s[25];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int r,c;

bool ok(int i,int j){
    return (i>=0 and j>=0 and i<r and j<c and s[i][j]=='.');
}

int bfs(int i,int j){
    queue<pii> pq;
    pq.push({i,j});
    map <pii,bool> vis;
    map <pii,int> dis;
    for (int i=0;i<r;i++){
        for (int j=0;j<c;j++) dis[{i,j}]=100000000;
    }
    int res=0;
    dis[{i,j}]=0;
    vis[{i,j}]=true;
    while (pq.size()){
        auto it=pq.front();
        int x=it.ff,y=it.ss;
        pq.pop();
        for (int i=0;i<4;i++){
            int ii=x+dx[i];
            int jj=y+dy[i];
            if (!vis[{ii,jj}] and ok(ii,jj)){
                pq.push({ii,jj});
                dis[{ii,jj}]=min(dis[{ii,jj}],1+dis[{x,y}]);
                res = max(res,dis[{ii,jj}]);
            }
            vis[{ii,jj}]=true;
        }
    }
    return res;
}

inline void solve(){
    cin>>r>>c;
    for (int i=0;i<r;i++) cin >> s[i];
    int ans=0;
    for (int i=0;i<r;i++){
        for (int j=0;j<c;j++){
            if (s[i][j]=='.') ans = max(ans,bfs(i,j));
        }
    } 
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3616
N = int(input())
a = list(map(int, input().split()))

odd = 0
multiple_2 = 0
multiple_4 = 0

for i in range(N):
    if a[i] % 4 == 0:
        multiple_4 += 1
    elif a[i] % 2 == 0:
        multiple_2 += 1
    else:
        odd += 1
        
if multiple_4 >= odd or multiple_4 == len(a) // 2:
    print("Yes")
else:
    print("No")

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

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, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

using pll = pair<ll, ll>;

int get(ll x, ll y) { //x choose y
	int f = 1;
	rep(i, 60) {
		int p = (x >> i) & 1;
		int q = (y >> i) & 1;
		if (p < q) f = 0;
	}
	return f;
}

int main() {
	int N; cin >> N;
	V<pll> vec(N);
	rep(i, N) cin >> vec[i].fi >> vec[i].se;

	ll x = TEN(18);

	//move all points to (?, x-?)
	//between (x, 0) and (x - r, r)

	ll l = 0, r = 0;
	for (int b = 60; b >= 0; --b) {
		ll nr = r + (1ll << b);
		int c = 0;
		rep(i, N) {
			ll p = x - vec[i].fi - vec[i].se, q = nr - vec[i].se;
			if (q >= 0 && q <= p) {
				c ^= (get(p, q));
			}
		}
		if (c) {
			r = nr;
		}
	}

	cout << x - r << endl;

	return 0;
}

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

int main(void){
    int x = 0,n;
    string s;
    cin >> n >> s;
    int max = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'I')x++;
        else x--;
        if(max < x)max = x;
    }
    cout << max << endl;
}

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


int main() 
{  
	int a;
	cin >> a;
	for (int b = 0; b < a; b++) 
	{
		int c, d, e;
		cin >> c >> d >> e;
		int s = 0;
		for (int f = 0; f <=c / 3; f++) {
			for (int g = 0; g <= (c - f * 3) / 2 && g <= d;g++) {
				vector<int>h{ (c - f * 3 - g * 2),d - g,e };
				sort(h.begin(), h.end());
				if (s < h[0]+f+g)s = h[0]+f+g;
			}
		}
		cout << s << endl;
	}
}

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

int main(){

  int n;
  string train, a, b, bre, are;
  vector<string> ans;


  cin >> n; 

  for(int i = 0; i < n; i++){
    cin >> train;
    for(int t = 1; t <= (int)train.size(); t++){
      a = train.substr(0,t);
      b = train.substr(t);
      are = a;
      bre = b;
      reverse(are.begin(), are.end());
      reverse(bre.begin(), bre.end());
      ans.push_back(a+b);
      ans.push_back(a+bre);
      ans.push_back(are+b);
      ans.push_back(are+bre);
      ans.push_back(b+a);
      ans.push_back(b+are);
      ans.push_back(bre+a);
      ans.push_back(bre+are);
    }
    sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(),ans.end()),ans.end());
    cout << ans.size() << endl;
    ans.clear();

  }



  return 0;
}

Measured memory_bytes: 1344
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    int c1x, c1y, c1r, c2x, c2y, c2r;
    double d; //distance of Between the centers

    //printf("input\n");
    scanf("%d %d %d", &c1x, &c1y, &c1r);
    scanf("%d %d %d", &c2x, &c2y, &c2r);

    d = sqrt((c1x-c2x)*(c1x-c2x) + (c1y-c2y)*(c1y-c2y));

    // 4 common tangent lines
    if(d > (c1r+c2r)) printf("4\n");

    // 3 common tangent lines
    if(d == (c1r+c2r)) printf("3\n");

    // 2 common tangent lines
    if((abs(c1r-c2r) < d) && (d < (c1r+c2r))) printf("2\n");

    // 1 common tangent lines
    if(abs(c1r-c2r) == d) printf("1\n");

    // 0 common tangent lines
    if(d < abs(c1r-c2r)) printf("0\n");

    return 0;
}


Measured memory_bytes: 2148
L,R = map(int,input().split())
if R-L+1 >= 2019:
    print(0)
    exit()
R %= 2019
L %= 2019
if R <= L:
    print(0)
    exit()
ans = 2020
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%2019)
print(ans)

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

namespace csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var csl = Console.ReadLine();
            var N = int.Parse(csl);
            var a = new int[N];
            for(int i=0; i<N; i++)
            {
                a[i] = int.Parse(Console.ReadLine()) - 1;
            }

            int current = 0;
            int counter = 0;
            for(int j=0; j<N; j++)
            {
                current = a[current];
                counter++;
                if(current == 1)
                {
                    break;
                }
            }

            if(current == 1)
            {
                Console.WriteLine(counter);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 13280
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<((x))<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  long a,b;
  while(cin>>a>>b){
    long g = __gcd(a,b);
    cout << g <<" "<< a/g*b << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
# ABC 86, C - not so diverse
from collections import Counter

n, k = map(int, input().split(' '))
A = [int(el) for el in input().split(' ')]

c = Counter(A)
if len(c) < k:
    print(0)
else:
    total = 0
    for a, b in c.most_common()[k:]:
        total += b
    print(total)


Measured memory_bytes: 39320
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n){
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());
  
  cout << s.size() << endl;
  
  return 0;
}


Measured memory_bytes: 9536
#include<iostream>
using namespace std;
#define MAX 10000

int main () {
    int x, i = 1;
    while (cin >> x && x != 0 && i++) {
        if (x != 0) {
            
           cout << "Case " << i-1 << ": " << x << endl;
           }
        if (x == 0) {
            break;
        }

           
        }
    
    return 0;
}







Measured memory_bytes: 3032
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j],c[i][k]+c[k][j])
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == -1: continue
        ans += c[a[i][j]][1]

print(ans)


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _f64 x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << fixed << setprecision(8);
        cout << sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2)) << endl;
    }
    return 0;
}


Measured memory_bytes: 3312
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

ll dp[100002] = {};
int main() {
  ll N;
  vector<ll> A;
  cin >> N;
  REP(i, N) {
    ll po;
    cin >> po;
    A.push_back(po);
    dp[i] = llINF;
  }
  dp[0] = 0;
  REP(i, N) {
    if (i + 1 < N)
      dp[i + 1] = min(dp[i] + abs(A[i + 1] - A[i]), dp[i + 1]);
    if (i + 2 < N)
      dp[i + 2] = min(dp[i] + abs(A[i + 2] - A[i]), dp[i + 2]);
  }
  cout << dp[N - 1] << endl;

  return 0;
}


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

const long long INF = 1LL<<61;
long long N, K;
vector<long long> A;

long long solve() {
    sort(A.begin(), A.end());
    long long left = -INF, right = INF;
    while (right - left > 1) {
        long long x = (left + right) / 2;
        long long S = 0, T = 0;
        for (int i = 0; i < N; ++i) {
            if (A[i] > 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) l2 = m;
                    else r2 = m;
                }
                S += r2;
            }
            else if (A[i] < 0) {
                int l2 = -1, r2 = N;
                while (r2 - l2 > 1) {
                    int m = (l2 + r2) / 2;
                    if (A[i] * A[m] <= x) r2 = m;
                    else l2 = m;
                }
                S += N - r2;
            }
            else if (x >= 0) S += N;
            if (A[i] * A[i] <= x) ++T;
        }
        long long num = (S - T) / 2;
        if (num >= K) right = x;
        else left = x;
    }
    return right;
}

int main() {
    cin >> N >> K;
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 4736
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] ar = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = in.nextInt();
            boolean ok = true;
            for (int i = 0; i < n - 1; i++)
                if (ar[i] > ar[i + 1]) {
                    ok = false;
                    break;
                }
            if (ok) {
                out.println("YES");
                return;
            }
            for (int i = 0; i < n - 1; i++)
                for (int j = i + 1; j < n; j++) {
                    int t = ar[i];
                    ar[i] = ar[j];
                    ar[j] = t;
                    ok = true;
                    for (int k = 0; k < n - 1; k++)
                        if (ar[k] > ar[k + 1]) {
                            ok = false;
                            break;
                        }
                    if (ok) {
                        out.println("YES");
                        return;
                    } else {
                        t = ar[i];
                        ar[i] = ar[j];
                        ar[j] = t;
                    }
                }
            out.println("NO");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n+1);
    rep(i,n+1) cin >> a[i];
    if (n == 0) {
        if (a[0] == 1) { cout << 1 << "\n"; return 0; }
        else { cout << -1 << "\n"; return 0; }
    }
    // cout << "a: " << a << "\n";
    vector<ll> ar(n+2);
    ar[n+1] = 0;
    rrepSE(i, n, -1) {
        ar[i] = ar[i+1] + a[i];
    }
    // cout << "ar: " << ar << "\n";
    vector<ll> b(n+1);
    b[0] = 1 - a[0];
    repSE(i,1,n+1) {
        if (2*b[i-1] < a[i]) { cout << -1 << "\n"; return 0; }
        b[i] = min(2*b[i-1] - a[i], ar[i+1]);
        // if (b[i] + a[i] < b[i-1]) { cout << -1 << "\n"; return 0; }
    }
    // cout << "b: " << b << "\n";
    ll ans = 0;
    rep(i,n+1) ans += a[i] + b[i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 5600
import sys
n,k=map(int,input().split())
d=list(map(int,input().split()))
allowed=set()
for i in d:
  allowed.add(i)
for i in range(n,10**7):
  b=str(i)
  c=set()
  for j in range(len(b)):
    c.add(int(b[j]))
  if allowed.intersection(c)==set():
    print(i)
    sys.exit()
    

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  vector<ll> A(N); REP(i, N) cin >> A[i];
  ll ans = 0; ll tmp = 0;
  REP(i, N) {
    tmp += A[i];
    if(A[i] == 0 || i == N - 1) {
      ans += tmp / 2;
      tmp = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

const int MAX = 300001;
bool data[MAX];
vector<int> MSPrime;


void make(){
  fill(data,data+MAX,false);
  for(int i = 0; i < MAX; i++){
    if(7*i+1 < MAX) data[7*i+1] = true;
    else break;
    if(7*i+6 < MAX) data[7*i+6] = true;
    else break;
  }

  for(int i = 5; i < sqrt(MAX); i++)
    if(data[i]) 
      for(int j = 2*i; j < MAX; j+=i) data[j] = false;

  for(int i = 2; i < MAX; i++)
    if(data[i])MSPrime.push_back(i);
}

void solve(int in){
  for(int i = 0; i < MSPrime.size(); i++){
    if(!(in%MSPrime[i])) cout << " " << MSPrime[i];
    if(MSPrime[i] > in) break;
  }
  
}
int main(){
  make();
  int in;
  while(scanf("%d",&in) != EOF){
    if(in == 1) break;
    printf("%d:",in);
    solve(in);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1512
def color(x):
  if(1 <= x and x <= 399):
    return "灰色"
  if(400 <= x and x <= 799):
    return "茶色"
  if(800 <= x and x <= 1199):
    return "緑色"
  if(1200 <= x and x <= 1599):
    return "水色"
  if(1600 <= x and x <= 1999):
    return "青色"
  if(2000 <= x and x <= 2399):
    return "黄色"
  if(2400 <= x and x <= 2799):
    return "橙色" 
  if(2800 <= x and x <= 3199):
    return "赤色"
  if(3200 <= x):
    return "free"

from collections import defaultdict
d = defaultdict(int)
n = int(input())
a = list(map(int, input().split()))
free = 0
for score in a:
  if color(score) == "free":
    free +=1
  else:
    d[color(score)] += 1
print(len(d) if len(d) != 0 else 1, len(d) + free)


Measured memory_bytes: 3316
#include<stdio.h>
#define NIL -1

struct Node{
    int parent; //節点の親
    int left;   //節点の一番左の子
    int right;  //節点のすぐ右の兄弟
};

Node T[100000];
int D[100000];

void print(int u){
    printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, D[u]);

    if(T[u].parent==NIL) printf("root, ");
    else if(T[u].left==NIL) printf("leaf, ");
    else printf("internal node, ");

    printf("[");
    for(int i=0, c=T[u].left; c!=NIL; i++, c=T[c].right){
        if(i) printf(", ");
        printf("%d", c);
    }
    printf("]\n");
}

//再帰的に深さを求めていく
int rec(int u, int d){  //節点uの深さはd
    D[u] = d;
    //再起する順番が大事
    if(T[u].right!=NIL) rec(T[u].right, d);
    if(T[u].left!=NIL) rec(T[u].left, d+1);
}


int main(){

    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    for(int i=0; i<n; i++){
        int v, d;
        scanf("%d %d", &v, &d);
        for(int j=0; j<d; j++){
            int c,l;
            scanf("%d", &c);
            if(j==0)T[v].left = c;
            else T[l].right = c;
            l=c;
            T[c].parent=v;
        }
    }
    int r;
    for(int i=0; i<n; i++){
        if(T[i].parent==NIL) r = i;
    }

    rec(r, 0);

    for(int i=0; i<n; i++) print(i);

    return 0;

}


Measured memory_bytes: 7292
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll cnt=0,ans=0;
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='B') {
      cnt++;
    }
    else {
      ans+=cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 720
N,A,B = map(int,input().split())
MOD = 10**9+7

MAXN = B+5
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD

a = pow(2,N,MOD) - 1
def comb(n,r):
    ret = 1
    for i in range(r):
        ret *= n-i
        ret *= inv[i+1]
        ret %= MOD
    return ret

ans = a - comb(N,A) - comb(N,B)
ans %= MOD
print(ans)

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

using namespace std;

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

    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<pair<int, int>>> g(N);
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a - 1].emplace_back(b - 1, c);
        g[b - 1].emplace_back(a - 1, c);
    }
    vector<vector<int>> mn(N, vector<int>(N, -1));
    for (int u = 0; u < N; ++u) {
        vector<vector<int>> mx(N, vector<int>(N + 1, -1));
        priority_queue<pair<int, int>> pq;
        mx[u][0] = L;
        pq.emplace(L, u);
        for (int i = 0; i < N; ++i) {
            for (int v = 0; v < N; ++v) {
                if (mx[v][i] >= 0) {
                    mx[v][i + 1] = L + 1;
                }
            }
            priority_queue<pair<int, int>> nxt;
            while (!pq.empty()) {
                auto tmp = pq.top();
                int left = tmp.first, v = tmp.second;
                pq.pop();
                if (mx[v][i] > left) continue;
                for (auto tmp : g[v]) {
                    int w = tmp.first, c = tmp.second;
                    if (left - c > mx[w][i]) {
                        mx[w][i] = left - c;
                        mx[w][i + 1] = L + 1;
                        //for (int j = i + 1; j <= N; ++j) {
                            //mx[w][j] = L + 1;
                        //}
                        pq.emplace(mx[w][i], w);
                    } else if (left - c < 0 && L - c > mx[w][i + 1]) {
                        mx[w][i + 1] = L - c;
                        nxt.emplace(mx[w][i + 1], w);
                    }
                }
            }
            pq = nxt;
        }
        for (int v = 0; v < N; ++v) {
            for (int j = 0; j <= N; ++j) {
                if (mx[v][j] != -1) {
                    mn[u][v] = j;
                    break;
                }
            }
        }
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int s, t;
        cin >> s >> t;
        --s;
        --t;
        cout << mn[s][t] << "\n";
    }
    return 0;
}

Measured memory_bytes: 2280
#include<stdio.h>

int n, a[101], b[201], mn, mx;

int main(void)
{
    int idx=0;
    int mins=2147483647, id;
    mn=100;
    mx=-100;

    scanf("%d", &n);
    for(int i=0; i<n; i++) {
        scanf("%d", a+i);
        if(mn>a[i]) mn=a[i];
        if(mx<a[i]) mx=a[i];

    }
    id=mn;

    for(int i=mn; i<=mx; i++) {
        for(int j=0; j<n; j++) {
            b[idx]+=(a[j]-i)*(a[j]-i);
        }
        if(mins>b[idx]) {
            mins=b[idx];
            id=i;
        }
        idx++;
    }
    printf("%d", mins);
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

int main() {
    ll N;
    cin >> N;
    
    vector<ll> A;
    vector<ll> A_sort;
    for (int i = 0; i < N; i++) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
        A_sort.push_back(tmp);
    }

    sort(A_sort.begin(), A_sort.end());

    for (int i = 0; i < N; i++) {
        ll maxA = A_sort[N-1];
        if (A[i] == maxA) {
            cout << A_sort[N-2] << endl;
        } else {
            cout << maxA << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6116
#include<bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

int main()
{
  Hello;
  
  int a, b;
  string s, t, u;
  
  cin>>s>>t>>a>>b>>u;
  if(u==s)  cout<<a-1<<" "<<b;
  else  cout<<a<<" "<<b-1;
  
  return 0;
}

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

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, s;
	inline int operator<(const seg &a) const {return s > a.s;}
} s[5010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[2510][2];

int main()
{
	ios::sync_with_stdio(0);
	cin >> n; m = n >> 1;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].s = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	for (int i = 0; i <= m; ++i)
		f[i][0] = f[i][1] = inf;
	f[0][0] = 0;
	
	int x = 1, y = 0;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 0; j <= m; ++j)
			f[j][x] = inf;
		for (int j = 0; j<i && j<=m; ++j)
		{
			const int k = i-j-1;
			if (j < m)
				f[j+1][x] = min(f[j+1][x], f[j][y] + s[i].r + s[i].s * j);
			if (k < m)
				f[j][x] = min(f[j][x], f[j][y] + s[i].l + s[i].s * k);
			if (n & 1)
				f[j][x] = min(f[j][x], f[j][y] + (n-1)/2 * s[i].s);
		}
		swap(x, y);
	}
	
	cout << f[m][y] << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int i,j,d,n,k,max,sa;
	int ondo[201],fuku[201][3];
	int data[201][201];
	
	scanf("%d %d",&d,&n);
	for(i=0;i<d;i++)	{
		scanf("%d",&ondo[i]);
	}
	for(i=0;i<n;i++)	{
		scanf("%d %d %d",&fuku[i][0],&fuku[i][1],&fuku[i][2]);
	}
	for(i=0;i<d;i++)	{
		for(j=0;j<n;j++)	{
			data[i][j]=-1;
		}
	}
	for(i=0;i<n;i++)	{
		if(ondo[0]>=fuku[i][0] && ondo[0]<=fuku[i][1])	{
			data[0][i]=0;
		}
	}
	for(i=1;i<d;i++)	{
		for(j=0;j<n;j++)	{
			if(ondo[i]>=fuku[j][0] && ondo[i]<=fuku[j][1]){
				for(k=0;k<n;k++)	{
					if(data[i-1][k]>=0)	{
						sa=fuku[k][2]-fuku[j][2];
						if(sa<0)	sa=0-sa;
						if(data[i][j]<data[i-1][k]+sa)	{
							data[i][j]=data[i-1][k]+sa;
						}
					}
				}
			}
		}
	}
	max=-1;
	for(j=0;j<n;j++)	{
		if(max<data[d-1][j])	{
			max=data[d-1][j];
		}
	}
	printf("%d\n",max);
	return 0;
}


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

int main(void) {
    int W,H,x,y,r;cin>>W>>H>>x>>y>>r;
    if (x >= r && x <= W - r && y >= r && y <= H - r) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>L(m), R(m);
	rep(i, m) {
		cin >> L[i] >> R[i];
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());
	int ans = max(0, R[0] - L[m - 1] + 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main(void) {
    int m, f, r;
    char c;
    while (1) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1)
            break;
        if (m == -1 || f == -1)
            c = 'F';
        else if ((m + f) >= 80)
            c = 'A';
        else if ((m + f) >= 65)
            c = 'B';
        else if ((m + f) >= 50)
            c = 'C';
        else if ((m + f) >= 30) {
            if (r >= 50)
                c = 'C';
            else
                c = 'D';
        } else
            c = 'F';
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 3136