akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    X = list(map(int, input().split()))
    Y = list(map(int, input().split()))

    XL = [X[i] - X[i - 1] for i in range(1, n)]
    YL = [Y[i] - Y[i - 1] for i in range(1, m)]

    cnt_X = [(i * (n - i)) % mod for i in range(1, n)]
    cnt_Y = [(i * (m - i)) % mod for i in range(1, m)]
    total_X = (sum([(XL[i] * cnt_X[i]) % mod for i in range(n - 1)])) % mod
    total_Y = (sum([(YL[i] * cnt_Y[i]) % mod for i in range(m - 1)])) % mod
    res = (total_X * total_Y) % mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 36912
#include<iostream>
#include<map>
#include<string> 
using namespace std;
int main(){
	int N;
	cin>>N;
	map<string,int>rec;
	for(int i=0;i<N;++i){
		string a;
		cin>>a;
		++rec[a];
	}
	for(auto s:{"AC","WA","TLE","RE"}){
		cout<<s<<" x "<<rec[s]<<endl;
	}
	return 0;
}

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

// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll p = 2; p * p <= n; p++) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      num++;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

int main() {
  ll n;
  cin >> n;
  auto pf = prime_factorize(n);
  ll ans = 0;
  for (auto p : pf) {
    ll e = p.second;
    ll tmp = 0, cur = 1;
    while (e >= cur) {
      e -= cur++;
      tmp++;
    }
    ans += tmp;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3560
# Python template 
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()


(d,t,s)= get_ints()

if(d/s>t):
    print("No")
else:
    print("Yes")
    

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

#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <deque>
#include <bitset>

#include <cmath>
#include <functional>

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for(int i = int(a); i < int(b); ++i)
#define RFOR(i, a, b) for(int i = int(b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define IN(a, x ,b) (a<_x && x < b)
template<class T> inline T CHMAX(T& a, T& b) {return a=(a<b)?b:a;}
template<class T> inline T CHMIN(T& a, T& b){return a=(a>b)?b:a;}

using ll = long long;

using std::vector;
using std::cout;
using std::endl;
using std::cin;


int main(){
  int n, t;
  cin >> n >> t;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  vector<int> g(h);
  REP(i,n-1) CHMAX(g[i+1], g[i]);

  ll sum = 0;
  REP(i, n) {
    sum += h[i];
    ll time = t - sum;
    int ans = 1;
    if(time >= 0) ans = time / g[i] + 2;
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#include <math.h> 


int main(){
    int N,M;
    //vector<int> vec(N);
    cin >> N >> M;
    
    int ans = 0;
    int ans1 = 0;
    int ans2 = 0;
    ans = (N*(N-1));
    ans1 = (M*(M-1));
    ans2 = ans+ans1;

    


    cout << ans2/2 << endl;
    

    
}


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

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		int f = 10 * (s[0] - '0') + (s[1] - '0');
		int b = 10 * (s[2] - '0') + (s[3] - '0');
		bool fm = false;
		bool bm = false;

		if (f > 0 && f <= 12) { fm = true; }
		if (b > 0 && b <= 12) { bm = true; }

		string ans = "NA";
		if (bm && fm) { ans = "AMBIGUOUS"; }
		else if(fm){ ans = "MMYY"; }
		else if(bm){ ans = "YYMM"; }

		Console.WriteLine(ans);
	}
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

struct Magic
{
	int a, b;

	bool operator>(const Magic& another) const {
		return a  > another.a;
	}
};


void solve()
{
	int h, n, a, b;
	cin >> h >> n;
	vector< Magic > magic(n);

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

	sort(magic.begin(), magic.end(), greater<Magic>());

	// モンスターの体力を i 減らすため消耗する魔力の最小値
	vector<int> dp(h + magic[0].a + 1, 1e9);
	dp[0] = 0;

	for(int i = magic[magic.size() - 1].a; i <= h + magic[0].a; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			if (0 <= i - magic[j].a)
			{
				dp[i] = min(dp[i], dp[i - magic[j].a] + magic[j].b);
			}
		}
	}

	int ans = 1e9;
	for(int i = h; i <= h + magic[0].a; ++i)
	{
		ans = min(ans, dp[i]);
	}
	cout << ans;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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(void){
    ll a, b;
    cin >> a >> b;

    cout << lcm(a, b) << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
n, m, c = input().split()
n, m, c = int(n), int(m), int(c)
b = np.array([int(x) for x in input().split()])
counter = 0
for i in range(n):
  temp = np.array([int(x) for x in input().split()])
  if np.dot(temp.T, b) + c > 0:
    counter += 1
print(counter)

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

// KMP 法, 文字列(s, t)に対して, sの中に含まれるwordの接頭辞のうち最長のものの長さを返す
// オプションとして, sのi番目以降から, あるいはwordが何回sに含まれるかを計算できる
int KMP(string word, string s){
    // KMP_table の作成, 同じwordに複数回するなら処理を分けて
    int n = word.size();
    vector<int> table(n+1, -1);
    int j = -1;
    for(int i = 0; i < n; ++i){
        while(j >= 0 && word[i] != word[j]) j = table[j];
        table[i+1] = ++j;
    }

    // KMP法
    int cur = 0, res = 0;
    for(char x : s){
        while(cur >= 0 && word[cur] != x) cur = table[cur];
        ++cur;
        res = max(res, cur);
        if(cur == n) break;
    }

    return res;
}

int main() {
    string s, t;
    cin >> s >> t;

    // KMP法でtをいっぱい並べた文字列の先頭から何文字が含まれるかを調べる
    string tk, sk;
    while(tk.size() < s.size() + t.size()){
        tk += t;
    }
    while(sk.size() < s.size() + t.size() * 2){
        sk += s;
    }
    // sk.size() > tk.size() >= 2 * t.size()

    int mx = KMP(tk, sk);

    int ans = -1;
    if(mx < (s.size() + t.size())){
        ans = mx / t.size();
    }
    cout << ans << "\n";
    return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer x;
  x = nil->next;
  while(x != nil && x->key != key){
    x = x->next;
  }
  return x;
    
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil)return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer t = nil->prev;
  if (t == nil) return;
  deleteNode(t);
}

void delete(int key){
  NodePointer x;
  x = listSearch(key);
  deleteNode(x);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
   
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
    
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
        if ( com[6] == 'F' ) deleteFirst();
        else if ( com[6] == 'L' ) deleteLast();
      } else {
        delete(key); nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}


Measured memory_bytes: 32956
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args)throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        int n=Integer.parseInt(br.readLine());
        int A[]=Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int cost[]=new int[n];
        cost[0]=0;
        cost[1]=cost[0]+Math.abs(A[1]-A[0]);
        for(int i=2;i<n;i++)
        cost[i]=Math.min(cost[i-1]+Math.abs(A[i]-A[i-1]),cost[i-2]+Math.abs(A[i]-A[i-2]));
        bw.write(Integer.toString(cost[n-1]));
        br.close();
        bw.close();
    }
}

