akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 3007;
string s, t;
int n, m;

int memo[N][N];

int solve(int i, int j) {
    if(i == n or j == m) return 0;
    int & st = memo[i][j];
    if(st == -1) {
        st = 0;
        if(s[i] == t[j]) st = 1 + solve(i+1, j+1);
        st = max(st, solve(i+1, j));
        st = max(st, solve(i, j+1));
    }
    return st;
}
string ans;
void build(int i, int j) {
    if(i == n or j == m) return;

    if(s[i] == t[j] and solve(i, j) == solve(i+1, j+1) + 1) {
        ans += s[i];
        build(i+1, j+1);
    } else if(solve(i, j) == solve(i+1, j)) {
        build(i+1, j);        
    } else {
        build(i, j+1);
    }
}
int main() {
    memset(memo, -1, sizeof memo);
    cin >> s >> t;
    n = s.size(), m = t.size();

    solve(0, 0);
    build(0, 0);
    cout << ans << endl;
}

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

int main(){

    int n,q;
    cin >> n >> q;

    string s;
    cin >> s;

    vector<int> r(n),l(n);

    rep(i,q){
        cin >> l[i] >> r[i];
    }

    vector<int> cnt(s.size(),0);

    rep(i,n-1){
        if(s[i]=='A'&&s[i+1]=='C'){
            cnt[i+1]++;
        }
    }
    rep(i,n-1){
        cnt[i+1]+=cnt[i];
    }

    //rep(i,n){
    //    cout << cnt[i] <<" ";
    // }cout << endl;

    rep(i,q){
        cout << cnt[r[i]-1]-cnt[l[i]-1] << endl;
    }

    return 0;
}

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

