akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <vector>
#include <queue>
 
#define MAX_V 1024
using namespace std;
 
void get_map();
void check();
struct edge
{
  int to;
  int weight;
};
 
 
const int INF = INT_MAX/4;
vector<edge> g[2000];
int graph[MAX_V][MAX_V];
int dist[MAX_V];
int numofedge;
int vertex;
int start;
int flag=0;
 
int main()
{
  get_map();
  check();
  //for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      //if(i==j)
        {
          if(graph[start][j]<INF/2 && graph[j][j]<0)
        {
          cout << "NEGATIVE CYCLE" <<endl;
          return 0;
        }
        }
    }
    }
   
    for(int i=0;i<vertex;i++)
      {
    if(graph[start][i]>=INF/2)
      {
        cout << "INF" << endl;
      }
    else
      {
    cout << graph[start][i] << endl;
      }
      }
  return 0;
}
 
int fastmin(int a, int b)
{
    int c = a-b;
  return (((c)>>31)&(c))+b;
}
 
void check()
{
  //  int next;
  //int here = start;
  //for(int i=0;i<vertex;i++)
   
  for(int k=0;k<MAX_V;k++)//v=4
    {
      for(int i=0;i<MAX_V;i++)
    {
      int gik= graph[i][k];
      for(int j=0;j<MAX_V;j++)
        {

          //if(graph[i][k] !=INF && graph[k][j]!=INF)
        {
          graph[i][j]= min(gik+graph[k][j], graph[i][j]);
        }
        }
    }
    }
   
}
 
void get_map()
{
  int edge, from ,to;
  cin >> vertex >> numofedge >> start;
   
  fill(graph[0], graph[vertex], INF);
   
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
      {
    if(i==j)
      {
        graph[i][j]=0;
      }
    /*else
      {
        graph[i][j]=INF;
        }*/
      }
    }
 
  /*for(int i=0;i<vertex;i++)
    {
      dist[i]=INF;
    }
  */
  for(int i=0;i<numofedge;i++)
    {
      cin>>from>>to;
      cin >> graph[from][to];
    }
 
  /*  for(int i=0;i<numofedge;i++)
    {
      int from, to, weight; 
      cin >> from >> to >> weight;
      g[from].push_back({to , weight});
   }
  */ 
 
  /*  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }
      cout << endl;
      }*/
  // dist[start]=0;
   
  /*  cout << vertex << endl;
  for(int i=0;i<vertex;i++)
    {
      for(int j=0;j<vertex;j++)
    {
      cout << graph[i][j] << " ";
    }  
      cout << endl;    
      }*/
   
 
}

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

using namespace std;

class UnionFind {
private:
  int n;
  vector<int> a;
public:
  UnionFind(int n) : n(n), a(n, -1) {}
  int find(int x) {return a[x] < 0 ? x : (a[x] = find(a[x]));}
  bool equal(int x, int y) {return find(x) == find(y);}
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (a[x] > a[y]) swap(x, y);
    a[x] += a[y];
    a[y] = x;
    --n;
  }
  int size() {return n;}
  int size(int x) {return -a[find(x)];}
};

int main() {
  int n, q;
  cin >> n >> q;
  UnionFind uf(n);
  for (int i = 0; i < q; ++i) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      uf.unite(x, y);
    } else {
      cout << (uf.equal(x, y) ? 1 : 0) << endl;
    }
  }
}

Measured memory_bytes: 1232
// finish date: 2018/01/15
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int i=a;i<b;i++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000

int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}

vector<int> a;
vector<int> b;
vector<vector<int>> path;
vector<bool> isPassed;
int N;

int calc(int pos = 0, int depth = 1) {
    if (depth == N) return 1;
    int nextpos;
    int sum=0;
    rep(i,path[pos].size()){
        nextpos = path[pos][i];
        if(isPassed[nextpos]) continue;
        isPassed[nextpos]=true;
        sum += calc(nextpos,depth+1);
        isPassed[nextpos]=false;
    }
    return sum;
}


int main() {
    int M;
    cin >> N >> M;
    a = vector<int>(M);
    b = vector<int>(M);
    path = vector<vector<int>>(N);
    isPassed = vector<bool>(N, false);
    isPassed[0] = true;

    rep(i, M) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        path[a[i]].emplace_back(b[i]);
        path[b[i]].emplace_back(a[i]);
    }
    cout << calc() << endl;

    return 0;
}


Measured memory_bytes: 256
n, t = list(map(int, input().split()))
a = [list(map(int, input().split())) for i in range(n)]

cost = []
time = []
for i in range(n):
    cost.append(a[i][0])
    time.append(a[i][1])

l = []
count = 0

for i in range(n):
    if t < time[i]:
        count += 1
    else:
        l.append(cost[i])

if count == n:
    print("TLE")
else:
    print(min(l))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define LL long long

LL pow(LL a, LL x) {
    LL tmp = 1;
    for(LL i = 0; i < x; ++i) {
        tmp *= a;
    }
    return tmp;
}

