akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;
typedef vector<vi> vvi;

int lp;
vi dist;

int dfs(vvi &gf, int n) {
	int p = 0;
	for (int i = 0; i < gf[n].size(); i++) {
		if (dist[gf[n][i]] == -1)
			p = max(p, 1 + dfs(gf, gf[n][i]));
		else
			p = max(p, 1 + dist[gf[n][i]]);
	}
	dist[n] = p;
	return dist[n];
}

int main() {FIN

	int n, m, x, y, i;
	cin >> n >> m;
	vvi gf(n);
	vi in(n);

	for (i = 0; i < m; i++) {
		cin >> x >> y;
		x--, y--;
		gf[x].push_back(y);
		in[y]++;
	}

	lp = 0;
	dist = vi(n, -1);
	for (i = 0; i < n; i++) {
		if (in[i] == 0)
			lp = max(lp, dfs(gf, i));
	}

	cout << lp << "\n";

	return 0;
}

Measured memory_bytes: 14224
#include <iostream>
#include <cmath>

using namespace std;

int main(){
 int n; cin >> n;
  int *a = new int[n];
  for(int i = 0; i < n; i++)cin >> a[i];
  int maxi = -1;
  for(int i = 0; i < n - 1; i++){
   for(int j = i + 1; j < n; j++){
    if(abs(a[i]-a[j]) > maxi)maxi=abs(a[i]-a[j]);
   }
  }
  cout << maxi << endl;
}


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


int main(){
	int A,B,M;
	scanf("%d %d %d",&A,&B,&M);
	int a[A];
	int b[B];
	int c[M];
	int x[M];
	int y[M];

	for(int i=0; i<A; i++){
		scanf("%d",&a[i]);
	}
	for(int i=0; i<B; i++){
		scanf("%d",&b[i]);
	}
	for(int i=0; i<M; i++){
		scanf("%d",&x[i]);
		scanf("%d",&y[i]);
		scanf("%d",&c[i]);
	}
	
	/*for(int i=0; i<A; i++){
		printf("%d ",a[i]);
	}
	printf("\n");
	for(int i=0; i<B; i++){
		printf("%d ",b[i]);
	}
	printf("\n");
	for(int i=0; i<M; i++){
		printf("%d %d %d\n",x[i],y[i],c[i]);
	}*/

	int min_A = a[0];
	int min_B = b[0];

	for(int i=0; i<A; i++){
		if(min_A > a[i]){
			min_A = a[i];
		}
	}	
	for(int i=0; i<B; i++){
		if(min_B > b[i]){
			min_B = b[i];
		}
	}	
	// printf("min_A = %d min_B = %d\n",min_A,min_B);
	int min = min_A + min_B;
	// printf("%d\n",min);
	/*for(int i=0; i<M; i++){
		for(int j=0; j<M; j++){
			if(i != j){
				if(x[i] == x[j] && y[i] == y[i]){
					if(c[i] > c[j]){
						c[j] == 0;
					}
					else{
						c[i] == 0;
					}
				}
			}
		}
	}*/

	for(int i=0; i<M; i++){
		if(min > a[x[i] - 1] + b[y[i] - 1] - c[i]){
			min = a[x[i] - 1] + b[y[i] - 1] - c[i];
		}
	}

	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

void selectionSort(int [],int);
void trace(int [],int);

int cnt=0;

int main(){
 int N=0,i,j;
  int A[100];

  scanf("%d",&N);
  for(i=0; i <= N-1; i++){
    scanf("%d",&A[i]);
      }
  selectionSort(A,N);

  return 0;
     }

void Trace(int A[],int N){
  int i;
  for(i=0;i <= N-1;i++){
    printf("%d",A[i]);



    if(i!=N-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
   }

void selectionSort(int A[],int N){
  int i,k=0,j=0,minj;
  for(i=0;i<=N-1;i++){
    /*printf("hoge1");*/
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j] < A[minj])minj = j;
	
      /*printf("hoge2");*/


    }
    k=A[i];   A[i] = A[minj];
    A[minj] = k;
    if(i!=minj) cnt++;
  } 
  Trace(A,N);
     }



Measured memory_bytes: 2104
N = int(input())
A = list(map(int,input().split()))
H = [[0] * 2 for i in range(N)]
for i in range(N):
    H[i][0] = i+1
    H[i][1] = A[i]
H.sort(key=lambda x:x[1])
ans = [0]*N
for i in range(N):
    ans[i] = H[i][0]
print(' '.join(map(str, ans)))

