akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll M = 1000000000;
    ll n;
    ll ans=0;
    ll x = 0;
    cin >> n;
    ll a[n+2],b[n+2];
    b[0]=0;b[n+1]=0;
    for(ll i=1;i<=n+1;i++)cin >> a[i];
    for(ll i=1;i<=n;i++)cin >> b[i];
    for(ll i=0;i<=n;i++){
        x = -b[i]+a[i+1];
        if(x>0)x= b[i];else x = a[i+1];
        a[i+1] -= x;
        b[i] -= x;
        ans += x;
        
        
        x = -b[i+1]+a[i+1];
        if(x>0)x = b[i+1];else x = a[i+1];
        a[i+1] -= x;
        b[i+1] -= x;
        ans += x;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	int H, W;
	while (true) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++)
				cout << "#";
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = a * b;
    if (a > 9 or b > 9) ans = -1;
    cout << ans << endl;
    return 0;
}

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

int main(){
  string S1, S2, S3;
  cin >> S1 >> S2 >> S3;
  cout << (char)(S1.at(0)-0x20) << (char)(S2.at(0)-0x20) << (char)(S3.at(0)-0x20) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rrep(i,n) for(ll i=(n)-1;i>=0;--i)
#define rep1(i,n) for(ll i=1;i<=(n);++i)
#define rrep1(i,n) for(ll i=(n);i>=1;--i)
#define fr first
#define sc second
#define pb push_back
#define INF 0xfffffff
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
struct edge{ll to,cap,rev; }; // ????????????????????????

vector<edge> G[100];
bool used[100];

void add_edge(ll from,ll to,ll cap){
	G[from].pb((edge){to, cap, G[to].size() });
	G[to].pb((edge){from, 0, G[from].size()-1} );
}

ll dfs(ll v,ll t,ll f){
	if(v==t) return f;
	used[v]=true;
	rep(i,G[v].size()){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			ll d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

ll max_flow(ll s,ll t){
	ll flow = 0;
	for(;;){
		memset(used, 0, sizeof(used));
		ll f = dfs(s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

ll V,E,u[1000],v[1000],c[1000];

void input(){
	scanf("%lld%lld",&V,&E);
	rep(i,E){
		scanf("%lld%lld%lld",&u[i],&v[i],&c[i]);
	}
}

int main()
{
	input();
	rep(i,E) add_edge(u[i], v[i], c[i]);
	cout<<max_flow(0,V-1)<<endl;
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m,n,x,ans;
	cin>>n>>m>>x;
	if(n>m)
	{
	    if(x%n==0)ans=x/n;
	    else    ans=x/n+1;
	}
	else
	{
		if(x%m==0)ans=x/m;
		else    ans=x/m+1;
	}
	cout<<ans;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		long bef = 0;
		long aft = 0;
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a.length; j++) {
				if (a[i] > a[j]) {
					if (i < j) {
						bef++;
					} else {
						aft++;
					}
				}
			}
		}
		long b = k * (k + 1) / 2 % 1000000007;
		long c = k * (k - 1) / 2 % 1000000007;
		long d = bef * b % 1000000007 + aft * c % 1000000007;
		System.out.println(d % 1000000007);
	}
}


Measured memory_bytes: 26196
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict, deque

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	#入力
	N = int(input())
	outE = defaultdict(list)
	inE = defaultdict(int)
	for i in range(N):
		A = getlist()
		for j in range(N - 2):
			a, b = sorted([A[j] - 1, i])
			c, d = sorted([A[j + 1] - 1, i])
			outE[a * N + b].append(c * N + d)
			inE[c * N + d] += 1

	#キュー初期化
	Q = []
	for i in range(N):
		for j in range(i + 1, N):
			if inE[i * N + j] == 0:
				Q.append(i * N + j)
	#print(Q)
	#計算
	judge = "Yes"
	cnt = 0
	ans = 1
	while True:
		q = []
		for i in Q:
			for j in outE[i]:
				inE[j] -= 1
				cnt += 1
				if inE[j] == 0:
					q.append(j)

		if q == []:
			break
		else:
			Q = q
		ans += 1
	# print(ans)
	# print(cnt)

	if cnt != N * (N - 2):
		print(-1)
	else:
		print(ans)

if __name__ == '__main__':
	main()

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

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define endl "\n"
#define all(V) V.begin( ), V.end( )
#define Unique(V) sort( all( V ) ), V.erase( unique( all( V ) ), V.end() )
#define Check( N , p ) ( !( ( N & ( 1LL << p ) ) == 0 ) )
#define ON( N , p ) ( N = N | ( 1LL << p ) )
#define OFF( N , p ) ( N = N & ~( 1LL << p ) )
std::mt19937 rng( chrono::steady_clock::now().time_since_epoch().count() );
#define rnd(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
#define ran(a, b) rng() % ( (b) - (a) + 1 ) + (a)
#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template < typename Arg1 >
void __f( const char* name , Arg1&& arg1 ) { cerr << name << " : " << arg1 << "\n"; }
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... ); }
typedef long long int LL;
typedef pair <int,int> pii;
typedef pair <long long,long long> pll;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
const int N = 1e5 + 5;
const int inf = 1e9;
const long long INF = 1e18;

int n , k;
int a[ N ];
bool dp[ N ];

int main( int argc , char const *argv[] ) {
        ios_base::sync_with_stdio( false ); cin.tie( nullptr );
        cin >> n >> k;
        for( int i = 1; i <= n; i++ ) cin >> a[i];
        memset( dp , false , sizeof( dp ) );
        // dp[i] = true , if first player wins when i stone remaining
        dp[0] = false;
        for( int i = 1; i < N; i++ ) {
                for( int j = 1; j <= n; j++ ) {
                        if( a[j] <= i && !dp[ i - a[j] ] ) {
                                dp[i] = true;
                        }
                }
        }
        cout << ( dp[k] ? "First" : "Second" ) << endl;
        return 0;
}














Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
 
int main() {
  ll A,B,N;
  cin >> A >> B >> N;
  ll x = min(B-1,N);
  
  cout << floor(A*x/B)-A*floor(x/B) << endl;
}

Measured memory_bytes: 3744
N = int(input())
A = list(map(int, input().split()))  #8 2 7 3 4 5 6 1
# u = [(c, i) for i, c in enumerate(A)]  #タプルはcが優先される
l = list()
for i,c in enumerate(A):  #タプルにする
    l.append((c,i))

l.sort()

for c, i in l:
    print(i+1, end=" ")

Measured memory_bytes: 59436
use std::io;
use std::collections::HashSet;

fn main() {
    let n = read_one::<usize>();
    let s = read_one::<String>().chars().collect::<Vec<_>>();

    let mut after = vec![0b0; n];
    let mut before = vec![0b0; n];

    for i in 1..n {
        before[i] |= before[i - 1] | 1 << (s[i - 1] as u8 - b'0');
    }

    for i in (0..n - 1).rev() {
        after[i] |= after[i + 1] | 1 << (s[i + 1] as u8 - b'0');
    }

    let mut hs = HashSet::new();
    for i in 0..n {
        for a in 0..=9 {
            if (after[i] & 1 << a) != 0 {
                for b in 0..=9 {
                    if (before[i] & 1 << b) != 0 {
                        hs.insert(format!("{}{}{}", b, s[i], a));
                    }
                }
            }
        }
    }

    println!("{}", hs.len());
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);
#define debug(x) cerr << #x << " = " << x << "\n" ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

const int mod = 1e9 + 7 ;

int mem[ 100005 ][ 14 ] ;

string str ;
int solve( int i , int rem ){
if( i == sz( str ) ){
    if( rem == 5 ) return 1 ;
    else return 0 ;
}
int & ret = mem[ i ][ rem ] ;
if( ~ret ) return ret ;
ret = 0 ;
if( str[ i ] == '?' ){
    forn( int , a , 0 , 10 ){
       ret = ( ret % mod + solve( i + 1 , ( ( rem * 10 ) % 13 + ( a % 13 ) ) % 13 ) % mod ) % mod ;
    }
}

if( str[ i ] != '?' ) ret = ( ret % mod + solve( i + 1 , ( ( rem * 10 ) % 13 + ( str[ i ] - '0' ) % 13 ) % 13 ) % mod ) % mod ;
return ret % mod ;
}

int main(){

 cin >> str ;
 Clear( mem , -1 ) ;
 cout << solve( 0 , 0 ) ;

 return 0 ;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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 string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B) {
  if( A * B % 2 ) cout << YES << endl;
  else cout << NO << endl;
}

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


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

int main() {
  int N;

  cin >> N;
  
  vector<char>color(N);
  for (int i = 0; i < N; i++) {
    cin >> color.at(i);
  
    if (color.at(i)=='Y'){
      cout << "Four" << endl;
      break;
    }
    else if(i==N-1){
      cout << "Three" << endl;
    }
  }

 
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    int N;
    cin >> N;
    int hen[N];
    int max = 0;
    int sum = 0;

    for(int i = 0; i < N; i++)
        cin >> hen[i];
    
    for(int i = 0; i < N; i++){
        if(max < hen[i])
            max = hen[i];
        sum += hen[i];
    }

    if(sum - 2*max > 0)
        cout << "Yes" << endl;
    else if (sum - 2*max <= 0)
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(b / a, c) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//everybody dies in their nightmares
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<string>
#include<vector>
#include<sstream>
#include<cmath>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 1e6+5;
int t;
int a[N], b[N];

int main()
{
	int n;
	while (cin >> n)
	{
		ll sum = 0;
		f(i,1,n)
			f(j, 1, n)
		{
			int tmp1 = gcd(i, j);
			f(k, 1, n)
				sum += gcd(tmp1, k);
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	int no1,no2,max;
	cin>>no1>>no2;
	max = no1 * no2;
	if(no1 + no2 > max){
		max = no1+no2;
	}
	if(no1 - no2 > max) {
		max = no1-no2;
	}
	cout<<max<<endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 25

typedef struct{
  int id,p,l,r,sibling,degree,depth,height;
}Node;

Node node[N];

int calc_degree(Node);
void calc_fa(int);
void calc_depth(int, int);
int calc_height(int);

int main(){
	int n, i, id, root = 0;;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&id);
	node[id].id = id;
	node[id].p = node[id].sibling = -1;
    scanf("%d %d",&node[id].l,&node[id].r);
  }
  for (i = 0; i < n; i++) {
	  node[i].degree = calc_degree(node[i]);
  }
  calc_fa(n);
  for (i = 0; i < n; i++) {
	  if (node[i].p == -1) {
		  root = i;
		  break;
	  }
  }

  calc_depth(root, 0);
  calc_height(root);

  for (i = 0; i < n; i++){
	  printf("node %d: ",node[i].id);
	  printf("parent = %d, ", node[i].p);
	  printf("sibling = %d, ", node[i].sibling);
	  printf("degree = %d, ", node[i].degree);
	  printf("depth = %d, ", node[i].depth);
	  printf("height = %d, ", node[i].height);
	  if (i == root) printf("root\n");
	  else if (node[i].degree == 0) printf("leaf\n");
	  else printf("internal node\n");
  }
  return 0;
}

int calc_degree(Node n) {
	if (n.l != -1 && n.r != -1) return 2;
	if (n.l != -1 || n.r != -1) return 1;
	return 0;
}

void calc_fa(int n) {
	int i;
	for (i = 0; i < n; i++) {
		//parent
		//node[i].p = -1;
		if (node[i].l != -1) node[node[i].l].p = node[i].id;
		if (node[i].r != -1) node[node[i].r].p = node[i].id;
	}
	for(i=0; i<n; i++){
		//sibling
		//node[i].sibling = -1;
		if (node[node[i].p].l == node[i].id)
			node[i].sibling = node[node[i].p].r;
		if (node[node[i].p].r == node[i].id)
			node[i].sibling = node[node[i].p].l;
		if (node[i].p == -1) node[i].sibling = -1;
	}
}

void calc_depth(int now_id, int now_depth) {
	if (calc_degree(node[now_id]) == 0) {
		node[now_id].depth = now_depth;
		return;
	}
	if (node[now_id].l != -1) {
		calc_depth(node[now_id].l, now_depth + 1);
	}
	if (node[now_id].r != -1) {
		calc_depth(node[now_id].r, now_depth + 1);
	}
	node[now_id].depth = now_depth;
}

int calc_height(int now_id) {
	int lh, rh;
	if (node[now_id].degree == 0) {
		node[now_id].height = 0;
		return 0;
	}
	else {
		lh = calc_height(node[now_id].l) + 1;
		rh = calc_height(node[now_id].r) + 1;
		if (lh > rh) {
			node[now_id].height = lh;
			return lh;
		}
		else {
			node[now_id].height = rh;
			return rh;
		}
	}
}


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

int main() {
	
	int w, h, x, y;
	cin >> w >> h >> x >> y;
	double sq = (ll) w * h / 2.0;
	cout << sq << endl;
	
	if(w%2==0 && h%2==0 && w/2==x && h/2==y){
		puts("1");
	}else puts("0");
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    long long n, sum = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 1; k <= n; ++k) {
                sum += __gcd(__gcd(i, j), k);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

int main(){
  int n;cin >> n;
  vector<int> A(n);
  rep_i(i, n){
    cin >> A[i];
  }
  int m;cin >> m;
  vector<int> B(m);
  rep_i(i, m){
    cin >> B[i];
  }
  vector<int> C;

  set_union(begin(A), end(A), begin(B), end(B), inserter(C, end(C)));
  rep_i(i, C.size()){
    say(C[i]);
  }
}


Measured memory_bytes: 6544
import           Control.Monad (replicateM)
import           Data.List     (sortOn)

main :: IO ()
main = do
  ts <- replicateM 5 readLn
  print $ solve ts

solve :: [Int] -> Int
solve ts =
  let
    m : rest  = sortOn ((`mod` 10) . subtract 1) ts
  in
    sum $ m : map ceiling10 rest

ceiling10 :: Int -> Int
ceiling10 = (* 10) . ceiling . (/ 10) . (fromIntegral :: Int -> Double)


Measured memory_bytes: 508
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void){

    int n, a, b, S=0;
    cin >> n >> a >> b;

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

        int s = findSumOfDigits(i);

        if(a <= s && s <= b){
            S += i;
        }
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>

int main(int argc, char const *argv[])
{
    int N;
    int A;
    int B;
    std::cin >> N ;
    
    if (N == 1) 
    {
        printf("Hello World\n");
    }
    if (N == 2)
    {
        std::cin >> A;
        std::cin >> B;

        printf("%d\n",A + B);
    }
    return 0;
}


Measured memory_bytes: 504
n = int(input())
cards = {}
for i in range(n):
    card = input()
    cards[card] = 1
    
#print(cards)

for c in ['S', 'H', 'C', 'D']:
    for n in range(1, 14):
        key = c + ' ' + str(n)
        if not key in cards:
            print(key)


Measured memory_bytes: 5596
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,m;
LL dp[101][100001] ; 
LL a[100000],b[100000] ; 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m ; 
    REP(i,n) cin>>a[i]>>b[i] ;
    memset(dp,63,sizeof(dp)) ; 
    //cout<<dp[n][n]<<endl ; 
    dp[1][0] = 0 ; 
    dp[1][b[1]] = a[1] ; 
    for(int i=2;i<=n;i++)
    {  for(int j=0;j<=100000;j++)
       {   if(j<b[i])
           dp[i][j] = dp[i-1][j] ;
           else dp[i][j] = min(dp[i-1][j],dp[i-1][j-b[i]] + a[i]) ; 
       } 
       
    }
    //cout<<dp[n][90]<<" "<<dp[2][50]<<" "<<dp[2][80]<<endl ; 
    for(int i=100000;i>=0;i--)
    {  if(dp[n][i]<=m) ret cout<<i,0 ; 

    }

}
//Check for 0,1 and other corner cases.

Measured memory_bytes: 79232
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
struct segtree{
private:
  vector<ll> node,lazy;
  ll siz;
public:
  segtree(int n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2,0);
    lazy.resize(siz*2,0);
  }
  void eval(ll pos){
    node[pos]+=lazy[pos];
    if(pos<siz-1) {
      lazy[pos*2+1]+=(lazy[pos]/2);
      lazy[pos*2+2]+=(lazy[pos]/2);
    }
    lazy[pos]=0;
  }
  void add_q(ll a,ll b,ll x,ll l,ll r,ll pos){
    eval(pos);
    if(b<=l||r<=a) return;
    if(a<=l&&r<=b){
      lazy[pos]+=(x*(r-l));
      eval(pos);
      return;
    }
    ll mid=(l+r)/2;
    add_q(a,b,x,l,mid,pos*2+1);
    add_q(a,b,x,mid,r,pos*2+2);
    node[pos]=node[pos*2+1]+node[pos*2+2];
  }
  ll sum_q(ll a,ll b,ll l,ll r,ll pos){
    if(b<=l||r<=a) return 0;
    eval(pos);
    if(a<=l&&r<=b){
      return node[pos];
    }
    ll mid=(l+r)/2;
    return (sum_q(a,b,l,mid,pos*2+1)+sum_q(a,b,mid,r,pos*2+2));
  }
  void add(ll a,ll b,ll x){
    add_q(a,b,x,0,siz,0);
  }
  ll sum(ll a,ll b){
    return sum_q(a,b,0,siz,0);
  }
  void debug(){
    cout<<"Node:"<<endl;
    ll t=2;
    for(int i=2;i<=siz*2;i++) {
      cout<<node[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
    cout<<"Lazy:"<<endl;
    t=2;
    for(int i=2;i<=siz*2;i++){
      cout<<lazy[i-2]<<" ";
      if(i==t){
        t*=2;
        cout<<endl;
      }
    }
  }
};
int main(){
  ll n,m;
  cin>>n>>m;
  priority_queue<P,vector<P>,greater<P>> pque;
  for(int i=1;i<=n;i++){
    ll l,r;
    cin>>l>>r;
    pque.push(P(r-l+1,l));
  }
  segtree seg(m+5);
  for(int i=1;i<=m;i++){
    while(!pque.empty()&&pque.top().first<i){
      P p=pque.top();
      pque.pop();
      seg.add(p.second,p.second+p.first,1);
    }
    ll ans=pque.size();
    for(int j=1;j*i<=m;j++) ans+=seg.sum(j*i,j*i+1);
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 11624
using System;
using System.Collections.Generic;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int n = int.Parse(Console.ReadLine());

            var d = new HashSet<string>();
            for (var c = 0; c < n; c++)
            {
                string s = Console.ReadLine();
                if (d.Contains(s)) continue;
                d.Add(s);
            }

            Console.WriteLine(d.Count);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 47076
//
//  main.cpp
//  rough
//
//  Created by abhishek kumar on 30/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//

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


ll max_length(vector<ll> graph[],vector<bool>& visited,vector<ll>& max_count,ll src)
{
    if(visited[src]) return max_count[src];
    visited[src]=true;
    ll ans=0;
    for(auto x : graph[src]){
        ans= max(ans, 1 + max_length(graph,visited, max_count, x));
    }
    max_count[src]=ans;
    return ans;
}


int main(int argc, const char * argv[]) {
    
    
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll vertices,edges,src,dest;
    cin>>vertices>>edges;
    vector<ll> graph[vertices+1];
    
    for(auto i=0;i<edges;i++){
        cin>>src>>dest;
        graph[src].push_back(dest);
    }
    
    vector<bool> visited(vertices+1,false);
    vector<ll> max_count(vertices+1,0);
    
    ll maxi=0;
    
    for(auto i=1;i<=vertices;i++)
    {
        if(visited[i]==false)
            maxi=max(maxi,max_length(graph, visited, max_count,i ));
    }
    cout<<maxi;
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 9984
H,W,K  =(map(int,input().split(" "))) #  H × W のグリッド
nums = [list(map(int,list(input())))  for  _ in range(H)]
ruiseki_2d = [ [0] * (W + 1)  for _ in range(H + 1) ] # 0 → 0
for w in range(W):
    for h in range(H):
        ruiseki_2d[h + 1][w + 1] =ruiseki_2d[h + 1][w] + ruiseki_2d[h][w + 1] + nums [h ][w]  - ruiseki_2d[h][w]


# Hの分割は決め打ち
# H =10 → 9箇所の分け目
# Wの分割は必要ならする
ans = 10 ** 10
for i in range(2 ** (H )):
    # print(i)
    cand = 0
    # print("pattern {}: ".format(i), end="")
    cuts = [0] #一番端っこでカット
    for j in range(0,H -1 ):  #
        if ((i >> j) & 1):  # j + 1の箇所でHを切る
            # print(i,j + 1)
            cuts.append(j + 1)
            cand += 1
    cuts.append(H)
    beforeW = 0 #個数が変化するのは beforeW からwの区間とwより右の区間
    for w in range(1,W + 1):
        mi = 10 ** 6
        ss = []
        for i in range(len(cuts) - 1): #広げたら超えてしまっていたら、その一個前で線を引く
            y1 = cuts[i]
            y2 = cuts[i + 1]
            x2  = w
            x1 = beforeW
            s = ruiseki_2d[y2][x2] -ruiseki_2d[y2][x1] -ruiseki_2d[y1][x2] +ruiseki_2d[y1][x1]
            ss.append(s)


        ma = max(ss)
        if ma > K :
            cand += 1
            beforeW = w -1
    ss = []
    for i in range(len(cuts) - 1):  # 広げたら超えてしまっていたら、その一個前で線を引く
        y1 = cuts[i]
        y2 = cuts[i + 1]
        x2 = W
        x1 = beforeW
        s = ruiseki_2d[y2][x2] - ruiseki_2d[y2][x1] - ruiseki_2d[y1][x2] + ruiseki_2d[y1][x1]
        ss.append(s)


    if max(ss) <= K :
        ans = min(cand,ans)
# if ruiseki_2d[-1][-1] <= K:
#     ans = 0
print(ans)




Measured memory_bytes: 57564
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}
template <typename T>
ll SIZEOF(T a){return (ll)a.size();}

ll dx[] = {1, 0, -1, 0};
ll dy[] = {0, 1, 0, -1};





void SOLVE(){
    inp(n);
    inpv(a, n);
    ll x = 0;
    for(auto i:a){
        x^=i;
    }
    for(auto &i:a){
        i^=x;
    }
    outv(a);
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif

    ll TC = 1;
    // cin >> TC;
    for(ll tc1=1; tc1<=TC; tc1++){
        // cout << "Case #" << tc1 << ": ";
        SOLVE();
    }
    printclock;
}

Measured memory_bytes: 5332
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
// using namespace boost::multiprecision;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep1(i,n) for(int i=1; i<=(int)(n); i++)
#define all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<型>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define ers erase
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

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

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;

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

    int cnt = 0;
    cnt += S[0] == 'R' ? 1 : 0;
    cnt += S[1] == 'R' ? 1 : 0;
    cnt += (S[1] != 'R' && S[2] == 'R') ? 0 : S[2] == 'R' ? 1 : 0;
    cnt += cnt == 0 && S[2] == 'R' ? 1 : 0;

    cout << cnt << endl;
}


Measured memory_bytes: 3624
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        x: i32,
        ca: [(i32,[i32;m]);n],
    }
    let mut s: i32=-1;
    for b in 0..1<<n {
        let mut y=vec![0;m];
        let mut d: u32=b;
        let mut t=0;
        while d>0 {
            let i=d.trailing_zeros() as usize;
            t += ca[i].0;
            for j in 0..m {
                y[j] += ca[i].1[j];
            }
            d&=d-1;
        }
        if y.into_iter().all(|z|z>=x) {
            if s==-1 {
                s = t;
            }
            else {
                s = std::cmp::min(s,t);
            }
        }
    }
    println!("{}", s);
}

Measured memory_bytes: 2156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  ll n, q;
  string s;
  V memo;
  cin >> n >> q;
  cin >> s;
  
  for(ll i=0; i<n; i++) {
    if(i == 0) {
      memo.push_back(0);
    } else {
      if(s[i-1] == 'A' && s[i] == 'C') {
        memo.push_back(memo[i-1]+1);
      } else {
        memo.push_back(memo[i-1]);
      }
    }
  }
  
  for(ll i=0; i<q; i++) {
    ll l, r;
    cin >> l >> r;
    cout << memo[r-1] - memo[l-1] << endl;;
  }
  
  return 0;
}


Measured memory_bytes: 1908
import sys
from collections import deque
import copy
def main():
    K = int(input())
    A, B = map(int, input().split())
    for i in range(A, B+1):
        if i % K == 0:
            print('OK')
            sys.exit()
    print('NG')


if __name__ == '__main__':
    main()


Measured memory_bytes: 68236
#include <stdio.h>
int main(){
  int N,T;
  scanf("%d %d",&N,&T);
  int c[N][2];
  int pre=10000;
  for(int i=0;i<N;i++){
    scanf("%d %d",&c[N][0],&c[N][1]);
    if(pre>c[N][0]&&T>=c[N][1])pre=c[N][0];
  }
  if(pre==10000)printf("TLE\n");
  else printf("%d\n",pre);
}


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

LL L,R;

int main()
{
#ifdef h10
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	int i,pos;
	scanf("%lld%lld",&L,&R);
	if (L==R) {puts("1"); return 0;}
	for (i=59;i>=0;i--)
	{
		if (((L>>i)&1)!=((R>>i)&1)) break;
		if ((L>>i)&1) L-=1ll<<i,R-=1ll<<i;
	}
	pos=i;
	R-=1ll<<i;
	for (i--;i>=0;i--)
		if ((R>>i)&1) break;
	printf("%lld\n",2ll*((1ll<<pos)-L)+min(L,1ll<<(i+1)));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll h, w, m;
    cin >> h >> w >> m;

    vector<ll> bomh(h, 0);
    vector<ll> bomw(w, 0);

    map<pll, ll> mp;

    rep(i, m){
        ll bh, bw;
        cin >> bh >> bw;
        bh--, bw--;

        mp[make_pair(bh, bw)] = 1;

        bomh[bh]++;
        bomw[bw]++;
    }

    vector<ll> ordh(h), ordw(w);
    iota(ALL(ordh), 0);
    iota(ALL(ordw), 0);
    sort(ALL(ordh), [&](ll x, ll y){
        return bomh[x] > bomh[y];
    });
    sort(ALL(ordw), [&](ll x, ll y){
        return bomw[x] > bomw[y];
    });

    ll ans = bomh[ordh[0]] + bomw[ordw[0]] - 1;
    rep(i, h){
        if(bomh[ordh[i]] != bomh[ordh[0]])break;
        rep(j, w){
            if(bomw[ordw[j]] != bomw[ordw[0]])break;
            if(mp.count(make_pair(ordh[i], ordw[j])) == 0){
                cout << ans + 1;
                return 0;
            }
        }        
    }

    cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
	string s, p;
	cin >> s >> p;
	s.append(s);
	if (s.find(p) != string::npos)	
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
//#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 500010;
ll num, ans=0, sum=0;
int main() {
  ll N, X, Y;
  cin >> N >> X >> Y;
  
  vl count(N-1);
  rep(i, N) rep2(j, i+1, N-1) count[min(j-i-1,abs(X-1-i)+abs(Y-1-j))]++;
  rep(i, N-1) cout << count[i] << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

bool fr[501];
bool fr2[501];
vector<ll> G[501];

ll n,m,x,y;
int main()
{while(1){
	scanf("%lld%lld",&n,&m);
	for(ll i=0;i<n;i++) G[i].clear();
	memset(fr,0,sizeof(fr));
	memset(fr2,0,sizeof(fr2));
	if(!n&&!m) return 0;
	for(ll i=0;i<m;i++){
		scanf("%lld%lld",&x,&y);
		G[--x].push_back(--y);
		G[y].push_back(x);
	}
	for(ll i=0;i<G[0].size();i++){
		fr[G[0][i]]=1;
	}
	for(ll i=1;i<=n-1;i++){
		if(fr[i]){
			for(ll j=0;j<G[i].size();j++){
				fr2[G[i][j]]=1;
			}
		}
	}
	ll cnt=0;
	for(ll i=1;i<=n-1;i++) if(fr[i]||fr2[i]) cnt++;
	printf("%lld\n",cnt);
	}
}

Measured memory_bytes: 3320
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<ll,ll>
typedef long long ll;
const int maxn=3e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,i,j,a[10][10]={0};
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		int x=i%10,y=i;
		while(y/10)y/=10;
		a[y][x]++;
	}
	ll ans=0;
	for(i=1;i<=9;i++)
	{
		for(j=0;j<=9;j++)
		{
			ans+=a[i][j]*a[j][i];
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
from fractions import gcd
from functools import reduce
def resolve():
    n, x = map(int,input().split())
    X = list(map(int,input().split()))
    for i in range(n):
        X[i] = abs(X[i] - x)

    res = reduce(gcd, X)
    print(res)
resolve()

Measured memory_bytes: 88300
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
h,n = readInts()
A = [readInts() for _ in range(n)]
dp = [INF] * (h+1)
dp[h] = 0
for idx in range(h,-1,-1):
    for i in range(n):
        a,b = A[i]
        dp[max(0,idx-a)] = min(dp[max(0,idx-a)], dp[idx] + b)
print(dp[0])


Measured memory_bytes: 79068
//ID

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, ll>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m;cin>>n>>m;
    vector<vector<p>>p(n+1);
    rep(i,0,m){
        int pp,y;cin>>pp>>y;
        p[pp].pb(mp(y,i));
    }
    vector<tuple<int,int,int>>ans;
    rep(i,0,n+1){
        if(!p[i].empty()){
            sort(range(p[i]));
            ll t = 1;
            for(auto j:p[i]){
                ans.pb(make_tuple(j.second,i,t));
                t++;
            }
        }
    }
    sort(range(ans));
    rep(i,0,m){
        int a,b;
        a=get<1>(ans[i]);b=get<2>(ans[i]);
        printf("%06d%06d\n",a,b);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;

#define INF (1e9)

// テンプレート関数
#define REP(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)

int main()
{
    int N, X;
    cin >> N >> X;
    vector<int> a(N);

    rep(i, N) cin >> a[i];

    int tmp = 0;
    int ans = 1;
    rep(i, N) {
        tmp += a[i];
        if (tmp > X) break;
        // cout << tmp << endl;
        ++ans;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {


	int a,x;
	cin>>a>>x;

	if(a>=x)cout<<"10"<<endl;
	else cout<<"0"<<endl;
	return 0;

}


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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
#define mp make_pair
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>;
using ld = long double;  using vld = vector<ld>; 

int main(void) {
	char x,y; cin >>x>>y;
	
	if(x<y)	cout << "<" <<endl;
	if(x==y)	cout << "=" <<endl;
	if(x>y)	cout << ">" <<endl;

	
   return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
void lcs(string X,string Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 

   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   int index = L[m][n]; 
  
   char lcs[index+1]; 
   lcs[index] = '\0'; 
  

   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; 
          i--; j--; index--;    
      } 
  
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
     cout<<lcs; 
} 
  
int main() 
{ 
  string str1,str2;
  cin>>str1>>str2;
  int m =str1.size(); 
  int n =str2.size(); 
  lcs(str1,str2, m, n); 
  return 0; 
} 

Measured memory_bytes: 35456
mod=10**9+7
n=int(input())
l=[int(x) for x in input().split()]
f=[0]*(10**5)
for ele in l:
    f[ele]+=1
if n%2==0 and f[0]:
    print(0)
elif f[0]>1:
    print(0)
else:
    cnt=0
    for i in range(1,n):
        if f[i]:
            cnt+=1
        if f[i]>2:
            print(0)
            break
    else:
        print(pow(2,cnt,mod))

Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
int n,a[123456],c;
int main(){
	cin>>n>>a[0];
	int m=a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
		a[i]-=m;
		if(a[i]<0)a[i]+=1;
		m+=a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]<0){//why?
			if(c==0)cout<<"No"<<endl;
			c++;
		}
	}
	if(c==0)cout<<"Yes"<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 10001
#define B 100
#define dmp make_pair
#define dpb push_back
#define fi first
#define se second
#define P pair<int,int>
typedef long long ll;
const int inf = 1e9;
const ll INF = 1e18;
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
/*chrono::system_clock::time_point  start;
void timerstart(){start = chrono::system_clock::now();}
void timerend(){
	auto end = chrono::system_clock::now();
	int elapsed = chrono::duration_cast<chrono::milliseconds>(end-start).count();
	printf("%d[ms]\n", elapsed);
}*/

string s, t;
int dp[2003][2003][3];
int main(){
	int n, m;
	cin >> n >> m >> s >> t;
	s = ' ' + s +  'x';t = ' ' + t + 'x';
	
	int t1, t2, t3, ans = 0;
	for(int i = n+1;i >= 1;i--){
		for(int j = m+1;j >= 1;j--){
			if(s[i-1] == 'I'){
				dp[i-1][j][1] = max(dp[i-1][j][1], dp[i][j][2]+1);
			}
			if(t[j-1] == 'I'){
				dp[i][j-1][1] = max(dp[i][j-1][1], dp[i][j][2]+1);
			}
			if(s[i-1] == 'O'){
				if(dp[i][j][1] != 0)
				dp[i-1][j][2] = max(dp[i-1][j][2], dp[i][j][1]+1);
			}
			if(t[j-1] == 'O'){
				if(dp[i][j][1] != 0)
				dp[i][j-1][2] = max(dp[i][j-1][2], dp[i][j][1]+1);
			}
			ans = max(ans, dp[i][j][1]);
		}
	}
	//cout << s[6] << endl;
	//printf("%d %d\n", s.size(), t.size());
	/*for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			printf("%d ", dp[i][j][1]);
		}
		printf("\n");
	}
	printf("\n");
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			printf("%d ", dp[i][j][2]);
		}
		printf("\n");
	}*/
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 50304