int main()
{
    LL n, m;
    cin >> n >> m;
    cout << (100*n + 1800*m)*pow(2, m) << endl;
    return 0;
}

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

int insertionSort(vector<int> &A, int N, int g, int &cnt) {
  int v, j;

  for (int i = g; i < N; i++) {
    v = A.at(i);
    j = i - g;

    while (j >= 0 && A.at(j) > v) {
      A.at(j + g) = A.at(j);
      j -= g;
      cnt++;
    }

    A.at(j + g) = v;
  }
}

int shellSort(vector<int> &A, int N) {
  int cnt = 0;
  vector<int> tmpG;
  int index = 0;

  while (true) {
    int tmp = 0;

    // 1 から始めて 3n + 1 していく
    if (index == 0) {
      tmp = 1;
    } else {
      tmp = (3 * tmpG.at(index - 1)) + 1;
    }

    if (tmp <= N) {
      tmpG.push_back(tmp);
    } else {
      break;
    }

    index++;
  }

  int m = 0;
  vector<int> G(tmpG.size());
  int indexG = tmpG.size() - 1;

  cout << tmpG.size() << endl;

  while (true) {
    G.at(m) = tmpG.at(indexG);

    cout << G.at(m);

    if (m == tmpG.size() - 1) {
      cout << endl;
    } else {
      cout << " ";
    }

    if (indexG == 0) {
      break;
    }

    m++;
    indexG--;
  }

  for (int i = 0; i < tmpG.size(); i++) {
    insertionSort(A, N, G.at(i), cnt);
  }

  cout << cnt << endl;
}

int outputVector(vector<int> vec, int N) {
  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }
}

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  shellSort(A, N);
  outputVector(A, N);
}



Measured memory_bytes: 10780
#include <stdio.h>
int main(void) {
	
	// ?????????????????\???
	int number;
	scanf("%d",&number);
	
	int sum = number;
	
	// ???????????????
	for(int cnt = 0; cnt < 2; cnt++) {
		
		sum *= number;
		
	}
	
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 1776
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>

int main(){
  long N,D;
  std::cin >> N >> D;
  long X[200000],Y[200000];
  for(long i=0; i<N; i++){
    std::cin >> X[i] >> Y[i];
  } 
  long count=0;
  for(long i=0; i<N; i++){
    if(X[i]*X[i]+Y[i]*Y[i]<=D*D){
      count++;
    }
  }
  std::cout << count << std::endl;
  return 0;
}

Measured memory_bytes: 6756
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

#include <array>

using namespace std;

int main ()
{
	double x;
	while( cin >> x )
	{
		cout <<(int) ( pow ( x  , 2.0 )/(2*9.8) + 5 +5-(1e-19)) / 5 << endl;
	}
}

Measured memory_bytes: 1232
n = int(input())
s = [input() for _ in range(n)]

numAC = 0
numWA = 0
numTLE = 0
numRE = 0

for i in s:
    if i == "AC":
        numAC += 1
    elif i == "WA":
        numWA += 1
    elif i == "TLE":
        numTLE += 1
    elif i == "RE":
        numRE += 1
        

print("AC x " + str(numAC))
print("WA x " + str(numWA))
print("TLE x " + str(numTLE))
print("RE x " + str(numRE))


Measured memory_bytes: 16332
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ve<ll> dp(2005,0);
    dp[0]=1;
    for(ll i=1;i<=2000;i++)
        for(ll j=3;j<=2000;j++)
            if(i-j>=0)
                dp[i]=(dp[i]+dp[i-j])%A;
    ll n;
    cin>>n;
    cout<<dp[n];
    subt;
    return 0;
}

Measured memory_bytes: 3836
import copy
import sys

sys.setrecursionlimit(10 ** 7)

N = int(input())
uvw = [list(map(int, input().split(' '))) for _ in range(N - 1)]

# 適当に最初の色を決める
# その点を親として、
# 親からの距離が偶数だったら親と同じ色
# 親からの距離が奇数だったら親と違う色

children = [[] for _ in range(N + 1)]

for e in uvw:
    children[e[0]].append([e[1], e[2]])
    children[e[1]].append([e[0], e[2]])

pool = [1]
result = [0 for i in range(N + 1)]  # 頂点1は白くする

marked = set()
marked.add(1)

while pool:
    top = pool.pop()
    for child in children[top]:
        child_edge = child[0]
        length = child[1]

        if child_edge not in marked:
            pool.append(child_edge)
            marked.add(child_edge)
        if length % 2 == 0:
            result[child_edge] = 0 if result[top] == 0 else 1
        else:
            result[child_edge] = 1 if result[top] == 0 else 0

for i in result[1:]:
    print(i)


Measured memory_bytes: 65160
// In the name of Allah the Most Merciful. 

import java.util.*;
import java.math.*;

public class Main{
   