Measured memory_bytes: 28388
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <__msvc_all_public_headers.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<"\n"; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll LL_INF=1e10;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
// cin>>questions;
 while(questions--)
 {
      int n;
      cin>>n;
      string s;
      cin>>s;
      int ans=0;
     int cnt=0;
     forn if(s[i]=='R') cnt++;
     
     for(int i=0;i<cnt;i++) if(s[i]=='R') ans++;
     cout<<cnt-ans;
 }
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

Measured memory_bytes: 3756
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	string s;
	cin >> s;
	if (s.back() == 's')s += "es";
	else s += "s";
	cout << s << endl;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	scan(N);
	int keta=0;
	int m=N;
	while(m>0) m/=10,keta++;
	if(keta==2) prin(9);
	else if(keta==4) prin(909);
	else if(keta==6) prin(90909);
	else if(keta==1) prin(N);
	else if(keta==3) prin(N-99+9);
	else if(keta==5) prin(N-9999+909);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb              push_back
#define ll              long long
#define scd(a)          scanf("%d",&a)
#define mp(a,b)         make_pair(a,b)
#define scl(w)          scanf("%lld",&w)
#define scdd(a,b)       scanf("%d %d",&a,&b)
#define srt(a)          sort(a.begin(),a.end())
#define rsrt(a)         sort(a.rbegin(),a.rend())
#define scll(a,b)       scanf("%lld %lld",&a,&b)
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
#define input(v,n)      for (int i=0;i<n;i++){int a;cin >> a;v.push_back(a);}
#define inputll(v,n)    for (ll i=0;i<n;i++){ll a;cin >> a;v.push_back(a);}
#define vii             vector < int >
#define vll             vector < ll >
#define pii             pair < int , int >
#define pll             pair < ll , ll >
#define mk              make_pair
#define inf8            100000008

using namespace std;


