akhauriyash/Code-Regression huggingface dataset:
Imports System.Collections.Generic
Imports System.Console
Module Program
    Sub Main()
        Dim tmp As String() = Split(Console.ReadLine())
        Dim a As String = tmp(0)
        Dim b As String = tmp(1)
        Dim c As String = tmp(2)
        Dim abc As String = a.Substring(0, 1) + b.Substring(0, 1) + c.Substring(0, 1)
        Console.WriteLine(abc.ToUpper())
    End Sub
End Module


Measured memory_bytes: 13532
# 10 5
# 1 2
# 1 3
# 1 4
# 8 10
# 1 8

n, m = map(int, input().split())

ends = []
starts = []
possible = False
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        starts.append([a, b])
    elif b == n:
        ends.append([a, b])

starts.sort(key=lambda x: x[1])
ends.sort(key=lambda x: x[0])

if not (starts and ends):
    print("IMPOSSIBLE")
    import sys

    sys.exit()

i = 0
j = 0
while i != len(starts) and j != len(ends):
    to = starts[i][1]
    fr = ends[j][0]

    if to == fr:
        possible = True
        break

    if to < fr:
        i += 1
    elif fr < to:
        j += 1

while j != len(ends):
    fr = ends[j][0]
    if to == fr:
        possible = True
        break
    j += 1

while i != len(starts):
    to = starts[i][1]
    if to == fr:
        possible = True
        break
    i += 1

print("POSSIBLE") if possible else print("IMPOSSIBLE")


Measured memory_bytes: 34664
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int w=s.nextInt();
		int a[]=new int[n];
		int v[]=new int[n];
		long dp[]=new long[w+1];
		
		for(int i=0;i<n;i++)
		{
		    a[i]=s.nextInt();
		    v[i]=s.nextInt();
		}
		
		for(int i=1;i<=n;i++)
		{
		   for(int j=w;a[i-1]<=j;j--)
		   {
		       dp[j]=Math.max(dp[j-a[i-1]]+v[i-1],dp[j]);
		   }
		}
		System.out.println(dp[w]);
	
	}
}


Measured memory_bytes: 23124
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False
s = lambda x: int(0.5*x*(x-1))

def main():
  n,m=ints()
  print(s(n)+s(m))

if __name__ == '__main__':
  main()

Measured memory_bytes: 3316
#include<stdio.h>
 int main(void){
    double a,b,c,d,e,f,x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        y=(c*d-a*f)/(b*d-a*e);
        x=(c-b*y)/a;

        x+=0.0004;
        y+=0.0004;
        printf("%.3lf %.3lf\n",x,y);
            }
            return 0;
    }

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

string rotate(string S){
  return S.substr(1) + S[0];
}