int main() {
  int N;
  int li, ri;
  int sum = 0;
  
  cin >> N;
  
  for(int i =0; i < N; i++){
    cin >> li >> ri;
    
    sum += ri - li + 1;
  }
  
  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    int ans = 100 * r + 10 * g + b;
    if (ans % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],b[3],i,j,k,x=0;
    int c[3][3];
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&c[i][j]);
        }
    }
    for(i=0;i<=100;i++)
    {
        a[0]=i;
        for(j=0;j<3;j++)
        {
            b[j]=c[0][j]-i;
        }
        for(j=0;j<3;j++)
        {
            a[j]=c[j][0]-b[0];
        }
        x=0;
        for(j=0;j<3;j++)
        {
            for(k=0;k<3;k++)
            {
                if(c[j][k]!=a[j]+b[k])
                {
                    x=1;
                }
            }
        }
        if(x==0)
        {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No");
    return 0;



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long num;
	int n;
	scanf("%lld %d", &num, &n);
	int i, j;
	long long sum = 0;
	for (i = 0; i < n; i++) {
		int q1;
		scanf("%d", &q1);
		sum += q1;
	}
	if (num <= sum) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,d,x,a[110];
int sum;
int main()
{
	cin>>n>>d>>x;
	sum+=n+x;
	int t=1;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
		while (t*a[i]+1<=d)
		{
			sum++;
			t++;
		}
		t=1;
	}
	cout<<sum<<endl;
	system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;
 
int main() {
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> A, AB, C, ABC;
    rp(i, 0, x) {
        ll a; cin >> a;
        A.emplace_back(a);
    }
    rp(i, 0, y) {
        ll b; cin >> b;
        rp(j, 0, x) {
            AB.emplace_back(A.at(j) + b);
        }
    }
    rp(i, 0, z) {
        ll c; cin >> c;
        C.emplace_back(c);
    }
    sort(AB.rbegin(), AB.rend());
    rp(i, 0, min(x*y, k)) {
        rp(j, 0, z) {
            ABC.emplace_back(AB.at(i) + C.at(j));
        }
    }
    sort(ABC.rbegin(), ABC.rend());
    rp(i, 0, k) cout << ABC.at(i) << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s.at(i) != s.at(s.size() - 1 - i)) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a,b,L,n,ans;
int f(int n){
    int cnt=0;
    for(int i=0;i<5;i++){
        cnt+=n%10;
        n/=10;
    }
    return cnt;
}
int main(void){
    cin>>n>>a>>b;
    for(int i=n;i>=1;i--){
        L=f(i);
        if(a<=L&&L<=b)ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
int main(){
   int k;
 	scanf("%d",&k);
 	ll ans=0;
 	for(int i=1;i<=k;i++)
 		for(int j=1;j<=k;j++)
 			for(int c=1;c<=k;c++)
 				ans+=__gcd(__gcd(i,j),c);
 	printf("%lld\n",ans);
  return 0;
};

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)

#define rep(i, a, b) for (ll i = a; i < (ll)b; ++i)
#define INF 10e12
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

int main(void)
{
    int s;
    cin >> s;
    vector<int> a;
    a.push_back(s);
    set<int> st;
    st.insert(s);
    bool flag = true;
    int cta = 1;
    int ans = 0;
    while (flag)
    {
        int tmp = a.back();
        if (tmp % 2 == 0)
            tmp /= 2;
        else
            tmp = 3 * tmp + 1;
        a.push_back(tmp);
        if (find(all(st), tmp) != st.end())
            flag = false;
        st.insert(tmp);
        ++cta;
    }
    ans = cta;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, A[222222], B[222222];

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> A[i];

  std::map<int, int> map;

  for (int i = 0; i < N; i ++) {
    B[i] = A[i] - i;

    map[B[i]] ++;
  }
  
  long long C = 0;

  for (int i = 0; i < N - 1; i ++) {
    assert(map.count(B[i]));
    
    map[B[i]] --;

    int x = - A[i] - i;

    if (map.count(x))
      C += map[x];
  }

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 13808
W = []
for w in range(10):
    w = int(input())
    W.append(w)

K = []
for k in range(10):
    k = int(input())
    K.append(k)

W.sort()
K.sort()
w = W[7] + W[8] + W[9]
k = K[7] + K[8] + K[9]
print(w,k)


Measured memory_bytes: 5600
// inputに入力データ全体が入る
function Main(input) {
	var ans = 0
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	s = input[0].split(' ').map((n) => (parseInt(n)))

	if (s[0] <= s[1]) {
		ans = 'unsafe'
	} else {
		ans = 'safe'
	}
	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

Measured memory_bytes: 29628
#include<stdio.h>
int main ()
{
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c)!=EOF)
	{
		int m;
		m=(a+b)<(a+c)?(a+b):(a+c);
		m=m<(b+c)?m:(b+c);
		printf("%d\n",m);
	}
} 


Measured memory_bytes: 128
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int sum = 0;
    int r = 10;
    REP(i, 5) {
        int tmp;
        cin >> tmp;
        sum += (tmp + 9) / 10;
        if (tmp % 10 && r > tmp % 10)
            r = tmp % 10;
    }

    cout << sum * 10 - 10 + r << '\n';
    return 0;
}


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

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      Map<Integer, List<Integer>> graph = new HashMap<>();
      int[] heights = new int[n + 1];
      for(int i = 1; i <= n; i++) {
        heights[i] = sc.nextInt();
        graph.put(i, new ArrayList<>());
      }

      for(int i = 0; i < m; i++) {
        int u = sc.nextInt();
        int v = sc.nextInt();
        graph.get(u).add(v);
        graph.get(v).add(u);
      }
      int res = 0;
      for(Map.Entry<Integer, List<Integer>> entry : graph.entrySet()) {
        int cnt = 0;
        for(int adj : entry.getValue()) {
          if(heights[adj] >= heights[entry.getKey()]) {
            cnt++;
            break;
          }
        }
        if(cnt == 0) res++;
      }
      System.out.println(res);
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> V(N);
  for (int i = 0; i < N; i++) {
    string S;
    int P;
    cin >> S >> P;
    V.at(i) = make_tuple(S, -P, i + 1);
  }
  sort(V.begin(), V.end());
  for (auto v : V) cout << get<2>(v) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define vi vector<int> 
#define vvi vector<vector<int>>
#define pll pair<ll, ll>
#define vl vector<ll> 
#define vvl vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define umap unordered_map
#define uset unordered_set
#define all(c) c.begin(), c.end()
#define maxarr(A) *max_element(A, A+n) 
#define maxvec(v) *max_element(all(v)) 
#define present(map,elem) map.find(elem)!=map.end()
#define lb(v,elem) (lower_bound(all(v),elem) - v.begin())
#define ub(v,elem) (upper_bound(all(v),elem) - v.begin())
#define pb push_back 
#define mp make_pair
#define For(i,a,b) for(int i=a; i<b; ++i) 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define mod 1000000007 

const int MAX = 100005;
int main() { 
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL); 
  cout.tie(NULL);
  
  ll N,K,Q;
  cin>>N>>K>>Q;
  vl A(N+1,K);
  rep(i,0,Q) {
    ll a;
    cin>>a;
    A[a]++;
  }
  rep(i,1,N+1) {
    A[i] = A[i]-Q;
    if(A[i]>0)
      cout<<"Yes"<<endl;
    else 
      cout<<"No"<<endl;
  } 
  return 0;
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Graph II - Single Source Shortest Path I
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int n = parseInt(br.readLine());

		Graph G = new Graph(n);

		for (int i = 0; i < n; i++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int u, k;
			u = parseInt(st.nextToken());
			k = parseInt(st.nextToken());
			for (int j = 0; j < k; j++) {
				int v, c;
				v = parseInt(st.nextToken());
				c = parseInt(st.nextToken());
				Edge e = new Edge();
				e.s = G.vs[u];
				e.t = G.vs[v];
				e.cost = c;
				G.es.get(e.s).add(e);
			}
		}

		//
		G.vs[0].cost = 0;

		Queue<Vertex> pq = new PriorityQueue<>();
		pq.offer(G.vs[0]);

		while (!pq.isEmpty()) {

			Vertex s = pq.poll();
			s.passed = true;

			//pq.clear();
			for (Edge e : G.es.get(s)) {
				if (e.t.cost > s.cost + e.cost) {
					e.t.cost = s.cost + e.cost;
					if (!pq.contains(e.t)) {
						pq.offer(e.t);
					}
				}
			}
		}

		for (int i = 0; i < n; i++) {
			System.out.println(i + " " + G.vs[i].cost);
		}

	} //end main
}