    public static void main(String arg[]){
        
        Scanner sc = new Scanner(System.in);
        
        long a , b , x;
        a = sc.nextLong();
        b = sc.nextLong();
        x = sc.nextLong();
        if(a==0) System.out.println(b/x + 1);
        else System.out.println(b/x - (a-1)/x);
        
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <cstring>
#include<string>
#define INF 9999999999
#define MAXN 105
using namespace std;
int q, t, f;
char c;

int main()
{
	string s, strfront, strback;;
	cin >> s;
	//cout << "s0=" << s << endl;
	cin >> q;
	int flag = 0;
	while (q--)
	{
		cin >> t;
		if (t == 1)
		{
			flag++;
			//cout << "s1=" << s << endl;
		}
		else if (t == 2)
		{
			cin >> f;
			cin >> c;
			if (flag % 2 == 0)
			{
				if (f == 2)s.insert(s.end(), c);
				else if (f == 1)
				{
					s.insert(s.begin(), c);
					//	cout << "s2=" << s << endl;
				}
			}
			else if (flag % 2 == 1)
			{
				if (f == 1)s.insert(s.end(), c);
				else if (f == 2)
					s.insert(s.begin(), c);
			}
		}
	}
	if (flag % 2 == 1)
	{
		for (int i = s.length()-1;i >= 0;i--) cout << s[i];
	}
	else cout << s << endl;
}
/*
a
8
2 1 p
1
2 2 c
1
2 1 b
1
2 2 d
1
*/

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

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

  int sum = 0;
  int hoge = 1;
  for (int i=0; i<8; i++) {
    sum += N/hoge - 10 * (N/(hoge*10));
    hoge *= 10;
    
  }

  if(sum!=0 && N%sum==0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};
const int mod = 1e9+7;

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<P>> t(n, vector<P>(n-1));
  rep(i,n){
    cin >> a[i];
    rep(j,a[i]){
      int x, y;
      cin >> x >> y;
      t[i][j] = make_pair(x,y);
    }
  }
  int ans = 0;
  for(int i = 0; i < (1<<n); i++){
    bitset<15> b(i);
    int cnt = b.count();
    bool ok = true;
    rep(j,n){
      if(b.test(j)){
        rep(k,a[j]){
          if(b[t[j][k].first-1] != t[j][k].second) ok = false;
        }
      }
    }
    if(ok) ans = max(ans, cnt);
  }
  cout << ans << endl;
}

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        String line = stdin.readLine();
        String[] temp = line.split(" ");
        int D = Integer.parseInt(temp[0]);
        int T = Integer.parseInt(temp[1]);
        int S = Integer.parseInt(temp[2]);

        if(T*S>=D){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}


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

int main(void){
	int n,m,a,sum=0,i;

	cin>>n>>m;

	for(i=0;i<m;i++){
		cin>>a;
		sum+=a;
	}

	if(n-sum>=0)
		cout<<n-sum<<endl;
	else
		cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"-1\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 300+5;

int dp[maxn][maxn][maxn]; // position, k, previous height index
int h[maxn]; // input height, totheight
vector<int> tot;
signed main(){
    IOS();
    int n, K; cin>>n>>K;
    for (int i = 0; i<n; i++){
        cin>>h[i+1]; tot.pb(h[i+1]);
    }
    tot.pb(0);
    SORT_UNIQUE(tot);
    for (int i = 0; i<n; i++) {
        h[i+1] = lower_bound(ALL(tot),h[i+1]) - tot.begin();
        bug(i,h[i+1]);
    }
    memset(dp, 0x3f, sizeof dp);
    dp[0][K][0] = 0;
    int m = tot.size();
    for (int i = 1; i<=n; i++) {
        for (int k = 0; k<=K; k++) {
            MN(dp[i][k][h[i]] , dp[i-1][k][ h[i-1] ] + max(tot[h[i]]-tot[h[i-1]],0ll));

            for (int ph = 0ll; ph < m; ++ph) {
                MN(dp[i][k][h[i]], dp[i-1][k][ph] + max(tot[h[i]]-tot[ph],0ll));
                MN(dp[i][k][ph] , dp[i-1][k+1][ ph ]);
                MN(dp[i][k][ph] , dp[i-1][k+1][ h[i-1] ] + max(tot[ph] - tot[h[i-1]], 0ll));
            }
        }
    }

    ll re = 0x3f3f3f3f3f3f3f3f;
    for (int k = 0; k<=K; k++) {
        for (int ph = 0; ph < m; ++ph) MN(re, dp[n][k][ph]);
    }
    cout<<re<<endl;

}


Measured memory_bytes: 221952
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n],min=200001,count=0,i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]<min){
      min=a[i];
      count++;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
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);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
    int len=(h2-h1)*60+m2-m1;
    cout<<len-k<<endl;
}


Measured memory_bytes: 3612
from collections import deque

K = int(input())

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

cnt  = 0


while q:
    x = q.popleft()

    cnt += 1
    if cnt == K:
        print(x)
        break

    y = x % 10
    z = 10*x+y
    if y != 0:
        q.append(z-1)
    q.append(z)
    if y != 9:
        q.append(z+1)

            