int main(void){
  string S, T;
  cin >> S >> T;

  int N = S.size();

  rep(i,N){
    if (S == T){
      cout << "Yes" << endl;
      return 0;
    }
    S = rotate(S);
  }
  cout << "No" << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
string str;
bool check(){
  REP(i,3){
    if(str[i]==str[i+1]) return true;
  }
  return false;
}

int main(){
  cin>>str;
  if(check())cout<<"Bad"<<endl;
  else cout<<"Good"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

main(){
  int a,b,sum;
  scanf("%d %d",&a,&b);
  
  if(a-b >= 1) sum = 2*a -1;
  else if(a-b <= -1) sum = 2*b -1;
  else sum = a+b;
  
  printf("%d",sum);
}


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

int main()
{
  int S, h, m, s;
  cin >> S;
  h = S/(60*60);
  m = (S%(60*60))/60;
  s = S%60;
  cout << h << ":";
  cout << m << ":";
  cout << s << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

int main() {
  int n,T;cin >> n >> T;
  int ans= 1001;
  int tmx=0;
  rep(i,n){
    int c,t;cin >> c >> t;
    if(t<=T){ans=min(ans,c);tmx=1;}
  }
  if(tmx)cout << ans;
  else cout << "TLE";
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
int S,h,m,s;

 do{
scanf("%d", &S);
}while(S<0||S>=86400);

h=S/3600;
m=(S%3600)/60;
s=(S%3600)%60;

printf("%d:%d:%d\n",h,m,s);
return 0;
}

Measured memory_bytes: 592
#include<iostream>

bool sieve[100000];
void makesieve();

int main()
{
	makesieve();
	while(1)
	{
		int n,ans=0;
		std::cin>>n;
		if(n==0)break;
		for(int i=0;i<=n/2;i++)
		{
			if(sieve[i]&&sieve[n-i])ans++;
		}
		std::cout<<ans<<std::endl;
	}
	return 0;
}

void makesieve()
{
	for(int i=0;i<100000;i++){sieve[i]=true;}
	sieve[0]=false;sieve[1]=false;
	for(int i=2;i<100000;i++)
	{
		for(int j=i*2;j<100000;j+=i)
		{
			sieve[j]=false;
		}
	}
}

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

int main(void){
    int n,x,y;
    cin >> n >> x >> y;
    x--;    y--;
    
    vector<int> ans(n+1);
    for(int i=0;i<n;i++){
        queue<int> q;
        vector<int> dist(n,-1);
        dist[i] = 0;
        q.push(i);

        while(!q.empty()){
            int now = q.front();
            q.pop();

            if(now!=0 && dist[now-1]==-1){
                dist[now-1] = dist[now]+1;
                q.push(now-1);
            }
            if(now!=n-1 && dist[now+1]==-1){
                dist[now+1] = dist[now]+1;
                q.push(now+1);
            }
            if(now==x||now==y){
                int next = x+y-now;
                if(dist[next]==-1){
                    dist[next] = dist[now]+1;
                    q.push(next);
                }
            }
        }

        for(int j=0;j<n;j++) ans[dist[j]]++;
    }

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

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

template<class T> struct Seg { 
	const T ID = 0; // comb(ID,b) must equal b
	T combine(T a, T b) { return max(a, b); } 
	int n; vector<T> seg;
	void init(int _n) { n = _n; seg.assign(2*n,ID);}

	void update(int p, T value) {	// set value at position p
		seg[p += n] = value;
		for (p /= 2; p; p /= 2) seg[p] = combine(seg[2*p], seg[2*p+1]);
	}
    
	T query(int l, int r) {	 // sum on interval [l, r]
		T ra = ID, rb = ID; 
		for (l += n, r += n+1; l < r; l /= 2, r /= 2) {
			if (l&1) ra = combine(ra,seg[l++]);
			if (r&1) rb = combine(seg[--r],rb);
		}
		return combine(ra,rb);
	}
};

Seg<int> seg;

int N;
vi arr;
vi ans;
vector<vi> graph;

void dfs(int cur, int par) {
	int before = seg.query(arr[cur], arr[cur]);
	seg.update(arr[cur], seg.query(0, arr[cur]-1) + 1);
	ans[cur] = seg.query(0, 2e5+9);
	for (int n : graph[cur]) if (n != par) dfs(n, cur);
	seg.update(arr[cur], before);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	seg.init(2e5+10);
	cin >> N;
	graph.resize(N);
	arr.resize(N);
	ans.resize(N);

	// coordinate compress values
	map<int, vi> inds;
	F0R(i, N) {
		int x; cin >> x;
		inds[x].push_back(i);
	}
	int j = 1;
	for (pair<int, vi> res : inds) {
		for (int i : res.second) arr[i] = j;
		++j;
	}

	F0R(i, N-1) {
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(0, -1);
	F0R(i, N) print(ans[i]);
	return 0;
}

Measured memory_bytes: 48848
#include<bits/stdc++.h>
using ll = int_fast64_t;
using Edge = std::pair<ll,ll>;
#define to first
#define cost second

int main(){
        ll n;
        scanf("%ld", &n);

        std::vector<std::vector<Edge>> links(n, std::vector<Edge>(0));
        for(ll i=0; i<n-1; i++){
                ll a, b, c;
                scanf("%ld %ld %ld", &a, &b, &c);
                links[a-1].push_back(Edge(b-1, c));
                links[b-1].push_back(Edge(a-1, c));
        }

        std::vector<ll> color(n), used(n, 0);
        color[0] = 1;

        std::queue<Edge> que;
        que.push(Edge(0, 0));
        while(!que.empty()){
                ll from = que.front().first;
                que.pop();
                used[from] = 1;
                for(Edge p: links[from]){
                        if(used[p.to]) continue;
                        que.push(p);
                        color[p.to] = color[from] ^ p.cost%2;
                }
        }

        for(ll i: color) printf("%ld\n", i);
        return 0;
}

Measured memory_bytes: 9472
a = gets.chomp.split(" ").map(&:to_i)
print (a[2]+(a[1]-a[3])).to_s + " " + (a[3]+(a[2]-a[0])).to_s + " " + (a[0]+(a[1]-a[3])).to_s + " " + (a[1]+(a[2]-a[0])).to_s


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

ll v[M][M], dp[M][M][4];
int n,m;
ll rec(int i, int j, int k) {
  if(i==0 || i==n+1 || j==0 || j==m+1) {
    return 0;
  }
  if(dp[i][j][k]!=(-1)) {
    return dp[i][j][k];
  }
  dp[i][j][k] = 0;
  if(k>1) {
    dp[i][j][k] = max(rec(i,j-1,k-1) + v[i][j], rec(i,j-1,k));
  } else if(k==1) {
    dp[i][j][k] = max({v[i][j] + rec(i,j,0), rec(i,j-1,k)});
  } else {
    dp[i][j][k] = max({rec(i-1,j,0), rec(i-1,j,1), rec(i-1,j,2), rec(i-1,j,3)});
  }
  return dp[i][j][k];
}
void solve() {
  int k,x,y,z;
  cin>>n>>m>>k;
  REP(i,1,k) {
    cin>>x>>y>>z;
    v[x][y] = z;
  }
  mms(dp, -1);
  dp[1][1][0] = 0;
  dp[1][1][1] = v[1][1];
  cout << max({rec(n,m,0), rec(n,m,1), rec(n,m,2), rec(n,m,3)});
}

int main() {
    //freopen("./sort/b2.in","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 356896
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4, xdiff, ydiff; cin >> x1 >> y1 >> x2 >> y2;
    xdiff = x2 - x1;
    ydiff = y2 - y1;
    x3 = x2 - ydiff;
    y3 = y2 + xdiff;
    x4 = x3 - xdiff;
    y4 = y3 - ydiff;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}

Measured memory_bytes: 256
require 'set'

N = gets.to_i

edges = Hash.new {|h,v| h[v] = [] }

(N-1).times do
  u, v, w = gets.split.map(&:to_i)
  edges[u-1] << [u-1, v-1, w]
  edges[v-1] << [v-1, u-1, w]
end

distance = Array.new(N)
distance[0] = 0


q = edges[0]

while !q.empty?
  u, v, w = q.shift
  next if distance[v]
  distance[v] = distance[u] + w
  edges[v].each do |u2,v2,w2|
    if distance[v2].nil?
      q << [u2, v2, w2]
    end
  end
end

distance.each do |d|
  puts d.even? ? '0' : '1'
end


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

using namespace std;

const int N=100000;
int n,m,v[N+5],viz[N+5];
vector<int>g[N+5];
int sol[N+5],y=0;
set<int>s;

void dfs(int nod){
    sol[++y]=nod;
    viz[nod]=1;
    for(int i=0;i<g[nod].size();i++){
        int nou=g[nod][i];
        if(viz[nou]==0)
            dfs(nou);
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>v[i];
    for(int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int add=0;
    for(int i=1;i<=n;i++)
        if(viz[i]==0){
            y=0;
            dfs(i);
            s.clear();
            for(int j=1;j<=y;j++){
                int nod=sol[j];
                s.insert(v[nod]);
            }
            for(int j=1;j<=y;j++){
                if(s.find(sol[j])!=s.end()){
                    add++;
                }
            }
        }
    cout<<add;
    return 0;
}
/**
**/


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

using namespace std;
using ll = int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using tpi = tuple<int, int, int>;

using vqi = vector<queue<int>>;
using vpi = vector<pii>;
using bs = bitset<60>;
using vbi = vector<bs>;
constexpr ll MOD = 1e9 + 7;


int main() {
    int N, M;
    cin >> N >> M;

    string ans;
    if (N == M) {
        ans = "Yes";
    } else {
        ans = "No";
    }

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,n;
    cin >> a >> b >> n;
    for(int i=0; i<n; i++){
    int x,y;
    cin >> x >> y;
    if(x<b&&a<y){
        cout << 1 << endl;
        return 0;
    }
  }
  cout << 0 << endl;
}


Measured memory_bytes: 3136
def main():
    N, A, B = map(int, input().split())
    if N == A and N == B:
        # 全員が両方読んでいる場合
        print(N, N)
        return

    max_result = max([A, B])
    min_result = min([A, B])
    if A + B > N:
        # AとBの合計がNより大きい場合、最大は小さい方の数、最小はmin - (N - max)
        print(min_result, min_result - (N - max_result))
    elif A + B <= N:
        # AとBの合計がNより小さい場合、最大は小さい方の数、最小は0
        print(min_result, 0)



main()


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

int main() {
    int K, A, B;
    std::cin >> K >> A >> B;

    for (int i = A; i <= B; ++i) {
        if (i % K == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;

    return 0;
}


Measured memory_bytes: 3636
x = int(input())
if 400 <= x <= 599:
	print(8)
elif 600 <= x <= 799:
	print(7)
elif 800 <= x <= 999:
	print(6)
elif 1000 <= x <= 1199:
	print(5)
elif 1200 <= x <= 1399:
	print(4)
elif 1400 <= x <= 1599:
	print(3)
elif 1600 <= x <= 1799:
	print(2)
elif 1800 <= x <= 1999:
	print(1)


Measured memory_bytes: 9180
#include<stdio.h>

int main()
{
    int n, i, j, k;
        scanf("%d", &n);
    int l[n], count=0;
            for(i = 0; i < n; i++){
        scanf("%d", &l[i]);
        }
            for(i = 0; i < n; i++){
            for(j = i + 1; j < n; j++){
            for(k = j + 1; k < n; k++){
                if((l[i] != l[j]) && (l[j] != l[k]) && (l[k] != l[i])){
                if((l[i] + l[j] > l[k]) && (l[j] + l[k] > l[i]) && (l[k] + l[i] > l[j])){
                    count++;
        }
        }
        }
        }
        }
        printf("%d", count);
    return 0;
}

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

int main() {
    int A,B,C,X;
    int count =0;
    cin >> A >> B >> C  >> X;
    for (int i = 0; i < A+1; i++)
    {
        for (int j = 0; j < B+1; j++)
        {
            for (int k = 0; k < C+1; k++)
            {
                if (500*i+100*j+50*k==X)
                {
                    count++;
                }
                
            }
            
        }
        
    }
    cout << count << endl;
}

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

int main() {
  char b;
  cin >> b;
  if(b == 'A') cout << 'T' << endl;
  else if(b == 'T') cout << 'A' << endl;
  else if(b == 'C') cout << 'G' << endl;
  else cout << 'C' << endl;
  return 0;
}

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

typedef vector <int> ve;
ve pedra;
vector <long int> memo;

long int dp(int n){
    if (n == 0) return 0;
    if (memo[n] != -1) return memo[n];
    memo[n] = dp(n-1) + abs(pedra[n] - pedra[n-1]);
    if (n-2 >= 0){
        memo[n] =  min(memo[n], dp(n-2) + abs(pedra[n] - pedra[n-2]));
    }

    return memo[n];
}

int main(){
    int n;
    cin >> n;
    pedra.assign(n, 0);
    memo.assign(n, -1);
    for (int i = 0; i < n; i++){
        int a;
        scanf("%d", &a);
        pedra[i] = a;
    }
    printf("%ld\n", dp(n-1));
    // for (int i = 0; i < n; i++) printf("%d ", pedra[i]);
}


Measured memory_bytes: 6144
#include<stdio.h>
int main(void){

  int x,y;
  while(1){
    scanf("%d%d",&x,&y);
    if(x == 0 && y == 0) break;
    if(x >= y)
      printf("%d %d\n",y,x);
    else if(y >= x)
      printf("%d %d\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int adj[101][101],d[101],n;

void BFS(int now){
	int Q[100000],front,tail, i;
	front=tail=0;

	Q[tail]=now;	++tail;


	while(front!=tail){
		//pop
		now=Q[front];	++front;
		for(i=1;i<=n;i++){
			if(adj[now][i]){
				if(d[i]>=0)continue;

				//push
				Q[tail]=i;	++tail;
				d[i]=d[now]+1;
			}
		}
	}
}

int main(){
	int i,j,u,k,v;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		d[u]=-1;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			adj[u][v]=1;
		}
	}
	d[1]=0;

	BFS(1);
	for(i=1;i<=n;i++){
		printf("%d %d\n",i,d[i]);
	}

	return 0;
}



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

public class Main {
	final int k=200000;
	boolean prime[]=new boolean[k+1];
	int ans[]=new int[k+1];
	public static void main(String[] args) {
		new Main().run();

	}
	void run(){
		Scanner sc=new Scanner(System.in);
		Arrays.fill(prime, true);
		prime[0]=prime[1]=false;
		for(int i=2;i<k;i++){
			if(prime[i]){
				for(int j=2;i*j<=k;j++){
					prime[i*j]=false;
				}
			}
		}

		int n,p;

		while(true){
			n=sc.nextInt();
			p=sc.nextInt();
			if(n==-1 && p==-1) break;
			System.out.println(slove(n+1,p));
		}
	}
	int slove(int n,int p){
		int count=0;

		for(int i=n;i<k;i++){
			if(prime[i]){
				for(int j=n;j<=i;j++){
					if(prime[j]){
						ans[count]=j+i;
						
						if(count==5*p){
							Arrays.sort(ans,0,count);
							for(int k=0;;k++){
								if(k==p){
									return ans[k-1];
								}
							}
						}
						count++;
					}
				}
			}
		}
		return -1;
	}//s

}

Measured memory_bytes: 26952
s = input()
t = input()

n_t = len(t)

res = n_t

for i in range(len(s) - n_t +1):
    tmp = s[i:i+n_t]
    count = 0
    for j in range(n_t):
        if tmp[j] != t[j]:
            count +=1
    res = min(res, count)

print(res)

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

using namespace std;

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

	int N, M, C;
	vector<int> B;

	cin >> N >> M >> C;
	B.assign(M, int(0));


	int cnt = 0;

	for (int m = 0; m < M; m++)
		cin >> B[m];

	for (int n = 0; n < N; n++) {
		int tmp = 0;

		for (int m = 0; m < M; m++) {
			int tmp2 = 0;
			cin >> tmp2;

			tmp += tmp2 * B[m];
		}

		if (tmp > C * -1)
			cnt++;
	}

	cout << cnt;
}

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

#define all(n) n.begin(),n.end()
#define ll long long

#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;
const ll maxn=5e6+2;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;
vector<ll> adj[maxn];
ll a[maxn];
ll cnt[maxn];
bool dd[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("TEAMS.INP","r"))
    {
        freopen("TEAMS.INP", "r", stdin);
        freopen("TEAMS.OUT", "w", stdout);
    }
    ll n;
     cin>>n ;
     for (int i=0;i<maxn;i++)
     {
         cnt[i]=0;
          dd[i]=0;
     }
     for (int i=1;i<=n;i++)
     {
         cin>>a[i];
         cnt[a[i]]++;
         if (cnt[a[i]]==1)
         {
             for (int j=a[i]*2;j<maxn;j+=a[i])
             {
                 dd[j]=1;
             }
         }
     }
     ll ans=0;
     for (int i=1;i<=n;i++)
     {
       //  cout <<cnt[a[i]]<<endl;
         if (cnt[a[i]]>1) continue;
         if (!dd[a[i]])
         {
             ans++;
         }
     }
     cout <<ans;
}


Measured memory_bytes: 166320
X,Y,A,B,C = map(int,input().split())
p_s = list(map(int,input().split()))
q_s = list(map(int,input().split()))
r_s = list(map(int,input().split()))
p_s.sort()
q_s.sort()
r_s.sort()
p = p_s[A-X:]
q = q_s[B-Y:]
r = r_s[max(C-(X+Y),0):]
p.reverse()
q.reverse()
r.reverse()
p.append(0)
q.append(0)
r.append(0)
i=0
j=0
k = 0
SUM = 0
cnt = 0
while cnt < X+Y:
    if i<len(p)-1 and p[i] >= q[j] and p[i] >= r[k]:
        SUM += p[i]
        i+=1
    elif j<len(q)-1 and q[j] >= p[i] and q[j] >= r[k]:
        SUM += q[j]
        j+=1
    elif k<len(r)-1 and r[k] >= q[j] and r[k] >= p[i]:
        SUM += r[k]
        k+=1
    cnt += 1
print(SUM)

Measured memory_bytes: 106476
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> p;
typedef long long ll;
const int inf = 1000000007;

struct rlcnt {
  ll id;
  ll rcnt;
  ll lcnt;
};

int main() {
  string s;
  cin >> s;
  vector<rlcnt> d;
  ll rc = 0;
  ll lc = 0;
  bool rl = true;  // true r false l
  rep(i, s.size() - 1) {
    if (s[i] == 'R' && rl) rc++;
    if (s[i] == 'L' && rl) rl = false;
    if (s[i] == 'R' && !rl) {
      rl = true;
      rc = 1;
    }
    if (s[i] == 'R' && s[i + 1] == 'L') {
      rlcnt tmp;
      tmp.id = i;
      tmp.rcnt = rc - 1;
      d.push_back(tmp);
    }
  }
  ll index = 0;
  rep(i, s.size() - 1) {
    if (s[i] == 'L' && s[i + 1] == 'R') {
      d[index].lcnt = i - d[index].id - 1;
      index++;
    }
  }
  d[d.size() - 1].lcnt = s.size() - 1 - d[d.size() - 1].id - 1;

  vector<ll> ans(s.size());
  index = 0;
  rep(i, s.size()) {
    if (i == d[index].id) {
      ans[i] = d[index].rcnt / 2 + d[index].lcnt / 2 + (d[index].lcnt % 2) + 1;
      ans[i + 1] =
          d[index].lcnt / 2 + d[index].rcnt / 2 + (d[index].rcnt % 2) + 1;
      index++;
    }
  }
  // rep(i, d.size()) cout << "(" << d[i].id << ", " << d[i].rcnt << ", "
  //                        << d[i].lcnt << ")"
  //                       << ", ";
  // cout << endl;

  // rep(i, s.size()) cout << ans[i] << ", ";
  // cout << endl;
  rep(i, s.size()) cout << ans[i] << endl;
  return 0;
}

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

int main() {
  string s;cin >> s;
	reverse(s.begin(),s.end());
	vector<string> v = {"maerd","remaerd","esare","resare"};

	string t = "";
	rep(i,s.size()){
		t.push_back(s.at(i));
		if( count(v.begin(),v.end(),t) ) t = "";
	}
	if( t == "" )
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3936
#include <iostream>

using namespace std;

int main()
{
    string S;
    cin >> S;
    int cnt = 0;

    for (int i = 0; i < S.size(); i++){
        if (S.at(i) == '+'){
            cnt++;
        }else{
            cnt--;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define bits(n) __builtin_popcount(n)


void solve()
{
    int n,x,t;
    cin>>n>>x>>t;
    int res=ceil(double(n)/x);
    cout<<res*t;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans[1000][1000],a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n;
    rrep(i,2,ohara){
            ll men=i*(i-1);
            if(men/2==n)fl=true;
    }
    if(!fl){
        Cout("No");
        return 0;
    }
    else{
        ll tate,yoko,gen;
        rrep(i,2,ohara){
            ll men=i*(i-1);
            if(men/2==n){
                tate=i;yoko=i-1;
                break;
            }
    }
    gen=1;
    rep(j,yoko){
        ans[0][j]=gen;
        gen++;
    }
    rrep(i,1,tate){
        rep(j,yoko){
            if(i>j){
                ans[i][j]=ans[j][i-1];
            }
            else{
                ans[i][j]=gen;
                gen++;
            }
        }
    }
    Cout("Yes");
    Cout(tate);
    rep(i,tate){
        cout<<yoko<<" ";
        rep(j,yoko){
            if(j==yoko-1){
                cout<<ans[i][j]<<"\n";
            }
            else{
                cout<<ans[i][j]<<" ";
            }
        }
    }
    }
    return 0;
}


Measured memory_bytes: 5376
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            var a = int.Parse(s[0].ToString());
            var b = int.Parse(s[1].ToString());
            var c = int.Parse(s[2].ToString());
            var d = int.Parse(s[3].ToString());

            for (int bit = 0; bit < (1 << 3); bit++)
            {
                var op = new string[3];
                for (int i = 0; i < 3; i++)
                {
                    var intFlag = (bit >> i) & 1;
                    op[i] = intFlag == 1 ? "+" : "-";
                }

                int calc = a;

                if (op[0] == "+") calc += b;
                else calc -= b;
                if (op[1] == "+") calc += c;
                else calc -= c;
                if (op[2] == "+") calc += d;
                else calc -= d;

                if (calc == 7)
                {
                    WriteLine(a + op[0] + b + op[1] + c + op[2] + d + "=7");
                    return;
                }
            }



        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

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


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

    ll maxi = vec[0];
    ll sum = 0;
    for(ll i=1; i<n; ++i){
        if(vec[i] < maxi){
            sum += abs(vec[i] - maxi);     
        }
        maxi = max(maxi,vec[i]);

    }
    cout<<sum<<endl;

}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


Measured memory_bytes: 4824
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        String s = sc.next();

        if (s.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (s.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }



    }
}


Measured memory_bytes: 21460
N = int(input())
char_lst = ['M', 'A', 'R', 'C', 'H']
counts = {'M' : 0, 'A': 0, 'R':0, 'C': 0, 'H': 0}
for i in range(N):
    S = input()
    if S[0] in char_lst:
        counts[S[0]] += 1
            
ans = 0
for i in range(len(char_lst) - 2):
    for j in range(i + 1, len(char_lst) - 1):
        for k in range(j + 1, len(char_lst)):
            ans += counts[char_lst[i]] * counts[char_lst[j]] * counts[char_lst[k]]
            
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,w;
	cin>>n>>w;
	int i;
	pair<int,int>a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	sort(a,a+n);
	long long ans[n][w+1];
	int j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<=w;j++)
		{
			if(a[i].first>j)
			{
				if(i==0)
				{
					ans[i][j]=0;
				}
				else
				{
					long long z=0;
					ans[i][j]=max(z,ans[i-1][j]);
				}
				
			}
			else
			{
				if(i==0)
				{
					ans[i][j]=a[i].second;
				}
				else
				{
					ans[i][j]=max(ans[i-1][j],a[i].second+ans[i-1][j-a[i].first]);
				}
			}
		}
	}
	cout<<ans[n-1][w];
}

Measured memory_bytes: 78336
N = int(input())
town = []
for _ in range(N):
    town.append(list(map(int,input().split())))

# print(town)
# print(town[1][0])

dst = []
for i in range(N-1):
    for j in range(i+1,N):
        #print(i,j)
        dst.append( (((town[i][0]-town[j][0])**2) + ((town[i][1]-town[j][1])**2) )**0.5 )
#print(dst)
print(((sum(dst))*(N-1))/len(dst))

Measured memory_bytes: 9440
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s;
	cin >> s;
	if (s == "ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    l=[]
    for i in range(N):
        l.append(list(map(int,input().split())))
    dp=[[0]*3 for _ in range(N+1)]
    for i in range(N):
        for k in range(3):
            dp[i+1][k]=max(dp[i][(k+1)%3]+l[i][k],dp[i][(k+2)%3]+l[i][k])
    print(max(dp[N]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 72412
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	    cin>>arr[i];
	bool dp[k+1]={false};
    for(int i=1;i<=k;i++)
    {
    	dp[i]=false;
    	for(int j=0;j<n;j++)
    	{
    		if(arr[j]<=i && dp[i-arr[j]]==false)
    		    dp[i]=true; 		    
		}
	}
	if(dp[k]==true)
	    cout<<"First\n";
	else
	   cout<<"Second\n";
}

Measured memory_bytes: 3716
#include <cstdio>
#include <string.h>
#include <string>
#include <vector>
#include <array>

int main()
{
    int K, N;

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

    std::vector<int> A;

    for (int i = 0; i < N; ++i)
    {
        int a;
        scanf("%d", &a);
        A.push_back(a);
    }

    // 最後の家と、一軒目の差
    int diff = A[0] + (K - A[N - 1]);
    const size_t size = A.size() - 1;
    for (size_t i = 0; i < size; ++i)
    {
        // 一番大きい差を探す
        int newDiff = A[i + 1] - A[i];
        if (diff < newDiff)
        {
            diff = newDiff;
        }
    }

    printf("%d", K - diff);

    return 0;
}



Measured memory_bytes: 1400
import java.io.IOException;
import java.util.Scanner;

public class Main {
    static int a, n;

    static int bfs(int p, int q, int startq, int count, int pi) {
        if (p == 0) return 1; /*??´??£???????????????*/
        if (p < 0 || n <= count) return 0; /*??????????????? or n???????????? */

        int res = 0;
        for (int i = startq; pi * i <= a; i++) {
            int np = p * i - q;
            int nq = q * i;
            res += bfs(np, nq, i, count + 1, pi * i);
        }
        return res;
    }

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

        while (true) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            a = sc.nextInt();
            n = sc.nextInt();
            if (p == 0)
                break;
            System.out.println(bfs(p, q, 1, 0, 1));
        }
    }
}

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

using namespace std;

int main()
{
	string s;
	
	cin>>s;
	
	int len=s.length(),ans=len;
	
	for (int i=0;i<len-1;i++){
		if (s[i]!=s[i+1]){
			ans=min(ans,max(i+1,len-i-1));
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
// union by size + path having
class UnionFind {
 public:
  vector<ll> par;  // 各元の親を表す配列
  vector<ll> siz;  // 素集合のサイズを表す配列(1 で初期化)

  // Constructor
  UnionFind(ll sz_) : par(sz_ + 1), siz(sz_ + 1, 1LL) {
    for (ll i = 1; i <= sz_; ++i) par[i] = i;  // 初期では親は自分自身
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
    for (ll i = 0; i < sz_; ++i) par[i] = i;  // 初期では親は自分自身
  }

  // Member Function
  // Find
  ll root(ll x) {  // 根の検索
    while (par[x] != x) {
      x = par[x] = par[par[x]];  // x の親の親を x の親とする
    }
    return x;
  }

  // Union(Unite, Merge)
  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    // merge technique（データ構造をマージするテク．小を大にくっつける）
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {  // 連結判定
    return root(x) == root(y);
  }

  ll size(ll x) {  // 素集合のサイズ
    return siz[root(x)];
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  UnionFind tree(n);
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    tree.merge(x, y);
  }
  map<ll, ll> f;
  for (ll i = 1; i <= n; i++) {
    ll num = tree.root(i);
    f[num]++;
  }

  ll ans = -1;
  auto begin = f.begin();
  auto end = f.end();
  for (auto iter = begin; iter != end; iter++) {
    ans = max(ans, iter->second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18676
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<algorithm>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;

const int N = 1e5;
const llong INF = 10000000000000000ll;
struct Element
{
	llong a,b,c;
	bool operator <(const Element &x) const
	{
		return a>x.a || (a==x.a && b>x.b);
	}
} p[N+2];
priority_queue<llong> pq2;
priority_queue<llong,vector<llong>,greater<llong> > pq1;
llong tmp1[N+2],tmp2[N+2];
int n1,n2,n3,n;

int main()
{
	scanf("%d%d%d",&n1,&n2,&n3); n = n1+n2+n3; llong tmp = 0ll;
	for(int i=1; i<=n; i++)
	{
		scanf("%lld%lld%lld",&p[i].a,&p[i].b,&p[i].c); tmp += p[i].b; p[i].a -= p[i].c; p[i].b -= p[i].c;
	}
	sort(p+1,p+n+1);
	for(int i=1; i<=n1; i++) {pq1.push(p[i].a-p[i].b); tmp1[n1] += p[i].a-p[i].b;}
	for(int i=n1+1; i<=n1+n2; i++)
	{
		pq1.push(p[i].a-p[i].b); int cur = pq1.top(); pq1.pop(); tmp1[i] = tmp1[i-1]+p[i].a-p[i].b-cur;
	}
	for(int i=n; i>=n1+n2+1; i--) {pq2.push(p[i].b); tmp2[n1+n2+1] += p[i].b;}
	for(int i=n1+n2; i>n1; i--)
	{
		pq2.push(p[i].b); int cur = pq2.top(); pq2.pop(); tmp2[i] = tmp2[i+1]+p[i].b-cur;
	}
	llong ans = -INF;
	for(int i=n1; i<=n1+n2; i++)
	{
		ans = max(ans,tmp1[i]-tmp2[i+1]);
	}
	printf("%lld\n",ans+tmp);
	return 0;
}

Measured memory_bytes: 4224
from fractions import gcd
n,k = map(int, input().split())
a = list(map(int, input().split()))
g = a[0]
for i in a:
    g = gcd(g, i)
m = max(a)
if m >= k and (m-k) % g == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 88684
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)

ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}

int main(){
	
		int n;
		cin>>n;
		vector<ll> x;
		vector<ll> y;
		rep(i,0,n){
			 ll u,v;
			 cin>>u>>v;
			 x.pb(u);
			 y.pb(v);
		}

        int res = 0, smallest, cur;
        for (int p : {1, -1}) {
            for (int q : {1, -1}) {
                smallest = p * x[0] + q * y[0] + 0;
                for (int i = 1; i < n; ++i) {
                    cur = p * x[i] + q * y[i];
                    res = max(res, cur - smallest);
                    smallest = min(smallest, cur);
                }
            }
        }
     cout<<res;
	
	
}

Measured memory_bytes: 6572
while 1:
	n = input()
	if n == 0: break
	rslt = [raw_input().replace("2","").split() for i in range(n)]
	rslt = sorted(sorted(rslt, key = lambda x:x.count("1")), key = lambda x:x.count("0"), reverse = True)
	for i in range(n):
		print rslt[i][0]

Measured memory_bytes: 4212
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int a[1000001];

int Func(int n) {
	if (n == 0)return 0;
	else return a[n] + Func(n - 1);
}

int main() {
	a[0] = 0;
	a[1] = 0;
	a[2] = 1;
	for (int i = 3; i <= 1000000; i++) {
		if (i % 2 == 0)a[i] = 0;
		else {
			int h = 1;
			for (int j = 3; j*j <= i && h == 1; j += 2) {
				if (i%j == 0)h = 0;
			}
			a[i] = h;
		}
	}
	int n;
	while (~scanf("%d", &n)) {
		printf("%d\n", Func(n));
	}
}




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

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

using namespace std;
typedef long long ll;
const int INF = 1001001001;

const int di[4] = {-1, 0 , 1, 0};
const int dj[4] = {0, -1 , 0, 1 };
typedef pair<int, int> P;

int main(){
    int h, w;
    int ans = 0;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    rep(si, h)rep(sj,w){
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));
        };
        update(si, sj, 0);
        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir, 4){
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if(s[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j] + 1);
            }
        }
        rep(i, h)rep(j,w){
            if(dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}


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

typedef long long ll;

const int mod = 998244353;
const int Maxn = 3005;

int A, B, C, D;
int dp[Maxn][Maxn][2];

int main()
{
    cin >> A >> B >> C >> D;
    dp[A][B][0] = 1;
    for (int j = B + 1; j <= D; j++)
        dp[A][j][0] = ll(dp[A][j - 1][0]) * A % mod;
    for (int i = A + 1; i <= C; i++)
        for (int j = B; j <= D; j++) {
            dp[i][j][0] = ll(j) * (dp[i - 1][j][0] + dp[i - 1][j][1]) % mod;
            // cur
            dp[i][j][1] = (dp[i][j - 1][0] + dp[i][j - 1][1]) % mod;
            // not cur
            dp[i][j][1] = (dp[i][j][1] + ll(i - 1) * dp[i][j - 1][1]) % mod;
        }
    int res = (dp[C][D][0] + dp[C][D][1]) % mod;
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 73980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char s[5];
    cin >> s;

    bool b = (s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]);

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)

count = as.count { |i| i < 0 }
to_abs = as.map { |e| e.abs }

if count.even?
    puts to_abs.reduce(:+)
else
    min = to_abs.min
    puts to_abs.reduce(:+) - min * 2
end

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

double n,m,d;

int main(){
	cin>>n>>m>>d;
	cout<<syosu(9)<<(d==0?1.0:2.0)*(n-d)/n*(m-1)/n<<endl;
}

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

#define ll long long
#define sq(a) (a)*(a)
#define caset int t; cin >> t; while(t--)
#define get1(a) ll int a; cin>>a;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define line '\n'

#define vi(v)	vector < int > v;
#define	all(v)	v.begin(), v.end()


//#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   #ifndef ONLINE_JUDGE   freopen("input.txt","r",stdin);		freopen("output.txt","w",stdout); 	#endif



int main() {
//	fast;

    long long int x, c=0,p=100;
    cin>>x;
    while(p<x)
    {
        p=p + floor(p*0.01);
        c++;
    }
    cout<<c;
return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
#define MAX_N 500000
#define SENTINEL 1000000001

int n, S[MAX_N], cnt = 0, L[(MAX_N / 2) + 1], R[(MAX_N / 2) + 1];

void merge(int left, int mid, int right) {
  int n1, n2, i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  for (i = 0; i < n1; ++i)
    L[i] = S[left + i];
  L[n1] = SENTINEL;
  for (i = 0; i < n2; ++i)
    R[i] = S[mid + i];
  R[n2] = SENTINEL;

  i = 0;
  j = 0;
  for (k = left; k < right; ++k) {
    ++cnt;
    if (L[i] <= R[j])
      S[k] = L[i++];
    else
      S[k] = R[j++];
  }
}

void mergeSort(int left, int right) {
  if (right - left > 1) {
    int mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int main() {
  int i;
  scanf("%d\n", &n);
  for (i = 0; i < n; ++i)
    scanf("%d ", &S[i]);

  mergeSort(0, n);

  for (i = 0; i < n - 1; ++i)
   printf("%d ", S[i]);
  printf("%d\n", S[n - 1]);
  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 6636