class Graph {

	static int INF = 1 << 29;

	Vertex[] vs;
	Map<Vertex, List<Edge>> es;

	Graph(int n) {
		vs = new Vertex[n];
		for (int i = 0; i < n; i++) {
			vs[i] = new Vertex();
		}
		es = new HashMap<>();
		for (int i = 0; i < n; i++) {
			es.put(vs[i], new ArrayList<>());
		}
	}
}

class Vertex implements Comparable<Vertex> {
	int cost = Graph.INF;
	boolean passed = false;

	@Override
	public int compareTo(Vertex o) {
		return Integer.compare(this.cost, o.cost);
	}
}

class Edge {
	Vertex s, t;
	int cost;
}

Measured memory_bytes: 27816
#include<stdio.h>

int main() {
  
  int i, j, N, K, tmp;
  
  scanf("%d%d", &N, &K);
  
  int p[N];
  
  for(i=0; i<N; i++) {
    
    scanf("%d", &p[i]);
    
  }
  
  for(i=0; i<N; i++) {
    
    for(j=i+1; j<N; j++) {
      
      if(p[i] > p[j]) {
        
        tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
        
      }
      
    }
    
  }
  
  int sum = 0;
  
  for(i=0; i<K; i++) {
    
    sum += p[i];
    
  }
  
  printf("%d", sum);
  
  return 0;
}

Measured memory_bytes: 1708
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
      print(0)
      return
    prod = 1
    for a in A:
      prod *= a
      if prod > 1000000000000000000:
        print(-1)
        return
    print(prod)
main ()

Measured memory_bytes: 84856
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}


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

using namespace std;

#define mem(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

const ll mod=998244353ll;
const int maxn=2050;
char s[maxn];
int n;
ll dp[maxn*2][maxn*2];
ll pre[maxn];

int main() {
    while(~scanf("%s",s+1)) {
        n=strlen(s+1);
        mem(dp,0);
        dp[0][0]=1;
        pre[0]=0;
        rep(i,1,n) {
            ll temp=0;
            if(s[i]=='0') temp=2;
            else if(s[i]=='1') temp=1;
            pre[i]=pre[i-1]+temp;
        }
        rep(i,1,2*n) {
            rep(j,0,2*n) {
                if(i<=n) {
                    if((2*i-pre[i])-(i-1-j)>0&&i-1>=j) {
                        dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                    }
                    if(pre[i]-(j-1)>0&&j>0) {
                        dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
                    }
                }
                else {
                    if((2*n-pre[n])-(i-1-j)>0&&i-1>=j) {
                        dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
                    }
                    if(pre[n]-(j-1)>0&&j>0) {
                        dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
                    }
                }
                // printf("%d %d %lld\n",i,j,dp[i][j]);
            }
        }
        printf("%lld\n",dp[2*n][pre[n]]);
    }
    return 0;
}

Measured memory_bytes: 131584
#include <iostream>
#include <vector>
#include <tuple>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#define REP(i, n) for(int i = 0; i < n; i++)
//using ll = long long;
using namespace std;


int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  const double PI=3.14159265358979323846;

  int n;
  float ans=0;
  cin >> n;
  
  ans = 2 * n * PI;
  


  cout << ans << endl;
      
}