Measured memory_bytes: 35868
#include<iostream>
#include<vector>
#include<map>
#include<utility>
using namespace std;
using ll = long long int;
constexpr char L = 'L';
constexpr char R = 'R';
constexpr char U = 'U';
constexpr char D = 'D';


int h, w, n;
int sr, sc;
int rlu, clu;
int rrd, crd;
string s, t;
int scnt[4] = { 0 }, tcnt[4] = { 0 };

void setCharCnt(int* scnt, char c) {
	if (c == L)
		scnt[0]++;
	else if (c == R)
		scnt[1]++;
	else if (c == U)
		scnt[2]++;
	else
		scnt[3]++;
}

void move(char c) {
	if (c == L)
		sr--;
	else if (c == R)
		sr++;
	else if (c == U)
		sc--;
	else
		sc--;
}

int main(void) {
	cin >> h >> w >> n;
	cin >> sr >> sc;
	cin >> s;
	cin >> t;
	sr--; sc--;

	rlu = sr; clu = sc;
	rrd = sr; crd = sc;
	string ret = "YES";
	//左方向と上方向
	for (int i = 0; i < n; i++) {
		char si = s[i], ti = t[i];

		if (si == L)
			clu--;
		else if (si == R)
			crd++;
		else if (si == U)
			rlu--;
		else if (si == D)
			rrd++;
		if (0 <= rlu && rlu < h && 0 <= clu && clu < w && 0 <= rrd && rrd < h && 0 <= crd && crd < w) {
			if (ti == L && 0 < crd)
				crd--;
			else if (ti == R && clu < w - 1)
				clu++;
			else if (ti == U && 0 < rrd)
				rrd--;
			else if (ti == D && rlu < h - 1)
				rlu++;
		}
		else {
			ret = "NO";
			break;
		}
	}
	cout << ret << endl;
	return 0;

}

Measured memory_bytes: 776
a=input()
if a[0]=='R' and a[1]=='R' and a[2]=='R':
  print(3)
elif a[0]=='R' and a[1]=='R':
  print(2)
elif a[1]=='R' and a[2]=='R':
  print(2)
elif a[0]=='R' and a[1]=='S' and a[2]=='S':
  print(1)
elif a[0]=='S' and a[1]=='R' and a[2]=='S':
  print(1)
elif a[0]=='S' and a[1]=='S' and a[2]=='R':
  print(1)
elif a[0]=='R' and a[1]=='S' and a[2]=='R':
  print(1)
else:
  print(0)

Measured memory_bytes: 9032
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <queue>
#include <tuple>
#include <cmath>
#include <map>
#include <cstring>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

using ll = long long;
using ull = unsigned long long;

using Pint = pair<int, int>;
using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
  string s;
	cin >> s;

  s[0] = '2';
  s[1] = '0';
  s[2] = '1';
  s[3] = '8';

  cout << s << endl;
	return ( 0 );
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  long double l; cin >> l;
  printf("%.9Lf\n", l * l * l / 27.0);
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    long long ans = 0;
    int ct = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') {
            ans += (i - ct);
            ct++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 720
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