int main()
{
    ll w,h,x,y;
    scll(w,h);
    scll(x,y);
    int temp = 1;

    printf("%.15lf ",(double)(w*h)/2.0);
    if (x*2==w && y*2==h)cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
from fractions import gcd

a, b, c, d = map(int,input().split())

if a%c == 0:
    c_number = b // c - a // c + 1
else:
    c_number = b // c - a // c
if a%d == 0:
    d_number = b // d - a // d + 1
else:
    d_number = b // d - a // d
if a%(c*d // gcd(c,d)) == 0:
    cd_number = b // (c*d // gcd(c,d)) - a // (c*d // gcd(c,d)) + 1
else:
    cd_number = b // (c*d // gcd(c,d)) - a // (c*d // gcd(c,d))
print(int((b-a+1) - (c_number + d_number - cd_number)))

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

int main(){
	int n, d, x;
	cin >> n >> d >> x;
	int a[n];
	for(int i=0;i<n;++i) cin  >> a[i];
	int64_t choco=0;
	for(int i=0;i<n;++i){
		int j=0;
		while(a[i]*j+1<=d){
			++choco;
			++j;
		}
	}
	choco+=x;
	cout << choco << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(((a+b)%3==0)||(a%3==0)||(b%3==0))
    {
        cout<<"Possible"<<endl;
    }
    else
    {
        cout<<"Impossible"<<endl;
    }
}

Measured memory_bytes: 256
#coding: UTF-8

while True:

	l = raw_input().split()

	a = int(l[0])
	b = int(l[2])

	op =l[1]



	if op == "+":
		x = a + b
		print x

	if op == "-":
		x = a - b
		print x

	if op == "*":
		x = a * b
		print x

	if op == "/":
		x = a / b
		print "%d" %x


	if op == "?":
		break

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, sum(0);
    cin >> n >> k;
    int w[n];
    for (int i = 0; i < n; ++i)
    {
        cin >> w[i];
        sum += w[i];
    }
    int ans = (sum % k == 0) ? sum / k : sum / k + 1;
    for (int i = 0; i < n; ++i)
    {
        if (w[i] > ans)
            ans = w[i];
    }
    int count, tmp;
    while (1)
    {
        count = 1;
        tmp = 0;
        for (int i = 0; i < n; ++i)
        {
            tmp += w[i];
            if (tmp > ans)
            {
                count++;
                tmp = w[i];
            }
        }
        if (count <= k)
            break;
        else
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int a,b,k;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i = a;i <= b;i++){
        if(i%k==0)ok = true;
    }
    if(ok)cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}

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

using i64 = int64_t;

int main(){
    int a, b;
    cin >> a >> b;
    for(int i=1;i<=10000;++i){
        int x = i * 8 / 100;
        int y = i / 10;
        if(x == a && y == b){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout <<"Sunny" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


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

    int t=1,te=0;
    // cin>>t;
    while(t--){
        string s;
        cin>>s;

        set<char>ss;

        for(int i=0;s[i];++i)ss.insert(s[i]);

        if(ss.size()>=2){
            printf("Yes\n");
        }    
        else{
            printf("No\n");
        }   


        //printf("Case %d: ",++te);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int main()
{
  ll N, P; cin >> N >> P;
  vector<ll> A(N);
  rep(i, 0, N) cin >> A[i];
  vector<ll> odd, even;
  rep(i, 0, N) {
  	if (A[i] % 2) odd.push_back(A[i]);
    else even.push_back(A[i]);
  }
//  ll Ecomb, Ocomb;
  if (odd.size() == 0) {
  	if (P == 1) {
    	cout << 0 << endl;
    } else {
    	cout << ((ll)1 << even.size()) << endl;
    }
  } else {
  	cout << ((ll)1 << (odd.size() - 1 + even.size())) << endl;
  }    
}

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

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

vector<vp> path;
vector<vi> gr;
int padre[100];
int depth[100];

void dfs(int nodo, int p){
	padre[nodo] = p;
	for(int x : gr[nodo]){
		if(x == p)
			continue;
		depth[x] = depth[nodo]+1;
		dfs(x, nodo);
	}
}

int main(){
	int n;
	si(n);
	gr.resize(n);
	for(int i = 1; i < n; i++){
		int a, b;
		sii(a, b);
		a--;
		b--;
		gr[a].push_back(b);
		gr[b].push_back(a);
	}
	depth[0] = 0;
	dfs(0, -1);
	int m;
	si(m);
	for(int i = 0; i < m; i++){
		int a, b;
		sii(a, b);
		a--;
		b--;
		vp tmp;
		while(depth[a] > min(depth[a], depth[b])){
			tmp.push_back({a, padre[a]});
			a = padre[a];
		}
		while(depth[b] > min(depth[a], depth[b])){
			tmp.push_back({b, padre[b]});
			b = padre[b];
		}
		while(a != b){
			tmp.push_back({b, padre[b]});
			b = padre[b];
			tmp.push_back({a, padre[a]});
			a = padre[a];
		}
		path.push_back(tmp);
	}
	ll ans = 0;
	for(ll mask = 1; mask < (1LL<<m); mask++){
		set<pi> ls;
		int cnt = 0;
		for(int i = 0; i < m; i++)
			if(mask&(1<<i)){
				cnt++;
				for(int p = 0; p < path[i].size(); p++)
					ls.insert(path[i][p]);
			}
		if(cnt%2)
			ans += (1LL<<(n-1-(int)ls.size()));
		else
			ans -= (1LL<<(n-1-(int)ls.size()));
	}
	ans = ((1LL<<(n-1)) - ans);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3792
#include <stdio.h>
int main()
{
    int a, max_1 = 0, max_2 = 0, max_3 = 0;
    using namespace std;
    for (int I = 0; I < 10; I++)
    {
        scanf("%d", &a);
        if (a>  max_1)
        {
            max_3 = max_2; max_2 = max_1; max_1 = a;
        }
        else if(a > max_2)
        {
            max_3 = max_2; max_2 = a;
        }
        else if (a > max_3)
        {
            max_3 = a;
        }
    }
    printf("%d\n%d\n%d\n", max_1, max_2, max_3);
    return 0;
}


Measured memory_bytes: 2688
import math
N = int(input())
dp = [10**15] * 1000000
dp[1] = 1
dp[0] = 0
for i in range(N + 1):
    dp[i + 1] = min (dp[i] + 1 , dp[i + 1])
    for k in range(7):
        dp[i + 6 ** k ] = min (dp[i] + 1 ,dp[i + 6 ** k ])
    for k in range( 7):
        dp[i + 9 ** k] = min(dp[i] + 1, dp[i + 9 ** k])
print(dp[N])

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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;

  if(A==0){
    cout << 0 << endl;
  }

  else if(N<=A){
    cout << N << endl;
  }

  else if(B==0){
    cout << N << endl;
  }

  else if(A==0 && B==0){
    cout << 0 << endl;
  }

  else if(N%(A+B)<A){
    cout << ((N/(A+B))*A)+(N%(A+B)) << endl;
  }

  else{
    cout << ((N/(A+B)*A)+A) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>

using namespace std;

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

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); }

int dy[] = {1,0,-1,0};//次に行くところ
int dx[] = {0,1,0,-1};//上に同じ


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

  vector<int> a(3);
  for (int i = 0; i < 3; i++){
    cin >> a[i];
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++){
    int c = 0;
    if (a[0] >= a[1]){
      a[1] *= 2;
      c++;
    }else if (a[1] >= a[2] && c == 0){
      a[2] *= 2;
      c++;
    }if (a[0] <= a[1] && a[1] <= a[2] && c == 0){
      a[2] *= 2;
    }
  }
  if (a[0] < a[1] && a[1] < a[2]){
    
    cout << "Yes\n";
  }else{
    
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3560
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
//        int a = sc.nextInt();
        System.out.println(n*n*3);

    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
vector<int> x4 = {0, 1, 0, -1};
vector<int> y4 = {1, 0, -1, 0};
vector<int> x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

struct edge {
  int to, cost;
  edge(int to, int cost) : to(to), cost(cost) {}
};
typedef pair<int, int> P; // firstは最短距離、secondは頂点の番号

int N; // 頂点数
const int MAX_N = 100000;
const int INFC = 1000000000;
vector<vector<edge>> G(MAX_N);
vector<int> d(MAX_N); // 頂点sからの最短距離

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que; // 小さい順に取り出す
  rep(i, N) d[i] = INFC;
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i=0; i<G[v].size(); i++){
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  cin >>N;
  int M; cin >>M;
  int s; cin >>s;
  rep(i, M){
    int a,b,c; cin >>a >>b >>c;
    G[a].push_back(edge(b, c));
  }
  dijkstra(s);
  rep(i, N){
    if (d[i] == INFC) cout <<"INF";
    else cout <<d[i];
    cout <<endl;
  }
}


Measured memory_bytes: 13008
#include<stdio.h>
#include<math.h>

int main(void){
	int n;
	char box[9][9]={0};
	int ans[9][9]={0};
	int x[100]={0},y[100]={0};
	int l,i,j,count=0;
	int start_x=0,start_y=0;
	int end_x=0,end_y=0;
	
	scanf("%d\n",&n);
	for(l=0;l<n;l++){
	for(i=0;i<8;i++)scanf("%s",box[i]);
	
	scanf("%d %d",&x[0],&y[0]);

	x[0]--;
	y[0]--;
	
	for(j=0;j<=count;j++){
		
		if(x[j]<=3)start_x=0;
		else start_x=x[j]-3;
		if(y[j]<=3)start_y=0;
		else start_y=y[j]-3;
	
		if(x[j]+3>=8)end_x=7;
		else end_x=x[j]+3;
		if(y[j]+3>=8)end_y=7;
		else end_y=y[j]+3;
		
		
		for(i=start_x;i<=end_x;i++){
			if(box[y[j]][i]=='1'){
				count++;
				y[count]=y[j];
				x[count]=i;
				box[y[j]][i]='0';
			}
		}
		
		for(i=start_y;i<=end_y;i++){
			if(box[i][x[j]]=='1'){
				count++;
				x[count]=x[j];
				y[count]=i;
				box[i][x[j]]='0';
			}
		}
	}
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				if(box[i][j]=='0')ans[i][j]=0;
				else if(box[i][j]=='1')ans[i][j]=1;
			}
		}	
		
		printf("Data %d:\n",(l+1));
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				printf("%d",ans[i][j]);
			}
			printf("\n");
		}	
		count=0;
	}
	return 0;
}

Measured memory_bytes: 600
S = input()

ans = 0
save = 0

for i in range(len(S)):
    if S[i] == 'g':  # グーの時の処理
        if save > 0:  # パーが出せるなら勝ちにいく
            save -= 1
            ans += 1
        else:  # パーが出せないならグーを出してあいこをしかける
            save += 1
    elif S[i] == 'p':  # パーの時の処理
        if save > 0:  # パーが出せるならあいこをしにいく
            save -= 1
        else:  # 負けるしかない
            save += 1
            ans -= 1

print(ans)
        

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=9111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}