Measured memory_bytes: 11884
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

void read_problem(int& a, int& b)
{
    scanf("%d %d", &a, &b);
}

int gcd(int a, int b)
{
    if(a < b) swap(a, b);

    if(b == 0) return a;

    int r = a % b;
    return gcd(b, r);
}

// ax + by = 1 ???????§£????±???????(a > b, a, b ?????????????´?)
void solve_eq(int a, int b, int& x, int& y)
{
    // r_k = a*x_k + b*y_k ??¨??¨????????????

    // r_0 = a - q_0*b
    //   x_0 = 1, y_0 = -q_0
    // r_1 = b - q_1*r_0 = -q_1*a + (1+q_0*q_1)*b
    //   x_1 = -q_1, y_1 = 1 + q_0*q_1
    //
    // r_k-2 = q_k*r_k-1 + r_k ??????
    // r_k = r_k-2 - q_k*r_k-1
    //     = a*(x_k-2 - q_k*x_k-1) + b*(y_k-2 - q_k*y_k-1)

    int q0 = a / b;
    int r0 = a % b;
    int x0 = 1;
    int y0 = -q0;
    // ?????????????????´??????b == 1 ?????????
    if(r0 == 0) {
        x = 1;
        y = 1 - a;
        return;
    }
    if(r0 == 1) {
        x = x0; y = y0;
        return;
    }

    int q1 = b / r0;
    int r1 = b % r0;
    int x1 = -q1;
    int y1 = 1 + q0*q1;
    // ?????????????????´?????? r0 == 1 ?????????????????????
    if(r1 == 1) {
        x = x1; y = y1;
        return;
    }

    for(;;) {
        int q2 = r0 / r1;
        int r2 = r0 % r1;
        int x2 = x0 - q2*x1;
        int y2 = y0 - q2*y1;

        if(r2 == 1) {
            x = x2; y = y2;
            return;
        }

        r0 = r1; r1 = r2;
        x0 = x1; x1 = x2;
        y0 = y1; y1 = y2;
    }
}

#define DBG
#undef DBG

int main()
{
    int a, b;
    read_problem(a, b);

    int d = gcd(a, b);
#ifdef DBG
    printf("gcd: %d\n", d);
#endif
    a /= d;
    b /= d;

    bool swp = a < b;
    if(swp) swap(a, b);

    int x, y;
    solve_eq(a, b, x, y);
    if(swp) {
        swap(a, b);
        swap(x, y);
    }

#ifdef DBG
    printf("x = %d + %d * n\n", x, b);
    printf("y = %d - %d * n\n", y, a);
#endif

    double n_cross = (0.0 + y - x) / (0.0 + a + b);
#ifdef DBG
    printf("n_cross: %lf\n", n_cross);
#endif
    int n1 = floor(n_cross);
    int n2 = ceil(n_cross);
    int x1 = x + b * n1;
    int y1 = y - a * n1;
    int x2 = x + b * n2;
    int y2 = y - a * n2;
#ifdef DBG
    printf("%d %d\n", x1, y1);
    printf("%d %d\n", x2, y2);
#endif

    int absum1 = abs(x1) + abs(y1);
    int absum2 = abs(x2) + abs(y2);
    if(absum1 < absum2) {
        printf("%d %d\n", x1, y1);
    }
    else if(absum1 > absum2) {
        printf("%d %d\n", x2, y2);
    }
    else {
        if(x1 <= y1) {
            printf("%d %d\n", x1, y1);
        }
        else {
            printf("%d %d\n", x2, y2);
        }
    }

    return 0;
}

Measured memory_bytes: 2728
import math
a,b,x = map(int,input().split())
if x/(a*a) == b:
    print(0)
elif(x/(a*a)>=b/2):
    print(90 - (math.atan(a/(2*(b -(x/(a*a)))))*180/math.pi))    
else:
     print(90 - ((math.atan(2*x/(a*b*b))*180/math.pi)))

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

vector<string> st(3);

int main() {
  st = {"Sunny", "Cloudy", "Rainy"};
  string S; cin >> S;
  auto iter = find(st.begin(), st.end(), S);
  auto ans_index = (iter - st.begin() + 1) % 3;
  cout << st[ans_index] << endl;
}


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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int dp[20][20] = {};

    while(true) {
        int a, b; cin >> a >> b;
        if(a == 0 && b == 0) break;
        int n; cin >> n;
        rep(i, 20) rep(j, 20) dp[i][j] = 0;
        dp[1][1] = 1;
        rep(i, n) {
            int x, y; cin >> x >> y;
            dp[y][x] = -1;
        }
        REP(i, 1, 19) REP(j, 1, 19) {
            if(dp[i][j] == -1) continue;
            if(dp[i+1][j] != -1) dp[i+1][j] += dp[i][j];
            if(dp[i][j+1] != -1) dp[i][j+1] += dp[i][j];
        }
        cout << dp[b][a] << '\n';
    }
    return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pdi = pair<double, int>;