int main(){
    int n, a[59];
    cin >> n;
    a[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    a[n+1] = 100;

    int tmp=a[0],cnt=0, sl,s, sh, gl,g, gh;
    for(int i=1;i<n;i++){
        if(a[i]>a[i+1]){
            cnt++;
            if(cnt==1){
                sl=a[i-1];
                sh=a[i+1];
                s = a[i];
            }
            if(cnt==2){
                gl = a[i];
                gh=a[i+2];
                g=a[i+1];
            }
        }
    }
    if(cnt==0 || (cnt==2 && sl < g && g < sh && gl < s << gh)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1000*1000*1000+889
const int N = 1010;
int arr[N];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    double a,t;
    cin>>n>>t>>a;
    double mn = INT_MAX;
    int pos;
    for(int i = 0; i < n; ++i)
    {
        cin>>arr[i];
        if(mn > abs(a - (t-arr[i] * 0.006)))
        {
            mn = abs(a - (t - arr[i] * 0.006));
            pos = i + 1;
        }
    }
    cout<<pos;
}


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(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;

    rep(l, n){
        vector<int> A(n+1, 0);
        string S = s.substr(l);
        A[0] = S.size();
        int i = 1, j = 0;
        while (i < S.size()) {
            while (i+j < S.size() && S[j] == S[i+j]) ++j;
            A[i] = j;
            if (j == 0) { ++i; continue;}
            int k = 1;
            while (i+k < S.size() && k+A[k] < j) A[i+k] = A[k], ++k;
            i += k; j -= k;
        }
        // rep(i, n+1) cout << A[i] << " ";
        // cout << endl;
        rep1(i, S.size()+1) chmax(ans, min(i, A[i]));
    }



    cout << ans << endl;

}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
    cin >> a.at(i);
  }
  
  int i = 1;
  int cnt = 0;
  bool b = false;
  while(cnt < n){
    cnt++;
    i = a.at(i-1);
    if (i == 2) {
      b = true;
      break;
    }
  }
  
  if(b) cout << cnt << endl;
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 768
<?php
fscanf(STDIN, '%d', $A);
fscanf(STDIN, '%d', $B);
fscanf(STDIN, '%d', $C);
fscanf(STDIN, '%d', $D);
$train_min = ($A > $B) ? $B : $A;
$bus_min = ($C > $D) ? $D : $C;
echo $train_min + $bus_min;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::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(...)
#endif
map<ll,int> ch;
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  ll n,m;
  cin>>n>>m;
  string s1,s2;
  cin>>s1>>s2;
  ll g=__gcd(n,m);
  ll l=(n*m)/g;
  rep(i,0,n)
    ch[(ll)i*(l/n)+1]=s1[i];
  rep(j,0,m)
    {
      ll tmp=(ll)j*(l/m)+1;
      if(ch.count(tmp) && ch[tmp]!=s2[j])
	{
	  cout<<-1<<endl;
	  return 0;
	}
    }
  cout<<l<<endl;
  return 0 ;
}


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

using namespace std;
int n, m, x;
const int INF = 1e9 + 5;
int min_cost = INF;

int main() {
    scanf("%d %d %d", &n, &m, &x);
    vector<int> cost(n);
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
        scanf("%d", &cost[i]);
        for (int j = 0; j < m; ++j) {
            scanf("%d", &a[i][j]);
        }
    }

    for (int mask = 0; mask < (1 << n); mask++) {
        int cur_cost = 0;
        vector<int> cur_level(m, 0);

        for (int i = 0; i < n; ++i) {
            if ((mask >> i & 1) == 1) {
                cur_cost += cost[i];
                bool found = true;
                for (int j = 0; j < m; ++j) {
                    cur_level[j] += a[i][j];
                    if (cur_level[j] < x) {
                        found = false;
                    }
                }
                if (found) {
                    min_cost = min(min_cost, cur_cost);
                    break;
                }
            }
        }
    }


    if (min_cost == INF) {
        printf("%d\n", -1);
    } else {
        printf("%d\n", min_cost);
    }
    return 0;
}


Measured memory_bytes: 3792
A, B, C, K = map(int, input().split())
if A < K:
    res = A
    K = K - A
elif K <= A:
    res = K
    K = 0
if 0 < K and B < K:
    K = K - B
elif 0 < K and K <= B:
    K = 0
if 0 < K:
    res = res - K 
print(res)

