akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        string[]array=Console.ReadLine().Split(' ');
        var X=int.Parse(array[0]);
        var A=int.Parse(array[1]);
        
        if(X<A)Console.WriteLine(0);
        else Console.WriteLine(10);
    }
}


Measured memory_bytes: 13268
ans = []
while True:
    N, X = map(int, input().split())
    if N == 0: break
    cnt = 0
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            for k in range(j+1, N+1):
                if i+j+k == X:
                    cnt += 1
    ans.append(cnt)
print(*ans, sep="\n")



Measured memory_bytes: 5600
#include "iostream"
#include "random"
#include "ctime"
#include "chrono"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"

using namespace std;


int main() {
	int N;
	cin >> N;
	string s;
	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		s.push_back(c);
	}
	for (int i = 0; i <= 1000000; i++) {
		if (s.find(to_string(i))>=s.size()) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3272
import Data.List
import Data.List.Split
import System.Environment (getArgs)

main = do
  l1 <- getLine
  let (x:unit:warp:xs) = map (read::String->Int) $ splitOn " " l1
  l2 <- getLine
  let ls = map (read::String->Int) $ splitOn " " l2
  putStrLn $ show $ sum $ map (\x -> min (x * unit) warp) $ zipWith (-) (tail ls) ls


Measured memory_bytes: 36220
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
//pとqの最大公約数
int gcd(int p,int q){
    if(p%q==0)
    return q;
    return gcd(q,p%q);
}
int main(){
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9)
    cout<<"hon"<<endl;
    else if(a==0||a==1||a==6||a==8)
    cout<<"pon"<<endl;
    else
    {
        cout<<"bon"<<endl;
    }
    
}

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

using namespace std;
typedef long long ll;
typedef pair<int, pair<int, int> > pip;

struct Edge {
    int cost;
    int from;
    int to;

    bool operator<(const Edge& another) const {
        return cost < another.cost;
    }
};

#define MAX 100001
vector<Edge> edges;
pip points[MAX];
int ace[MAX];


bool cmp_x(pip p1, pip p2) {
    return p1.second.first < p2.second.first;
}

bool cmp_y(pip p1, pip p2) {
    return p1.second.second < p2.second.second;
}

int ancestor(int x) {
    return x == ace[x] ? x : ace[x]=ancestor(ace[x]);
}