Measured memory_bytes: 3788
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n;
	double a[10000];
	while(cin >> n && n){
		int ans = 0;
		double ave = 0;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			ave += a[i];
		}
		ave /= n;
		for(int i = 0; i < n; i++){
			if(a[i] <= ave){
				ans++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}


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

const int INF = (1 << 30);

typedef struct Network {
  std::vector< std::tuple<int, int> > *edges;
  int v;
} Network;

namespace hidden {
  std::stack<Network*> networks;
};
void push(Network& network) {
  hidden::networks.push(&network);
}
void pop(Network& network) {
  hidden::networks.pop();
}

Network initNetwork(int v) {
  Network network;
  network.edges = new std::vector< std::tuple<int, int> > [v + 3];
  network.v     = v + 3;
  return network;
}

void deleteNetwork(Network network) {
  if( network.edges == nullptr ) {
    delete [] network.edges;
  }
}

void addEdge(int from, int to, int weight) {
  Network *network = hidden::networks.top();
  network->edges[from].push_back(std::tuple<int, int>(to, weight));
}

std::vector<int> dijkstra(Network network, int source) {
  std::vector<int> res(network.v, INF);
  res[source] = 0;
  std::priority_queue< std::tuple<int, int> > q;
  q.push(std::tuple<int, int>(0, source));
  while( not q.empty() ) {
    int dist; int id;
    std::tie(dist, id) = q.top(); q.pop();
    dist = -dist;
    for(std::tuple<int, int> edge : network.edges[id]) {
      int next; int weight;
      std::tie(next, weight) = edge;
      int nextdist = dist + weight;
      if( nextdist >= res[next] ) continue;
      res[next] = nextdist;
      q.push(std::tuple<int, int>(-nextdist, next));
    }
  }
  return res;
}

int main() {
  int v, e, r;
  scanf("%d %d %d", &v, &e, &r);
  Network network = initNetwork(v);
  push(network);
  for(int i = 0; i < e; ++i) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    addEdge(s, t, d);
  }
  pop(network);
  std::vector<int> dists = dijkstra(network, r);
  for(int i = 0; i < v; ++i) {
    if( dists[i] != INF ) {
      printf("%d\n", dists[i]);
    }
    else {
      puts("INF");
    }
  }
}

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

int main() {
  char ans ;
  cin >> ans;
  if(ans >='a' && ans <='z'){
    cout << 'a'<< endl;
  }
  else{
    cout << 'A' << endl;
  }
  
  return 0;
  

}

Measured memory_bytes: 3592
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n/2];
		int[] b = new int[n/2];
		for(int i=0; i<n/2; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		
		Map<Integer, Integer> aMap = new HashMap<>();
		Map<Integer, Integer> bMap = new HashMap<>();
		for (int i=0; i<n/2; i++) {
			aMap.putIfAbsent(a[i], 0);
			aMap.compute(a[i], (k,v) -> ++v);
			bMap.putIfAbsent(b[i], 0);
			bMap.compute(b[i], (k,v) -> ++v);
		}
		int aFirstKey = 0;
		int aFirstValue = 0;
		int aSecondValue = 0;
		int bFirstKey = 0;
		int bFirstValue = 0;
		int bSecondValue = 0;

		for(Map.Entry<Integer, Integer> entry : aMap.entrySet()) {
			int key = entry.getKey();
			int value = entry.getValue();
			if (value > aFirstValue) {
				aSecondValue = aFirstValue;
				aFirstKey = key;
				aFirstValue = value;
			} else if (value > aSecondValue) {
				aSecondValue = value;
			}
		}
		for(Map.Entry<Integer, Integer> entry : bMap.entrySet()) {
			int key = entry.getKey();
			int value = entry.getValue();
			if (value > bFirstValue) {
				bSecondValue = bFirstValue;
				bFirstKey = key;
				bFirstValue = value;
			} else if (value > bSecondValue) {
				bSecondValue = value;
			}
		}
		
		if (aFirstKey == bFirstKey) {
			System.out.println(n - Math.max(aFirstValue+bSecondValue, aSecondValue+bFirstValue));
		} else {
			System.out.println(n - (aFirstValue + bFirstValue));
		}
	}
}


Measured memory_bytes: 55988
def main():
  n = int(input())
  plus = {}
  for i in range(n):
    p_key = input()
    if plus.get(p_key) is None:
      plus[p_key] = 1
    else:
      plus[p_key] += 1
  m = int(input())
  minus = {}
  for i in range(m):
    m_key = input()
    if plus.get(m_key) is None:
      plus[m_key] = -1
    else:
      plus[m_key] -= 1
  
  for k in plus.keys():
    if minus.get(k) is None:
      pass
    else:
      plus[k] += minus[k]
  
  res = 0
  for v in plus.values():
    res = max(res, v)    
  print(res)
  return 0

if __name__ == "__main__":
  main()

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#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()

const ll MOD = 1000000007;

ll f[4000010];
ll invf[4000010];

ll mod_pow(ll x, ll k)
{
    ll res = 1;
    for (; k; x = x * x % MOD, k /= 2) if (k & 1) res = res * x % MOD;
    return res;
}

ll comb(int n, int k)
{
    if (k < 0 || k > n) return 0;
    return f[n] * invf[k] % MOD * invf[n-k] % MOD;
}

int N, K;

ll dp[2010][2010]; // j = num of front 0
ll acm[2010];