int N, K;
vector<int> a;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		int tmpa;
		cin >> tmpa;
		a.push_back(tmpa);
	}

	vector<ll> b;
	for (int i = 0; i < N; i++)
	{
		ll tmpb = 0;
		for (int j = i; j < N; j++)
		{
			tmpb += a[j];
			b.push_back(tmpb);
		}
	}

	const int m = 40;
	unordered_set<int> us;
	for (int i = 0; i < b.size(); i++)
	{
		us.insert(i);
	}
	ll ans = 0;
	for (int j = m - 1; j >= 0; j--)
	{
		ans <<= 1;
		unordered_set<int> tmpus;
		int cnt = 0;
		for (const int &i : us) {
			if (((b[i] >> j) & 1) == 1) {
				cnt++;
				tmpus.insert(i);
			}
		}
		if (cnt >= K) {
			ans++;
			us = tmpus;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 29428
#define _CRT_SECURE_NO_WARNINGS
#define TASK "painting"
#pragma comment(linker, "/STACK:210886422")
#include <cstdio>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <assert.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <complex>
using namespace std;

const int MOD = 1000000007;
const int INF = 1000000001;
const double EPS = 1e-11;
const int HASH_POW = 29;
const long double PI = acos(-1.0);
mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

long long nextLong(long long l, long long r) {
	uniform_int_distribution <long long> foo(l, r);
	return foo(rnd);
}

double nextDouble(double l, double r) {
	uniform_real_distribution <double> foo(l, r);
	return foo(rnd);
}

double workTime() {
	return double(clock()) / CLOCKS_PER_SEC;
}

void myReturn(int code = 0) {
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);*/
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
#endif

	int n;
	vector <int> p;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		int x;
		scanf("%d", &x);
		p.push_back(x - i);
	}
	sort(p.begin(), p.end());

	long long ans = 0;
	int pos = n / 2;
	for (int i = 0; i < n; ++i) {
		ans += abs(p[i] - p[pos]);
	}
	printf("%lld\n", ans);

	myReturn();
}

Measured memory_bytes: 1400
#include <iostream>
#include <stack>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#define ll long long
using namespace std;

int main() {
    int n,m;
    vector<int> fac;
    cin>>n>>m;
    for(int i=1;i*i<=m;i++){
        if(m%i==0){
            fac.push_back(i);
            fac.push_back(m/i);
        }
    }
    sort(fac.begin(),fac.end());
    for(int i=fac.size()-1;i>=0;i--){
//cout<<fac[i]<<' ' ;
        
        if(m/fac[i]>=n){
            cout<<fac[i];
            return 0;
        }
    }
}


Measured memory_bytes: 256
N = int(input())
flag = 0
if N < 10:
    print('Yes')
    flag = 1
else:
    for i in range(2,10):
        if N % i == 0 and (N // i) < 10 and flag == 0:
                print('Yes')
                flag = 1

if flag == 0:
    print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a1,a2,a3;
    cin>>a1>>a2>>a3;
    cout<<(a1+a2+a3>=22?"bust":"win")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int N; std::cin >> N;
    bool flag = false;
    for (int i{ 0 }; i < N; ++i) {
        int a; std::cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 && a % 5 != 0)
                flag = true;
        }
    }
    if (flag == true) std::cout << "DENIED" << std::endl;
    else std::cout << "APPROVED" << std::endl;

    return 0;
}


Measured memory_bytes: 3624
// https://beta.atcoder.jp/contests/abc106

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

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

    int i = 0;
    auto one_count = 0;
    while (i < S.length() && S[i] == '1') {
        one_count++;
        i++;
    }

    if (K <= one_count) cout << "1" << endl;
    else cout << static_cast<char>(S[i]) << endl;
    return 0;
}


Measured memory_bytes: 256
use std::cmp;

const INF: u64 = 1e17 as u64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);
    let b = a.iter().rev().map(|&a| a).collect();

    let dp = forward_dp(a);
    let inv = forward_dp(b);

    let mut ans = cmp::min(*dp[n].iter().min().unwrap(), *inv[n].iter().min().unwrap());
    for i in 1..n {
        let prefix = *dp[i].iter().min().unwrap();
        let suffix = *inv[n - i].iter().min().unwrap();
        ans = cmp::min(ans, prefix + suffix);
    }
    println!("{}", ans);
}