int dp[2222][2222];

signed main(){
    int N,K;
    cin>>N>>K;

    if(K==1){
        cout<<1<<endl;
        return 0;
    }

    dp[0][0]=1;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            if(i<N&&i<=j)add(dp[i+1][j],dp[i][j]);
            if(j<N){
                add(dp[i][j+1],dp[i][j]*nCk(K-2+i-1+j*(K-1),K-2)%mod);
            }
        }
    }

    cout<<dp[N][N]*fact[N]%mod<<endl;

    return 0;
}


Measured memory_bytes: 179072
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a, b;
    cin >> a >> b;
    ll cnt = 0, g = __gcd(a, b);
    for(ll i = 2; i*i <= g; i++)
    {
        if(g%i != 0) continue;
        cnt++;
        while(g%i == 0) g /= i;
    }
    if(g != 1) cnt++;
    cout << cnt+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int S;
    cin >> S;
    if(S<3){
        cout << 0 << endl;
        return 0;
    }
    vector<ll> ans(S+1);
    // ans[i] = ans[i-3] + ans[i-4] + ... + ans[0]
    // ans[i-1] =          ans[i-4] + ... + ans[0]
    // ans[i] = ans[i-1] + ans[i-3]
    ans[3]=1;
    for(int i=4;i<=S;i++){
        ans[i] = ans[i-1] + ans[i-3];
        ans[i] %= MOD;
    }
    cout << ans[S] << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

        int n = in.nextInt();
        int res = 0;
        while(n-- > 0) {
            int x = in.nextInt();
            res += num2(x);
        }
        out.println(res);

        out.close();
        //INT OVERFLOW -> USE LONG
        //ARR OUT OF BOUNDS
    }

    static int num2(int x) {
        int res = 0;
        while((x & 1) == 0) {
            x >>= 1;
            res++;
        }
        return res;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public double[] nextDoubleArray(int n) {
            double[] arr = new double[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextDouble();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

        public char[] nextCharArray(int n) {
            char[] arr = nextLine().trim().replaceAll("\\s", "").toCharArray();
            return arr;
        }

        public String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 27220
#include <iostream>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

int main(int argc, char **argv)
{
        int V, E;
        cin >> V >> E;

        int64_t D[100][100];
        for (int i = 0; i < V; i++)
                for (int j = 0; j < V; j++)
                        D[i][j] = i == j ? 0 : INT_MAX;

        for (int i = 0; i < E; i++) {
                int s, t, d;
                cin >> s >> t >> d;
                D[s][t] = d;
        }

        for (int k = 0; k < V; k++)
                for (int i = 0; i < V; i++)
                        for (int j = 0; j < V; j++)
                                if (D[i][k] != INT_MAX && D[k][j] != INT_MAX)
                                        D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
        
        for (int i = 0; i < V; i++) {
                if (D[i][i] < 0) {
                        cout << "NEGATIVE CYCLE" << endl;
                        return 0;
                }
        }

        for (int i = 0; i < V; i++) {
                for (int j = 0; j < V; j++) {
                        if (D[i][j] == INT_MAX)
                                cout << "INF";
                        else
                                cout << D[i][j];
                        cout << (j == V - 1 ? '\n' : ' ');
                }
        }

        return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll max1=0,max2=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        if(max1<a[i]){
            max2=max1;
            max1=a[i];
        }
        else if(max2<a[i]){
            max2=a[i];
        }
    }
    for(ll i=0;i<n;i++){
        if(a[i]!=max1)cout<<max1<<endl;
        else cout<<max2<<endl;
    }
}

Measured memory_bytes: 3200
#include<stdio.h>
int main(){
	int n;
	scanf("%d", &n);
	int hasil=0;
	
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j==n){
				i=10,j=10;
				hasil=1;
			}
		}
	}
	
	if (hasil==1) printf("Yes");
	else printf("No");
}

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