int main() {
    f[0] = invf[0] = 1;

    for (int i = 1; i <= 4000000; ++i) {
	f[i] = f[i-1] * i % MOD;
	invf[i] = mod_pow(f[i], MOD - 2);
    }
    
    cin >> N >> K;

    if (K == 1) {
	puts("1");
	return 0;
    }

    dp[1][1] = 1;

    for (int i = 2; i <= N; ++i) {
	memset(acm, 0, sizeof(acm));

	for (int j = 2000; j >= 0; --j) {
	    acm[j] = (acm[j + 1] + dp[i-1][j]) % MOD;
	}

	for (int j = 1; j <= i; ++j) {
	    int pos = (i - 1) * K - j + 1;

	    ll t = comb(pos + K - 2, K - 2);
	    dp[i][j] = (dp[i][j] + acm[j - 1] * t) % MOD;
	}
    }

    ll ret = 0;
    rep(i, 2010) ret = (ret + dp[N][i]) % MOD;
    ret = ret * f[N] % MOD;

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 85376
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    ll n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    ll res = n*(n-1)/2;

    cout<<res<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    //int a,b,c;
    char ch[4];
    scanf("%s",ch);
    //scanf("%d %d",&a, &b);
    int n=3;
    int i=0,flag = 0;
    while(n--){
        if(ch[i]=='1') flag++;
        i++;
    }
    printf("%d\n",flag);
    return 0;
}

Measured memory_bytes: 128
/*
------------____________----------------
--------------CRISTIANO-----------------
SUUUUUUUUUIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
GOOOOOOOOOOOOOOAAAAAAAALLLLLLLLLLLLLLLLL
 
Author- Shubham Jha
IIIT- ALLAHABAD
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl "\n"
int main()
{
  ll n,k;
  cin>>n>>k;
  ll sum=0;
  while(k--)
  {
      ll num;
      cin>>num;
      sum+=num;
  }
  if(sum>=n)
    cout<<"Yes";
else 
    cout<<"No";
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

int main() {
    int n;
    cin >> n;
    int ans;
    cin >> ans;
    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
n,s=map(x->parse(Int,x),readlines())
A=n+2
f(b,n)=n<b?n:f(b,div(n,b))+n%b
g(b)=b>1&&f(b,n)==s?min(A,b):A
A=g(n+1)
for b=1:isqrt(n);A=g(b);A=g(div(n-s,b)+1);end
println(A>n+1?-1:A)

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

int main(){
  int n, m, sum = 0;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  cout << max(n - sum, -1) << endl;
}

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

int main()
{

  int n,m,p;
  string s;
  int flg[100005] = {};
  int cnt[100005] = {};
  int wacnt = 0, accnt = 0;

  cin >> n >> m;

  for(int i=0; i<m; i++){

    cin >> p >> s;

    if(s == "AC"){

      if(flg[p] == 0){
	accnt++;
	wacnt += cnt[p];
	flg[p] = 1;
      }

    } else if(s == "WA"){

      if(flg[p] == 0) cnt[p]++;

    }

  }

  cout << accnt << " " << wacnt << endl;

  return 0;

}


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }


inline char getRem(char a, char b) {
    return 'R' ^ 'G' ^ 'B' ^ a ^ b;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;

    /**
     * R G B
     * 
     * j-i != k-j (j!= i+k/2) -> j > avg or j < avg
     * 01234567
     * RRGBGBGB
     */

    vector<ll> cntR(n, 0);
    vector<ll> cntG(n, 0);
    vector<ll> cntB(n, 0);

    for (int i = n-1; i > 0; --i) {
        cntR[i-1] = cntR[i] + ((s[i] == 'R') ? 1 : 0);
        cntG[i-1] = cntG[i] + ((s[i] == 'G') ? 1 : 0);
        cntB[i-1] = cntB[i] + ((s[i] == 'B') ? 1 : 0);
    }
    map<char, vector<ll>> m;
    m['R'] = cntR;
    m['G'] = cntG;
    m['B'] = cntB;

    ll ans = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            if (s[i] != s[j]) {
                char r = getRem(s[i], s[j]);
                auto len = j-i;
                ans += m[r][j];
                if (j+len < n && s[j+len]==r) {
                    ans -= 1;
                }
            }  
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 3748
# D

import itertools
n = int(input())
l = list(map(int, input().split()))
l.sort()
 
from bisect import bisect_left
ans = 0

for i, j in itertools.combinations(range(len(l)),2):
    t = l[i]+l[j]
    idx = bisect_left(l, t)
    ans += max(0, idx-j-1)
print(ans)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(11);
    string S, year = "", month = "", day = "";
    cin >> S;
    for(int i=0; i < 4; i++){
        year += S[i];
    }
    for(int i=5; i < 7; i++){
        month += S[i];
    }
    for(int i=8; i < 10; i++){
        day += S[i];
    }
    int y = atoi(year.c_str());
    int m = atoi(month.c_str());
    int d = atoi(day.c_str());
    int flag = 0;
    if(y > 2019) flag = 1;
    else if(y == 2019 && m > 4) flag = 1;
    else if(y == 2019 && m == 4 && d > 30) flag = 1;
    if(flag) cout << "TBD" << endl;
    else cout << "Heisei" << endl;
    return 0;
}