int main(void) {
    int N, x, y;
    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        scanf("%d%d", &x, &y);
        points[i] = make_pair(i, make_pair(x, y));
    }

    sort(points, points+N, cmp_x);
    for(int i = 1; i < N; i++) {
        pip p1 = points[i], p2 = points[i-1];
        edges.push_back(Edge{p1.second.first - p2.second.first, p1.first, p2.first});
    }

    sort(points, points+N, cmp_y);
    for(int i = 1; i < N; i++) {
        pip p1 = points[i], p2 = points[i-1];
        edges.push_back(Edge{p1.second.second - p2.second.second, p1.first, p2.first});
    }
    sort(edges.begin(), edges.end());

    for(int i=0; i<N; i++) ace[i] = i;
    ll ans = 0;
    int num = 0;
    for(int i=0; i<edges.size(); i++) {
        Edge e = edges[i];
        int from = e.from, to = e.to;

        if(ancestor(from) != ancestor(to)) {
            ans += e.cost;
            ace[ancestor(from)] = ancestor(to);
            num++;
        }
        
        if(num == N) break;
    }

    return !printf("%lld\n", ans);
}

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


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




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
string s[300];
int ans[300][300];
int main(){
    int H;
    int W;
    int K;
    cin >> H >> W >> K;
    for(int i = 0; i < H; i++){
        cin >> s[i];
    }

    vector <int> prev_seps;
    vector <int> prev_secs;
    int sec_count = 1;
    bool found_strawberry = false;
    for(int i = 0; i < H; i++){
        bool found_straw_berry_row = false;
        bool found_first = false;
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#'){
                if(!found_strawberry){
                    found_strawberry = true;
                    found_first = true;
                }
                found_straw_berry_row = true;
            }
        }

        if(found_straw_berry_row){
            prev_seps.clear();
            prev_secs.clear();
            for(int j = 0; j < W; j++){
                if(s[i][j] == '#'){
                    if(prev_seps.size() == 0){
                        for(int k = 0; k <= j; k++){
                            ans[i][k] = sec_count;
                        }
                    } 
                    prev_seps.push_back(j);
                    prev_secs.push_back(sec_count);
                    ans[i][j] = sec_count;
                    sec_count ++;
                } else {
                    if(prev_seps.size() != 0){
                        ans[i][j] = prev_secs[prev_secs.size() - 1];
                    }
                }
            }
            if(found_first){
                for(int j = 0; j < i; j++){
                    for(int k = 0; k < W; k++){
                        ans[j][k] = ans[i][k];
                    }
                }
            }
        } else {
            if(prev_seps.size() != 0){
                for(int j = 0; j < prev_seps[0]; j ++){
                    ans[i][j] = prev_secs[0];
                }
                int cur_sep_ind = 0;
                for(int j = prev_seps[0]; j < W; j++){
                    if(cur_sep_ind + 1 >= prev_seps.size() || j < prev_seps[cur_sep_ind + 1]){
                        ans[i][j] = prev_secs[cur_sep_ind];
                    } else {
                        cur_sep_ind ++;
                        ans[i][j] = prev_secs[cur_sep_ind];
                    }
                    
                }
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(j < W - 1){
                cout << ans[i][j] << " ";
            } else {
                cout << ans[i][j] << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 1280
prime = [0]*2 + [1] * 10**6
for i in xrange(2, 1001):
    for j in xrange(i*i, 10**6+1, i):
        prime[j] = 0
while 1:
    a, d, n = map(int, raw_input().split())
    if a==d==n==0: break
    while 1:
        if prime[a]:
            n -= 1
            if n==0: break
        a += d
    print a

Measured memory_bytes: 21872
import java.util.Scanner;

public class Main {

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

    int s = sc.next().length();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < s; i++) {
      sb.append("x");
    }

    System.out.println(sb.toString());

    sc.close();
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
#define ll long long
const int mod=1e9+7;
ll n, a, b;

ll q_pow(ll a, ll b){
    ll res = 1;
    while (b){
        if (b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

ll C(ll a, ll b){
    ll ans=1, c=1, i;
    for (i=a; i>=a-b+1; i--) ans=ans*i%mod;
    for (i=b; i>=1; i--) c=c*i%mod;
    return ans*q_pow(c, mod-2)%mod;
}

int main(){
    ll ans=0;
    scanf("%lld%lld%lld", &n, &a, &b);
    ans+=q_pow(2,n)-1;
    ans-=C(n, a);
    ans-=C(n, b);
    ans=(ans%mod+mod)%mod;
    printf("%lld\n", ans);
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << min(a,b)+min(c,d) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int N;
	cin >> N;
	int n = 0;
	int i = 1;
	while (n <= N)
	{
		n += i;
		if (n == N)
		{
			cout << "Yes" << endl;
			cout << i + 1 << endl;
			vector< vector<pii> >v;
			int t = 1;
			REP(j, i + 1)
			{
				vector<pii> p;
				REP(k, v.size())
				{
					if (v[k][i - 1].second== 0)continue;
					REP(l, i)
					{
						if (v[k][l].second == 0)continue;
						v[k][l].second = 0;
						p.push_back(v[k][l]);
						break;
					}
					if (p.size() == i)break;
				}

				int s = i - p.size();
				REP(k, s)
				{
					p.push_back(pii(t,1));
					t++;
				}
				cout << i ;
				REP(k, i)
				{
					cout << " " << p[k].first;
				}
				cout << endl;
				v.push_back(p);
			}
			return 0;
		}
		i++;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>
#include<string.h>
#define N 200001
void QuickSort(char s[][11], int l, int h)
{
    int i = l;
    int j = h;
    char t[11],d[11];
    strcpy(t,s[(l+h)/2]);
        while (i <= j)
        {
            while(strcmp(s[j],t)>0)     
            j--;
            while(strcmp(s[i],t)<0)      
            i++;
            if(i<=j)
            {
                strcpy(d,s[i]);
                strcpy(s[i],s[j]);
                strcpy(s[j],d);
                i++;
                j--;
            }
        }    
        if(l<j) QuickSort(s, l, j);     
        if(i<h) QuickSort(s, i, h);    
    
}
int main()
{
	int i,j,n,a[N]={0},b=0,q=0;
	char s[N][11],t[11];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	scanf("%s",s[i]);
	QuickSort(s,0, n-1);
	//for(i=0;i<n;i++)
    //printf("%s",s[i]);
    for(j=0;j<n;j++)
	{
		if(strcmp(s[j],s[j+1])==0)
		{
			a[j-b]++;
			b=a[j-b];
		}
		else
		{
			if(a[j-b]>q)
			q=a[j-b];
			b=0;
		}
	}
	//printf("%d",q);
	for(i=0;i<n;i++)
	{
		if(a[i]==q)
		printf("%s\n",s[i]);
	}



return 0;
}

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

    using namespace std;
    const long long mod = 1e9+7;
    vector<long long>sum(200005);
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        long long n,k;
        cin>>n>>k;
        for(int i=1;i<=200002;i++)
            sum[i]=sum[i-1]+i;
        long long ans=0;
        for(int i=k;i<=n+1;i++){
            long long mini=sum[i-1];
            long long maxi;
            if(i==n+1)
                maxi=sum[n];
            else
                maxi=sum[n]-sum[n-i];
            ans=ans+(maxi-mini+1);
            ans=ans%mod;
        }
        cout<<ans%mod;
        return 0;
    }


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

int main() {

    string S,T;
    cin>>S>>T;

    int s=S.size();

    string t=T.substr(0,s);

    if (S==t){
        cout<<"Yes"<<endl;
    }

    else {
        cout<<"No"<<endl;
    }

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long a,b,c,d,e;
 cin >> a >> b;
 if(a%b==0)
    cout << 0 << endl;
 else
 {
     long long p=a%b;
     long long h=(b-a%b);
     cout << min(p,h)<< endl;



 }

}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

int main() {
	Int n,m,cnt; cin >> n>>m;
	if (m >= 2 * n) cnt = n + (m-2*n) / 4;
	else cnt = m / 2;

	cout << cnt;

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int m=2019;
int dp[m];
int main(){
  string s;
  cin>>s;
  int n=s.size();
  int l=s[n-1]-'0';
  dp[l]++;
  int z=1;
  int p,k;
  for(int i=n-2;i>=0;i--){
    z=(10*z)%m;
    k=(((s[i]-'0')*z)%m+l)%m;
    dp[k]++;
    l=k;
  } 
  ll ans=0;
  for(int i=0;i<2019;i++){
    ans+=(1LL*dp[i]*(dp[i]-1)/2);
  }
  ans+=dp[0];
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=200010;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int main(){
    string s;cin>>s;
    int ans=700;
    for(int i=0;i<3;i++){
        if(s[i]=='o'){
            ans+=100;
        }
    }
    cout<<ans<<endl;
	return 0;
}

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

int main() {
	int A, B, C;
	int s[4];
	cin >> A >> B >> C;
	s[0] = A; s[1] = B; s[2] = C;
	sort(s, s + 3);
	cout << s[0] + s[1] + s[2] * 10;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;

main(){
  cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v[i];
  }

  sort(all(v));
  if(v[n-1]-v[0]>1){
    cout<<"No"<<endl;
  }else if(v[n-1]-v[0]==1){
    int x=0,y=0;
    rep(i,n){
      if(v[i]==v[0]) x++;
      else y++;
    }
    if(x<v[n-1]&&2*(v[n-1]-x)<=y)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else{
    if(v[0]==n-1||2*v[0]<=n)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
}



Measured memory_bytes: 1024
import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().split()]
B = [int(x) for x in readline().split()]

Acum = list(itertools.accumulate(A))
Bcum = list(itertools.accumulate(B))
ans = 0
for i in range(N):
    if i - 1 >= 0:
        ans = max(ans, Acum[i] + Bcum[-1] - Bcum[i - 1])
    else:
        ans = max(ans, Acum[i] + Bcum[-1])
print(ans)


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");
			
			int m = Integer.parseInt(tmpArray[0]);
			int nmin = Integer.parseInt(tmpArray[1]);
			int nmax = Integer.parseInt(tmpArray[2]);
			
			if(m == 0 && nmax == 0 && nmin == 0){
				break;
			}
			
			int score[] = new int[m];
			
			for(int i = 0 ; i < m; i++){
				score[i] = Integer.parseInt(br.readLine());
			}
			
			int gap = -1;
			int pass = 0;
			
			for(int i = nmin - 1 ; i < nmax ; i++){
				if(score[i] - score[i + 1] >= gap){
					gap = score[i] - score[i + 1];
					pass = i + 1;
//					System.out.println("gap "+gap+" pass "+pass);
				}
			}
			
			System.out.println(pass);
		}
	}

}

Measured memory_bytes: 31592
import java.util.Scanner;

class Main {
	public static void main(String[] $) {
		Scanner sc = new Scanner(System.in);
		int d=sc.nextInt(),g=sc.nextInt();
		int[] p=new int[d];
		int[] c=new int[d];
		double min=Long.MAX_VALUE;

		for(int i=0;i<d;i++) {
			p[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		for(int i=0;i<Math.pow(2, d);i++) {
			int[] status = new int[d];
			double sum=0,count=0;
			int max=0;
			for(int j=0;j<d;j++) {//iを2進数にした場合にどこの桁が1になっているか判定し、1の場合はstatusに代入
				if((1&i>>j)==1) {
					status[j]=1;
				}
			}
			for(int j=0;j<d;j++) {
				if(status[j]==1) {
					sum+=p[j]*(j+1)*100+c[j];
					count+=p[j];
				}else {
					max=j+1;
				}
			}
			if(sum<g) {
				count+=Math.ceil((g-sum)/(max*100));
				sum+=max*100*p[max-1];
			}
			if(sum>=g)min=Math.min(count, min);
			//System.out.println(sum+" "+count+" "+max+" "+min);
		}
		System.out.println((long)min);
	}
}


Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H1 = sc.nextInt();
        int M1 = sc.nextInt();
        int H2 = sc.nextInt();
        int M2 = sc.nextInt();
        int K = sc.nextInt();
        sc.close();

        int M = 0;

        if (H1 <= H2) {
            M = (H2 * 60 + M2) - (H1 * 60 + M1);
        } else {
            M = ((H2 + 24) * 60 + M2) - (H1 * 60 + M1);
        }

        M -= K;
        System.out.println(M);
    }
}


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

main() {
    int N; cin >> N;
    map<int,int> m;
    vector<int> v(2),v2(2);
    rep(i,N){
        int a; cin >> a;
        m[a]++;
    }
    for(auto p:m){
        if(p.second>=4) v.push_back(p.first);
        else if(p.second>=2) v2.push_back(p.first);
    }
    sort(v.begin(),v.end(),greater<int>());
    sort(v2.begin(),v2.end(),greater<int>());
    
    if(v[0]>=v2[0]) cout << v[0]*v[0] << endl;
    else cout << v2[0]*max(v[0],v2[1]) << endl;
    
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int max(int x,int y){
    if(x>y){
        return x;
        cout<<"po";
    } else{
        return y;
    } 
}
int min(int x,int y){
    if(x<y)return x;
    else return y;
}
int main(void){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    int ma_x,ma_y,temp;
    cin>>ma_x;
    for (int i=1;i<N;i++){
        cin>>temp;
        ma_x=max(ma_x,temp);
    }
    ma_x=max(ma_x,X);
    cin>>ma_y;
    for (int i=1;i<M;i++){
        cin>>temp;
        ma_y=min(ma_y,temp);
    }
    ma_y=min(ma_y,Y);
    if(ma_x<ma_y){
        cout<<"No War"<<endl;
    } else {
        cout<<"War"<<endl;
    }
     
     return 0;
    
}


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

#define MAX_NUM (1000000000 + 7)

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

template <typename T>
static inline T ArraySum(vector<T>& A) {
  T res = 0;
  for (auto itr = A.begin(); itr < A.end(); ++itr) res += *itr;
  return res;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int main() {
  cout << setprecision(18);
  u32 N, K;
  cin >> N >> K;
  set<u32> Sunuke;
  for (u32 i = 0; i < K; ++i) {
    u32 d;
    cin >> d;
    for (u32 j = 0; j < d; ++j) {
      u32 A;
      cin >> A;
      Sunuke.insert(A);
    }
  }
  cout << N - Sunuke.size() << endl;

  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define pb push_back
#define INF 10000009
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

double coins(double p[],vector<vector<double>> &dp,int &n,int count,int i)
{
	if(i>=n && count==0)
	{
		return 1;
	}
	if(i>=n && count>0)
	{
		return 0;
	}
	if(dp[i][count]!=-1)
	{
		return dp[i][count];
	}
	if(n-i<count)
	{
		return dp[i][count]=0;
	}
	if(count>0)
	{
		return dp[i][count]=p[i]*coins(p,dp,n,count-1,i+1)+(1-p[i])*coins(p,dp,n,count,i+1);
	}
	return dp[i][count]=(1-p[i])*coins(p,dp,n,count,i+1);
}

int main()
{
	fastio
	int i,n;
	cin>>n;
	double p[n];
	for(i=0;i<n;i++)
	{
		cin>>p[i];
	}
	vector<vector<double>> dp(n,vector<double>(n+1,-1));
	double ans=0.0;
	for(i=(n+1)/2;i<=n;i++)
	{
		ans+=coins(p,dp,n,i,0);
	}
	cout<<fixed<<setprecision(10)<<ans;
	//printf("%lf",ans);
}

Measured memory_bytes: 74032
def inv(a,m):
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m

mod=998244353
n,m,k=map(int,input().split())
frac=[1 for i in range(n+1)]
frac_inv=[1 for i in range(n+1)]
beki=[m for i in range(n+1)]

for i in range(1,n+1):
    frac[i]=frac[i-1]*i%mod
    frac_inv[i]=inv(frac[i],mod)
    beki[i]=beki[i-1]*(m-1)%mod
ans=0
for i in range(n-k,n+1):
    ans+=beki[i-1]*frac[n-1]%mod*frac_inv[n-i]*frac_inv[i-1]%mod
print(ans%mod)

Measured memory_bytes: 94292
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

A1.insert(0,0)
A2.insert(0,0)

from itertools import accumulate

AC1 = list(accumulate(A1))
AC2 = list(accumulate(A2))

ans = -1
for i in range(N):
  ans = max(ans, AC1[i+1] + AC2[N] - AC2[i])
print(ans)

Measured memory_bytes: 3064
from bisect import bisect_left

def main():
# input
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()

# loop
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            ind = bisect_left(l, l[i]+l[j])
            ans += ind - j - 1
    print(ans)


if __name__ == '__main__':
    main()


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

const int MAXN = 3*(1e5)+10, MAXM = (1e5)+10;
int n, m, diaMul[MAXM], diaAdd[MAXM],ans[MAXM];
vector<pair<int, pair<int,int> > > seg;
long long int read_int(){
		char r;
			bool start=false,neg=false;
				long long int ret=0;
				while(true){
							r=getchar();
							if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
											continue;
													
							}
							if((r-'0'<0 || r-'0'>9) && r!='-' && start){
											break;
													
							}
									if(start)ret*=10;
											start=true;
													if(r=='-')neg=true;
															else ret+=r-'0';
																
				}
					if(!neg)
								return ret;
						else
									return -ret;

}
void internalUpdate(int i, int mul, int add) {
	while (i <= m) {
		diaMul[i] += mul;
		diaAdd[i] += add;
		i |= (i + 1);
	}
}
void update(int left, int right, int by) {
	internalUpdate(left, by, -by * (left - 1));
	internalUpdate(right, -by, by * right);
}
int query(int i) {
	int mul = 0;
	int add = 0;
	int start = i;
	while (i >= 0) {
		mul += diaMul[i];
		add += diaAdd[i];
		i = (i & (i + 1)) - 1;
	}
	return mul * start + add;
}
int main() {
	n = read_int();
	m = read_int();
	for(int i = 0,l,r; i < n; i++) {
		l = read_int();
		r = read_int();
		seg.emplace_back(r-l, make_pair(l, r));
		update(l, r, 1);
	}
	sort(seg.begin(), seg.end());
	for(int x = m, curr = 0; x >= 1; x--) {
		while(!seg.empty() && seg.back().first >= x) {
			update(seg.back().second.first, seg.back().second.second, -1);
			curr++;
			seg.pop_back();
		}
		ans[x] = curr;
		for(int i = 0; i <= m; i += x) ans[x] += query(i) - (i > 0 ? query(i-1) : 0);
	}
	for(int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0218

int main() {
	int n;
	while (cin >> n) {
		for (int i = 0; i < n; i++) {
			int m, e, j;
			cin >> m >> e >> j;
			int avg = (m + e + j) / 3;
			if (m == 100 || e == 100 || j == 100) cout << "A";
			else if ((m + e) / 2 >= 90) cout << "A";
			else if (avg >= 80) cout << "A";
			else if (avg >= 70) cout << "B";
			else if (avg >= 50 && (m >= 80 || e >= 80)) cout << "B";
			else cout << "C";
			cout << endl;
		}
	}
	return 0;
}

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

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            var list = new List<int>();
            for (int i = 0; i < input.Length; i++)
            {
                list.Add(int.Parse(input[i]));
            }
            list.Sort();
            var score = Math.Abs(list[0] - list[1]) + Math.Abs(list[1] - list[2]);
            Console.WriteLine(score);
        }
    }
}


Measured memory_bytes: 11220
n=int(input())
l="abcdefghijklmnopqrstuvwxyz"
for r in range(0,11):
    start=0
    for x in range(r+1):
        start+=26**x
    end=start+26**(r+1)-1

    if start<=n<=end:
        o=[]
        for x in range(r+1)[::-1]:
            o.append(l[((n-start)//(26**x))%26])
        print("".join(map(str,o)))
        exit()

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

using namespace std;

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

    if(s[4]==s[5] && s[2]==s[3])
    {
        cout<<"Yes"<<endl;
    }

    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
// const ll INF = 1000000000000000000LL;

int main() {
	int n;
	cin >> n;
	string a,b,c;
	cin >> a >> b >> c;
	vector<int> x(n);
	rep(i,n){
		int cnt=1;
		if(a[i]==b[i]) cnt++;
		if(b[i]==c[i]) cnt++;
		if(a[i]==c[i]) cnt++;
		if(a[i]==b[i]&&a[i]==c[i])
			cnt--;
		x[i]=cnt;
	}
	int sum=0;
	rep(i,n) sum+=x[i];
	cout << n*3-sum << endl;
	return 0;
}



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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ld long double

int n, m, ans = 0;
vector<vector<int>> g(200010);
bool vis[200010];
 
void dfs(int v) {
	vis[v] = true;
	for(int i = 0; i < g[v].size(); i++) {
		if(!vis[g[v][i]]) {
			dfs(g[v][i]);
		}
	}
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
 
	int a, b;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i = 1; i <= n; i++) {
		if(!vis[i]) {
			ans += 1;
			dfs(i);
		}
	}
	cout << ans - 1;
	return 0;
}

Measured memory_bytes: 11984
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#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>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;


int main(){
    ll n;
    sfl(n);
    if(n&1){
        printf("0\n");
        return 0;
    }
    ll val = 1,ans=0;
    while(val<=n/5){
        val = val*5;
        ans += (n/(val*2));
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

    int x_left = X - K + 1;
    int x_right = X + K - 1;
    for (int i = x_left; i <= x_right; i++)
        std::cout << i << (i < x_right ? " " : "\n");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
  long int n,d,x,y;
  long int ans=0;
  scanf("%ld %ld",&n,&d);
  for(int i=0;i<n;i++){
    scanf("%ld %ld",&x,&y);
    if(((x*x)+(y*y))<=(d*d)){
      ans++;
    }
  }
  printf("%ld",ans);
  return 0;
}

Measured memory_bytes: 1692
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
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;}
using namespace std;
int main(){
  int n,f=0;
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    if(a%2==0){
      if(a%3!=0){
        if(a%5!=0)f=1;
      }
    }
  }

  if(f==0) cout<<"APPROVED";
  else cout<<"DENIED";
}


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

using namespace std;

int main()
{
	string str;
	int n = 0;
	int flg = 0;
	int sum = 0;
	int tmp = 0;
	vector<int> v;

    cin >> n;
    for(int i=0;i<n;i++){
    	cin >> tmp;
    	sum=sum+tmp;
    	v.push_back(tmp);
    }

    sort(v.begin(),v.end());

    if(sum%10 == 0){
    	for(int i=0;i<n;i++){
    		if(v[i]%10 != 0){
    			sum = sum - v[i];
    			flg=1;
    			break;
    		}
    	}
    	if(flg!=1){
    	    	sum = 0;
    	}
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main () {
    int n = 0;
    cin >> n;
    vector<vector<int>> in(n+1, vector<int>(n-1));
    for (int i=1; i<n+1; i++) {
        for (int j=0; j<n-1; j++) {
            cin >> in.at(i).at(j);
        }
    }
    vector<int> now(n+1);
    vector<bool> check(n+1, false);
    int cnt = 0;
    vector<set<int>> aite(n+1);
    for (int i=1; i<n+1; i++) {
        aite.at(in.at(i).at(0)).insert(i);
    }
    int finish = 0;
    bool unable = true;
    while (finish < n) {
        unable = true;
        for (int i=1; i<n+1; i++) {
            if (check.at(i)) continue;
            if (aite.at(i).empty()) continue;
            if (now.at(i) == n-1) continue;
            int next = in.at(i).at(now.at(i));
            if (check.at(next)) continue;
            if (aite.at(i).find(next) != aite.at(i).end()) {
                check.at(i) = check.at(next) = true;
                now.at(i)++;
                now.at(next)++;
                aite.at(i).erase(next);
                aite.at(next).erase(i);
                if (now.at(i) == n-1) finish++;
                else aite.at(in.at(i).at(now.at(i))).insert(i);
                if (now.at(next) == n-1) finish++;
                else aite.at(in.at(next).at(now.at(next))).insert(next);
                unable = false;
            }
        }
        if (unable) {
            cout << -1 << endl;
            return 0;
        }
        cnt++;
        check = vector<bool> (n+1, false);
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
	int n;
	while (cin >> n, n) {
		int Min = INT_MAX;
		rep(i, n / 200 + 1) {
			rep(j, n / 300 + 1) {
				rep(k, n / 500 + 1) {
					if (i * 200 + j * 300 + k * 500 == n) {
						Min = min(Min, 380 * i + 550 * j + 850 * k - i / 5 * 380 - j / 4 * 330 - k / 3 * 306);
					}
				}
			}
		}
		cout << Min << endl;
	}
}

Measured memory_bytes: 3108
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int N, M;
long long a[50], b[50];
long long c[50], d[50];

long long md(long long aa, long long bb, long long cc, long long dd){
    return abs(aa-cc) + abs(bb-dd);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];
    for(int i=0; i<M; i++) cin >> c[i] >> d[i];

    for(int i=0; i<N; i++){
        long long mind = 1000000000;
        int optj;
        for(int j=0; j<M; j++){
            long long dst = md(a[i], b[i], c[j], d[j]);
            if(dst < mind){
                mind = dst;
                optj = j;
            }
        }
        cout << 1 + optj << endl;
    }
    return 0;
}


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

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

using namespace std;

using graph=vector<vector<int>>;

void add_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
	G[v].emplace_back(u);
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		add_edge(G,u,v);
	}

	int q; scanf("%d",&q);
	vector<int> v0(q),d(q),c(q);
	rep(i,q) scanf("%d%d%d",&v0[i],&d[i],&c[i]), v0[i]--;

	vector<int> color(n);
	vector<vector<bool>> vis(n,vector<bool>(11));

	for(int i=q-1;i>=0;i--) if(!vis[v0[i]][d[i]]) {
		vis[v0[i]][d[i]]=true;

		queue<pair<int,int>> Q; Q.emplace(v0[i],d[i]);
		while(!Q.empty()){
			int u,k; tie(u,k)=Q.front(); Q.pop();

			if(color[u]==0) color[u]=c[i];
			if(k==0) continue;

			for(int v:G[u]) if(!vis[v][k-1]) {
				vis[v][k-1]=true;
				Q.emplace(v,k-1);
			}
		}
	}

	rep(u,n) printf("%d\n",color[u]);

	return 0;
}


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

int n,m,dp[100001],c;
vector<int>v[100001];

int fun(int i){
    if(v[i].empty())return 0;
    if(dp[i])return dp[i];
    for(int j=0;j<v[i].size();j++){
        dp[i]=max(dp[i],1+fun(v[i][j]));
    }
    return dp[i];
}

int main(){
cin>>n>>m;
int a,b;
for(int i=1;i<=m;i++){
    cin>>a>>b;
    v[a].push_back(b);
}
for(int i=1;i<=n;i++){
    c=max(c,fun(i));
}
cout<<c;
}


Measured memory_bytes: 8192
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int n, a[100000], v[100000];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    
    for (int i = 0; i < n; ++i) {
        if (v[i] == 0) {
            int t = i;
            queue<int> q;
            while (1) {
                if (v[t] == 1) { //?????????
                    while (!q.empty()) {
                        if (q.front() != t)
                            v[q.front()] = 2;
                        else
                            break;
                        q.pop();
                    }
                    break;
                }
                
                v[t] = 1;
                q.push(t);
                
                (t += a[t]) %= n;
            }
        }
    }
    
    cout << count(v, v + n, 1) << endl;
    
    return 0;
}

Measured memory_bytes: 4004
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 1e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> pre(N, 0);
    for(int i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        pre[a] += b;
    }
    for(int i = 1; i <= N; i++){
        pre[i] += pre[i - 1];
    }
    ll lo = 0, hi = 1e5 + 1;
    while(hi - lo > 1){
        ll mid = lo + hi >> 1;
        ll yo = pre[mid];
        ll yo1 = pre[mid - 1];
        if(yo1 < k && k <= yo){
            cout << mid;
            break;
        }else if(k > yo) lo = mid;
        else hi = mid;
    }
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 1024
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;

int g[20][20];
int ideg[20];

int main(){
  int n,m;
  deque<int> s, ans;
  
  cin >> n >> m;
  for (int i=0; i<m; i++){
    int x,y; cin >> x >> y;
    g[x-1][y-1] = 1;
    ideg[y-1]++;
  }
  // initialize S
  for (int i=0; i<n; i++){
    if (ideg[i]==0) s.push_back(i);
  }
  while (s.size()){
    int t;
    t = s.front();
    s.pop_front();
    ans.push_back(t);
    for (int i=0; i<n; i++){
      if (g[t][i]){
        g[t][i] = 0;
        if (--ideg[i] == 0) s.push_back(i);
      }
    }
  }
  while (ans.size()){
    cout << (ans.front() + 1) << endl;
    ans.pop_front();
  }
        
  return 0;
}


Measured memory_bytes: 3104
#include <stdio.h>

int main(){
	int n,m;
	int A[100][100]={},b[100]={},c[100]={};
	int bool;
	//n m?????\???
	//printf("n m?????\???\n");
	do{
		printf("");
		scanf("%d %d",&n,&m);
	}while(!(n>=0 && n<=100 && m>=0 && m<=100));
	
	//A?????\???
	//printf("A?????\???\n");
	int s,t;
	for(s=0;s<n;s++){
		loop:
		bool=0;
		printf("");
		for(t=0;t<m;t++){
			scanf("%d ",&A[s][t]);
			if(!(A[s][t]>=0 && A[s][t]<=1000))bool=1;
		}
		if(bool)goto loop;
	}
	
	//b?????\???
	//printf("b?????\???\n");
	for(t=0;t<m;t++){
		printf("");
		scanf("%d",&b[t]);
	}
	
	//?¨????
	//printf("??????\n");
	for(s=0;s<n;s++){
		for(t=0;t<m;t++){
			c[s]=c[s]+A[s][t]*b[t];
		}
	}
	
	for(t=0;t<n;t++){
		printf("%d\n",c[t]);
	}
	
	//A?????????
	/*
	printf("A?????????\n");
	for(s=0;s<n;s++){
		for(t=0;t<m;t++){
			printf("%d ",A[s][t]);
		}
		printf("\n");
	}
	*/
	
	
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
int n;
double p[3005];

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }

    vector<vector<double>> dp(n + 1, vector<double>(n + 1));
    dp[1][1] = p[1];
    dp[1][0] = 1 - p[1];
    for (int i = 2; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
        for (int j = 1; j <= i; j++) {
            dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]);
        }
    }

    double ans = 0;
    for (int j = (n + 1) / 2; j <= n; j++) {
        ans += dp[n][j];
    }

    cout << fixed << setprecision(10) << ans << '\n';
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  static const int MAX = 100010;
  int N, outdeg[MAX], next_visit[MAX];
  ll dp[2][2][MAX];
  vector<int> G[MAX];
  vector<pair<int, int> > postorder;

  void init() {
    cin >> N;
    int x, y;
    rep(i, N-1) {
      cin >> x >> y;
      x--;
      y--;
      G[x].push_back(y);
      G[y].push_back(x);
    }
  }

  void set_postorder() {
    stack<pair<int, int> > st;
    st.push({0, -1});
    while(!st.empty()) {
      auto pr = st.top();
      int u = pr.first;
      int parent = pr.second;
      if(next_visit[u] >= G[u].size()) {
        postorder.push_back(make_pair(u, parent));
        st.pop();
      } else {
        while(next_visit[u] < G[u].size()) {
          int v = G[u][next_visit[u]];
          next_visit[u]++;
          if(v != parent) {
            st.push({v, u});
            break;
          }
        }
      }
    }
  }

  void solve() {
    set_postorder();
    for(const auto& v : postorder) {
      int s = v.first;
      int p = v.second;
      dp[0][0][s] = 1;
      dp[0][1][s] = 1;
      dp[1][0][s] = 1;
      dp[1][1][s] = 0;
      for(const int& t : G[s]) if(t != p) {
        dp[0][0][s] = dp[0][0][s] * ((dp[0][0][t] + dp[0][1][t]) % MOD_1_000_000_007) % MOD_1_000_000_007;
        dp[0][1][s] = dp[0][1][s] * ((dp[1][0][t] + dp[1][1][t]) % MOD_1_000_000_007) % MOD_1_000_000_007;
        dp[1][0][s] = dp[1][0][s] * ((dp[0][0][t] + dp[0][1][t]) % MOD_1_000_000_007) % MOD_1_000_000_007;
      }
    }
    cout << (dp[0][0][0] + dp[0][1][0]) % MOD_1_000_000_007 << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 11300
/*
 * Author: madlogic
 * It's better to do something than nothing
*/
#include <bits/stdc++.h>
using namespace std;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
// #define int long long
const int INF = 1000000000;
const int MOD = 1000000007;
const double PI = 2*acos(0.0);
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int res = 0;
	for(int i=0;i<n-1;i++)
	{
		if(i==a[i]-1)
		{
			++res;
			swap(a[i],a[i+1]);
		}
	}
	if(a[n-1]-1==n-1)
		++res,swap(a[n-1],a[n-2]);
	cout<<res<<endl;
	return 0;	
}

Measured memory_bytes: 640
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break

    for i in range(h):
        for j in range(w):
            if (i==0 or i==h-1)or(j==0 or j==w-1):
                print("#",end="")
            else :
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin >> s >> t;
	cout << t << s << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int h=0,x;
string s;
int a[2000002];
void add(int i){
	 int t;
	 while (i!=0){
	 	   if (a[i/2]<a[i] && i/2!=0){
	 	       t=a[i]; a[i]=a[i/2]; a[i/2]=t;	
		   }
		   else
		      break;
		   i/=2;
	 }
}
void maxheap(int i){
	 int l=2*i,t,m=i;
	 if (a[l]>a[i] && l<=h)
	    m=l;
	 if (a[l+1]>a[m] && (l+1)<=h)
        m=l+1;
     if (m!=i){
     	t=a[i]; a[i]=a[m]; a[m]=t;
	    maxheap(m);
	 }
}
int main(){
	while (s!="end"){
		  cin>>s;
		  if (s[0]=='i'){
		  	 cin>>a[++h];
		  	 add(h);
		  }
		  if (s[1]=='x'){
		  	 cout<<a[1]<<endl;
		  	 a[1]=a[h];
		  	 h--;
		  	 maxheap(1);
		  }
	}
    return 0;
}



Measured memory_bytes: 7056