Measured memory_bytes: 9120
#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;
    cin>>s;
    int n=s.size();
    int a=0,b=0,c=0;
    rep(i,n){
        if(s[i]=='a')a++;
        if(s[i]=='b')b++;
        if(s[i]=='c')c++;
    }
    bool ok=false;
    int mx=max({a,b,c});
    int mn=min({a,b,c});
    if(mx-mn<=1)ok=true;
    cout<<(ok?"YES":"NO")<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
}p[10];
int a[10];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n,m,f=0,h=0;
	cin >> n >> m;
	a[1]=1;
	for(int i=0;i<m;i++){
		cin >> p[i].x >> p[i].y;
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<m;j++){
			if(p[i].x==p[j].x&&p[i].y!=p[j].y) f=1;
		}
		if(p[i].x==1){
			if(p[i].y==0) f=1;
		}
		a[p[i].x]=p[i].y;
	}
	if(n==1 && m==1 && p[0].x==1&& p[0].y==0){cout<<0<<endl;return 0;}
	if(n==1&&m==0) cout << 0 << endl;
	else if(f==1) cout << -1 << endl;
	else if(f==0){
		for(int i=1;i<=n;i++){
			cout << a[i] ;
		}
		cout << endl;
	}
	return 0;
}


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

enum Dir
{
	U,R,D,L,DirSize
};