using namespace std;

int n,k,i,j;
int tablica[103];
int dp[103][100003];
int tablica2[103][100003];
 
int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k;
    for(i=1;i<=n;i++){
        cin >> tablica[i];
    }
    for(i=0;i<=n;i++){
        dp[i][0]=1;
        tablica2[i][0]=1;
    }
    for(i=0;i<=k;i++){
        tablica2[0][i]=1;
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=k;j++){
            if(j-tablica[i]<=0){
                dp[i][j]=tablica2[i-1][j];
            }
            else{
                dp[i][j]=(tablica2[i-1][j]-tablica2[i-1][j-tablica[i]-1]+1000000007)%1000000007;
            }
        }
        for(j=1;j<=k;j++){
            tablica2[i][j]=(tablica2[i][j-1]+dp[i][j])%1000000007;
        }
    }
    cout << dp[n][k];
    return 0;
}

Measured memory_bytes: 80128
def solve(n, s_list):
    max_score = sum(s_list)

    if max_score % 10 != 0:
        return max_score
    else:
        for i in s_list:
            if (max_score - i) % 10 != 0:
                return max_score - i
    return 0

if __name__ == "__main__":
    n = int(input())
    s_list = sorted([int(input()) for i in range(n)])
    print(solve(n, s_list))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>
using namespace std;
typedef long long ll;




// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    vector<int> A(5);
    for (int i = 0; i < 5; i++) cin >> A[i];
    vector<int> P = { 0,1,2,3,4 };
    int ans = 1e9;
    do {
        int num = 0;
        for (int i = 0; i < 5; i++) {
            while (num % 10 != 0) num++;
            num += A[P[i]];
        }
        ans = min(num, ans);
    } while (next_permutation(P.begin(), P.end()));
    cout << ans << endl;
}


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

void solve(long long A, long long B){
	int ans = (int)B/100 - (int)A/100 + 1;

	int upperA = (int)(A/1000);
	int upperB = (int)(B/1000);
	int lowerA = A%100;
	int lowerB = B%100;
	int valA = (int)(A%10000/1000)*10 + (int)(A/10000);
	int valB = (int)(B%10000/1000)*10 + (int)(B/10000);
	if (valA < lowerA){
		ans--;
	}
	if (valB > lowerB){
		ans--;
	} 
	
	cout << ans << endl;
}