Measured memory_bytes: 256
x,y,a,b,c = map(int ,input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

p = p[:x]
q = q[:y]

pq = p+q
pq.sort(reverse=True)

pqr = pq + r
pqr.sort(reverse=True)

yamm = sum(pqr[:x+y])
print(yamm)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int dp[1000] = {};

int count(string num) {
    // cout << "# num : " << num << endl;
    if (dp[stoi(num)] != 0) return dp[stoi(num)];

    int ans = 0;
    string s(num.size(), '1');
    for (int n = stoi(s); n <= stoi(num); n++) {
        if (to_string(n).find('0') == string::npos) ans++;
    }

    // cout << "## num : " << num << " ans : " << ans << endl;
    return dp[stoi(num)] = ans;
}

int main() {
    string N; cin >> N;
    int K; cin >> K;

    if (K > N.size()) {
        cout << 0 << endl;
        return 0;
    }

    string S(N.size(), '0');
    REP(i, 0, K) S[S.size() - 1 - i] = '1';

    ll ans = 0;
    string prev;
    while (1) {
        string num = "";
        if (S[0] == '1') {
            num += N[0];
            bool a = true;
            REP(i, 1, N.size()) {
                if (S[i] == '1') {
                    if (a) num += N[i];
                    else num += '9';
                } else if (N[i] != '0') {
                    a = false;
                }
            }
        } else {
            REP(i, 0, K) num += '9';
        }

        ans += count(num);

        prev = S;
        next_permutation(ALL(S));
        if (prev >= S) break;
    }

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

Measured memory_bytes: 256
A=input()
B=input()
C=input()

n=A[0]
A=A[1:]
"""
if len(A)==0:
    print('A')
    exit()
"""
for i in range(len(A)+len(B)+len(C)):
    if n=='a':
        if len(A)==0:
            print('A')
            exit()
        n=A[0]
        A=A[1:]
        """
        if len(A)==0:
            print('A')
            exit()
        """
    elif n=='b':
        if len(B)==0:
            print('B')
            exit()
        n=B[0]
        B=B[1:]
        """
        if len(B)==0:
            print('B')
            exit()
        """
    else:
        if len(C)==0:
            print('C')
            exit()
        n=C[0]
        C=C[1:]
        """
        if len(C)==0:
            print('C')
            exit()
        """
    #print('card: {}\tA: {}\tB: {}\tC: {}'.format(n,A,B,C))



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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
SPs = []
for n in range(N):
    s, p = input().split()
    p = int(p)
    SPs.append((s, -p, n))
SPs.sort()
for s, p, n in SPs:
    print(n + 1)


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    int diff;
    vector<int> sub(n-k+1);
    for(int i = 0; i < n-k+1; i++){
        diff = h.at(i+k-1) - h.at(i);
        sub.at(i) = diff;
    }
    sort(sub.begin(), sub.end());
    cout << sub.at(0) << endl;
}

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

int main() {
  int N,A;
  int M,S;
  cin >> N >> A;
  M = N % 500;
  if (M <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;

typedef long long ll;

using V = vector<int>;
using Q = queue<int>;
using Graph = vector<vector<int>>;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define inn(x, y) int x,y;cin>>x>>y
#define innn(x, y, z) int x,y,z;cin>>x>>y>>z
#define bit(n) (1<<(n))

#define out(x) cout<<(x)<<endl
#define outt(x,y) cout<<(x)<<" "<<(y)<<endl
#define err(x) cerr<<(x)<<endl
#define errr(x,y) cerr<<(x)<<" "<<(y)<<endl
#define errrr(x,y,z) cerr<<(x)<<" "<<(y)<<" "<<(z)<<endl

#define rep(i,n) for (int i=0;i<(n);i++)
#define repp(i,n) for (int i=1;i<=(n);i++)
#define reppp(j, i, n) for (int j=i+1; j<n; j++)

#define lim5 200010
#define lim9 1000000010

#define deg(_rad) (((_rad)/2/M_PI)*360)
#define rad(_deg) (((_deg)/360)*2*M_PI)
#define mid(min, max) ((min + max) / 2)

int main() {
	ll a;
	long double b;
	cin >> a >> b;
	out((ll)(a * b));

    return 0;
}


Measured memory_bytes: 3732
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  string s,t; cin >> s >> t;
  int n=s.size();
  map<char,int> mps;
  map<char,int> mpt;
  string ss,tt;
  rep(i,n){
    if(mps[s[i]]==0){
      mps[s[i]]=i;
      ss+='0'+i;
    }
    else{
      ss+='0'+mps[s[i]];
    }
  }
  rep(i,n){
    if(mpt[t[i]]==0){
      mpt[t[i]]=i;
      tt+='0'+i;
    }
    else{
      tt+='0'+mpt[t[i]];
    }
  }
  //cout << ss << endl;
  //cout << tt << endl;
  if(ss==tt){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 1168
import sys
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        sys.exit()
    cnt=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            k=x-i-j
            if k > j and k <= n:
                cnt+=1
            else:
                continue
    print(cnt)


Measured memory_bytes: 5596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            String[] values = line.split(" ");
            int a = Integer.parseInt(values[0]);
            int b = Integer.parseInt(values[1]);
            if(a < b) {
                System.out.println("a < b");
            } else if(a > b) {
                System.out.println("a > b");
            } else {
                System.out.println("a == b");
            }
        }
    }
}


Measured memory_bytes: 24240
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		Date date1 = new Date(Integer.parseInt(str.substring(0, 4)), Integer.parseInt(str.substring(5, 7)), Integer.parseInt(str.substring(8, 10)));
		Date date2 = new Date(2019, 4, 30);
		if(date1.after(date2)) {
			System.out.println("TBD");
		} else {
			System.out.println("Heisei");
		}
	}
}