int main()
{
	bitset<DirSize+1> node[10][10];
	for(int y=0; y<5; y++)
	for(int x=0; x<5; x++)
	{
		node[y*2  ][x*2  ].set(R);
		node[y*2  ][x*2  ].set(D);
		node[y*2  ][x*2+1].set(D);
		node[y*2  ][x*2+1].set(L);
		node[y*2+1][x*2+1].set(L);
		node[y*2+1][x*2+1].set(U);
		node[y*2+1][x*2  ].set(U);
		node[y*2+1][x*2  ].set(R);
	}
	node[0][0].reset(D);
	node[1][0].reset(U);

	char str[16];
	for(int y=0; y<5; y++)
	{
		cin>>str;
		for(int x=0; x<4; x++)
		{
			if(str[x]=='1')
			{
				node[y*2  ][x*2+1].set(R);
				node[y*2  ][x*2+1].reset(D);
				node[y*2+1][x*2+1].set(R);
				node[y*2+1][x*2+1].reset(U);
				node[y*2  ][x*2+2].set(L);
				node[y*2  ][x*2+2].reset(D);
				node[y*2+1][x*2+2].set(L);
				node[y*2+1][x*2+2].reset(U);
			}
		}

		if(y==4) break;

		cin>>str;
		for(int x=0; x<5; x++)
		{
			if(str[x]=='1')
			{
				node[y*2+1][x*2  ].set(D);
				node[y*2+1][x*2  ].reset(R);
				node[y*2+1][x*2+1].set(D);
				node[y*2+1][x*2+1].reset(L);
				node[y*2+2][x*2  ].set(U);
				node[y*2+2][x*2  ].reset(R);
				node[y*2+2][x*2+1].set(U);
				node[y*2+2][x*2+1].reset(R);
			}
		}
	}

	int y=0,x=0;
	const int  dx[]={ 0, 1, 0,-1};
	const int  dy[]={-1, 0, 1, 0};
	const char dc[]={'U','R','D','L'};

	bool end=false;
	while(!end)
	{
		end=true;
		for(int i=0; i<4; i++)
		{
			if(node[y][x][i])
			{
				int nx=x+dx[i];
				int ny=y+dy[i];

				if(x/2!=nx/2 || y/2!=ny/2)
				{
					cout << dc[i];
				}
				x=nx; y=ny;
				node[y][x].reset((i+2)%4);
				end=false; break;
			}
		}	
	}
	cout << endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  int A;
  cin >> N;
  if(N % 2 == 0){
    A = N / 2;
  }
  else{
	A = N / 2 + 1;
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define Fast ios_base::sync_with_stdio(false); cin.tie(0);
    using namespace std;

    int main() {

     int tst;
     for(int i =1;i<= 5;i++){
        int a;
        cin>>a;
        if(a == 0){
            cout<<i<<endl;
            return 0;
        }
     }

        return 0;
    }


Measured memory_bytes: 3632
# input
N = int(input())
A = [int(input()) for _ in range(N)]

b = []
count = 0
i = 0

while count < N:
    b.append(A[i])
    i = A[i] - 1
    count += 1

if 2 in b:
    for i in range(N):
        if b[i] == 2:
            print(i + 1)
            break
else:
    print(-1)

Measured memory_bytes: 7960
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    cin >> n;
    vector <int> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    ll cur = 0;
    ll ans = 1e18;
    cur = a[0];
    sum -= a[0];
    for (int i = 1; i < n; i++)
    {
        ans = min(ans, abs(cur - sum));
        if (i != n)
        {
            cur += a[i];
            sum -= a[i];
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {

    long long int a, b;
    cin >> a >> b;

    if ( a < 10 && b < 10 ) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

int fib(int);
int num[45];
  
int main(void){
  int n;
  
  scanf("%d" ,&n);
  printf("%d\n" ,fib(n));
  return 0;
}
  
int fib(int n){

  if(num[n] > 0)return num[n];
  if(n <= 1)return 1;
  else{
    num[n] = fib(n-1) + fib(n-2);
    return num[n];
      }
  
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <stdexcept>
#include <utility>
// #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; i++)
#define rep1(i,h) for(int i = 0; i <= h; i++)
#define rep2(i,n,h) for(int i = n; i < h; i++)
#define rep3(l,n,h) for(int l = n; i <= h; i++)
using namespace std;



int main() {
    typedef pair<int,int> int_pair;
    int n, t, c, k,ans = 1e5;
    cin >> n >> t;
    vector<int_pair> data(n);
    rep(i,n) {
        cin >> c >> k;
        data.at(i) = make_pair(c , k);
        if(data.at(i).second <= t) {
            ans = min(ans, data.at(i).first);
        }
    }
    if(ans == 1e5) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

vll adj[MAXN]; ll visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m;
string s;
vll f;
// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	vll a(n);
	ll val = 1000;
	ll amt = 0;
	ll i = 0;
	vll buy,sell;
	for(ll i=0;i<n;i++) cin >> a[i];
	while(i+1 < n && a[i]>=a[i+1]) {
		i++;
		//cout<<a[i]<<" "<<a[i+1];
	}
	//cout<<i;newl;
	buy.pb(i);
	while(i < n) {
		//buy.pb(i);
		while(i+1<n && a[i]<=a[i+1]) i++;
		sell.pb(i);
		i++;
		while(i<n && a[i-1]>=a[i]) i++;
		buy.pb(i-1);
	}
	//DISP(buy);
	//DISP(sell);
	m = sell.size();
	for(ll i=0;i<m;i++) {
		amt = val/a[buy[i]];
		val%=a[buy[i]];
		val += amt*a[sell[i]];
	}
	cout << val;
}

int main() {
	fastio; randomINT;
	//cin>>t;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 238048
s=input()

al="abcdefghijklmnopqrstuvwxyz"
ishoge = False

for a in al:
    isExist = False
    for char in s:
        if a==char:
            isExist = True
            break
            
    if not isExist:
        print(a)
        ishoge = True
        break
        
if not ishoge:
    print("None")


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <stack>
using namespace std;
#define debug(x) cerr << #x << "=" << x << endl;
#define lgx cerr << "--------------" << endl;
const int MAxn = 1e5 + 5;

int main() {
	string s1, s2;
	while(cin >> s1 >> s2){
		int l = 0, r = 2;
		int flag = 1;
		while (l < 3 && r >= 0) {
			if(s1[l] != s2[r]) flag = 0;
			l++;
			r--;
		}
		if(flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1000000007;
const int lim = 1e18;
using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int binpow(int a, int n) { if(n == 0) return 1; if(n == 1) return a; int x = binpow(a, n/2); if(n%2 == 0) return x*x; return x*x*a; }

main()
{
//	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	int n; string s; cin >> n >> s;
	for(int i=0;i<s.length();i++)
	{
		s[i] = char((s[i]-'A' + n - 25 > 0)? s[i] + n - 26: s[i] + n);
	}
	cout << s;
}


Measured memory_bytes: 256
use proconio::{fastout, input, marker::Chars};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut c: Chars,
    }

    let mut ans = 0;

    let mut l = 0;
    let mut r = n - 1;
    while r as i64 - l as i64 > 0 {
        if c[l] == 'R' {
            l += 1;
        } else if c[r] == 'W' {
            r -= 1;
        } else if c[l] == 'W' && c[r] == 'R' {
            ans += 1;
            c[l] = 'R';
            c[r] = 'W';
            l += 1;
            r -= 1;
        }
    }

    println!("{}", ans)
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<int> a(n), b(n);
	cin >> a >> b;

	if(accumulate(all(a), 0LL) < accumulate(all(b), 0LL)){
		cout << -1 << endl;
		return 0;
	}

	int need = 0;
	int ans = 0;
	vector<int> d;
	rep(i,n){
		if(b[i] > a[i]){
			need += b[i] - a[i];
			ans++;
		}else{
			d.emplace_back(a[i] - b[i]);
		}
	}
	sort(all(d), greater<int>());
	
	int i = 0;
	while(need > 0){
		need -= d[i];
		i++;
	}

	cout << ans + i << endl;
}


Measured memory_bytes: 2936
/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <stdio.h>
#include <cstdio>
#include <queue>
#include <set>
#include <math.h>
using namespace std;

long int C = 1000000007;

int ipow2(int n){
  int ans = 1;
  for(int i = 0; i < n; i++){
    ans *=2;
  }
  return ans;
}

int get_rungs(int W, int rungs[128][7]){
  
  int ans=0;
  
  int rung_tmp[7];
  int tmp = 0;
  for(int i = 0; i < ipow2(W-1); i++){
    /* generate all combination of rungs*/
    tmp = i;
    for(int j = 0; j < W-1; j++){
      rung_tmp[j] = tmp%2;
      tmp /= 2;
    }
    //for(int j = 0; j < W-1; j++)printf("%d", rung_tmp[j]); printf("\n");
    /* check the combination*/
    int check = 1;
    for(int i = 0; i < W-2; i++){
      if(rung_tmp[i] == 1 && rung_tmp[i+1] == 1){
        check = 0;
      }
    }
    if(check == 1){
      /*copy possible rung*/
      for(int i = 0; i < W-1; i++){
        rungs[ans][i] = rung_tmp[i];
      }
      ans++;
    }
  }
  
  return ans;
}



int main(){
  /* read problem from input*/
  int H;
  int W;
  int K;
  scanf("%d", &H);
  scanf("%d", &W);
  scanf("%d", &K);
  
  if(W==1){
    printf("1");
  }
  else{
  
  int rungs[128][7];
  int num_rungs;
  num_rungs = get_rungs(W, rungs);
  
  /* print rungs*/
  /*printf("%d\n", num_rungs);
  for(int i = 0; i < num_rungs; i++){
    for(int j = 0; j < W-1; j++){
      printf("%d", rungs[i][j]);
    }printf("\n");
  }*/
  
  /* solve problem using DPA*/
  long int table[101][8];
  // initialize
  for(int i = 0; i < 101; i++){
    for(int j = 0; j < 8; j++){
      table[i][j] = 0;
    }
  }
  table[0][0] = 1;
  
  // DPA
  for(int i = 1; i <= H; i++){
    for(int j = 0; j < num_rungs; j++){
      if(rungs[j][0] == 1){
        table[i][0] += table[i-1][1];
      }
      else table[i][0] += table[i-1][0];
      table[i][0] %= C;
      
      if(rungs[j][W-2] == 1){
        table[i][W-1] += table[i-1][W-2];
        
      }
      else table[i][W-1] += table[i-1][W-1];
      table[i][W-1] %= C;
      
      for(int k = 1; k <= W-2; k++){
        if(rungs[j][k-1] == 1){
          table[i][k] += table[i-1][k-1];
        }
        else if(rungs[j][k] == 1){
          table[i][k] += table[i-1][k+1];
        }
        else table[i][k] += table[i-1][k];
        table[i][k] %= C;
      }
    }
    //for(int k = 0; k < W; k++)printf("%ld", table[i][k]);printf("\n");
  }
  
  printf("%ld", table[H][K-1]);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define inf (int)1e18+7
const int nmax = (int) 3e3 + 10;


int lsub[nmax][nmax];
    
                     
signed main() {

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


    string a, b;
    cin >> a >> b;

    
    for (int i = 1; i <= a.size(); i ++) {
        for (int j = 1; j <= b.size(); j ++) {
            if (a[i - 1] == b[j - 1]) {
                lsub[i][j] = lsub[i - 1][j - 1] + 1;    
            } else {
                lsub[i][j] = max(lsub[i - 1][j], lsub[i][j - 1]);
            }
        } 
    }
    
    int n = a.size();
    int m = b.size();

    string ans = "";
    while ( true) {

        if ( n == 0 || m == 0) break;

        if ( a[n - 1] == b[ m - 1]) {
            ans += a[n - 1];
            n --;
            m --;
        } else {
            if ( lsub[n][m] == lsub[n - 1][m]) {
                n --;
            } else {
                m --;
            }
        }
           
    }


    reverse(ans.begin(), ans.end());
    cout << ans << endl;


                                                                                                        

    return 0;
}

Measured memory_bytes: 70784
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		int s = sc.nextInt();
		ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    graph.add(new ArrayList<>());
		}
		int cheap = sc.nextInt();
		int expensive = sc.nextInt();
		PriorityQueue<Path> queue = new PriorityQueue<>();
		boolean[] isOut = new boolean[n];
		for (int i = 0; i < k; i++) {
		    int x = sc.nextInt() - 1;
		    queue.add(new Path(x, 0));
		    isOut[x] = true;
		}
		for (int i = 0; i < m; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    graph.get(a).add(b);
		    graph.get(b).add(a);
		}
		boolean[] dangerous = new boolean[n];
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (dangerous[p.idx]) {
		        continue;
		    }
		    dangerous[p.idx] = true;
		    if (p.value >= s) {
		        continue;
		    }
		    for (int x : graph.get(p.idx)) {
		        if (!dangerous[x]) {
		            queue.add(new Path(x, p.value + 1));
		        }
		    }
		}
		long[] costs = new long[n];
		Arrays.fill(costs, Long.MAX_VALUE);
		queue.add(new Path(0, 0));
		while (queue.size() > 0) {
		    Path p = queue.poll();
		    if (costs[p.idx] <= p.value || isOut[p.idx]) {
		        continue;
		    }
		    costs[p.idx] = p.value;
		    for (int x : graph.get(p.idx)) {
		        if (isOut[x] || costs[x] != Long.MAX_VALUE) {
		            continue;
		        }
		        long next = p.value;
		        if (dangerous[p.idx]) {
		            next += expensive;
		        } else {
		            next += cheap;
		        }
		        queue.add(new Path(x, next));
		    }
		}
		long ans = costs[n - 1];
		if (dangerous[0]) {
		    ans -= expensive;
		} else {
		    ans -= cheap;
		}
		System.out.println(ans);
	}
	
	static class Path implements Comparable<Path> {
	    int idx;
	    long value;
	    
	    public Path (int idx, long value) {
	        this.idx = idx;
	        this.value = value;
	    }
	    
	    public int compareTo(Path another) {
	        if (value == another.value) {
	            return 0;
	        } else if (value < another.value) {
	            return -1;
	        } else {
	            return 1;
	        }
	    }
	}
}



Measured memory_bytes: 160748
code = r"""
# distutils: language=c++
# distutils: include_dirs=/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include
from libcpp cimport bool
from libcpp.vector cimport vector
cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cdef cppclass dsu:
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()

from libc.stdio cimport scanf, printf
cdef int i
cdef int N, Q
cdef int t, u, v
scanf("%d%d", &N, &Q)
cdef dsu *d = new dsu(N)
for i in range(Q):
    scanf("%d%d%d", &t, &u, &v)
    if t == 0:
        d.merge(u, v)
    else:
        printf("%d\n", d.same(u, v))

"""
import os
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

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

namespace{
   constexpr int g1 = 1000 * 1000 * 1000, si = 1001 * 1002, si_log = 8 + 10, mod = static_cast<int>(1e9) + 7;
   constexpr long double eps = 1.0e-9;
   int n, m, k, ar[500][500];
   char br[500][500];
}

int64_t sol() {
   if (n <= 1)
      return 0;
   if (n <= 2) {
      return ar[1][2];
   }

   for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++)
      for (int k = 1; k <= n; k++)
      {
         const auto c = ar[i][k] + ar[j][k];
         if (c < ar[i][j])
            return -1;

         if (i != k && j != k) {
            if (ar[i][j] == c)
            {
               br[i][j] = 0;
            }
         }
      }

   auto ret = 0 * numeric_limits<int64_t>::max();
   for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++)
      {
         if (br[i][j])
            ret += ar[i][j];
      }

   return ret;
}

int main() {
   ios_base::sync_with_stdio(0); cin.tie(0);
   
   while (cin >> n)
   {
      memset(br, 1, sizeof br);
      for (int i = 1; i <= n; i++) br[i][i] = 0;
      //for (int i = 0; i <= 100*1000+1; i++) { gr[i].clear(); }
      for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> ar[i][j];
      auto s = sol();
      cout << s << '\n';
#ifndef _DEBUG
      break;
#endif
   }
   return 0;
}

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

int main() {
    double a, b, x, l;
    cin >> a >> b >> x;
    l = 2 * x / (a * b);
    if (l <= a) {
        cout << setprecision(10) << atan2(b, l) * 180.0 / M_PI << endl;
    } else {
        l = (2 * x - a * a * b) / (a * a);
        cout << setprecision(10) << atan2(b - l, a) * 180.0 / M_PI << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;

class Program
{
	static void Main()
	{
		int[] D = new int[int.Parse(Console.ReadLine())];
		string[] sD = Console.ReadLine().Split(' ');
		for (int i = 0; i < sD.Length; i++)
		{
			D[i] = int.Parse(sD[i]);
		}
		Array.Sort(D);
		long a = 0;
		for (int i = 0; i < D.Length; i++)
		{
			a += D[i];
		}
		Console.WriteLine("{0} {1} {2}", D[0], D[D.Length - 1], a);
	}
}

Measured memory_bytes: 9792
/*
２つの整数 a, b と１つの演算子 op を読み込んで、a op b を計算するプログラムを作成して下さい。ただし、演算子 op は、"+"(和)、"-"(差)、"*"(積)、"/"(商)、のみとし、割り算で割り切れない場合は、小数点以下を切り捨てたものを計算結果とします。
*/
#include <stdio.h>

int main(void) {
    int a, b;
    char op[2];
    
    while (1) {
        fscanf(stdin, "%d %1s %d", &a, op, &b);
    
        if (op[0] == '+') {
            a += b;
        } else if (op[0] == '-') {
            a -= b;
        } else if (op[0] == '*') {
            a *= b;
        } else if (op[0] == '/') {
            a /= b;
        } else {
            break;
        }

        printf("%d\n", a);
    }

    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin >> S;
  string E=S;
  reverse(E.begin(),E.end());
  string A = S.substr(0,(S.size()-1)/2);
  string B = S.substr((S.size()+3)/2-1);
  string C=A;
  string D=B;
  reverse(C.begin(),C.end());
  reverse(D.begin(),D.end());
  if(S==E&&A==C&&B==D)cout << "Yes" << endl;
  else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
def solve():
    N,M = map(int,input().split())
    S=[]
    for i in range(M):
        S.append(list(map(int,input().split()))[1:])
    P = list(map(int,input().split()))

    ans = 0
    for i in range(2 ** N):
        st = [(i >> j) & 1 for j in range(N)]
        for j in range(M):
            #print(i,j,S[j])
            if sum([st[k-1] for k in S[j]]) % 2 != P[j]:
                break
        else:
            ans += 1

    print(ans)

solve()


Measured memory_bytes: 42352
///created: 12/Jun/2019 16:41:33

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
#define db(x) cerr << "debug: " << #x << " = " << x << '\n';
template<class __Ty> bool minimize(__Ty& a, __Ty b) {
	if (a > b) { a = b; return true; }
	return false;
}
template<class __Ty> bool maximize(__Ty& a, __Ty b) {
	if (a < b) { a = b; return true; }
	return false;
}

ll fpow(ll a, int n) {
	if (n == 1) return a;
	ll tmp = fpow(a, n / 2);
	tmp *= tmp;
	if (n % 2)
		tmp *= a;
	return tmp;
}

int n, ip[101], cnt[101] = {0};
vector<ll> prime;

struct t3 {
	ll a, b, c;
	t3() { }
	t3(ll i, ll j, ll k) {
		a = i;
		b = j;
		c = k;
	}
};
bool operator<(t3 l, t3 r) {
	return (l.a < r.a) ||
		(l.a == r.a && l.b < r.b) ||
		(l.a == r.a && l.b == r.b && l.c < r.c);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 2; i <= 100; ++i)
		ip[i] = 1;
	for (int i = 2; i * i <= 100; ++i)
		if (ip[i])
			for (int j = i * i; j <= 100; j += i)
				ip[j] = 0;
	for (int i = 2; i <= 100; ++i)
		if (ip[i])
			prime.push_back(1LL * i);
	for (int i = 0; i < int(prime.size()); ++i) {
		for (int j = prime[i]; j <= n; j *= prime[i])
			cnt[i] += n / j;
		fprintf(stderr, "prime: %lld -> %d\n", prime[i], cnt[i]);
	}
	int ans = 0;
	set<t3> st;
	for (int i = 0; i < int(prime.size()); ++i)
		for (int j = 0; j < int(prime.size()); ++j)
			for (int k = 0; k < int(prime.size()); ++k) {
				if (cnt[i] < 2 || cnt[j] < 4 || cnt[k] < 4 || i == j || j == k || k == i)
					continue;
				t3 t(prime[i], min(prime[j], prime[k]), max(prime[j], prime[k]));
				if (st.find(t) == st.end()) {
					ans++;
					st.insert(t);
				}
			}
	typedef pair<ll, ll> il;
	set<il> stil;
	for (int i = 0; i < int(prime.size()); ++i)
		for (int j = 0; j < int(prime.size()); ++j) {
			if (cnt[i] < 24 || cnt[j] < 2 || i == j) continue;
			il t(prime[i], prime[j]);
			if (stil.find(t) == stil.end()) {
				stil.insert(t);
				ans++;
			}
		}
	stil.clear();
	for (int i = 0; i < int(prime.size()); ++i)
		for (int j = 0; j < int(prime.size()); ++j) {
			if (cnt[i] < 14 || cnt[j] < 4 || i == j) continue;
			il t(prime[i], prime[j]);
			if (stil.find(t) == stil.end()) {
				stil.insert(t);
				ans++;
			}
		}
	cout << ans + (cnt[0] >= 74);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private final static Scanner sc = new Scanner(System.in);

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        int x = nextInt();
        int t = nextInt();

        out((x - t < 0) ? 0 : x - t);
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt() {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString() {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(int n) {
        int[] arr = new int[n];

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

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }
}


Measured memory_bytes: 21332
#include <stdio.h>

int main(void) {
	int n, r;
	
	scanf("%d", &n);
	
	if (n == 10 || n == 100 || n == 1000 || n == 10000 || n == 100000) {
		r = 10;
	}else if (n < 10) {
		r = n;
	}else if (n < 100) {
		r = n / 10 + n % 10;
	}else if (n < 1000) {
		r = n / 100 + n % 100 / 10 + n % 10;
	}else if (n < 10000) {
		r = n / 1000 + n % 1000 / 100 + n % 100 / 10 + n % 10;
	}else if (n < 100000) {
		r = n / 10000 + n % 10000 / 1000 + n % 1000 / 100 + n % 100 / 10 + n % 10;
	}
	
	printf("%d\n", r);
	
	return 0;
}

Measured memory_bytes: 128
n,cc=gets.split.map(&:to_i)
d=[]
cc.times do
  d << gets.split.map(&:to_i)
end
c=[]
3.times do
  c << [0]*cc
end
n.times do |i|
  ccc=gets.split.map(&:to_i)
  n.times do |j|
    c[(i+j)%3][ccc[j]-1]+=1
  end
end
m=1/0.0
[*0...cc].permutation(3) do |b|
  ct=0
  3.times do |i|
    cc.times do |j|
      ct+=d[j][b[i]]*c[i][j]
    end
  end
  m=ct if m>ct
end
puts m


Measured memory_bytes: 14240