int main(){	
	long long A;
	long long B;
	scanf("%lld",&A);
	scanf("%lld",&B);
	solve(A, B);
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" : "<<x<<'\n';
#define int long long
#define PI 3.141592653589793238

double angle(int hr,int mi){
	double h = (60*hr+mi)*0.5;
	double m = mi*6;
	return min(abs(h-m),360-abs(h-m));
}

void solve()
{
	int a,b,h,m; cin>>a>>b>>h>>m;
	double theta = angle(h,m);
	double c = sqrt(a*a + b*b - 2*a*b*cos(theta*PI/180));
	cout<<fixed<<setprecision(15)<<c<<'\n';
}

main()
{
	int t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 4168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	cout << "Christmas";
	rep(i, 25 - n) {
		cout << " Eve";
	}
	cout << endl;
}


Measured memory_bytes: 256
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')

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

using namespace std;

static const int INF = 1e9 + 7;

void hawawa()
{
  long long n, a, b;
  cin >> n >> a >> b;
  if (a > b || (n == 1 && a != b)) {
    cout << "0\n";
    return;
  }
  long long ans = (b * (n - 1) + a) - (a * (n - 1) + b) + 1;
  cout << ans << "\n";
}

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

Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
int n,m,a[300][300],k[300],x=1e5;
set<int> s;

void f(int p){
    int c[300],d=0;
    fill(c, c+m, 0);
    for(int i=0;i<n;i++){
        bool f=true;
        while(f){
            if(s.find(a[i][k[i]])==s.end()){
                f=false;
            }else{
                k[i]++;
            }
        }
        c[a[i][k[i]]]++;
        if(c[a[i][k[i]]]>c[d])d=a[i][k[i]];
    }
    x=min(x, c[d]);
    s.insert(d);
    if(p<m-1)f(p+1);
}

int main(void){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            a[i][j]--;
        }
        k[i]=0;
    }
    f(0);
    cout<<x<<endl;
}


Measured memory_bytes: 1024
s = input()
score = 0
toUse = 0
for it in s:
  if it == 'g' and toUse > 0:
    toUse -= 1
    score += 1
    continue
  if it == 'g':
    toUse += 1
    continue
  if toUse > 0:
    toUse -= 1
  else:
    toUse += 1
    score -=1
    
print(score)


Measured memory_bytes: 3316
/*
ID: barish21
LANG: C++14
TASK: test
*/

/****Author: Barish Namazov****/
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>

using namespace std;

/***TEMPLATE***/
#define intt long long

#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sz(s) (intt)s.size()

#define ms0(arr) memset(arr,0,sizeof arr)
#define ms63(arr) memset(arr,63,sizeof arr)

#define forn(i,a,b) for(intt i=a;i<=b;i++)
#define rofn(i,a,b) for(intt i=a;i>=b;i--)
#define setf(it,myset) for(set<intt>::iterator it=myset.begin();it!=myset.end();it++)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define VI vector<intt>
#define PII pair<intt,intt>
#define VPII vector< PII >

#define posl(ch) (int)(ch-'a'+1)
#define posL(ch) (int)(ch-'A'+1)

#define IO ios_base::sync_with_stdio(false);cin.tie();
/***************/

/***Additional Functions***/
intt powmod(intt a,intt b,intt mod){intt res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
intt gcd(intt a,intt b){return __gcd(a, b);}
intt lcm(intt a,intt b){return a*b/gcd(a,b);}
intt is_prime(intt n){if(n==1)return 0;if(n==2)return 1;if(n%2==0)return 0;for(intt i=3;i<=sqrt(n);i+=2)if(n%i==0)return 0;return 1;}
intt is_integer(double n){if(floor(n)==ceil(n))return 1;return 0;}

intt sto_int(string s){stringstream ss(s);intt n;ss>>n;return n;}
string to_string(intt n){stringstream ss;ss<<n;string s=ss.str();return s;}

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

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    IO;
    intt a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 764
def main():
  import sys
  n,s,_,*t=sys.stdin.buffer.read().split()
  n=int(n)
  d=[0]*n+[1<<c-97for c in s]
  for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
  for q,a,b in zip(*[iter(t)]*3):
    i,s=int(a)+n-1,0
    if q<b'2':
      d[i]=1<<b[0]-97
      while i>1:
        i//=2
        d[i]=d[i+i]|d[i-~i]
      continue
    j=int(b)+n
    while i<j:
      if i&1:
        s|=d[i]
        i+=1
      if j&1:
        j-=1
        s|=d[j]
      i//=2
      j//=2
    print(bin(s).count('1'))
main()

Measured memory_bytes: 45536
#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 = 1e9;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  ll n, k, g, ans = 0, mx = 0;
  cin >> n >> k;
  vector<ll> a(n);

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mx = max(mx, a[i]);
    if (i == 0) g = a[0];
    g = gcd(g, a[i]);
  }

  if (k <= mx && k % g == 0)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 3972