Measured memory_bytes: 22096
#include <stdio.h>


int main(){
    int N,i,j,num[1001],v,x;
    
    scanf("%d",&N);
    for (i=0; i<N; i++) {
        scanf("%d",&num[i]);
    }
    for (x=0; x<N;x++) {
        if (x==N-1) printf("%d",num[x]);
        else printf("%d ",num[x]);
    }
    printf("\n");

    
    for (i=1; i<N; i++) {
        v=num[i];
        j=i-1;
        while (j>=0 && num[j]>v) {
            num[j+1]=num[j];
            j--;
        }
        
        num[j+1]=v;
        for (x=0; x<N;x++) {
            if (x==N-1) printf("%d",num[x]);
            else printf("%d ",num[x]);
        }
        if (i != N) printf("\n");

    }
    
    return(0);
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	int x;
	cin >> x;

	if (x == 0) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(void){
  int i,n,m,count[1000001],res;
  char s[1000001],ioi[4]="IOI";
  
  while(scanf("%d",&n),n){
    scanf("%d %s",&m,s);
    for(i=0;i<1000001;count[i]=0,i++);

    for(i=0;i<=m;i++)
      if(strncmp(s+i,ioi,3)==0)count[i]=count[i-2]+1;
    
    for(i=0,res=0;i<m;i++)if(count[i]>=n)res++;
    printf("%d\n",res);
  }
  return 0;
}

Measured memory_bytes: 0
n=int(input())
dp=[[0]*3 for _ in range(n)]
dp[0]=list(map(int,input().split()))
for i in range(1,n):
  a,b,c=map(int,input().split())
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b
  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c
print(max(dp[-1]))

Measured memory_bytes: 22772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
#define umap unordered_map
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    ll N;
    cin>>N;
    int ans=1000;
    int a;
    for(ll i=1; i*i<=N;i++){
        if(N%i==0){
            string b, c;
            b=to_string(i);
            c=to_string(N/i);
            a=max(b.size(), c.size());
            ans=min(a, ans);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, m;
  if (scanf("%d %d", &n, &m) == -1) return -1;
  int lr[2][m];
  int i = 0;
  for(i = 0;i < m;i++) {
    if (scanf("%d %d", &lr[0][i], &lr[1][i]) == -1) return -1;
  }
  int left = 1;
  int right = 1000000;
  for(i=0;i<m;i++) {
    if (left < lr[0][i]) left = lr[0][i];
    if (right > lr[1][i]) right = lr[1][i];
  }
  int ans = right - left + 1;
  printf("%d\n", ans < 0 ? 0 : ans);
  return 0;
}

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

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

int main(){
    int h,w;
    cin>>h>>w;
    vector<string>s(h);
    rep(i,h)cin>>s[i];
    vector<vector<int>>dist(h,vector<int>(w,INF));
    queue<P>q;
    rep(i,h)rep(j,w){
        if(s[i][j]=='#'){
            q.push(P(i,j));
            dist[i][j]=0;
        }
    }
    while(!q.empty()){
        int y=q.front().first;
        int x=q.front().second;
        q.pop();
        rep(dir,4){
            int vy=y+dy[dir];
            int vx=x+dx[dir];
            if(vy<0||vy>=h||vx<0||vx>=w)continue;
            if(dist[vy][vx]!=INF||s[vy][vx]=='#')continue;
            dist[vy][vx]=dist[y][x]+1;
            s[vy][vx]='#';
            q.push(P(vy,vx));
        }
    }
    int ans=0;
    rep(i,h)rep(j,w)ans=max(ans,dist[i][j]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 17012
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] X = new int[N];
		int max = 0;

		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();

			if (X[i] > max) {
				max = X[i];
			}
		}

		int[] score = new int[max];
		int ans = 1000000000;

		for (int i = 0; i < max; i++) { // i + 1 = P
			for (int j = 0; j < N; j++) {
				int s = (int) Math.pow(X[j] - (i + 1), 2);
				score[i] += s;
			}

			if (score[i] < ans) {
				ans = score[i];
			}
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> road(N,0);
  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    road[a-1]++;
    road[b-1]++;
  }
  for(int i = 0; i < N; i++){
    cout << road[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

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

    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    vll cnt(110000, 0);
    rep(i,N) cnt[A[i]]++;

    ll ans = 0;
    rep(i,N) ans += A[i];

    ll Q;
    cin >> Q;
    rep(_, Q) {
        ll b, c;
        cin >> b >> c;
        cnt[c] += cnt[b];
        ans -= b * cnt[b];
        ans += c * cnt[b];
        cnt[b] = 0;
        cout << ans << endl;
    }
}


Measured memory_bytes: 4708
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import connected_components


def create_graph(V: int, edges: np.array, dtype=None):
    """csr_matrix を作成する

    もし精度が足りない場合は dtype=object にする。
    """
    return csr_matrix((edges[:, 2], (edges[:, 0], edges[:, 1])),
                      shape=(V, V), dtype=dtype)


def main() -> None:
    N, M = map(int, input().split())
    edges = []
    adj_list = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(int, input().split())
        edges.append([x-1, y-1, 1])
        adj_list[x-1].append(y-1)
    graph = create_graph(N, np.asarray(edges))
    _, labels = connected_components(
        csgraph=graph, directed=True,
        connection="strong", return_labels=True)
    order = [(x, i) for i, x in enumerate(labels)]
    order.sort(reverse=True)
    dp = [0] * N
    for _, i in order:
        for v in adj_list[i]:
            dp[v] = max(dp[v], dp[i] + 1)
    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 65040
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(m)]
counts = [1] * n
for i in ab:
    if h [i[0]-1] >= h[i[1]-1]:
        counts[i[1]-1] -= 1
    if h [i[0]-1] <= h[i[1]-1]:
        counts[i[0]-1] -= 1
print(counts.count(1))

Measured memory_bytes: 32020
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var WHN = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var W = WHN[0];
            var H = WHN[1];
            var N = WHN[2];
            var xyaList = Enumerable.Range(0, N)
                .Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray());

            var minx = 0;
            var miny = 0;
            var maxx = W;
            var maxy = H;
            foreach (var xya in xyaList)
            {
                var x = xya[0];
                var y = xya[1];
                var a = xya[2];

                switch (a)
                {
                    case 1:
                        minx = Math.Max(minx, x);
                        break;

                    case 2:
                        maxx = Math.Min(maxx, x);
                        break;

                    case 3:
                        miny = Math.Max(miny, y);
                        break;

                    case 4:
                        maxy = Math.Min(maxy, y);
                        break;
                }
            }

            var output = Math.Max(0, (maxx - minx)) * Math.Max(0, (maxy - miny));

            Console.WriteLine(output);
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int sum=0;
  vint v(n);
  vint c(n);
  rep(i,n){
    cin>>v[i];
  }
  rep(i,n){
    cin>>c[i];
  }
  rep(i,n){
    if(v[i]-c[i]>0){
      sum+=v[i]-c[i];
    }
  }
  cout<<sum<<'\n';
  return(0);
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main (int argc, char const* argv[])
{
    double a,b,c,d,e,f;
    double x,y;
    
    while(cin >> a >> b >> c >> d >> e >> f){
        x = (c*e - b*f) / (a*e - b*d);
        y = (c*d - a*f) / (b*d - a*e);

        x = round(x * 1000)/1000.0;
        y = round(y * 1000)/1000.0;
        
        if(x == 0)x = 0;
        if(y == 0)y = 0;
        
        printf("%.03lf %.03lf\n",x,y);
    }
    
    return 0;
}

Measured memory_bytes: 1248
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] a = new int[n + 1];
    for (int i = 0; i < n; i++) {
      int num = sc.nextInt();
      a[num]++;
    }
    Arrays.sort(a);
    int count = 0;
    for (int i = 0; i < k; i++) {
      count += a[a.length - i - 1];
    }
    System.out.println(n - count);
  }
}

Measured memory_bytes: 59716
N = int(input())
T = [0] * N
A = [0] * N
for i in range(N):
    T[i], A[i] = map(int, input().split())

x = 1
y = 1
for i in range(N):
    k = max(-(-x // T[i]), -(-y // A[i]))
    x = k * T[i]
    y = k * A[i]
else:
    print(x + y)

Measured memory_bytes: 3064