// 0 .. 0 e .. e o .. o e .. e 0 .. 0
fn forward_dp(a: Vec<u64>) -> Vec<Vec<u64>> {
    let n = a.len();
    let mut dp = vec![vec![INF; 3]; n + 1];
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;
    for i in 0..n {
        let even_cost = if a[i] == 0 { 2 } else { a[i] % 2 };
        dp[i + 1][0] = cmp::min(dp[i + 1][0], dp[i][0] + a[i]);

        dp[i + 1][1] = cmp::min(dp[i + 1][1], dp[i][0] + even_cost);
        dp[i + 1][1] = cmp::min(dp[i + 1][1], dp[i][1] + even_cost);

        dp[i + 1][2] = cmp::min(dp[i + 1][2], dp[i][0] + (a[i] + 1) % 2);
        dp[i + 1][2] = cmp::min(dp[i + 1][2], dp[i][1] + (a[i] + 1) % 2);
        dp[i + 1][2] = cmp::min(dp[i + 1][2], dp[i][2] + (a[i] + 1) % 2);
    }
    dp
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 30972
#include<iostream>
#include<stdio.h>
using namespace std;




int main() {
	int T, H, S, time;
	while (true) {
		cin >> T >> H >> S;
		if (T == -1 && H == -1 && S == -1) {
			break;
		}
		time = 7200 - (T * 3600 + H * 60 + S);
		printf("%02d:%02d:%02d\n", time / 3600, (time % 3600) / 60, (time % 3600) % 60);
		time = 3 * time;
		printf("%02d:%02d:%02d\n", time / 3600, (time % 3600) / 60, (time % 3600) % 60);



	}
	return 0;
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int MOD = 1e9 + 7;
long long PS[100001], F[100001], FI[100001];

long long mod(long long a)
{
	if (a >= 0) return a % MOD;
	return ((-a / MOD + 1)*MOD + a) % MOD;
}

long long fast_pow(long long a, long long b)
{
	long long ret = 1;
	for (; b; b >>= 1) {
		if (b & 1) ret = (ret*a) % MOD;
		a = (a*a) % MOD;
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	int N;
	long long ans = 0, temp = 0;
	cin >> N;
	F[0] = FI[0] = 1;
	for (int i = 1; i <= N; i++) {
		cin >> PS[i];
		PS[i] = (PS[i] + PS[i - 1]) % MOD;
		F[i] = (F[i - 1] * i) % MOD;
	}
	FI[N] = fast_pow(F[N], MOD - 2);
	for (int i = N - 1; i > 0; i--) {
		FI[i] = (FI[i + 1] * (i + 1)) % MOD;
	}
	for (int i = 1; i < N - 1; i++) {
		temp = mod(temp + PS[N - i] - PS[i]);
		ans = mod(ans + mod(mod(mod(mod(mod(F[N] * FI[2 + i])*F[2])*F[i]))*temp));
		ans = mod(ans + mod(mod(mod(F[N] * FI[1 + i])*F[i])*PS[i]));
		ans = mod(ans + mod(mod(mod(F[N] * FI[1 + i])*F[i])*(PS[N] - PS[N - i])));
	}
	ans = mod(ans + mod(F[N - 1] * PS[N - 1]));
	ans = mod(ans + mod(F[N - 1] * (PS[N] - PS[1])));
	ans = mod(ans + mod(F[N] * PS[N]));
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 2560
import collections

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

c = collections.Counter(A_list)
c_value_list = list(c.values())
#print(c_value_list)

ans = 0

for i in range(len(c_value_list)):
    ans += c_value_list[i]*(c_value_list[i] - 1) // 2

for k in range(N):
    ans_temp = ans - c[A_list[k]] + 1
    print(ans_temp)


Measured memory_bytes: 34064
def resolve():
    S = input()
    pats = ('dream', 'dreamer', 'erase', 'eraser')

    dp = [False for _ in range(len(S) + 1)]
    dp[0] = True
    for i in range(len(S)):
        if not dp[i]:
            continue
        for pat in pats:
            if S[i:i + len(pat)] == pat:
                dp[i + len(pat)] = True
    if dp[-1]:
        print("YES")
    else:
        print("NO")


resolve()


Measured memory_bytes: 9768
def solve():
    A, B, K = map(int, input().split())

    cnt = 0
    for i in range(min(A, B), 0, -1):
        if A % i == 0 and B % i == 0:
            cnt += 1
            if cnt == K:
                print(i)
                exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define for_p(i, a, b) for(int i = a; i < b; i++)
#define for_m(i, a, b) for(int i = a - 1; i >= b; i--)

//a = s1.size();
//vector<string> s1;
//string s2 = accumulate( s1.begin(), s1.end(), string() );

using namespace std;

int main()
{
  int a, b;
  int i, count = 0;
  
  cin >> a >> b;
  
  if(a >= b){
    count += a;
    a--;
  }else{
    count += b;
    b--;
  }
  if(a >= b){
	count += a;
  }else{
    count += b;
  }
  cout << count << endl;
}
  


Measured memory_bytes: 384
class Union:
  def __init__(self, num):
    self.T = [-1 for i in range(num)]

  def root(self, x):
    if self.T[x] < 0: return x
    return self.root(self.T[x])

  def size(self, x):
    return -self.T[self.root(x)]

  def merge(self, x, y):
    a = self.root(x)
    b = self.root(y)
    if a == b: return False
    if self.size(a) < self.size(b): a, b = b, a
    self.T[a] += self.T[b]
    self.T[b] = a
    return True


N, M = list(map(int, input().split()))
XYZ = [list(map(int, input().split())) for i in range(M)]

uni = Union(N)

for x,y,z in XYZ:
  uni.merge(x - 1, y - 1)

Ans = 0
for i in uni.T:
  if i < 0:
    Ans += 1

print(Ans)

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

int main(){
  string s,t,u;
  cin >>s >>t >>u;
  char dif='A'-'a';
  printf("%c%c%c\n" , s[0]+dif , t[0]+dif , u[0]+dif);
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ "; for(auto v : V) os << v << " "; return os << "]";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1<<" | ";
	__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mems(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define irep(i, n) for (int i = 1; i <= n; ++i)
#define print(x) cout << x << '\n'
#define err(x) clog << x << '\n'
typedef long long ll;
#define int ll
typedef long double ld;
#define double ld
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f;
const int M = 1e9+7;
const int N = 1e5+5;

vi g[N];
int dp[N];
bool done[N];

int dfs(int v) {
	if (done[v]) return dp[v];
	int mx = 0;
	for (int u: g[v]) mx = max(mx, dfs(u) + 1);
	dp[v] = mx; done[v] = true;
	return mx;
}

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

	int n, m; cin >> n >> m;
	rep(i, m) {
		int x, y; cin >> x >> y;
		g[x].pb(y);
	}

	int mx = 0;
	irep(i, n) {
		mx = max(mx, dfs(i));
	}

	print(mx);
}


Measured memory_bytes: 8064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        float n = sc.nextFloat();
        sc.close();
        if (n % 2 == 0) {
            System.out.println((n / 2) / n);
        } else {
            System.out.println((((n + 1) / 2)) / n);
        }
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
using namespace std;
long long a[1000000];
signed main(){
  while(1){
    long long n,b,c,d,max;
    b=0;
    cin>>n;
    if(n==0) break;  
    d=n;
    for(int i=0;i<n;i++){
      cin>>c;
      b=b+c;
    }
    max=d*b;
    for(int i=0;i<n-1;i++){
      cin>>a[i];
    }
    sort(a,a+n-1,greater<long long>());
    for(int i=0;i<n-1;i++){
      b=b+a[i];
      d--;
      if(max<b*d){
	max=b*d;
      }
      else{
	break;
      }
    }
    cout<<max<<"\n";
  }
  return(0);
}


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

int n;
int A[32];
int q;
int m[2048];

bool P[65536];

int main(void) {

  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> A[i];
  }
  std::cin >> q;
  for(int i = 0; i < q; ++i) {
    std::cin >> m[i];
  }

  for(int i = 0; i < (1<<n); ++i) {
    int num = 0;
    for(int j = 0; j < n; ++j) {
      if( ( i & (1 << j) ) != 0 ) {
        num += A[j];
      }
    }
    P[num] = true;
  }

  for(int i = 0; i < q; ++i) {
    if( P[m[i]] ) {
      std::cout << "yes" << std::endl;
    }
    else {
      std::cout << "no" << std::endl;
    }
  }
        
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, a, b;
	long long k;
	cin >> n >> k;
	vector<long long> A(100001, 0);
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		A[a] += b;
	}
	int i = 1;
	int ans = 0;
	while (k > 0) {
		k -= A[i];
		if (k <= 0) ans = i;
		++i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
board = [["." for i in range(8)] for i in range(8)]
N = int(input())
row = [1] * 8
col = [1] * 8
dpos = [1] * 15
dneg = [1] * 15


for i in range(N):
  x, y = map(int, input().split())
  row[x] = col[y] = dpos[x+y] =dneg[x-y+7] = 0
  board[x][y] = "Q"

def solve(i):
  while i < 8 and not row[i]:
    i += 1
  if i == 8:
    for i in range(8):
      print(''.join(board[i]))
  for j in range(8):
    if not col[j] or not dpos[i+j] or not dneg[i-j+7]:
      continue
    row[i] = col[j] = dpos[i+j] = dneg[i-j+7] = 0
    board[i][j] ='Q'
    solve(i+1)
    row[i] = col[j] = dpos[i+j] =dneg[i-j+7] = 1
    board[i][j] = '.'

solve(0)


Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
int ans;
string s;
int sta[200010],topp;
int main()
{
	cin>>s;
	for(int i = 0; i < s.length(); i++)
	{
		if(s[i] == 'S') sta[++topp] = 1;
		else if(sta[topp] == 1) topp--;
		else sta[++topp] = 2;
	}
	cout<< topp << endl;
	return 0;
}


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

int a[200005];

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

	int all = 0;
	for (int i = 1; i <= N; i++) {
		cin >> a[i];
		all ^= a[i];
	}

	for (int i = 1; i <= N; i++) {
		cout << (a[i] ^ all) << ' ';
	}

	return 0;
}

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

int main() {
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx = abs(x2 - x1);
  int dy = abs(y2 - y1);

  if (x2 > x1) {
    if (y2 > y1) {
      x3 = x2 - dy;
      y3 = y2 + dx;
    } else {
      x3 = x2 + dy;
      y3 = y2 + dx;
    }
  } else {
    if (y2 > y1) {
      x3 = x2 - dy;
      y3 = y2 - dx;
    } else {
      x3 = x2 + dy;
      y3 = y2 - dx;
    }
  }

  dx = abs(x3 - x2);
  dy = abs(y3 - y2);

  if (x3 > x2) {
    if (y3 > y2) {
      x4 = x3 - dy;
      y4 = y3 + dx;
    } else {
      x4 = x3 + dy;
      y4 = y3 + dx;
    }
  } else {
    if (y3 > y2) {
      x4 = x3 - dy;
      y4 = y3 - dx;
    } else {
      x4 = x3 + dy;
      y4 = y3 - dx;
    }
  }


  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}


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

struct Forest_Uni{
private:
	vector<int> arr;
	int numTrees;
public:
	Forest_Uni():numTrees(0){}
	int add(){
		int p = arr.size();
		arr.push_back(p);
		numTrees++;
		return p;
	}
	int root(int tg){
		int buf = tg;
		while(buf != arr[buf]){
			buf = arr[buf];
		}
		arr[tg] = buf;
		return buf;
	}
	void unite(int a, int b){
		if(root(a) == root(b)) return;
		arr[root(a)] = root(b);
		numTrees--;
	}
	bool same(int a, int b){
		return root(a) == root(b);
	}
	int nTrees(){ return numTrees; }
};



int main(){

	int n, m;
	cin >> n >> m;
	Forest_Uni g;

	for(int i = 0; i< n; i++){
		g.add();
	}

	int x, y, z;
	for(int i = 0; i < m; i++){
		cin >> x >> y >> z;
		g.unite(x-1, y-1);
	}
	
	cout << g.nTrees() << endl;

	return 0;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);

        while(true){
            int w = scan.nextInt();
            int h = scan.nextInt();
            if(w == 0 && h == 0)break;
            int map[][] = new int[w][h];
            for(int i = 0;i < h;i++){
                for(int j = 0;j < w;j++){
                    map[j][i] = scan.nextInt();
                }
            }
            int count = 0;
            for(int i = 0;i < h;i++){
                for(int j = 0;j < w;j++){
                    if(findIsland(map, j, i))count++;
                }
            }

            System.out.println(count);

        }

        scan.close();
    }

    static boolean findIsland(int map[][], int w, int h){
        if(map[w][h] == 0)return false;
         map[w][h] = 0;
        boolean up = false, down = false, right = false, left = false;
        int H = map[0].length;
        int W = map.length;
        if(h-1 >= 0)up = true;
        if(h+1 < H)down = true;
        if(w+1 < W)right = true;
        if(w-1 >= 0)left = true;
        if(up){
            if(map[w][h-1] == 1)
            findIsland(map, w, h-1);
        }
        if(down){
            if(map[w][h+1] == 1)
            findIsland(map, w, h+1);
        }
        if(right){
            if(map[w+1][h] == 1)
            findIsland(map, w+1, h);
        }
        if(left){
            if(map[w-1][h] == 1)
            findIsland(map, w-1, h);
        }
        if(up && right){
            if(map[w+1][h-1] == 1)
            findIsland(map, w+1, h-1);
        }
        if(up && left){
            if(map[w-1][h-1] == 1)
            findIsland(map, w-1, h-1);
        }
        if(down && right){
            if(map[w+1][h+1] == 1)
            findIsland(map, w+1, h+1);
        }
        if(down && left){
            if(map[w-1][h+1] == 1)
            findIsland(map, w-1, h+1);
        }
        return true;

    }

}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		List<String> s = new ArrayList<>();
		for(int i=0; i<N; i++) {
			String word = sc.next();
			if(s.contains(word)) {
				System.out.println("No");
				return;
			}
			s.add(word);
		}

		char c = s.get(0).charAt(0);
		for (String w : s) {
			if(w.charAt(0) == c) {
				c = w.charAt(w.length()-1);
			}else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 21588
def grade score
  avg = score.inject(:+) / score.size
  if score.include?(100) || (score[0] + score[1]) / 2 >= 90 || avg >= 80
    "A"
  elsif avg >= 70 || (avg >= 50 && (score[0] >= 80 || score[1] >= 80))
    "B"
  else
    "C"
  end
end

while (n = $stdin.gets.to_i) != 0 do
  n.times do
    puts grade($stdin.gets.chomp.split(" ").map(&:to_i))
  end
end

Measured memory_bytes: 6100
def read(): return list(map(int, input().split()))


MOD = 10 ** 9 + 7
n, m = read()
x = read()
y = read()

xs, ys = 0, 0
for i in range(n):
    xs += x[i] * (2 * i + 1 - n)
    xs %= MOD

for i in range(m):
    ys += y[i] * (2 * i + 1 - m)
    ys %= MOD

print((xs * ys) % MOD)

Measured memory_bytes: 18624