### classes

class Pt
  attr_accessor :x, :y

  def initialize() end
  def initialize(x, y) @x = x; @y = y end

  def ==(pt) @x == pt.x && @y == pt.y end
  def +(pt) Pt.new(@x + pt.x, @y + pt.y) end
  def -(pt) Pt.new(@x - pt.x, @y - pt.y) end
  def -@() Pt.new(-@x, -@y) end
  def *(t) Pt.new(@x * t, @y * t) end
  def /(t) Pt.new(@x / t, @y / t) end
  def dot(v) @x * v.x + @y * v.y end
  def cross(v) @x * v.y - @y * v.x end
  def d2() @x * @x + @y * @y end
  def d() Math.sqrt(d2()) end
  def to_s() "(#{@x},#{@y})" end
end

### subroutines

def cross_segs(a0, a1, b0, b1)
  av = a1 - a0
  bv = b1 - b0
  cr01 = av.cross(bv)
  return nil if cr01 == 0.0

  ab = b0 - a0
  cr0 = ab.cross(av)
  cr1 = ab.cross(bv)

  t0 = cr1 / cr01
  t1 = cr0 / cr01

  cl = av * t0 + a0
  #p [ap.to_s, av.to_s, bp.to_s, bv.to_s, cl.to_s]
  return nil if t0 < 0.0 || t0 > 1.0 || t1 < 0.0 || t1 > 1.0
  [cl, t0]
end

### main

gets.to_i.times do
  xa, ya, xb, yb = gets.split.map(&:to_f)
  pta = Pt.new(xa, ya)
  ptb = Pt.new(xb, yb)
  
  n = gets.to_i

  lns = []
  for i in (0...n)
    x0, y0, x1, y1, oi, li = gets.split.map(&:to_i)
    lns << [Pt.new(x0.to_f, y0.to_f), Pt.new(x1.to_f, y1.to_f), oi, li]
  end
  #p lns
  
  cts = []

  for i in (0...n)
    pt0, pt1, oi, li = lns[i]
    csg = cross_segs(pta, ptb, pt0, pt1)
    if csg
      cts << [csg[1], (oi ^ 1) ^ li]
    end
  end
  cts.sort!
  #p cts

  count = 0
  if cts.length > 1
    prvl = cts[0][1]
    for i in (1...cts.length)
      count += 1 if prvl != cts[i][1]
      prvl = cts[i][1]
    end
  end

  puts count
end

Measured memory_bytes: 6116
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#define rep(i,s,n) for(int i=s;i<n;i++);
#define all(x) (x).begin,(x).end;
typedef long long ll;
using namespace std;
int n;
string s;

int main() {
	cin >> n >> s;
	int ans = n;
	for(int i=0;i<n-1;i++)
		if (s.at(i) == s.at(i + 1))
			ans -= 1;
	cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(void){
    long int K, A, B;
    long int bis=1;
    scanf("%ld %ld %ld", &K, &A, &B);
    if(B-A > 2){
        if(K < A-1){
            bis+=K;
            printf("%ld\n",bis);
            return 0;
        }
        K-=(A-1);
        bis=A;
        bis += (K/2)*(B-A) + (K%2)*1;
    }else{
        bis+=K;
    }
    printf("%ld\n",bis);
    return 0;
}


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

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        rep(i,N){
            par[i] = i;
        }
    }

    int root(int x) { 
        if (par[x] == x){
            return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry){
            return; 
        }
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M,count;
    cin >> N >> M;
    count = 0;

    UnionFind tree(N);

    rep(i,M){
        int  x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }


    rep(i,N){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3764
until (n = gets.to_i).zero?
  x, y = Array.new, Array.new
  n.times do
    xy = gets.split
    x << xy[0].to_i
    y << xy[1].to_i
  end
  m = gets.to_i
  a = 0
  nx, ny = 10, 10
  m.times do
    dl = gets.split
    d = dl[0].to_s
    l = dl[1].to_i
    l.times do
      case d
      when 'N'
        ny += 1
      when 'E'
        nx += 1
      when 'W'
        nx -= 1
      when 'S'
        ny -= 1
      end
      (0 .. n-1).each do |i|
        if x[i] == nx and y[i] == ny then
          a += 1
          x[i] = -1
          y[i] = -1
        end
      end
    end
  end
  if n == a then
    puts 'Yes'
  else
    puts 'No'
  end
end

Measured memory_bytes: 8644
var s = require("fs").readFileSync("/dev/stdin", "utf8");
var n = parseInt(s.split("\n")[0].split(" ")[0], 10);
var x = parseInt(s.split("\n")[0].split(" ")[1], 10);
var a = s.split("\n")[1].split(" ").map(e => parseInt(e, 10)).sort((a, b) => a - b);
var cnt = 0;
for (var i = 0; i < n; i++) {
  if (x >= a[i]) {
    x -= a[i];
    cnt++;
  } else {
    break;
  }
}
if (x > 0 && cnt >= n) {
  cnt--;
}
console.log(cnt);


Measured memory_bytes: 21192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long x[100010];
	long long n, a, b;
	long long co = 0;
	cin >> n >> a >> b;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		if (i != 0) {
			if ((x[i] - x[i - 1]) * a < b) {
				co += (x[i] - x[i - 1]) * a;
			}
			else {
				co += b;
			}
		}
	}
	cout << co << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define fi first
#define se second
#define reset(n,k) memset((n),k,sizeof(n))
#define all(n) n.begin(),n.end()
#define pb push_back
using namespace std;
using ll=long long;
using pii=pair<int,int>;
int cnt[100005];
vector<int> hate[100005];
int pa[100005];
int siz[100005];

int fp(int x){
	if(x==pa[x])return x;
	return pa[x] = fp(pa[x]);
}

void merge(int x,int y){
	x = fp(x) , y = fp(y);
	if(x == y)return;
	if(siz[x] < siz[y]) swap(x,y);
	siz[x] += siz[y];
	pa[y] = x;
}



int main(){
	IOS;
	ll n,m,k;
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++) pa[i] = i , siz[i] = 1;
	for(int i=1,a,b;i<=m;i++){
		cin>>a>>b;
		cnt[a] ++;
		cnt[b] ++;
		merge(a,b);
	}
	for(int i=1,a,b;i<=k;i++){
		cin>>a>>b;
		hate[a].pb(b);
		hate[b].pb(a);
	}
	
	for(int i=1;i<=n;i++){
		ll ta = siz[fp(i)];
		ta = ta - 1 - cnt[i];
		for(auto x:hate[i]){
			if(fp(x) == fp(i)){
				ta--;
			}
		}
		cout<<ta<<" \n"[i==n];
	}
	
}


Measured memory_bytes: 7168
#include<stdio.h>

int n, p[100];

int min(int x, int y){

  if(x>y)return y;

  else return x;

}

void matrixChainOrder(int* p){

  int q, i, j, k, l, m[100][100];

  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i+l-1;
      m[i][j] = 1000000000;
      for(k=i;k<=j-1;k++){
	q = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j], q);
      }
    }
  }
  printf("%d\n",m[1][n]);
}

int main(){

  int a,i,cnt=0;

  scanf("%d",&n);

scanf("%d",&p[0]);

  for(i=1;i<=n;i++){

  
scanf("%d",&p[i]);
 if(i!=n)scanf("%d",&a);
 
  }

  /* for(i=0;i<=n;i++){
      printf("%d\n",p[i]);
      }*/

  	 matrixChainOrder(p);

       return 0;
       }

Measured memory_bytes: 632
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function ftAdd(ft::Array{Int,1},k::Int,x::Int)
	t = k
	n = length(ft)
	while t<=n
		ft[t] += x
		t += t&(-t)
	end
	ft
end

function ftSum(ft::Array{Int,1},ll::Int,rr::Int)
	l = ll
	r = rr
	s = 0
	while r>0
		s += ft[r]
		r -= r&(-r)
	end
	while l>0
		s -= ft[l]
		l -= l&(-l)
	end
	s
end

function main()
	n = readline() |> parseInt
	s = readline() |> chomp
	t = [Int(s[i])-96 for i in 1:n]
	d = [zeros(Int,n) for i in 1:26]
	for i in 1:n
		ftAdd(d[t[i]],i,1)
	end
	q = readline() |> parseInt
	for iter in 1:q
		qr = readline() |> chomp |> split
		if qr[1][1]=='1'
			k = parseInt(qr[2])
			ftAdd(d[t[k]],k,-1)
			ftAdd(d[Int(qr[3][1])-96],k,1)
			t[k] = Int(qr[3][1])-96
		else
			l = parseInt(qr[2])-1
			r = parseInt(qr[3])
			f = 0
			for i in 1:26
				if ftSum(d[i],l,r)>0
					f += 1
				end
			end
			println(f)
		end
	end
end

main()

Measured memory_bytes: 244900